Hi Maik,

I'll be fixing this issue for the next release of the C# target. In the
meantime, you can make the follow 3 changes to the CSharp3 templates and
things will work for you.

1. Add the following rule CSharp3.stg:

ruleListLabelType() ::= "<ASTLabelType>"

2. Add the following rule to ST.stg:

ruleListLabelType() ::= "StringTemplate"

3. In CSharp3.stg, find the ruleLabelDefs rule. Change the reference from
<ASTLabelType> to <ruleListLabelType()>.

Sam

-----Original Message-----
From: antlr-interest-boun...@antlr.org
[mailto:antlr-interest-boun...@antlr.org] On Behalf Of Maik Schmidt
Sent: Thursday, August 25, 2011 10:15 AM
To: antlr-interest@antlr.org
Subject: [antlr-interest] Problems with Tree Grammars outputting Templates
in C#

Hi!

I am working through the "Language Implementation Patterns" book and I am
translating all examples to C#. Unfortunately, I cannot get StringTemplate
output to work.

Attached you'll find a grammar named Cymbol.g3 and a tree parser named
Gen.g3. I have downloaded them from the publisher's web site and only had to
change a few minor thing to make them compliant with C#.

VisualStudio 2010 turns the g3 files into grammars and lexers nicely, but
unfortunately I cannot compile them. The problem seems to appear whenever an
expression such as "d+=" is used as in the following rule:

compilationUnit:   ( d+=classDeclaration | d+=methodDeclaration |
d+=varDeclaration )+ -> file(defs={$d})

For such rules I get errors like the following:

Error 6 Argument 1: cannot convert from 'Antlr3.ST.StringTemplate' to
'Antlr.Runtime.Tree.CommonTree' c:\users\mschmidt2\documents\visual studio
2010\Projects\StringTemplateTest\StringTemplateTest\obj\x86\Debug\Gen.cs

The corresponding code snippet looks as follows:

case 1:
DebugEnterAlt(1);
// Gen.g3:13:11: d+= classDeclaration
{
DebugLocation(13, 12);
PushFollow(Follow._classDeclaration_in_compilationUnit74);
d=classDeclaration();
PopFollow();
if (state.failed) return retval;
if (list_d==null) list_d=new List<StringTemplate>(); list_d.Add(d.Template);

The problem seems to be the initial definition of list_d which is

List<CommonTree> list_d = null;

What am I doing wrong?

Cheers,
Maik


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to