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

Tarun Khanna tarunkhanna at gmail.com
Fri Jul 15 06:55:50 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)?
> ;
> ...



Here is what you need to do

Add an action
{ ## = #([INFERASSIGN, "Implicit Alias"], #column, #identifierLiteral);}

However you'll need to add some if then else clause so because you won't 
need this tree in case an ALIAS is not used

Actually reading the following link would help
file:///home/tkhanna/documents/projects/learn/antlr/antlr-2.7.5/doc/trees.html


-- 
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050715/9f038a77/attachment-0001.html


More information about the antlr-interest mailing list