Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 461 – Oct. 17 Creating parse machine On what input do we reduce?

Similar presentations


Presentation on theme: "CS 461 – Oct. 17 Creating parse machine On what input do we reduce?"— Presentation transcript:

1 CS 461 – Oct. 17 Creating parse machine On what input do we reduce?
Convert grammar into sets of items Determine goto and reduce actions On what input do we reduce? Whatever “follows” the nonterminal we’re reducing to. Declaration grammar

2 0n 1n+1 There are 5 states. When the cursor is at the end of the item, our transition is a reduce. Now, we are done finding states and transitions! One question remains, concerning the reduce transitions: On what input should we reduce? I0: S’   S 1 S   1 2 S   0S1 3 I1: S’  S  r I2: S  1  r I3: S  0  S1 4 I4: S  0S  1 5 I5: S  0S1  r

3 When to reduce If you are at the end of an item such as S  1 , there is no symbol after the  telling us what input to wait for. The next symbol should be whatever “follows” the variable we are reducing. In this case, what follows S. We need to look at the original grammar to find out. For example, if you were reducing A, and you saw a rule S  A1B, you would say that 1 follows A. Since S is start symbol, $ (end of input) follows S. For more info, see parser worksheet. New skill: for each grammar variable, what follows?

4 First( ) To calculate first(A), look at A’s rules.
If you see A  c…, add c to first(A) If you see A  B…, add first(B) to first(A). Note: don’t put $ in first( ).

5 Follow( ) What should be included in follow(A) ?
If A is start symbol, add $. If you see Q  …Ac…, add c. If you see Q  …AB…, add first(B). If you see Q  …A, add follow(Q). Note: don’t put ε in follow( ).


Download ppt "CS 461 – Oct. 17 Creating parse machine On what input do we reduce?"

Similar presentations


Ads by Google