| Related articles |
|---|
| [3 earlier articles] |
| Re: Grammar with low-precedence postfix operator? rljacobson@gmail.com (Robert Jacobson) (2015-02-07) |
| Re: Grammar with low-precedence postfix operator? monnier@iro.umontreal.ca (Stefan Monnier) (2015-02-08) |
| Re: Grammar with low-precedence postfix operator? kaz@kylheku.com (Kaz Kylheku) (2015-02-09) |
| Re: Grammar with low-precedence postfix operator? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2015-02-09) |
| Re: Grammar with low-precedence postfix operator? jgk@panix.com (2015-02-10) |
| Re: Grammar with low-precedence postfix operator? kaz@kylheku.com (Kaz Kylheku) (2015-02-11) |
| Re: Grammar with low-precedence postfix operator? rljacobson@gmail.com (Robert Jacobson) (2015-02-21) |
| From: | Robert Jacobson <rljacobson@gmail.com> |
| Newsgroups: | comp.compilers |
| Date: | Sat, 21 Feb 2015 12:55:52 -0800 (PST) |
| Organization: | Compilers Central |
| References: | 15-02-006 |
| Keywords: | parse |
| Posted-Date: | 21 Feb 2015 22:37:28 EST |
Thank you everyone for your help. The solution I found for solving my language
ambiguity uses ANTLR's semantic predicates feature which can turn off
production alternatives at parse time. I use a predicate (below) to suppress
implicit multiplication in the presence of a binary plus operator.
expr
: LEAF
| LPAREN expr RPAREN //parentheses
| <assoc=right> expr POWER expr
| (PLUS | MINUS) expr //unary plus/minus
| expr { _input.LT(1).getType() != PLUS && _input.LT(1).getType() != MINUS}?
expr //implicit multiplication
| expr (DIV | MUL) expr //division and explicit multiplication
| expr (PLUS | MINUS) expr //addition/subtraction
| expr '&' //postfix parenthesization.
;
Best regards,
Robert
Return to the
comp.compilers page.
Search the
comp.compilers archives again.