Coccinelle release 1.0.0-rc13
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / demos / calc-two / algebraic.mly
diff --git a/bundles/menhirLib/menhir-20120123/demos/calc-two/algebraic.mly b/bundles/menhirLib/menhir-20120123/demos/calc-two/algebraic.mly
new file mode 100644 (file)
index 0000000..2493845
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************/
+/*                                                                        */
+/*  Menhir                                                                */
+/*                                                                        */
+/*  François Pottier, INRIA Rocquencourt                                  */
+/*  Yann Régis-Gianas, PPS, Université Paris Diderot                      */
+/*                                                                        */
+/*  Copyright 2005-2008 Institut National de Recherche en Informatique    */
+/*  et en Automatique. All rights reserved. This file is distributed      */
+/*  under the terms of the Q Public License version 1.0, with the change  */
+/*  described in file LICENSE.                                            */
+/*                                                                        */
+/**************************************************************************/
+
+(* This partial grammar specification defines the syntax of expressions
+   in algebraic notation. *)
+
+%left PLUS MINUS        /* lowest precedence */
+%left TIMES DIV         /* medium precedence */
+%nonassoc UMINUS        /* highest precedence */
+
+%%
+
+%public expr:
+| i = INT
+    { i }
+| LPAREN e = expr RPAREN
+    { e }
+| e1 = expr PLUS e2 = expr
+    { e1 + e2 }
+| e1 = expr MINUS e2 = expr
+    { e1 - e2 }
+| e1 = expr TIMES e2 = expr
+    { e1 * e2 }
+| e1 = expr DIV e2 = expr
+    { e1 / e2 }
+| MINUS e = expr %prec UMINUS
+    { - e }
+