[antlr-interest] how to print tokens?

Nigel Sheridan-Smith nbsherid at secsme.org.au
Thu May 12 19:57:10 PDT 2005


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Nigel Sheridan-Smith
> Sent: Friday, 13 May 2005 12:34 PM
> To: antlr-interest at antlr.org
> Subject: RE: [antlr-interest] how to print tokens?
> 
> 
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Michael West
> > Sent: Friday, 13 May 2005 9:13 AM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] how to print tokens?
> >
> > I have a thousand sql select statements and need to report on the tables
> > and
> > views they refer to.  Can antlr help me with this?  Should antlr help me
> > with this?
> >
> > Almost all of the sql is sqlserver2000.  The grammer at:
> > http://www.antlr.org/grammar/1062280680642/MS_SQL_SELECT.html
> >
> > seems to parse fine, and I can have it print out matches to simple leaf
> > rules using element labels.  Can I do it with rule references?  I don't
> > see how.
> >
> > I think I would be happy if I could just print out all of the leaves
> > attached to
> > the tokens which match a rule.  It seems that AST is more suited to
> > this, but this is not an AST grammer.
> >
> 
> You need to find the relevant rules, and add some actions, and probably
> some
> return values... replace the following 3 rules, and tell us how it goes!
>

Whoops... it's for C#, not Java... see the attachments. That should get you
started...

Nigel

--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: sql.g
Type: application/octet-stream
Size: 19528 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050513/3dd35f3b/sql-0001.obj
-------------- next part --------------

using System;

public class SqlMain
{
	public static void Main ()
	{
        SqlLexer lex = new SqlLexer (Console.In);
        
        /* Create the parser */
        SqlParser par = new SqlParser (lex);
		
		par.statement();
	}
}
		


More information about the antlr-interest mailing list