[antlr-interest] @init actions in "C Target " have problems with MSVS compilers

Jim Idle jimi at temporal-wave.com
Thu Mar 22 21:51:15 PDT 2007


Be careful with those auto initializations though. As general rule most
compilers will let the last declaration be initialized while being
declared but many moan about anything else. To be strictly correct you
should use:

PragmaComment 
@declarations 	{int isPragma;}	
@init			{ isPragma = 0; }
:

Then I will guarantee that the codegen will compile everywhere.

Jim

PS: Thanks for emailing the warnings generated by the Intel compiler -
my goal is that the runtime will compile on all non-broken compilers at
maximum warning level without issuing any warnings. It was doing this
until you ran the Intel compiler against it ;-) I will fix those couple
of warnings up when I return from Mexico, where I shall be on vacation
next week.



-----Original Message-----
From: Alexander Stasenko [mailto:astasenko at gmail.com] 
Sent: Thursday, March 22, 2007 9:40 PM
To: Jim Idle; Gavin Lambert; Mike Aubury; antlr-interest at antlr.org
Subject: Re: [antlr-interest] @init actions in "C Target " have problems
with MSVS compilers

I appreciate your help. Thanks everyone for useful suggestions (and
explanations!). Any of them can solve the issue.

In my specific situation, new "@declarations" rule looks appropriate
solution.
So for example I can separate comment from pragma in the following
grammar part:

	// A comment in SISAL source begins with a percent sign and ends
with a newline
	// character.
	// If the character immediately following a percent sign is a
dollar sign, the
	// comment is a compiler directive, or pragma.

	PragmaComment @declarations {int isPragma = 0;}	: '%' (
		( '$' {isPragma = 1;} | ~('$' | '\n' | '\r') ) ~('\n' |
'\r')*
	)? '\r'? '\n' {
		if (!isPragma) _channel=99; // ignores comment
	};

P.S. ANTLR community is really great :

-- 
Best regards, Alexander.


More information about the antlr-interest mailing list