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

Alexander Stasenko astasenko at gmail.com
Thu Mar 22 06:34:27 PDT 2007

Consider the following rule with @init action:

		CharacterConstant @init {
				char c; int o;

For C target the following code will be generated:

		void mCharacterConstant(pSisal2Lexer ctx)
		    ANTLR3_UINT32	    _type;
		    ANTLR3_UINT64	    _start;
		    ANTLR3_UINT64	    _end;
		    ANTLR3_UINT64	    _line;
		    ANTLR3_UINT32	    _charPosition;
		    ANTLR3_UINT32	    _channel;
		    /* Initialize rule variables

		    _type	    = CharacterConstant;
		    _start	    = getCharIndex();
		    _end	    = 0;
		    _line	    = getLine();
		    _charPosition   = getCharPositionInLine();
		    _channel	    = ANTLR3_TOKEN_DEFAULT_CHANNEL;

		    	char c; int o;

MSVS 2005 compiler can not compiler it since "char c; int o;"
declarations are placed after executable statements. This restriction
was relazed in C99 standart which is unfortunately is not supported
even in MSVS 2005 in its C-mode. Trying to compile in C++ mode causes
other problems in other places, so usage of C++ mode is not a solution

Is there any possible workaround? Thanks at advance.

Best regards, Alexander.

More information about the antlr-interest mailing list