[antlr-interest] antlr 3.1 ast rewriting

Floris van Nee floris.vannee at gmail.com
Wed Mar 11 16:24:24 PDT 2009


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

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+)
    ;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090312/44a168e2/attachment.html 


More information about the antlr-interest mailing list