I'm trying to get a super-simple grammar working for ANTLR3 with a C++ target.
I'm finding that if I refer to any variables in my action, I get the following error:
invalid conversion from ‘const CommonTokenType* {aka const CommonToken<Traits<NlpCfgRuleAntlrLexer, NlpCfgRuleAntlrParser>>*}’ to ‘Traits<NlpCfgRuleAntlrLexer, NlpCfgRuleAntlrParser>::CommonTokenType* {aka CommonToken<Traits<NlpCfgRuleAntlrLexer, NlpCfgRuleAntlrParser>>*}’ [-fpermissive]
Here's the core part of my grammar:
def
: ID ':' {$ID.text;}
;
ID : 'a'..'z'+ ;
If I go into the generated C++ source to this line:
ImplTraits::CommonTokenType* ID1 = NULL;
... and change it to:
const ImplTraits::CommonTokenType* ID1 = NULL;
... then the compile error goes away.
Perhaps the fix is here: (?)
https://github.com/ibre5041/antlr3/commit/0c90ab8f8506a46e37f54988207cb4d6a1d2596a
If so, might I ask why super-super-super basic functionality is broken in ANTLR's C++ target?
If it's helpful to anyone else, I'm currently working around this by running a command in my Makefile to manually search and replace in the generated code:
perl -p -i -e 's/ ImplTraits::CommonTokenType\*/ const ImplTraits::CommonTokenType*/g' $(GEN)/mydir/*.cpp