Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

parser.mly 846 Bytes
Newer Older
Frédéric Bour's avatar
Frédéric Bour committed
1 2
%location<MyLocation>

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
%token <int> INT
%token PLUS MINUS TIMES DIV
%token LPAREN RPAREN
%token EOL

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

%start <int> main

%%

main:
| e = expr EOL
    { e }

expr:
| i = INT
Frédéric Bour's avatar
Frédéric Bour committed
22
    { prerr_endline (MyLocation.trace $loc);i }
23
| LPAREN e = expr RPAREN
Frédéric Bour's avatar
Frédéric Bour committed
24
    { prerr_endline (MyLocation.trace $loc);e }
25
| e1 = expr PLUS e2 = expr
Frédéric Bour's avatar
Frédéric Bour committed
26
    { prerr_endline (MyLocation.trace $loc); e1 + e2 }
27
| e1 = expr MINUS e2 = expr
Frédéric Bour's avatar
Frédéric Bour committed
28
    { prerr_endline (MyLocation.trace $loc);e1 - e2 }
29
| e1 = expr TIMES e2 = expr
Frédéric Bour's avatar
Frédéric Bour committed
30
    { prerr_endline (MyLocation.trace $loc);e1 * e2 }
31
| e1 = expr DIV e2 = expr
Frédéric Bour's avatar
Frédéric Bour committed
32
    { prerr_endline (MyLocation.trace $loc);e1 / e2 }
33
| MINUS e = expr %prec UMINUS
Frédéric Bour's avatar
Frédéric Bour committed
34
    { prerr_endline (MyLocation.trace $loc);- e }
35