[antlr-interest] Syntactic predicates (in reverse)
Paul J. Lucas
dude at darkfigure.org
Fri Oct 18 11:27:43 PDT 2002
First, in the lexer documentation for the example for Pascal INT, REAL, or range, RANGE_OR_INT is never used.
Second, what I'm looking to do is match backwards in addition to forwards. For example, consider:
define function foo
in some language. "define" and "function" should be returned as keywords DEFINE and FUNCTION respectively, but only if they occur together; otherwise IDENTIFIER for each.
Using the FORTRAN DO loop from the lexer documentation as a guide, I can do:
DEFINE
: (DEFINE_FUNCTION)=> "define"
;
protected DEFINE_FUNCTION
: "define" FUNCTION
;
FUNCTION
: "function"
;
This (I believe) will correctly return the DEFINE token to the parser only of "define" is followed by "function." But how can I get the lexer to return FUNCTION as the next token, but only if it was *preceded* by "define"?
- Paul
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list