[antlr-interest] Identifiers starting with numbers

Ahuja, Vinay Vinay.Ahuja at idea.com
Wed Jul 19 12:31:52 PDT 2006


Hi,

We are writing an antlr grammar for a scripting language (very similar
to pascal as far as basic constructs go).

This is how we have defined IDENT

IDENT
	options {testLiterals=true;}
	:	('a'..'z') ('a'..'z'|'0'..'9'|'_')*   //pspsps
	;

We also have numeric integer defined as follows:

NUM_INT
	:	('0'..'9')+ // everything starts with a digit sequence
		(	(	{(LA(2)!='.')&&(LA(2)!=')')}?
// force k=2; avoid ".."
//PSPSPS example ARRAY (.1..99.) OF char; // after .. thinks it's a
NUM_REAL
				'.' {$setType(NUM_REAL);}	// dot
means we are float
				('0'..'9')+ (EXPONENT)?
			)?
		|	EXPONENT {$setType(NUM_REAL);}	// 'E' means we
are float
		)
	;


In our scripting language, the identifier can start with numbers. We
changed IDENT to be like this


IDENT
	options {testLiterals=true;}
	:	('a'..'z'|'0'..'9'|'_')*   //pspsps
	;

Now, the parser is causing ambiguities and does not parse integers
correctly. We expected ambiguities anyways.

What is a good way to make this work? Any suggestions. Do we need to put
any syntactic predicate? If so how?

Thanks for your help.

Regards,
Vinay






Confidentiality Notice: The material in this e-mail is intended only for the use of the individual to whom it is addressed and may contain information that is confidential, privileged, and exempt from disclosure under applicable law. If you are not the intended recipient, be advised that the unauthorized use, disclosure, copying, distribution, or the taking of any action in reliance on this information is strictly prohibited. If you have received this e-mail in error, please immediately notify us at 866-335-3289 to arrange for the return of this material to us. Thank You.


More information about the antlr-interest mailing list