[antlr-interest] internal error

Olivier Lefevre lefevrol at yahoo.com
Fri Feb 1 12:54:11 PST 2008


Hi Mark,

Thanks for the advice. I was pilfering the JSON grammar but
my mental map of ANTLR is still very imperfect. Doesn't
ANTLR still have a bug, though? It should *never* blow up.

>> list : '['! (elements)? ']'! -> ^(ARRAY elements) ;
> 
> You are using AST operators (in this case !) and a tree construction
> rewrite rule in the same rule alternative. I thought that wasn't
> allowed.

OK, that makes sense.

> I think you want this: 
> list: '[' elements? ']' -> ^(ARRAY elements?);

I am unclear as to what the '?' will do in a tree rewrite rule.

> or maybe
> list: '[' elements ']' -> ^(ARRAY elements);

Intuitively that makes more sense to me.

> Should this be change to the following?
> item: INT -> ^(ITEM INT);

Actually I think one can dispense with the ITEM token entirely and
have items hang directly from the ARRAY token in this case since
they are atomic.

>> WS: (' '|'\t'|'\n'|'\r')+ {skip();} ;
> 
> If you want to use newlines as statement terminators then you can't
> skip the characters that make them up.

Expr.g in § 3.3 of the book does just that, though. Isn't that what
the NEWLINE as a stat option is for?

The attached grammar works fine but only for a single line of input.
With more lines it puts:

Exception in thread "main" 
org.antlr.runtime.tree.RewriteEmptyStreamException: rule elements
         at 
org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:158)
         at 
org.antlr.runtime.tree.RewriteRuleElementStream.next(RewriteRuleElementStream.java:145)
         at ListExprParser.list(ListExprParser.java:307)
         at ListExprParser.stat(ListExprParser.java:158)
         at ListExprParser.prog(ListExprParser.java:78)
         at Test_ListExpr.main(Test_ListExpr.java:12)

which is really unhelpful. It looks like ANTLR is blowing up again.

Regards,

-- O.L.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ListExpr.g
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20080201/169d12ed/attachment.pl 


More information about the antlr-interest mailing list