The Definitive ANTLR Guide starts with a simple recognizer. Using grammar verbatim to target C-runtime fails because %s means something to ANTLR:
$ cat T.g
grammar T;
options {
language = C;
}
@parser::includes
{
#include <stdio.h>
}
/** Match things like "call foo;" */
r : call ID ; {printf("invoke %s
", $ID.text);} ;
ID: a .. z + ;
WS: ( |
|
)+ {$channel=HIDDEN;} ; // ignore whitespace
$ java org.antlr.Tool T.g
error(146): T.g:13:19: invalid StringTemplate % shorthand syntax: %s .
How to tell ANTLR to ignore % in this case?