[antlr-interest] 3.1b1 trouble with a CSharp2/AST example

Hamilton Link helink at sandia.gov
Fri May 23 14:29:00 PDT 2008


Link, Hamilton wrote:
>
> > java -cp 
> ".;./antlr-3.1b1/lib/antlr-3.1b1.jar;./antlr-3.1b1/lib/stringtemplate-3.1.jar;./antlr-3.1b1/lib/antlr-runtime-3.1b1.jar;./antlr-3.1b1/lib/antlr-2.7.7.jar;./antlr-3.1b1/lib/gunit-1.0.2.jar" 
> Program
>
> It printed
>
> (+ (* 2 x) (* 3 (^ x 5)))
>
> as desired, so obviously it's building the AST properly (and it's 
> getting farther than the C# version by merit of not throwing an error 
> during parsing).
>
>  
>
> So the Java target and Java runtime seem to be OK and C# target 
> generation is a likely suspect.  I will do a side-by-side comparison 
> between the FooParser.java and FooParser.cs and see what I can turn 
> up.  _If_ I can identify a possible bug I will report it and also see 
> if I can decipher what Johannes was suggesting re: fixing and rebuilding.
>
>  
>
> h
>

The C# parser code dies calling NextNode() on stream_INT.

stream_INT is a RewriteRuleTokenStream and I don't have the code for 
that to the best of my knowledge, it's in the runtime.  It's throwing a 
RewriteEmptyStreamException when calling stream_INT.NextNode().

In both the Java and the C# the Parser code looks equivalent to me, and 
without the code to RewriteRuleTokenStream I can't begin to determine 
when it would throw this exception.

The operations performed on this object are as follows...
- It's allocated (new RewriteRuleTokenStream(adaptor, "token INT");)
- IToken INT4 is set to (IToken)Match({2x+3x^5}, INT=5, 
FOLLOW_INT_in_term61={6}), but INT4 comes back null (could this be the 
problem or is this the right answer?)
- stream_INT.Add(INT4) is called, passing in null.
- stream_INT now has Description="token INT", cursor=0, dirty=false, 
elements=null and singleElement=null, and adaptor=CommonTreeAdaptor
- stream_INT.NextNode() gets called and throws an error at this point.

Comments?  Am I supposed to have code for the runtime classes?  'cause I 
don't know that I have that and this will be about as far as I can go if so.

thanks,
hamilton





More information about the antlr-interest mailing list