2
votes

This should be a simple question. Given this parser rule:

ifStatement
 : expr3b=IF logical (~(THEN)) expression* (ELSE expression *)? ENDIF // missing THEN
 ;

Why does this not match this String?

"IF CODE=\"10\" DUE_DATE < YESTERDAY ENDIF"

(IF, THEN, ELSE, and ENDIF are tokens defined to exactly what you'd assume they are. logical and expression are other rules).

1
Without seeing the productions for logical and expression, my guess is that the CODE = "10" is a mal-formed expression, perhaps in the lexical handling of "10". But you've given too little information to know. - msw

1 Answers

1
votes

I assume the following line is verbatum from your grammar.

ifStatement : expr3b=IF logical (~(THEN)) expression* (ELSE expression *)? ENDIF;

If that's the case, then you'll want to change it to this:

ifStatement : expr3b=IF logical expression* (ELSE expression *)? ENDIF;

As it is, (~(THEN)) says "match any one token, as long as it isn't THEN." The first token after logical finishes is ID (or similar) for DUE_DATE. ifStatement consumes it to fulfill (~(THEN)). This leaves < YESTERDAY to fulfill expression, which fails.

The following input would be accepted by the ifStatement in your question because ENDIF fulfills (~(THEN)):

IF CODE=\"10\" ENDIF DUE_DATE < YESTERDAY ENDIF

This would work as expected because the first ENDIF is consumed only to match (~(THEN)).