[antlr-interest] Follow-up on line numbers

David Smith david.smith at cc.gatech.edu
Wed Aug 10 13:09:29 PDT 2011


Sam,
I understood the answer, but we're talking novice here - if the front 
end of my grammar looks like this:

prog:   body EOF!
         ;

body    :
         parts -> ^(BODY parts)
         ;

parts   :
         ( (stat
            | ifStat
            | switchStat
            | whileStat
            | forStat)   )*
         ;

stat:
         (ID OPENP actualParameters CLOSEP DOT ID GETS)
          => str=ID OPENP actualParameters CLOSEP  DOT fld=ID GETS expr
          -> ^(GETS ?????? ^(STRUCTA $str $fld actualParameters) expr)
     |   (ID OPENP actualParameters CLOSEP DOT OPENP)
          => str=ID OPENP actualParameters CLOSEP DOT OPENP var=ID 
CLOSEP GETS expr
          -> ^(GETS ???????? ^(STRUCTAV $str $var actualParameters) expr)
// etc
     ;
how would I insert the line number at the ???????

DMS
Message: 13
Date: Wed, 10 Aug 2011 10:02:22 -0400
From: David Smith <david.smith at cc.gatech.edu>
Subject: [antlr-interest] Access to line numbers
To: antlr-interest at antlr.org
Message-ID: <E1Qr9MO-00037I-B1 at elasmtp-curtail.atl.sa.earthlink.net>
Content-Type: text/plain; charset="us-ascii"; format=flowed

It seems that the parse tree generated by the parser has a data field
'line' that seems to correspond to the source line when parsing.  How
do i access that to include the line number in the tree generated by
my grammar?

DMS

David M. Smith http://www.cc.gatech.edu/fac/David.Smith
Georgia Institute of Technology, College of Computing
Sent from my ASR-33 Teletype



------------------------------

Message: 14
Date: Wed, 10 Aug 2011 09:36:28 -0500
From: "Sam Harwell" <sharwell at pixelminegames.com>
Subject: Re: [antlr-interest] Access to line numbers
To: "'David Smith'" <david.smith at cc.gatech.edu>,
         <antlr-interest at antlr.org>
Message-ID: <06e601cc576a$e4a48980$aded9c80$@pixelminegames.com>
Content-Type: text/plain;       charset="us-ascii"

Both the Tree and Token interfaces have a method getLine().

Sam

 >From: antlr-interest-bounces at antlr.org
 >[mailto:antlr-interest-bounces at antlr.org] On Behalf Of David Smith
 >Sent: Wednesday, August 10, 2011 9:02 AM
  ...snip...
 >List: http://www.antlr.org/mailman/listinfo/antlr-interest
 >Unsubscribe:
 >http://www.antlr.org/mailman/options/antlr-interest/your-email-address



David M. Smith http://www.cc.gatech.edu/fac/David.Smith
Georgia Institute of Technology, College of Computing
Sent from my ASR-33 Teletype 



More information about the antlr-interest mailing list