precedence - operators vs identifiers

May 12, 2009 at 6:35 AM

I have a grammar where my boolean operators are eq, ne, le, lt, ge, gt rather than symbolic (eg in same order =, <>, <=, <, >=, >).

I am also using the IdentifierTerminal for my variable names.

When I set a precedence, it is ignored, and it looks like when the parser is comparing operator precedences and looking at the stack, it is seeing the previous operator as an identifier with precedence 0 rather than the operator it is.

For example - "a eq 7 or b ne 5" with:

            BinExpr.Rule = Expr + BinOp + Expr;
            BinOp.Rule = Symbol("+") | "**" | "*" | "/" | "-" | "eq" | "ne" | "lt" | "le" | "gt" | "ge" | "and" | "or";
            RegisterOperators(60, Associativity.Right, "**");
            RegisterOperators(50, "*", "/");
            RegisterOperators(40, "+", "-");
            RegisterOperators(30, "eq", "ne", "lt", "le", "gt", "ge");
            RegisterOperators(20, "and", "or");

comes out with the operators in the order specified. If I alter my grammar to make them symbolic, it all works fine and the tree is correct, but I am trying to parse a different DSL and need to have the "named" operators.

How can I get the operators to be identified as operators rather than as identifiers during precedence checking?

Coordinator
May 12, 2009 at 6:46 AM

which Irony version are you using? if it is Dec build from Downloads page, then no surprise - this was a known issue. Try with latest build from Source Code page, and look at SQL grammar, it has the same thing with precedence for identifier-like operators "AND", "OR". Try it with SQL sample sql_op_test.txt, which shows that precedence works correctly.

Roman

May 12, 2009 at 6:57 AM

Thanks! Perfect!