Coccinelle release 1.0.0-rc13
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / demos / calc / parser.mly
1 /**************************************************************************/
2 /* */
3 /* Menhir */
4 /* */
5 /* François Pottier, INRIA Rocquencourt */
6 /* Yann Régis-Gianas, PPS, Université Paris Diderot */
7 /* */
8 /* Copyright 2005-2008 Institut National de Recherche en Informatique */
9 /* et en Automatique. All rights reserved. This file is distributed */
10 /* under the terms of the Q Public License version 1.0, with the change */
11 /* described in file LICENSE. */
12 /* */
13 /**************************************************************************/
14
15 %token <int> INT
16 %token PLUS MINUS TIMES DIV
17 %token LPAREN RPAREN
18 %token EOL
19
20 %left PLUS MINUS /* lowest precedence */
21 %left TIMES DIV /* medium precedence */
22 %nonassoc UMINUS /* highest precedence */
23
24 %start <int> main
25
26 %%
27
28 main:
29 | e = expr EOL
30 { e }
31
32 expr:
33 | i = INT
34 { i }
35 | LPAREN e = expr RPAREN
36 { e }
37 | e1 = expr PLUS e2 = expr
38 { e1 + e2 }
39 | e1 = expr MINUS e2 = expr
40 { e1 - e2 }
41 | e1 = expr TIMES e2 = expr
42 { e1 * e2 }
43 | e1 = expr DIV e2 = expr
44 { e1 / e2 }
45 | MINUS e = expr %prec UMINUS
46 { - e }
47