I wrote a grammar for an undefined Java-like DSL. Although there are still some problems with it (it does not recognize all the inputs as I would like), what worries me most is that the generated C code does not compile.
I am using AntlrWorks 1.5 with Antlr 3.5 (Antlr 4 does not seem to support target C).
The problem is the rules of expression. I have prio14Expression rules for prio0Expression that handle operator priority. The problem is priority 2, which evaluates the prefix and postfix operators:
... prio3Expression: prio2Expression (('*' | '/' | '%') prio2Expression)*; prio2Expression: ('++' | '--' | '!' | '+' | '-')* prio1Expression ('++' | '--')*; prio1Expression: prio0Expression ( ('.' prio0Expression) | ('(' (expression (',' expression)*)? ')') | ('[' expression (',' expression)* ']') )*; prio0Expression: /*('(') => */('(' expression ')') | IDENTIFIER | //collectionLiteral | coordinateLiteral | 'true' | 'false' | NUMBER | STRING ; ...
The expression is a label for prio14Expression. You can see the full grammar here .
The code generation itself is successful (without any errors or serious warnings). It generates the following code:
CONSTRUCTEX(); EXCEPTION->type = ANTLR3_MISMATCHED_SET_EXCEPTION; EXCEPTION->name = (void *)ANTLR3_MISMATCHED_SET_NAME; EXCEPTION->expectingSet = &FOLLOW_set_in_prio2Expression962; RECOVERFROMMISMATCHEDSET(&FOLLOW_set_in_prio2Expression962); goto ruleprio2ExpressionEx;
What is not built with the error " Error 5 error C2065: 'FOLLOW_set_in_prio2Expression962' : undeclared identifier ".
Did I do something wrong in the grammar? No other rules cause this error, and if I reformulate the corresponding rule a little, the generated code will be valid (but then the grammar will not do what I want). What can I do to fix this problem?
Thanks for any help.
c antlr antlr3 antlrworks grammar
Matěj Zábský
source share