[antlr-interest] Simple expression grammar

Jim Idle jimi at temporal-wave.com
Thu May 15 08:56:08 PDT 2008


On Thu, 2008-05-15 at 17:42 +0200, Maciej Bakalarz wrote:

> Hi again !
> 
> OK I have written my grammar for boolean expressions mentioned earlier 
> (like ( (a>=3 || b<=5)&& c>=4 )  ).
> 
> But my grammar accept also expressions like "abc def ght" and many other 
> strange constructions


I think it is only accepting that because you have used:

logical_or_expression+

Remove the + and it will only accept a single logical expression. this
code accepts  abc def ght as 3 separate logical_or_expressions.


> .
> 
> Do you have any clues how to change it to accept only boolean 
> expressions, -->nothing more<-- ....
> 
> This is grammar:
> 
> grammar GuardCondition;
> 
> options {
>      output=AST;
>      ASTLabelType=CommonTree;
> backtrack=true;
> memoize=true;
> }
> 
>     @rulecatch {
>         catch ( RecognitionException ex ) {
>             throw ex;
>         }
>     }
> 
> prog:
> 	logical_or_expression+
> 	;
> 


Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080515/438b46fa/attachment-0001.html 


More information about the antlr-interest mailing list