问题描述
我是ANTLR和ANTLRWorks的新手,所以我对此感到很困惑:我正在使用ANTLRWorks 2.1进行语法创建以及随后的词法分析器和解析器(Java目标)的创建.然后,我创建了一个小的Eclipse项目,并从ANTLRWorks导入了ANTLR4 jar,以手动调用词法分析器和解析器,如ANTLR书籍示例中所述.运行应用程序时,出现以下异常:
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
但是,当在ANTLRWorks TestRig中运行相同的语法并输入数据时,一切正常.这是怎么了?我已经找到有关版本问题的类似帖子,但是都没有解决此UUID问题.有人可以帮我吗?
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?
提前谢谢!
推荐答案
ANTLRWorks使用非标准版本的ANTLR,以支持其某些编辑器功能(代码完成等).它的设计方式支持正确的代码生成,但是为了编译和运行解析器,您需要使用 antlr.org .
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.
这篇关于ANTLRWorks 2.1:在Eclipse中生成Lexer + Parser导致UUID异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!