A line of the form state terminal reduce rule is read as:
"If the DFA is in state, and terminal is first in the unread input, reduce by rule number rule."
Here terminal represents the lookahead symbol that is sometimes needed to resolve shift-reduce or reduce-reduce conflicts. (There will be no conflicts in the LR(1) DFAs used on the assignment.)
A line of the form state1 symbol shift state2 is read as:
"If the DFA is in state1, shift symbol and transition to state2."
Shift actions exist for both terminals and nonterminals; the shift actions involving nonterminals are used in the process of reducing by a rule.
Note that there is no reduce action for rule 0 in the LR(1) DFA, even though you are required to output the rule corresponding to this final reduction in your parser. Rule 0 will always be the unique rule which has the start symbol on the LHS.
One or more tokens representing a single sequence to be parsed, with each pair of tokens separated by whitespace, including newlines.
Your parser must support inputs where tokens are separated by newlines. For example, the sample sequence BOF id - ( id ) - id EOF
in the file below could also be written as:
BOF
id - ( id ) - id
EOF
Or even:
BOF
id
-
(
id
)
-
id
EOF
6 BOF EOF id - ( ) 3 S expr term S 5 S BOF expr EOF expr term expr expr - term term id term ( expr ) 11 28 8 EOF reduce 2 9 - reduce 4 7 - shift 1 1 id shift 2 6 ( shift 3 6 term shift 4 10 EOF shift 5 2 - reduce 3 4 ) reduce 1 3 id shift 2 4 EOF reduce 1 2 ) reduce 3 0 BOF shift 6 8 - reduce 2 2 EOF reduce 3 3 expr shift 7 9 ) reduce 4 9 EOF reduce 4 4 - reduce 1 1 term shift 8 3 term shift 4 3 ( shift 3 10 - shift 1 6 id shift 2 8 ) reduce 2 1 ( shift 3 7 ) shift 9 6 expr shift 10 BOF id - ( id ) - id EOF