[antlr-interest] Syntax error recognition in parser

Christophe Boutter boutter at ps.uni-sb.de
Thu Jan 11 07:07:56 PST 2007


Hey folks,

I need help again. I use the generated parser to report syntactical
errors in the language I'm parsing. Everathing works fine if in the
programm a literal is replaced by an identifier:

action foo bar (action being a literal, and bar replacing ';')

In the case the literal (here ';') is replaced with another literal the
parser boils out and doesn't even give an error message
(defaultErrorHandler is set to true):

action foo . ('.' being a literal)

I would like the parser to report the error and continue with the next
input. Although this can also be a problem when someone just omits a ';'
and the parser matches the next literal to the actual rule. Then it
would be nice to recover the token and start anew:

action foo (error recognition here by matching the next action literal)
action bar; (start of the action rule with action)

If someone can help me or has any ideas how to solve my problems I would
be very thankful.

For Information here the action rule on which the examples are based:
actionDeclaration
	: "action" idList SEMI
	| "patient" "action" idList SEMI
	| "impatient" "action" idList SEMI
	;

idList
	: ID (COMMA ID)*
	;

And the identifier rule of the lexer:
ID options { testLiterals=true; paraphrase = "an identifier";}
    : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'$'|'-')*
    ;

SEMI: ';' ; (for completeness)


Chris

-- 
Try not to become a man of success, but rather try to become a man of value.
-- Albert Einstein


More information about the antlr-interest mailing list