[antlr-interest] ANTLR problem

Zulfiqar Malik zulfiqar.malik at gmail.com
Sun Jul 30 02:51:30 PDT 2006


Hi,

I am using ANTLR 2.7.6. I am familiar with other parser generating
tools like bison, slk etc. but this is the first time i am using
ANTLR. I am writing a grammar with a C# like syntax and bison was
proving to be quite restrivtive so i decided to switch to ANTLR.
I got everything up and running and made a dll (VS8.0) for usage in
C++. Trying out the minimalistic parser given in the "getting started"
page i encounter an exception at the following line of code (for any
token, in this particular case mNEWLINE in the lexer):

	if ( _createToken && _token==ANTLR_USE_NAMESPACE(antlr)nullToken &&
_ttype!=ANTLR_USE_NAMESPACE(antlr)Token::SKIP ) {
	   _token = makeToken(_ttype);
	   _token->setText(text.substr(_begin, text.length()-_begin));
	}
	_returnToken = _token; // <--- CRASH ON THIS LINE

and it should crash since _returnToken is not initialized and points
to an invalid memory address. I don't know how to solve this problem.
I am using VS8.0 on WinXP SP2 (which shouldn't be an issue). Thanks in
advance.

Grammar is given below:

options {
	language="Cpp";
}

class P extends Parser;
options {
	k = 2;
}

startRule
    :   n:NAME
        //{printf("Hi there, %s\n", n);}
    ;

class L extends Lexer;

// one-or-more letters followed by a newline
NAME:   ( 'a'..'z'|'A'..'Z' )+ NEWLINE
    ;

NEWLINE
    :   '\r' '\n'   // DOS
    |   '\n'        // UNIX
		{
		/*_ttype = antlr::Token::SKIP; newline();*/ }
    ;

-- 
Regards,
Zulfiqar Inayat Malik.


More information about the antlr-interest mailing list