[antlr-interest] Parser sneaks out of file with unknown tokens

Ploett, Norbert norbert.ploett at siemens.com
Wed Jul 12 01:06:07 PDT 2006


Hi all,

let me give you an example:

Here is what my parser looks like, simplified of course:
==================================
class SimpleParser extends Parser;

options { k = 2; buildAST = true; defaultErrorHandler = false ; }

edd 
    		options {defaultErrorHandler=true;} 
	:	(definition)+
	;

definition
	:	VARIABLE IDENTIFIER SEMICOLON
	;
==================================

Now I give this input:
==================================
VARIABLE A ;
VARIABLE B ;
C LIKE VARIABLE A ;
==================================

The parser should (in my opinion) choke on the last line and report an
error. But this is not the case. In the edd() method the parser is in an
infinite loop, trying to evaluate "definition"s. When trying to evaluate
another "definition" it notes that an IDENTIFIER token is not in the
entry set to the "definition" rule, exits the loop and just quits
without any error indication.

What is the intended way to get an error message in this situation?

Thanks for hints


Norbert Ploett




More information about the antlr-interest mailing list