[antlr-interest] Generating exceptions with location info

FranklinChen at cmu.edu FranklinChen at cmu.edu
Tue Apr 13 15:36:51 PDT 2004


I'm parsing a language in which there are matched (and possibly
overlapping) "begin" and "end" brackets, i.e.,

      <a foo bar <b baz a> foo b>

so I have a "begin" token and an "end" token 

BEGIN : '<'! ('a'..'z')+
END: ('a'..'z')+ '>'!

and a parser that parses a "sentence" of tokens and pushes each
"begin" tag found onto a stack of seen tags and then each "end" tag
seen is checked for a matching one.  If there is a failure, I throw a
SemanticException.  So far, so good.

Problem:  I don't know how to get the current line and column numbers
from the parser, to pass to the SemanticException!  I looked at the
ANTLR source and it looks like things are protected so that I can't
get at the lexer information.  

I think it would be important to provide access and convenience methods
to location information so that user actions in a parser can generate
good error messages.

-- 
Franklin


 
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