[antlr-interest] Question problem constant value?

Kevin J. Cummings cummings at kjchome.homeip.net
Sun Aug 15 15:27:26 PDT 2010


On 08/15/2010 04:02 AM, sunao furukawa wrote:
> Hello,
> 
> My grammar file is improved one by one.
> Constant 'b' is used by the rule level_symbol.
> I want to use variable name b.
> But, variable name b collides with constant 'b'.
> variable name b is red letter when debugging.
> Please teach the way not to collide constant 'b'.

Sunao,
	This is the classic "keyword" vs "reserved word" problem.
If you wish for your keywords to be available as identifiers, you need
to include them in your simple_identifier rule.

I'd have a keyword rule:

keyword : 'b'
	;

and then


Something like:

simple_identifier: ALPHA
		 | ALPHANUM
		 | keyword
		 ;

BTW, this really is a FAQ and has been answered many times on this email
list.  Check out the archives listed on the wiki page.

> input text when debugging
> 
> primitive mux (y, a, b, sel);
> output y;
> input sel, a, b;
> table // a b sel : y
>  0 ? 0 : 0;  1 ? 0 : 1;  ? 0 1 : 0;  ? 1 1 : 1; endtable
> endprimitive
> 
> Thanks

-- 
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list