[antlr-interest] validating semantic predicates

Matt Benson gudnabrsam at yahoo.com
Wed Jun 18 11:45:07 PDT 2003


I have Tooled my grammar and it has generated a
parser.  I have written the grammar to process the
different elements of the file by calling methods on a
registered implementation of a handler object.  Thus,
I am currently concerned only with content.  I am
providing the handler a Stack of relevant tokens in
case something farther away than the current context
is needed.  So every time I enter a rule, I push the
primary token onto the stack (remember I'm dealing
with XML so this is pretty straightforward), and pop
it before I return from the rule.  I figure while I'm
doing the pop, I might as well do a kind of sanity
check by way of a validating semantic predicate:

{t == tokenStack.pop()}?

One thing I noticed right away is that the
SemanticException thrown in the event that this is not
true contains the exact text.  I don't see in the docs
whether and how to customize this text; I am currently
doing this:

{t == tokenStack.pop() /*unexpected token on the
stack*/}?

which is good enough, but I just wondered if there was
a better way.

TIA,
Matt


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

 

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




More information about the antlr-interest mailing list