[antlr-interest] Switching between literals and keywords

mzukowski at yci.com mzukowski at yci.com
Wed Feb 18 15:34:26 PST 2004


There have been numerous posts on this list and an entry on the ANTLR FAQ at
jguru.com.  Search for "ambiguous keywords".  Once you've gotten the basics
down post back with a proposal and we'll go into detail from there.

Monty

-----Original Message-----
From: Donovan, Bob [mailto:bob.donovan at ugsplm.com] 
Sent: Tuesday, February 10, 2004 3:02 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Switching between literals and keywords


I have a language that I am preparing a grammer for. The language sometimes
has dual uses for some of the tokens.

For instance, I sometimes have to match keywords like "integer" in the
following phrase:
"define integer constant HostNameLength = 20;"

In this case, I match this phrase with the following:

protected
defineIntegerConstant
	:	"define" "integer" "constant" ID EQUAL  INT ((SEMI)=>SEMI)?
	;


But then I sometimes I have other phrases where I don't won't the "integer"
keyword returned as the LITERAL_integer, but instead returned as a
IDENTIFIER. For example in the following phrase, the word integer could be
any type: integer, ObjectPtr, float, boolean, string, etc. In the example
below, I need to match "update" COLON ID ID

"define object message EvaluateForFrozen (
	update: integer mfail);"

How do I get the lexer to return a INDENTIER instead of a LITERAL_integer?

Thanks, Bob



 
Yahoo! Groups Links



 


 
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