[antlr-interest] THE STEAMROLLER PROBLEM!

John B. Brodie jbb at acm.org
Thu Oct 2 19:28:34 PDT 2008


On Thursday 02 October 2008 09:43:44 pm Randall R Schulz wrote:
> 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

Solution attached.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.g
Type: text/x-java
Size: 1171 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081002/9c10ab8d/attachment.bin 


More information about the antlr-interest mailing list