-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add menhir support * Add menhir support * Fixed bug with Menhir --------- Co-authored-by: XAMPPRocky <[email protected]> Co-authored-by: Basile Pesin <[email protected]>
- Loading branch information
1 parent
913df07
commit 099092f
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 47 lines 31 code 7 comments 9 blanks | ||
|
||
(* Example from the menhir development with instrumented comments. | ||
* (* Note: nested C style comments are not allowed. *) | ||
* https://gitlab.inria.fr/fpottier/menhir/-/tree/master/demos/calc-alias *) | ||
|
||
%token<int> INT "42" | ||
%token PLUS "+" | ||
%token MINUS "-" | ||
%token TIMES "*" | ||
%token DIV "/" | ||
%token LPAREN "(" | ||
%token RPAREN ")" | ||
%token EOL | ||
|
||
(* Token aliases can be used throughout the rest of the grammar. E.g., | ||
they can be used in precedence declarations: *) | ||
|
||
%left "+" "-" /* lowest " precedence */ | ||
%left "*" "/" /* medium precedence */ | ||
%nonassoc UMINUS // highest "precedence" | ||
%start <int> main | ||
%% | ||
main: | ||
| e = expr EOL | ||
{ e } | ||
(* Token aliases can also be used inside rules: *) | ||
expr: | ||
| i = "42" | ||
{ i } | ||
| "(" e = expr ")" | ||
{ e } | ||
| e1 = expr "+" e2 = expr | ||
{ e1 + e2 } | ||
| e1 = expr "-" e2 = expr | ||
{ e1 - e2 } | ||
| e1 = expr "*" e2 = expr | ||
{ e1 * e2 } | ||
| e1 = expr "/" e2 = expr | ||
{ e1 / e2 } | ||
| "-" e = expr %prec UMINUS | ||
{ - e } |