[antlr-interest] Re: MSVC 7.0

Arnar Birgisson arnarb at oddi.is
Sat Oct 4 05:17:30 PDT 2003


Hello again.

Ric said:
> Did you by any chance see where the invalid sign extension 
> happened? Or do
> you have a small example lexer+input file that triggers this ?

I traced this and it seems that it happens in
antlr::CharScanner::match(std::string&):

virtual void match(const ANTLR_USE_NAMESPACE(std)string& s)
{
	int len = s.length();

	for (int i = 0; i < len; i++)
	{
		int la_1 = LA(1);

		if ( la_1 != s[i] )  /* trouble here */
			throw MismatchedCharException(la_1, s[i], false,
this); /* and here */

		consume();
	}
}

Since string is a basic_string<char, char_traits<char>, allocator<char>
>, and basic_string<..>.operator[] returns an allocator::reference,
string.operator[] returns a char. The constructor for
MismatchedCharException takes it second parameter as an int, so that's
where the conversion takes place. Changing the above code to

virtual void match(const ANTLR_USE_NAMESPACE(std)string& s)
{
	int len = s.length();

	for (int i = 0; i < len; i++)
	{
		int la_1 = LA(1);

		/* next two lines changed */
		if ( la_1 != (s[i] & 0xff) )
			throw MismatchedCharException(la_1, (s[i] &
0xff), false, this);

		consume();
	}
}

fixes the problem.

Arnar



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list