On 2/15/2010 10:22 AM, Nazim Oztahtaci wrote:
> Hello,
>
> I have written a grammar based on an example on the Net to parse an 
> expression like (a OR B)AND(C OR D) to a tree like
>       AND
> OR       OR
> A B       C D
> It works fine but if expression has more then 2 children, like (A OR B OR 
> C)AND(D OR E OR F)
> Then it creates problem because it does something like
> AND
>
> D     OR
>         E    F
> I want it to be like
>
> OR
> D  E  F
>
> In other words, a tree node might have capability to have more then 2 nodes 
> as children. How can I set this? I work on C# but couldnt find any setter 
> function in library.
> Best regards,
> Nazim
>                                       
>    
I am not sure if this is too simple for your needs but this allows a 
more generic tree structure for your example.

grammar test;
options
{
   output = AST;
}
expr : andexpr EOF;
andexpr : orexpr (AND orexpr)+ -> ^(AND orexpr+);
orexpr : WORD (OR WORD)+ -> ^(OR WORD+)
     | LPAREN! orexpr RPAREN!;

LPAREN : '(' ;
RPAREN : ')' ;
AND : 'AND';
OR : 'OR';
WS :  ( ' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;}  ;
WORD :  (~( ' ' | '\t' | '\r' | '\n' | '(' | ')' ))*;


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to