[antlr-interest] C# tree parser memoize issue?

Sam Harwell sharwell at pixelminegames.com
Sat Mar 19 14:57:21 PDT 2011


Hi David,

Is there any way you can send me the full grammar you're using (you could
send it to just me if you don't want to send it to the public list)? I don't
use memoization in any of my grammars, so I don't have a way to test this
feature extensively.

Thanks,
Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of David Daeschler
Sent: Thursday, March 03, 2011 1:45 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] C# tree parser memoize issue?

I have a grammar that contains a 3d vector type.

Parsing the grammar for my test case yields the following AST:
http://graph.gafol.net/dZxqGkwww

<http://graph.gafol.net/dZxqGkwww>During the code generation step I am using
a tree grammar with backtracking and memoization turned on.

With memoization the following generates an error:

float f;
vector v = <1.0,1.0,1.0> * <f,f,f>;
^Z
Gen.g: node from line 2:28 mismatched tree node: f expecting FLOAT_LITERAL

Turning off memoization fixes the issue.

The grammar fragments involved are (trying to cut down as much as I can):

expression
@init {MyAst t = (MyAst )input.LT(1);}
@after { $expression.st = DoPromotion(t, $expression.st); }
: ^(EXPR expr) -> {$expr.st}
;

expr
: multiplicativeExpression-> {$multiplicativeExpression.st} ;

multiplicativeExpression
: mult -> {$mult.st}
| primary -> {$primary.st}
;

mult
: ^(op='*' l=multiplicativeExpression r=multiplicativeExpression)
->
mul(subtemplate={TemplateMapping.Multiplication[$l.start.evalType.TypeIndex,
$r.start.evalType.TypeIndex]}, lexpr={$l.st}, rexpr={$r.st}) ; primary @init
{MyAst t = (MyAst)input.LT(1);} @after { $primary.st = DoPromotion(t,
$primary.st); }
| vecConst -> {$vecConst.st}
| vecLiteral -> {$vecLiteral.st}
| expression -> {$expression.st}
;

vecConst
: ^(VECTOR_LITERAL x=FLOAT_LITERAL y=FLOAT_LITERAL z=FLOAT_LITERAL) ->
vconst(x={$x.text}, y={$y.text}, z={$z.text}) ;

vecLiteral
: ^(VECTOR_LITERAL x=expr y=expr z=expr) -> buildvec(x={$x.st}, y={$y.st},
z={$z.st}) ;

Sorry for the verbosity of this post, and thank you ahead of time for any
help.
--
David Daeschler

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