title: ANTLR - Writing a tree grammar for an AST
body: <p>I have an AST outputted for some Lua code by my grammar file, which currently does parsing and lexing for me. I want to add a tree grammar to this, but since i'm using C# i'm not sure how to do it. What's the basic process for generating tree grammar code when you already have a parser and lexer written?</p>
  
  <p>UPDATE: I have the following grammar file:</p>
  
  <pre><code>tree grammar LuaGrammar;
  
  options {
    backtrack=true;
    language=CSharp2;
    //output=AST;
    tokenVocab=Lua;
    filter=true;
    ASTLabelType=CommonTree;
  }
  @lexer::namespace{/*my namespace*/}
  @parser::namespace{/*my namespace*/}
  
  dummyRule
      :   ^('=' x=. y=.) {};
  </code></pre>
  
  <p>placed in the same directory as my main grammar file, which generates fine. However, when trying to compile this i get the following errors:</p>
  
  <pre><code>[02:54:06] error(143): C:\Users\RCIX\Desktop\AguaLua\Project\trunk\AguaLua\AguaLua\ANTLR Data\LuaGrammar.g:12:18: unknown or invalid action scope for tree grammar: lexer
  [02:54:06] error(143): C:\Users\RCIX\Desktop\AguaLua\Project\trunk\AguaLua\AguaLua\ANTLR Data\LuaGrammar.g:13:19: unknown or invalid action scope for tree grammar: parser
  </code></pre>
  
  <p>Am i on the right track or totally off?</p>