The situation: We are porting our old simulation platform for math/physics/CS popularization MobiNet from C++ to online JS. At that time the MobiNet language was dealt using Antlr 2.7.3.
calc.g
to directly work in Antlr4? (I'm afraid by the suffix renamed .g4). Note: We have no energy for re-design, just porting, and already many aspects to deal with.
Q1: As Lex also pointed out, no, the original grammar won't work.
Q2:
Upgrading from ANTLR 2 to ANTLR 4 can be a tedious task depending on lots of small details. In your calc.g
, the parser rules do not seem to be so complex, but you have to know that the concepts of the parsing technology changed from ANTLR 2 to ANTLR 3 (LL(k)
to LL(*)
, see details here) and also from ANTLR 3 to ANTLR 4 (LL(*)
to AdaptiveLL(*)
, details here). If you use the AST generation, it has changed a lot too.
Also, you'll have to change the target from C++ and rewrite the actions anyway.
Q3: Upgrading from ANTLR 2 to ANTLR 3 is probably easier and might solve your migration issue. But it is another question if it's really worth spending time on upgrading to ANTLR 3 (and then, maybe, upgrade to another version later), or spending some (probably more) time on upgrading directly to ANTLR 4.