[antlr-interest] THE STEAMROLLER PROBLEM!

Loring Craymer lgcraymer at yahoo.com
Thu Oct 2 19:10:31 PDT 2008


This one is easy with the ^ annotation:

opRule
        :
        term
        (
               OP^
               term
               (
                          OP!
                          term
               )*
         )?
         ;

--Loring




----- Original Message ----
> From: Randall R Schulz <rschulz at sonic.net>
> To: antlr-interest at antlr.org
> Sent: Thursday, October 2, 2008 6:43:44 PM
> Subject: [antlr-interest] THE STEAMROLLER PROBLEM!
> 
> Hi,
> 
> Sorry for shouting, but I really would like a definitive answer to this
> question. ("Steamroller" referring to creating a flat AST.)
> 
> If one is to parse an infix operator notation, exemplified by this
> input:
> 
>     1 OP 2 OP 3 OP 4 OP 5
> 
> and produce from it this AST:
> 
>     (OP 1 2 3 4 5)
> 
> How, if it is indeed possible, would one do this?
> 
> It seems simple enough, but so far, no suggestion offered nor idea of my
> own has succeeded in producing anything other than one of these results:
> 
> Result 1:
>     (OP 1 (OP 2 (OP 3 (OP 4 5))))
> 
> Result 2:
>     (OP (OP (OP (OP 1 2) 3) 4) 5))))
> 
> Result 3:
> 
> Exception in thread "main" org.antlr.runtime.tree.RewriteEmptyStreamException: 
> token OP
> 
> 
> Any definitive answers out there? Terence??
> 
> Thanks.
> 
> 
> Randall Schulz
> 
> 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