[antlr-interest] ASTLabelType C# Problem

Sam Harwell sharwell at pixelminegames.com
Mon Jul 11 06:55:36 PDT 2011


You should throw a NotImplementedException instead of returning null.

The rewrite exception indicates a mismatch between the matching and rewrite
portions of the rules in your grammar. Typically that particular message
appears when you have a rule written like one of the following:

Example 1:

foo : bar -> bar;
bar : x*;

In the above case, the rule "bar" won't create a tree if 0 instances of "x"
are matched. The rule "foo" should actually be written "foo : bar->bar?;" to
handle this.

Example 2:

foo : bar? -> bar;

In the above case "bar" might again be missing, so you should write "foo :
bar? -> bar?;".

Example 3:

foo : bar -> bar;
bar : x;
x : y!;

In the above case, the rule "x" doesn't return a tree because it explicitly
ignores the result of y. Since rule "bar" doesn't have a rewrite rule
associated with it, it implies "bar : x -> x?;" which works fine. The net
result in "foo" is similar to example 1 above. Another way to handle this is
simply remove the explicit rewrite from "foo" to make "foo : bar;"

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of DJB MASTER
Sent: Sunday, July 10, 2011 8:18 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] ASTLabelType C# Problem

Ok, Got all that, but now I'm getting a RewriteEmptyStreamException on this
line...

'adaptor.AddChild(root_1, stream_expression.NextTree());'. 

A soon as I fix something, something else goes wrong lol. BTW, i'm just
returning null from ErrorNode(..) for the moment, although I'm passing in
valid code to my parser so it shouldn't need any error nodes.

--
View this message in context:
http://antlr.1301665.n2.nabble.com/ASTLabelType-C-Problem-tp6567453p6569254.
html
Sent from the ANTLR mailing list archive at Nabble.com.

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