Hi Johannes,<br><br>I&#39;ve attached the lexer/parser file. If you generate that first and then generate the tree grammar, you&#39;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">&lt;<a href="mailto:jaluber@gmx.de">jaluber@gmx.de</a>&gt;</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">&gt; Hello!<br>
&gt;<br>
&gt; I&#39;ve got a question about rewriting an AST in a tree grammar, with C# as<br>
&gt; target language. The code Antlr generates just won&#39;t compile when I set<br>
&gt; the &#39;output=AST&#39; in my tree grammar options.<br>
&gt; It complains about lines like this:<br>
&gt;<br>
&gt; if ( _first_1==null ) _first_1 = qual.Tree;<br>
&gt;<br>
&gt; Error    2    Cannot implicitly convert type &#39;object&#39; to<br>
&gt; &#39;Antlr.Runtime.Tree.CommonTree&#39;. An explicit conversion exists (are you<br>
&gt; missing a cast?)    C:\Users\floris\Documents\Visual Studio<br>
&gt; 2008\Projects\Vnvd\Vnvd\vNVDCheckerPassTwo.cs    315    58    Vnvd<br>
&gt;<br>
&gt; Here _first_1 is of type CommonTree, and qual.Tree of type object. It<br>
&gt; needs an explicit cast there, but when Antlr generates the code, it<br>
&gt; doesn&#39;t add one. Is this something I did wrong in my grammar file, or is<br>
&gt; this a bug?<br>
&gt; I am using the latest version of Antlr (3.1.2).<br>
&gt;<br>
&gt; Thanks in advance,<br>
&gt; Floris<br>
<br>
</div>I need a full working grammar, which includes at least the .tokens-file.<br>
I haven&#39;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">&gt;<br>
&gt; Here are the contents of my (simplified) grammar file:<br>
&gt;<br>
&gt; tree grammar vNVDCheckerPassTwo;<br>
&gt;<br>
&gt; options<br>
&gt; {<br>
&gt;     ASTLabelType = CommonTree;<br>
&gt;     tokenVocab = vNVD;<br>
&gt;     language = CSharp2;<br>
&gt;     rewrite = true;<br>
&gt;     output = AST;<br>
&gt; }<br>
&gt;<br>
&gt; program<br>
&gt;     :    ^(node=PROGRAM import_stat* namespace_decl*)<br>
&gt;     ;<br>
&gt;<br>
&gt; import_stat<br>
&gt;     :    ^(node=USING qual=qualifier)<br>
&gt;     ;<br>
&gt;<br>
&gt; namespace_decl<br>
&gt;     :    ^(node=NAMESPACE qual=qualifier (namespace_decl)*)<br>
&gt;     ;<br>
&gt;<br>
&gt; qualifier<br>
&gt;     :    ^(fqual=FQUALIFIER IDENTIFIER+)<br>
&gt;     ;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div>&gt; ------------------------------------------------------------------------<br>
&gt;<br>
&gt;<br>
&gt; List: <a href="http://www.antlr.org/mailman/listinfo/antlr-interest" target="_blank">http://www.antlr.org/mailman/listinfo/antlr-interest</a><br>
&gt; 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>