Parser Animation
e.g. Byacc grammar to input simple infix expressions (without using a Flex):
%%
line : exp '=' '\n'
;
exp : term | exp '+' term | exp '-' term
;
term : factor | term '*' factor | term '/' factor
;
factor : number | '(' exp ')'
;
number : digit | number digit
;
digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
;
given the input line:
1+2=
Roskind's modification to Byacc produces the following:
.... look ahead at '1' `1'
'1' <-- `1'
digit
number
| .... look ahead at '+' `+'
factor
term
exp
| '+' <-- `+'
| | .... look ahead at '2' `2'
| | '2' <-- `2'
| | digit
| | number
| | | .... look ahead at '=' `='
| | factor
| | term
+-------+-------+
|
exp
| '=' <-- `='
| | .... look ahead at '\n' `
'
| | '\n' <-- `
'
+-------+-------+
|
line
| .... look ahead at end-of-file `'