ANTLRWorks 2.1: generated Lexer+Parser in Eclipse causing UUID exception

我只是一个虾纸丫 提交于 2019-12-13 01:15:18

问题


I'm new to ANTLR and ANTLRWorks, so I'm quite puzzled by this: I'm using ANTLRWorks 2.1 for grammar creation and subsequent creation of the lexer and parser (Java target). I have then created a small Eclipse project and imported the ANTLR4 jars from ANTLRWorks to manually call the lexer and parser as described in the ANTLR book examples. When running the application I get the following exception:

Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not  deserialize ATN with UUID 33761b2d-78bb-4a43-8b0b-4f5bee8aacf3 (expected e4178468-df95-44d0-ad87-f22a5d5fb6d3).
    at org.antlr.v4.runtime.atn.ATNSimulator.deserialize(ATNSimulator.java:111)
    at org.antlr.v4.runtime.atn.ATNSimulator.deserialize(ATNSimulator.java:90)
    at TestLexer.<clinit>(TestLexer.java:177)
    ... 1 more
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with UUID 33761b2d-78bb-4a43-8b0b-4f5bee8aacf3 (expected e4178468-df95-44d0-ad87-f22a5d5fb6d3).
    ... 4 more

However, when running the same grammar and input data in the ANTLRWorks TestRig, everything works fine. What is going wrong here? I have already found similar posts regarding versioning issues, however none addressing this UUID issue. Can anyone help me with this?

Thanks in advance!


回答1:


ANTLRWorks uses a non-standard build of ANTLR in order to support some of its editor features (code completion, etc.). It is designed in a way that supports proper code generation, but in order to compile and run your parser you'll need to use the reference ANTLR library from antlr.org.




回答2:


The most probable reason is that you're using different version of the antlr runtime at parser generation time and at runtime.

Make double sure you use the exact same antlr version in both cases, and the error should go away.

Disclaimer: I may be wrong, as I'm using antlr in .Net.



来源:https://stackoverflow.com/questions/24468009/antlrworks-2-1-generated-lexerparser-in-eclipse-causing-uuid-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!