[antlr-interest] Tree Evaluation with Logical Operators (AND and OR)

Oliver Zeigermann oliver.zeigermann at gmail.com
Thu Jan 22 04:29:34 PST 2009


OK, so you need a tree grammar that can parse complex boolean
expressions, right?

expression
  : ^((AND|OR) expression expression)
  | ^(('<'|'>'|'='|'!=') expression expression)
  | ^(('+'|'-'|'*'|'/') expression expression)
  | ID
  | literal
  ;

Would that work?

-Oliver

2009/1/22 Priolo, Scott <spriolo at walkerinfo.com>:
> Sorry about that, I'm trying to setup a walker that will know what to do
> with "OR" and "AND" operators.  I have the parser setup so that the AST is
> nicely formed with expr such as (< a 3).  I'm able to walk and evaluate
> these simple expr too. But! when I walk (or (and (< a 3) (< b 3)) (< c 3))
> I'm stumped.
>
> This must have been solved before and I would guess that there is probably a
> design pattern for walking boolean AST.
>
> Thanks,
> Scott
>
> -----Original Message-----
> From: Oliver Zeigermann [mailto:oliver.zeigermann at gmail.com]
> Sent: Thu 1/22/2009 4:19 AM
> To: Priolo, Scott
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Tree Evaluation with Logical Operators (AND
> and OR)
>
> Hi!
>
> Not quite sure what your problem is. Are you asking how an AST for a
> logical expression might look like? Or the grammar that creates it? Or
> the tree grammar that walks it? Or something else?
>
> -Oliver
>
>
> 2009/1/22 Priolo, Scott <spriolo at walkerinfo.com>:
>> Hello,
>>
>>
>>
>> I've searched high and low and can't find a reference to describe the
>> Logical Operators (and, or) design pattern for Tree Evaluation (after
>> purchasing the book I came up empty handed too).
>>
>>
>>
>> Any help?
>>
>>
>>
>> Thanks.
>>
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>>
>
>


More information about the antlr-interest mailing list