Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1534

Re: Grammar with low-precedence postfix operator?

From Robert Jacobson <rljacobson@gmail.com>
Newsgroups comp.compilers
Subject Re: Grammar with low-precedence postfix operator?
Date 2015-02-21 12:55 -0800
Organization Compilers Central
Message-ID <15-02-032@comp.compilers> (permalink)
References <15-02-006@comp.compilers>

Show all headers | View raw


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

Back to comp.compilers | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Grammar with low-precedence postfix operator? Robert Jacobson <rljacobson@gmail.com> - 2015-02-05 13:27 -0500
  Re: Grammar with low-precedence postfix operator? Kaz Kylheku <kaz@kylheku.com> - 2015-02-05 21:10 +0000
    Re: Grammar with low-precedence postfix operator? Robert Jacobson <rljacobson@gmail.com> - 2015-02-07 10:30 -0800
  Re: Grammar with low-precedence postfix operator? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-07 11:27 +0000
    Re: Grammar with low-precedence postfix operator? jgk@panix.com (Joe keane) - 2015-02-10 21:03 +0000
      Re: Grammar with low-precedence postfix operator? Kaz Kylheku <kaz@kylheku.com> - 2015-02-11 02:19 +0000
  Re: Grammar with low-precedence postfix operator? Stefan Monnier <monnier@iro.umontreal.ca> - 2015-02-08 12:34 -0500
    Re: Grammar with low-precedence postfix operator? Kaz Kylheku <kaz@kylheku.com> - 2015-02-09 01:24 +0000
      Re: Grammar with low-precedence postfix operator? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2015-02-09 08:05 +0100
  Re: Grammar with low-precedence postfix operator? Robert Jacobson <rljacobson@gmail.com> - 2015-02-21 12:55 -0800

csiph-web