[antlr-interest] Inserting an imaginary token into AST Tree
Tarun Khanna
tarunkhanna at gmail.com
Fri Jul 15 09:07:45 PDT 2005
hell yes...
http://www.antlr.org/doc/trees.html#_bb1
On 7/15/05, Schehl, Micah <Micah.Schehl at omnicare.com> wrote:
>
> Tarun,
> Thank you, I will look into that. The link you posted was
> file:///home/tkhanna/documents/projects/learn/antlr/antlr-2.7.5/doc/trees.html.
> I am guessing you meant to send a different one.
> Thanks,
> Micah
>
> -----Original Message-----
> *From:* Tarun Khanna [mailto:tarunkhanna at gmail.com]
> *Sent:* Friday, July 15, 2005 9:56 AM
> *To:* Micah Schehl
> *Cc:* antlr-interest at antlr.org
> *Subject:* Re: [antlr-interest] Inserting an imaginary token into AST Tree
>
>
> > 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
>
>
--
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050715/8b36e13a/attachment.html
More information about the antlr-interest
mailing list