I have a very long antlr4 grammar file, and recently I got into an error looking like this
Exception in thread "main" java.lang.UnsupportedOperationException: Serialized ATN data element 68939 element 11 out of range 0..65535
at org.antlr.v4.runtime.atn.ATNSerializer.serialize(ATNSerializer.java:361)
at org.antlr.v4.runtime.atn.ATNSerializer.getSerialized(ATNSerializer.java:601)
at org.antlr.v4.Tool.generateInterpreterData(Tool.java:745)
at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:400)
at org.antlr.v4.Tool.process(Tool.java:361)
at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:328)
at org.antlr.v4.Tool.main(Tool.java:172)
I have seen previous questions and it turns out this is a memory issue. I have also done a full debugging exercise and reduced the grammar until this error disappears multiple times with multiple parts of the grammar, and there doesn't appear to be any specific bit of the grammar code which is causing the error, it's just the size. As soon as I reduce the grammar below a certain size, no matter what I remove, it starts working again. So my question is: is there any way around this issue within antlr4? For example, using a computer with bigger RAM memory, specify a setting when running antlr4 that increases the max allowed grammar size, etc., or is reducing the grammar the only possible solution (short of not using antlr4 and trying a completely different parser)?