Quiz 9 Flashcards
(10 cards)
Which of the following is not typically the responsibility of lexical analysis in a compiler?
Identifying keywords, identifiers, and literals; Detecting syntax errors in the code; Removing whitespace and comments; Tokenizing input code into lexemes
Detecting syntax errors in the code
The parsing phase, also known as syntax analysis, is the process of breaking down source code into basic units called tokens, T/F?
False
Which of the following statements about parse trees and ASTs is false?
Both parse trees and ASTs are used in semantic analysis in compilers; ASTs provide a simplified, abstracted view of the source code structure, focusing on the essential syntax elements; Parse trees are generally deeper than ASTs because they include all grammar rule applications; Parse trees contain all tokens from the source code, whereas ASTs may omit certain tokens like punctuation
Both parse trees and ASTs are used in semantic analysis in compilers
Reserved words are identifiers that have special meaning in a programming language and cannot be used for variable names, T/F?
True
Which of the following is an example of the longest match principle?
Source: ==
Tokens: = and == are both valid tokens
The lexer throws an error due to ambiguity; The lexer matches a single == token; the lexer matches two == tokens; the lexer ignores both tokens
The lexer matches a single == token
Which of the following best describes the role of syntactic analysis in a compiler?
Optimizing the code for better performance; Breaking down the code into tokens for easier processing; Translating high-level code to machine code; Checking that the program conforms to the language’s grammatical structure
Checking that the program conforms to the language’s grammatical structure
Which of the following context-free grammar G:
S -> aSb | e
Which of the following is not a valid sentence in G?
abab; aabb; aaabbb; ab
abab
In Backus-Naur Form (BNF), which of the following symbols is typically used to denote a non-terminal?
…
::=
<…>
|
<…>
Which of the following is typically represented as a leaf node in both a parse tree and an AST?
Grammar rules like <expression> or <term>; Identifiers and literals; Keywords like if and else; Operators like + and *</term></expression>
Identifiers and literals
Which of the following strings does not match with the regular expression (a|b)?[0-9]+c*
b52; a3cc; ac; 123
ac