[antlr-interest] antlr 3.1 ast rewriting
Johannes Luber
jaluber at gmx.de
Thu Mar 12 00:16:05 PDT 2009
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
More information about the antlr-interest
mailing list