[antlr-interest] newline() -> parser

matthew ford Matthew.Ford at forward.com.au
Fri Jun 25 17:52:14 PDT 2004


> [To the ANTLR developers:  I suggest that something like this be made
> a standard part of the ANTLR distribution, since it is to useful.]

I agree.  Handline line and columns should be automatic in AST creation.

----- Original Message ----- 
From: <FranklinChen at cmu.edu>
To: <antlr-interest at yahoogroups.com>
Sent: Saturday, June 26, 2004 9:01 AM
Subject: Re: [antlr-interest] newline() -> parser


> Kaleb Pederson writes:
> > I'm successfully calling newline in my lexer actions, and my lines and
columns
> > are getting correctly set.
> >
> > However, I want all the token information available to me in the parser.
When
> > I call getLine() or getColumn(), I get 0 and 0 returned.
>
> Since I heavily use ASTs, and delay a lot of semantic checks to the
> AST level (simplifying parsing), I use the following class.
>
> [To the ANTLR developers:  I suggest that something like this be made
> a standard part of the ANTLR distribution, since it is to useful.]
>
>
> import antlr.*;
> import antlr.collections.AST;
>
>
> /**
>  * AST with location information.
>  */
> public class LocationAST extends CommonAST {
>     private int line = 0;
>     private int column = 0;
>
>     /** Override. */
>     public int getLine() {
>         return this.line;
>     }
>
>     /** Override. */
>     public int getColumn() {
>         return this.column;
>     }
>
>     public void setLine(int line) {
>         this.line = line;
>     }
>
>     public void setColumn(int column) {
>         this.column = column;
>     }
>
>     /** Override. */
>     public void initialize(Token tok) {
>         super.initialize(tok);
>         setLine(tok.getLine());
>         setColumn(tok.getColumn());
>     }
>
>     /** Override. */
>     public void initialize(AST t) {
>         super.initialize(t);
>         if (t instanceof LocationAST) {
>             LocationAST actual = (LocationAST) t;
>             setLine(actual.getLine());
>             setColumn(actual.getColumn());
>         }
>     }
> }
>
> -- 
> Franklin
>
>
>
> Yahoo! Groups Links
>
>
>
>
>



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list