Syntax Analysis Flashcards

1
Q

How is a CFG defined?

A

N: a set of non-terminals
T: a set of terminals
P: a set of production rules
S: a start non-terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why are ambiguous grammars problematic?

A

Different parse trees may have different meaning - may not know which one to select.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are PDAs?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two different kinds of parsers?

A

Top-Down (Recursive Descent): Construct parse tree from root - LEFTMOST.

Bottom-Up: Construct parse tree from leaves - RIGHTMOST.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some issues with LL(k) parsers?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do LR(k) parsers work?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly