ATN version check error, ANTLR4, Python, Visual code studio

735 views
Skip to first unread message

John Gentilin

unread,
Apr 26, 2022, 12:18:27 AM4/26/22
to antlr-discussion
I am having a problem generating and running grammar that produces Python code.

The problem is related to deserializing and failing the version check.
Here is my research on the problem,  questions are at the bottom of this message

I am using the latest Visual Code Studio with the latest Antlr4 plugin and latest pip instsalled runtime using https://github.com/virresh/ANTLR4-Example as a python example

My VSCode settings for the plugin are 
"antlr4.generation": {
"mode": "external",
"language": "Python3",
"listeners": true,
"visitors": false,
"outputDir": "./parser"
},
"antlr4.debug": {
"visualParseTreeHorizontal": true,
"visualParseTreeClustered": false
}

When I go to run my python code, the ATN deserializer is reporting that it needs version 4, this appears to be baked into the ANTLR4 runtime
It does not seem to report the version it found, but it emits this exception

Could not deserialize ATN with version (expected 4).
File "/Users/jgentilin/Projects/ANTLR/PythonExample/arithmeticLexer.py", line 28, in arithmeticLexer atn = ATNDeserializer().deserialize(serializedATN()) File "/Users/jgentilin/Projects/ANTLR/PythonExample/arithmeticLexer.py", line 26, in <module> class arithmeticLexer(Lexer): File "/Users/jgentilin/Projects/ANTLR/PythonExample/main.py", line 3, in <module> from arithmeticLexer import arithmeticLexer

if version != SERIALIZED_VERSION:
raise Exception("Could not deserialize ATN with version " + str(version) + " (expected " + str(SERIALIZED_VERSION) + ").")

Not sure why the str(version) is not bring printed unless ANTLR is not emitting the version into the ATN

It appears I can disable it by setting verifyATN to false, but haven't found docs on if I should do that or not and how to do it. 
def verifyATN(self, atn:ATN):
if not self.deserializationOptions.verifyATN:

If I don't specify mode: External, it won't listen to either the language or outputDir options and builds a Java parser in the .antlr dir

Besides the ANTLR version installed in the plugin, this version of Antlr is installed in my system.    ANTLR Parser Generator  Version 4.9.3

If I download the latest jar, store it in the bin/ directory at the root of my workspace then add

"alternativeJar": "bin/antlr-4.10.1-complete.jar",
to my settings, I get the following exception when the plugin tries to process my grammar files
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/antlr/v4/Tool, offset=6

My questions are:

  • Do I need to set the version somewhere in my code? 

  • Is there a way to have ANTLR just bake the runtime into my grammar output so I don't have to worry about versions. 

  • I am assuming this could happen again when the plugin updates but the runtime hasn't 

  • Any clue where to check next ?

Thank you

-John



Eric Vergnaud

unread,
Apr 26, 2022, 3:12:37 AM4/26/22
to 'Mike Lischke' via antlr-discussion
Hi,

you need to regenerate your parser using the latest antlr

Eric

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/136ac3c5-7cb9-4000-a464-24c80d42f309n%40googlegroups.com.

John Gentilin

unread,
Apr 26, 2022, 12:02:35 PM4/26/22
to antlr-discussion
Hi Eric,

Thank you for the response, what version of Java is required for 4.10.1 ?
If I specify an alternative jar or try to run antlr via the command line I get a unsupported class version.

java -jar antlr-4.10.1-complete.jar

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/antlr/v4/Tool, offset=6

I am running JDK 1.8 on a Mac
 java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
Eclipse OpenJ9 VM (build openj9-0.26.0, JRE 1.8.0 Mac OS X amd64-64-Bit Compressed References 20210421_909 (JIT enabled, AOT enabled)

OpenJ9 - b4cc246d9
OMR - 162e6f729
JCL - 2a5e268814 based on jdk8u292-b10)

Terence Parr

unread,
Apr 26, 2022, 3:49:22 PM4/26/22
to antlr-discussion
The 4.10.1 tool itself needs Java 11 but the runtime only needs java 8. I think that's why you're getting the crash.
Ter



--
Dictation in use. Please excuse homophones, malapropisms, and nonsense.
Reply all
Reply to author
Forward
0 new messages