parser-menhir.mly 1 KB
Newer Older
1
2
3
4
%token <int> INT
%token PLUS MINUS TIMES DIV
%token LPAREN RPAREN
%token EOL
5
%token DOT COMMA
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

%left PLUS MINUS        /* lowest precedence */
%left TIMES DIV         /* medium precedence */
%nonassoc UMINUS        /* highest precedence */

%start<unit> main

%%

main:
| nothing expr EOL
    {}

/* Added just to exercise productions with an empty right-hand side. */
nothing:
| /* nothing */
    { Aux.print "nothing" $startpos $endpos }

/* Added just to exercise productions with an empty right-hand side, in a choice. */
optional_dot:
| nothing
| DOT
    { Aux.print "optional_dot" $startpos $endpos}

30
31
32
33
34
35
36
37
38
optional_comma:
| nothing
| COMMA
    { Aux.print "optional_comma" $startpos $endpos}

annotations:
  optional_dot optional_comma
    { Aux.print "annotations" $startpos $endpos }

39
40
41
42
43
%inline operator:
  PLUS | MINUS | TIMES | DIV {}

raw_expr:
| INT
44
| annotations LPAREN nothing expr RPAREN optional_dot
POTTIER Francois's avatar
POTTIER Francois committed
45
| expr operator expr
46
47
48
49
50
51
52
| MINUS expr %prec UMINUS
    {}

expr:
  raw_expr
    { Aux.print "expr" $startpos $endpos }