[antlr-interest] Inserting an imaginary token into AST Tree

Micah Schehl micah.schehl at omnicare.com
Thu Jul 14 18:46:53 PDT 2005


I am working on a pretty printer for MS SQL Select Statements, and have 
started from Tomasz Jastrzebski's grammar.

I am adding the tree parsing info to the grammar and can't figure out 
how to insert an imaginary token. 

Given a sql fragment:
       select realname as aliasname,  realname2 aliasname2

I would like to generate the tree:
       SELECT
            AS
                 realname
                 aliasname
            INFERASSIGN
                 realname2
                 aliasname2

The trouble I am having is getting that INFERASSIGN into the tree.  Can 
this be done?

Here is grammar fragments that didn't work:
      class SqlParser extends Parser;
      ...
      someRule
          :  (dbObject (AS^ indentifierLiteral)? COMMA) => column (AS^ 
indentifierLiteral)?
          | (dbObject (indentifierLiteral)? COMMA) => column 
(INFERASSIGN^ indentifierLiteral)?
          ;
      ...

      class SqlLexer extends Lexer;
      ...
      tokens {
          INFERASSIGN;
      }
      ...



More information about the antlr-interest mailing list