Syntax Analysis Flashcards
How is a CFG defined?
N: a set of non-terminals
T: a set of terminals
P: a set of production rules
S: a start non-terminal
Why are ambiguous grammars problematic?
Different parse trees may have different meaning - may not know which one to select.
What are PDAs?
Pushdown automata.
A word is accepted once it is read and the stack is empty.
An instance description/ID is a triple (q, w, a) where:
q = current state
w = word to read
a = current stack.
What are the two different kinds of parsers?
Top-Down (Recursive Descent): Construct parse tree from root - LEFTMOST.
Bottom-Up: Construct parse tree from leaves - RIGHTMOST.
What are some issues with LL(k) parsers?
Must choose a derivation rule based on k tokens only.
Requires eliminating left recursions.
Some grammars are not LL(1) - 1 symbol being enough to decide which rule to apply.
How do LR(k) parsers work?
Initially:
- input string to parse: w$
- stack: $ (start symbol)
Algorithm:
- shift input symbols to stack
- reduce a string B of grammar symbols on top of the stack to the head of the appropriate production rule.
- repeat until stack has start symbol + input is empty, or error