[antlr-interest] Grammar not detecting stray syntax after certain valid blocks

David Daeschler david.daeschler at gmail.com
Tue Apr 5 11:27:08 PDT 2011


Hello list,

I currently have a grammar that looks something like this:

//this is the root
public prog
: globalStmt+
 ;

globalStmt: stateDef;

stateDef
 : 'state' ID stateBlock;

stateBlock
 : '{' stateBlockContent* '}'
 ;

stateBlockContent
 : NEWLINE!
 ;

This is enough to demonstrate the problem. When I create a program such as:

state hello
{

}
}

The trailing close bracket is not detected as an error. In fact, the grammar
only seems to trigger an error when the trailing content could be part of a
subrule farther down the chain such as an ID. What am I doing wrong and what
is the best way to resolve this?

Under antlrworks when the debugger gets to the errant bracket the
debug cusor moves to the semi at the end of prog and the closing bracket
stays greyed out like it's never consumed or evaluated.

Thank you for your time.
-- 
David Daeschler


More information about the antlr-interest mailing list