[antlr-interest] C Target won't compile with MSVC

Jim Idle jimi at temporal-wave.com
Thu Jul 7 05:36:11 PDT 2011


That is what the @declarations section is for. It will ensure the variable
declaration is in the right place.

http://antlr.markmail.org/search/C+declarations

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ivan Brezina
> Sent: Thursday, July 07, 2011 1:12 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] C Target won't compile with MSVC
>
> Hi
> I'm not sure whether this is a bug or not.
> In my grammar I use following rule to match Perl style quoted strings:
>
> /* Perl-style quoted string */
> QSTRING             : ('q'|'Q') ( QS_ANGLE | QS_BRACE | QS_BRACK |
> QS_PAREN | QS_OTHER) ;
> fragment QS_ANGLE   : QUOTE '<' ( options {greedy=false;} : . )* '>'
> QUOTE ;
> fragment QS_BRACE   : QUOTE '{' ( options {greedy=false;} : . )* '}'
> QUOTE ;
> fragment QS_BRACK   : QUOTE '[' ( options {greedy=false;} : . )* ']'
> QUOTE ;
> fragment QS_PAREN   : QUOTE '(' ( options {greedy=false;} : . )* ')'
> QUOTE ;
>
> fragment QS_OTHER_CH: ~('<'|'{'|'['|'('|' '|'\t'|'\n'|'\r'); fragment
> QS_OTHER
> 		@init {
>      		ANTLR3_UINT32 (*oldLA)(struct ANTLR3_INT_STREAM_struct
> *, ANTLR3_INT32);
> 			oldLA = INPUT->istream->_LA;
>              INPUT->setUcaseLA(INPUT, ANTLR3_FALSE);
> 		}
> 		:
> 		QUOTE delimiter=QS_OTHER_CH
> /* JAVA Syntax */
> // 		( { input.LT(1) != $delimiter.text.charAt(0) || (
input.LT(1)
> ==
> $delimiter.text.charAt(0) && input.LT(2) != '\'') }? => . )*
> // 		( { input.LT(1) == $delimiter.text.charAt(0) &&
input.LT(2)
> ==
> '\'' }? => . ) QUOTE
> /* C Syntax */
> 		( { LA(1) != $delimiter->getText(delimiter)->chars[0] ||
> LA(2) != '\'' }? => . )*
> 		( { LA(1) == $delimiter->getText(delimiter)->chars[0] &&
> LA(2) == '\'' }? => . ) QUOTE
>   		{ INPUT->istream->_LA = oldLA; }
> 		;
>
> The problem is, that I need to declare my own variable inside @init
> section.
>
> Antlr generates such a C source:
>
> static ANTLR3_INLINE
> void mQS_OTHER(pOracleSQLLexer ctx)
> {
> 	ANTLR3_UINT32	_type;
>      pANTLR3_COMMON_TOKEN delimiter;
>
>
>      delimiter = NULL;
>
>
>          		ANTLR3_UINT32 (*oldLA)(struct
ANTLR3_INT_STREAM_struct
> *, ANTLR3_INT32);
>      			oldLA = INPUT->istream->_LA;
>                  INPUT->setUcaseLA(INPUT, ANTLR3_FALSE);
>
> ... etc.
>
> MSVC complains that the variable oldLA is declared AFTER assignment
> statement. Could you modify the it into this?
>
> static ANTLR3_INLINE
> void mQS_OTHER(pOracleSQLLexer ctx)
> {
>      ANTLR3_UINT32	_type;
>      pANTLR3_COMMON_TOKEN delimiter = NULL;
>
>      ANTLR3_UINT32 (*oldLA)(struct ANTLR3_INT_STREAM_struct *,
> ANTLR3_INT32);
>      oldLA = INPUT->istream->_LA;
>      INPUT->setUcaseLA(INPUT, ANTLR3_FALSE);
>
> ...etc
>
> Ivan
>
>
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list