important Flashcards
(16 cards)
What is an attribute grammar?
A grammar that adds attributes and equations to describe properties of AST nodes.
What is an intrinsic attribute?
An attribute set during AST creation, like token values or children.
What is a synthesized attribute?
An attribute computed from the node or its children, flows upward.
Add.val = left.val + right.val
→ If left = 3 and right = 5, then Add.val = 8
Flows up from children to parent.
What is an inherited attribute?
An attribute passed from parent to child, flows downward.
Add.type = int → passed to both children.
Int.expectedType = int
Flows down from parent to children.
What are the major compiler phases?
Lexical Analysis (Scanning) – breaks source code into tokens.
Syntactic Analysis (Parsing) – constructs a parse tree from tokens.
Semantic Analysis – checks for type errors, undeclared variables, etc.
Intermediate Code Generation – produces platform-independent code.
Optimization – improves code performance or size.
Target Code Generation – translates intermediate code into assembly/machine code.
true/false
Every LL(1) grammar must be unambiguous.
✅ True
If a production is Nullable, its FOLLOW set must be considered in the LL(1) table.
✅ True
A grammar with a collision in the LL(1) table is not LL(1).
✅ True
The FIRST set of a terminal is the terminal itself.
✅ True
Nullable(X) is true if X can derive ε (the empty string).
✅ True
The FOLLOW set of the start symbol includes the end-of-file symbol $.
✅ True
Fixed-point iteration can be used to compute Nullable, FIRST, and FOLLOW sets.
✅ True
If a nonterminal can derive a terminal directly, that terminal is in its FIRST set.
✅ True
LL(1) parsers use a single lookahead token to choose a production.
✅ True
Nullable values can be computed by recursive or iterative methods.
✅ True
true/false2
Nullable(e) is always true.
✅ True
If a nonterminal X has a production X → ε, then X is Nullable.
✅ True
FIRST(X) includes all terminals that X can derive at the beginning of some sentence.
✅ True
FOLLOW(X) includes terminals that can appear immediately after X in a derivation.
✅ True
The FOLLOW set helps handle Nullable productions in the LL(1) table.
✅ True
If a grammar has two productions with the same FIRST set, it is not LL(1).
✅ True
A grammar with left recursion cannot be parsed by an LL(1) parser.
✅ True
The LL(1) parsing table must have at most one entry per cell.
✅ True
Fixed-point iteration ensures that Nullable computation will terminate.
✅ True
The FIRST set is computed recursively and depends on Nullable.
✅ True
If a nonterminal’s production has a sequence of symbols, the FIRST of that sequence depends on the Nullable status of the symbols.
✅ True
FOLLOW(S) always includes $ if S is the start symbol.
✅ True
An LL(1) grammar allows predictive parsing without backtracking.
✅ True
The computation of FOLLOW uses both FIRST and Nullable.
✅ True
A Nullable production can cause multiple entries in the LL(1) table if FOLLOW is not handled.
✅ True
A terminal symbol cannot be Nullable.
✅ True
In fixed-point iteration, values only change from false to true for Nullable.
✅ True
The FIRST set of a sequence may include tokens from multiple nonterminals if they are Nullable.
✅ True
LL(1) parsing is a top-down parsing strategy.
✅ True
If a production is selected in multiple table cells, the grammar is not LL(1).
✅ True
what does shift mean?
Push token onto task and read next token
what does reduce mean?
Pop RHS , Push LHS , build part of tree
what is common prefix ?
when two productions of the same nonterminal start with the same symbols
what is left recursion?
When non-terminal calls itself at the beginning of production
what does it mean a grammar to be ambiguous
if a sentence in language derived by two or more different parse trees
what is nullable , first, follow
nullable: A nonterminal X is Nullable if it can derive the empty string
First: is the set of terminals that can appear first in any string derived from X.
Follow: is the set of terminals that can appear immediately after X in some derivation.
how we decide if grammar is LL(1) or not
If any cell has more than one production, the grammar is not LL(1)
What does collison mean in LL(1) table?
if both element are in the same cell