[antlr-interest] antlr 3.1 ast rewriting
Floris van Nee
floris.vannee at gmail.com
Thu Mar 12 03:02:45 PDT 2009
Hi Johannes,
I've attached the lexer/parser file. If you generate that first and then
generate the tree grammar, you'll get the error when compiling the generated
code.
Floris
On Thu, Mar 12, 2009 at 8:16 AM, Johannes Luber <jaluber at gmx.de> wrote:
> Floris van Nee schrieb:
> > Hello!
> >
> > I've got a question about rewriting an AST in a tree grammar, with C# as
> > target language. The code Antlr generates just won't compile when I set
> > the 'output=AST' in my tree grammar options.
> > It complains about lines like this:
> >
> > if ( _first_1==null ) _first_1 = qual.Tree;
> >
> > Error 2 Cannot implicitly convert type 'object' to
> > 'Antlr.Runtime.Tree.CommonTree'. An explicit conversion exists (are you
> > missing a cast?) C:\Users\floris\Documents\Visual Studio
> > 2008\Projects\Vnvd\Vnvd\vNVDCheckerPassTwo.cs 315 58 Vnvd
> >
> > Here _first_1 is of type CommonTree, and qual.Tree of type object. It
> > needs an explicit cast there, but when Antlr generates the code, it
> > doesn't add one. Is this something I did wrong in my grammar file, or is
> > this a bug?
> > I am using the latest version of Antlr (3.1.2).
> >
> > Thanks in advance,
> > Floris
>
> I need a full working grammar, which includes at least the .tokens-file.
> I haven't tested yet, if that is enough or if I do need also the parser
> and lexer. Full working means that I can generate the grammar on my
> system so I can look up where I seemingly missed the conversion.
>
> Johannes
> >
> > Here are the contents of my (simplified) grammar file:
> >
> > tree grammar vNVDCheckerPassTwo;
> >
> > options
> > {
> > ASTLabelType = CommonTree;
> > tokenVocab = vNVD;
> > language = CSharp2;
> > rewrite = true;
> > output = AST;
> > }
> >
> > program
> > : ^(node=PROGRAM import_stat* namespace_decl*)
> > ;
> >
> > import_stat
> > : ^(node=USING qual=qualifier)
> > ;
> >
> > namespace_decl
> > : ^(node=NAMESPACE qual=qualifier (namespace_decl)*)
> > ;
> >
> > qualifier
> > : ^(fqual=FQUALIFIER IDENTIFIER+)
> > ;
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090312/632936cf/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vNVD.g
Type: application/octet-stream
Size: 7484 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090312/632936cf/attachment.obj
More information about the antlr-interest
mailing list