[antlr-interest] Syntactic predicates (in reverse)

mzukowski at yci.com mzukowski at yci.com
Fri Oct 18 11:34:09 PDT 2002


You could set a flag in your lexer and check it when you are in FUNCTION.
Or you could use lexer states.

Actually you are going to want to handle this in your ID rule and use
literal checking by setting the testLiterals option to true.  Read the docs
about literals.

Monty

-----Original Message-----
From: Paul J. Lucas [mailto:dude at darkfigure.org]
Sent: Friday, October 18, 2002 11:28 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Syntactic predicates (in reverse)


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/ 


 

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



More information about the antlr-interest mailing list