diff options
| author | kartofen <kartofen.mail.0@protonmail.com> | 2025-08-26 01:17:10 +0300 |
|---|---|---|
| committer | kartofen <kartofen.mail.0@protonmail.com> | 2025-08-26 01:17:10 +0300 |
| commit | 46e786db9d1b48b8fbc3502e36f093b755f3e09f (patch) | |
| tree | 9e279216e68f3fe4b0849d1e07184fe674dc551f /demos/sample-files/gram.g | |
| parent | 1c83c514c8108fccfec9764da5e4563b98eb871b (diff) | |
grammar for the grammar and lexing and parsing of a new language lbp
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)); }. |
