[antlr-interest] validating semantic predicates

Mark Volkmann r.mark.volkmann at gmail.com
Fri Nov 30 07:37:19 PST 2007


I'm trying to determine how to use validating semantic predicates in a
rule that has no terminating token. Here's an example of the approach
I've tried.

statement
  : simpleStatement
  | ^('if' c=condition { $c.result }? simpleStatement)
  ;
  catch[FailedPredicateException fpe] {
    consumeUntil(input, STMT_TERMINATOR);
    input.consume();
  }

The problem is that simpleStatements have no terminating token. They
are a keyword optionally foIlowed by a number. I know whether to
expect the number based on the keyword. There's no such thing as
STMT_TERMINATOR in my grammar.

I think in order to continue parsing when the condition evaluates to
false, I have to consume all the tokens that make up the
simpleStatement being skipped. How can I consume those tokens?

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list