[antlr-interest] Knowing line and position in tree parser

Jim Idle jimi at temporal-wave.com
Sun Nov 21 09:36:31 PST 2010


Use the API in CommonTree to get the token(s) from tree nodes, then use the
API in CommonToken to ask for line and position of individual tokens. Use
the individual tokens where necessary. 

 

Jim

 

From: BeRniTo [mailto:bernito.lb at gmail.com] 
Sent: Saturday, November 20, 2010 6:34 PM
To: Jim Idle
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Knowing line and position in tree parser

 

I'm doing type checking within a Tree Grammar and want to include line and
position (if possible) of where the error was.

 

For example:

 

int i = "a";

 

When analysing the expression part the type won't match so I want to emit an
error saying "type missmatch in X:Y" where X would be the line number and Y
the position where the error happened.

 

I don't know where to start searching in the API. I think an example would
be much better.

 

Thanks!



More information about the antlr-interest mailing list