[antlr-interest] Fundamental question

Mari Matinlassi mmatinlassi at icinetic.com
Wed Nov 9 08:18:56 PST 2011


Hi,

There is something fundamental and important that I have not understood with
ANTLR grammars.

If I need to parse something like...

	int test;
	strig another; 
	int variable;
	string here;

You notice there is a typing error on the second line ('strig' instead of
'string').

How do I make a grammar that will not stop parsing but, continues after an
error??

Below is an example how I CANNOT make it work the right way (created AST
contains only 'int test ;')..

grammar List;

options {
	language = CSharp3;
	TokenLabelType = CommonToken;
	output=AST;
	ASTLabelType = CommonTree; 
}

@lexer::namespace{ConsoleApplication4}
@parser::namespace{ConsoleApplication4}


public r 
	: variables*
	;

variables
	: type ID ';'
	;

type
	: 'int'
	| 'string'
	;

ID : 'a'..'z' + ;

WS : (' ' |'\n' |'\r' ) {$channel=Hidden;} ;


Many thanks for your time and help,

Mari




More information about the antlr-interest mailing list