From 3fd6858fb803d84eb9fd103c4ccb74a9ad5cd386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 4 Sep 2018 17:03:54 +0200 Subject: [PATCH] Macroprocessor: fix priority of operators - == and != have now lower priority than <= < >= >, for consistency with the Dynare modelling language (and incidentally C and C++, but not Julia). - ^ has now higher priority and no associativity, for consistency with the Dynare modelling language (and usual arithmetic notation). - & has now higher priority than |, and both have lower priority than + and -, but higher than inequality comparators. This is not the same as C and C++ (in which & and | are just above && and ||), but this allows for expressions such as "a|b == c" to have their most natural semantics (i.e. this will compare the union of a and b with c; the C/C++ priority level would have resulted in a type error). Ref #5. --- src/macro/MacroBison.yy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/macro/MacroBison.yy b/src/macro/MacroBison.yy index 14f62226..c91cfc29 100644 --- a/src/macro/MacroBison.yy +++ b/src/macro/MacroBison.yy @@ -74,12 +74,16 @@ class MacroDriver; %left LOGICAL_OR %left LOGICAL_AND -%left LESS GREATER LESS_EQUAL GREATER_EQUAL EQUAL_EQUAL EXCLAMATION_EQUAL +%left EQUAL_EQUAL EXCLAMATION_EQUAL +%left LESS GREATER LESS_EQUAL GREATER_EQUAL %nonassoc IN %nonassoc COLON +%left UNION +%left INTERSECTION %left PLUS MINUS -%left TIMES DIVIDE UNION INTERSECTION POWER +%left TIMES DIVIDE %precedence UMINUS UPLUS EXCLAMATION +%nonassoc POWER %precedence LBRACKET %type > comma_name