chapter 5 Flashcards

1
Q

…………….is the set of tokens that can occur first in sentences derived from g :
FIRST(g) = {t ∈ T | g =>* t d

A

FIRST

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

What does it mean if there is a collision in an LL(1) table?

A

A collision means two rules in the same cell.
This means the grammar is not LL(1).

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

Why can it be useful to add an end-of-file rule to some grammars?

A

To know where the input ends.

handle empty input and determine when to accept.

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

How can we decide if a grammar is LL(1) or not?

A

f the LL(1) table has no collisions, it is LL(1).

If there are conflicts, it is not LL(1).

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

………X can become empty (ε).

A

Nullable

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

………….First token that can appear in a string derived from X.

A

FIRST

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

………..Tokens that can come after X in any valid sentence.

A

FOLLOW

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

What is a fixed-point problem?

A

A problem where we want to find x = f(x).

We keep applying f until the value doesn’t change anymore.

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

Left Recursion:

A

Happens when a non-terminal refers to itself on the left side.

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

Common Prefix:

A

Two rules start with the same tokens.

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

A grammar that allows more than one parse tree.

A

Ambiguous Grammar

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

Why it’s not LL(1):

A

LL(1) must have only one entry per cell in the parsing table.

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

A grammar with a common prefix is not LL(1).

Might be LL(k), but not guaranteed.

A

done

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

No Conflict Meaning:

A

A grammar is LL(1) if the parsing table has no cell with more than one rule.

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

Nullable(g) is true if g can derive ε (empty string).

A

Nullable Definition:

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

Where ε Appears:

A

In the production: Y -> ε

17
Q

Push current token to stack, read next

18
Q

Replace RHS with LHS rule in stack

19
Q

Parsing is complete

20
Q

LR(1) Parsing:

A

Uses DFA to decide actions: shift, reduce, accept

21
Q

Shift-Reduce Conflict:

A

Parser can’t decide between shift and reduce

22
Q

Reduce-Reduce Conflict:

A

Parser can’t decide between two reduce rules

Example: A -> B | C, both can reduce at same time

23
Q

LR Parser Types:

A

LR(0): No lookahead

SLR: Uses FOLLOW to reduce

LALR(1): Merges similar states (used in practice)

LR(1): Full lookahead, large table

GLR: Parses all CFGs, handles ambiguity

24
Q

Fix Conflicts

A

Use operator precedence rules:

  • has higher priority than +

Left-associative → reduce first

Right-associative → shift first

25
LL vs LR Parsers: LL: Top-down, leftmost derivation LR: Bottom-up, rightmost derivation LR is more powerful (can handle left recursion)