Created
January 19, 2016 02:54
-
-
Save objmagic/4556ce7d2b4759853960 to your computer and use it in GitHub Desktop.
calc transition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
State 0: | |
s' -> . s [ # ] | |
-- On LPAREN shift to state 1 | |
-- On ID shift to state 2 | |
-- On t shift to state 3 | |
-- On s shift to state 11 | |
-- On f shift to state 6 | |
-- On e shift to state 12 | |
State 1: | |
f -> LPAREN . e RPAREN [ RPAREN MUL EOF ADD ] | |
-- On LPAREN shift to state 1 | |
-- On ID shift to state 2 | |
-- On t shift to state 3 | |
-- On f shift to state 6 | |
-- On e shift to state 7 | |
State 2: | |
f -> ID . [ RPAREN MUL EOF ADD ] | |
-- On RPAREN reduce production f -> ID | |
-- On MUL reduce production f -> ID | |
-- On EOF reduce production f -> ID | |
-- On ADD reduce production f -> ID | |
State 3: | |
e -> t . [ RPAREN EOF ADD ] | |
t -> t . MUL f [ RPAREN MUL EOF ADD ] | |
-- On MUL shift to state 4 | |
-- On RPAREN reduce production e -> t | |
-- On EOF reduce production e -> t | |
-- On ADD reduce production e -> t | |
State 4: | |
t -> t MUL . f [ RPAREN MUL EOF ADD ] | |
-- On LPAREN shift to state 1 | |
-- On ID shift to state 2 | |
-- On f shift to state 5 | |
State 5: | |
t -> t MUL f . [ RPAREN MUL EOF ADD ] | |
-- On RPAREN reduce production t -> t MUL f | |
-- On MUL reduce production t -> t MUL f | |
-- On EOF reduce production t -> t MUL f | |
-- On ADD reduce production t -> t MUL f | |
State 6: | |
t -> f . [ RPAREN MUL EOF ADD ] | |
-- On RPAREN reduce production t -> f | |
-- On MUL reduce production t -> f | |
-- On EOF reduce production t -> f | |
-- On ADD reduce production t -> f | |
State 7: | |
e -> e . ADD t [ RPAREN ADD ] | |
f -> LPAREN e . RPAREN [ RPAREN MUL EOF ADD ] | |
-- On RPAREN shift to state 8 | |
-- On ADD shift to state 9 | |
State 8: | |
f -> LPAREN e RPAREN . [ RPAREN MUL EOF ADD ] | |
-- On RPAREN reduce production f -> LPAREN e RPAREN | |
-- On MUL reduce production f -> LPAREN e RPAREN | |
-- On EOF reduce production f -> LPAREN e RPAREN | |
-- On ADD reduce production f -> LPAREN e RPAREN | |
State 9: | |
e -> e ADD . t [ RPAREN EOF ADD ] | |
-- On LPAREN shift to state 1 | |
-- On ID shift to state 2 | |
-- On t shift to state 10 | |
-- On f shift to state 6 | |
State 10: | |
e -> e ADD t . [ RPAREN EOF ADD ] | |
t -> t . MUL f [ RPAREN MUL EOF ADD ] | |
-- On MUL shift to state 4 | |
-- On RPAREN reduce production e -> e ADD t | |
-- On EOF reduce production e -> e ADD t | |
-- On ADD reduce production e -> e ADD t | |
State 11: | |
s' -> s . [ # ] | |
-- On # accept s | |
State 12: | |
e -> e . ADD t [ EOF ADD ] | |
s -> e . EOF [ # ] | |
-- On EOF shift to state 13 | |
-- On ADD shift to state 9 | |
State 13: | |
s -> e EOF . [ # ] | |
-- On # reduce production s -> e EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%token EOF | |
%token ADD | |
%token MUL | |
%token LPAREN | |
%token RPAREN | |
%token<string> ID | |
%start <T.exp> s | |
%% | |
s: e EOF { $1 } | |
e: | |
| e ADD t { T.Add ($1, $3) } | |
| t { $1 } | |
t: | |
| t MUL f { T.Mul ($1, $3) } | |
| f { $1 } | |
f: | |
| LPAREN e RPAREN { $2 } | |
| ID { T.Id $1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment