Hi Johannes,<br><br>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.<br><br>Floris<br><br><div class="gmail_quote">
On Thu, Mar 12, 2009 at 8:16 AM, Johannes Luber <span dir="ltr"><<a href="mailto:jaluber@gmx.de">jaluber@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Floris van Nee schrieb:<br>
<div class="im">> Hello!<br>
><br>
> I've got a question about rewriting an AST in a tree grammar, with C# as<br>
> target language. The code Antlr generates just won't compile when I set<br>
> the 'output=AST' in my tree grammar options.<br>
> It complains about lines like this:<br>
><br>
> if ( _first_1==null ) _first_1 = qual.Tree;<br>
><br>
> Error 2 Cannot implicitly convert type 'object' to<br>
> 'Antlr.Runtime.Tree.CommonTree'. An explicit conversion exists (are you<br>
> missing a cast?) C:\Users\floris\Documents\Visual Studio<br>
> 2008\Projects\Vnvd\Vnvd\vNVDCheckerPassTwo.cs 315 58 Vnvd<br>
><br>
> Here _first_1 is of type CommonTree, and qual.Tree of type object. It<br>
> needs an explicit cast there, but when Antlr generates the code, it<br>
> doesn't add one. Is this something I did wrong in my grammar file, or is<br>
> this a bug?<br>
> I am using the latest version of Antlr (3.1.2).<br>
><br>
> Thanks in advance,<br>
> Floris<br>
<br>
</div>I need a full working grammar, which includes at least the .tokens-file.<br>
I haven't tested yet, if that is enough or if I do need also the parser<br>
and lexer. Full working means that I can generate the grammar on my<br>
system so I can look up where I seemingly missed the conversion.<br>
<br>
Johannes<br>
<div class="im">><br>
> Here are the contents of my (simplified) grammar file:<br>
><br>
> tree grammar vNVDCheckerPassTwo;<br>
><br>
> options<br>
> {<br>
> ASTLabelType = CommonTree;<br>
> tokenVocab = vNVD;<br>
> language = CSharp2;<br>
> rewrite = true;<br>
> output = AST;<br>
> }<br>
><br>
> program<br>
> : ^(node=PROGRAM import_stat* namespace_decl*)<br>
> ;<br>
><br>
> import_stat<br>
> : ^(node=USING qual=qualifier)<br>
> ;<br>
><br>
> namespace_decl<br>
> : ^(node=NAMESPACE qual=qualifier (namespace_decl)*)<br>
> ;<br>
><br>
> qualifier<br>
> : ^(fqual=FQUALIFIER IDENTIFIER+)<br>
> ;<br>
><br>
><br>
><br>
</div>> ------------------------------------------------------------------------<br>
><br>
><br>
> List: <a href="http://www.antlr.org/mailman/listinfo/antlr-interest" target="_blank">http://www.antlr.org/mailman/listinfo/antlr-interest</a><br>
> Unsubscribe: <a href="http://www.antlr.org/mailman/options/antlr-interest/your-email-address" target="_blank">http://www.antlr.org/mailman/options/antlr-interest/your-email-address</a><br>
<br>
</blockquote></div><br>