[antlr-interest] internal error

Olivier Lefevre lefevrol at yahoo.com
Fri Feb 1 13:41:38 PST 2008


Thanks again very much for the explanations.

> The cardinality of a rewrite rule element must match the cardinality of 
> the actual element.  In the case above, you're telling the rewrite 
> engine that "elements" might not have any value, so it needs to insert a 
> test to check for that before inserting it into the tree.  Had you left 
> the ? out, it treats it as an assertion that "elements" always has 
> exactly one value and thus won't include the test (for performance 
> reasons), which will lead to a runtime exception if it turns out that it 
> wasn't actually supplied.

Wonderful! As you pointed out farther down, that was the reason for the
RewriteEmptyStreamException I posted earlier, not the presence of multiple 
lines in the input (there was a "[]" in my inputs).

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

I have attached it. You don't need the book to get it, as all the
code from the book is available somewhere on the ANTLR site as a
zip file.

> In particular, if you have both a NEWLINE and a WS rule

But I need a WS because I want to allow superfluous spaces anywhere,
e.g. not just [1,2], [1, 2], [ 1 , 2 ] etc etc without encumbering
the array rule with ( *) and such.

> It's not that unhelpful 

OK, maybe with experience one can decode it but do all runtime
problems lead to blowups? Why doesn't it just say "Invalid input:
[] at line 3" or some such?

-- O.L.



More information about the antlr-interest mailing list