diff options
Diffstat (limited to 'demos/sample-files/gram.g')
| -rw-r--r-- | demos/sample-files/gram.g | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/demos/sample-files/gram.g b/demos/sample-files/gram.g new file mode 100644 index 0000000..f9daded --- /dev/null +++ b/demos/sample-files/gram.g @@ -0,0 +1,42 @@ +-terminal + TERMINAL NONTERM LEFT RIGHT COLON NOPREC + PIPE SEMICOL DOT + IDEN NUM ACTION; +-nonterminal + S A B C + Type Prec Prod Preclist Prodlist + Actionlist Idenlist IorNlist. + +-noprec. + +S: A B C {}; + +A: TERMINAL Idenlist SEMICOL NONTERM Idenlist DOT { handle_type(A(1), A(4)) }; + + +B: Preclist { handle_prec(A(0)); } + | NOPREC DOT { handle_prec(NULL); }; + +Preclist: Prec SEMICOL Preclist { v = list_new_head(A(2), A(0)); } + | Prec DOT { v = A(0); }; + +Prec: LEFT IorNlist { v = prec_new(A(1), PRECEDENCE_LEFT_ASSOC); } + | RIGHT IorNlist { v = prec_new(A(1), PRECEDENCE_RIGHT_ASSOC); }; + + +C: Prodlist { handle_prod(A(0)); }; + +Prodlist: Prod SEMICOL Prodlist { v = list_new_head(A(2), A(0)); } + | Prod DOT { v = A(0); }; + +Prod: IDEN COLON Actionlist { v = prod_new(A(0), A(2)); }; + +Actionlist: Idenlist ACTION PIPE Actionlist { v = list_new_head(A(3), action_new(A(0), A(1))); } + | Idenlist ACTION { v = action_new(A(0), A(1)); }; + +Idenlist: IDEN Idenlist { v = list_new_head(A(1), ptr_new(A(0))); } + | IDEN { v = ptr_new(A(0)); }; +IorNlist: IDEN IorNlist { v = list_new_head(A(1), ptr_new(A(0))); } + | IDEN { v = ptr_new(A(0)); } + | NUM IorNlist { v = list_new_head(A(1), num_new(A(0))); } + | NUM { v = num_new(A(0)); }. |
