[antlr-interest] Re: line number counter reset

tdknghi <nk.truong at student.qut.edu.au> nk.truong at student.qut.edu.au
Mon Feb 17 13:53:13 PST 2003


  Hi there,

Thanks a lot for your response. However, I don't think copy the line 
number of the modifier to the type token would be appropriate. As if the 
students type varaible declaration like below. The line number will not 
be correct:
   int
       i = 5;

Do you have any further suggestions?

Thanks.
MiMi

--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> On Sat, Feb 15, 2003 at 07:40:22AM -0000, tdknghi 
<nk.truong at s...> wrote:
> > I would like tracking the line number in my program when parse 
Java 
> > program. I wrote a class to extend antlr.CommonAST then instruct 
the 
> > parser to use my custom AST type rather than the default AST 
node 
> > type. I have everything work beautifully except one problem. I 
> > attach all the files together with the description so that you could 
> > get a better idea of what goes wrong.
> ....
> >  a. The line number of the "ScreenWriter token" (type one) 
suddently 
> > reset to 0 (the correct line number should be 5), but the line 
> > number of the token "writer" is correct which is 5. The rest of 
> > tokens in that line is correct.
> >  b. Similarity  with the line int i = 5; the line number of the 
> > token "int" is reset to 0 but the line number of toke "i", "=", "5" 
> > is correct.
> 
> You have to set line numbers manually on manually created tokens 
(and
> there's a lot of manually created stuff in the java grammar). At least 
that
> is my guess.
> 
> >  I have done several tests. the line number only reset for the first 
> > token of the variable declaration line only. 
> 
> My guess is that you can fix this particular one by meddling a bit with 
the
> variableDeclarator rule. (e.g. copy line info of the modifiers into the
> synthetic node VARIABLE_DEF etc.
> 
> Cheers,
> 
> Ric
> -- 
> -----+++++*****************************************************+++++++++--
-----
>     ---- Ric Klaren ----- j.klaren at u... ----- +31 53 4893722  ----
> -----+++++*****************************************************+++++++++--
-----
>  'And this 'rebooting' business? Give it a good kicking, do you?' 'Oh, 
no,
>   of course, we ... that is ... well, yes, in fact,' said Ponder. 'Adrian
>     goes round the back and ... er ... prods it with his foot. But in a
>      technical way,' he added. --- From: Hogfather by Terry Pratchett.


 

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



More information about the antlr-interest mailing list