Skip to content

Instantly share code, notes, and snippets.

@virtualsafety
Last active May 10, 2022 02:09
Show Gist options
  • Save virtualsafety/9d27a62ab615c9425d830fb35a4d5b76 to your computer and use it in GitHub Desktop.
Save virtualsafety/9d27a62ab615c9425d830fb35a4d5b76 to your computer and use it in GitHub Desktop.
(一)idea配置ANTLR plugin
https://blog.dgunia.de/2017/10/26/creating-and-testing-an-antlr-parser-with-intellij-idea-or-android-studio/
https://qiita.com/kazy/items/ad99142111bba2f0e708(kotlin版)
(二)简单例子
--Hello.g4
grammar Hello;
main: 'Hello ' name '!';
name: ANY+;
ANY: .;
--Hello.kt
package antlrdemo
import com.huawei.antr.*
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.CharStreams
fun main(args: Array<String>) {
val text = "Hello world!"
val source = CharStreams.fromString(text)
val lexer = HelloLexer(source)
val tokenStream = CommonTokenStream(lexer)
val parser = HelloParser(tokenStream)
val name = parser.main().name().text
println(name)
}
(三)问题
(1)Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with UUID 59627784-3be5-417a-b9eb-8131a7286089 (expected aadb8d7e-aeef-4415-ad2b-8204d6cf042e or a legacy UUID).
ANTLR plugin版本和项目中maven依赖的antlr版本不一致
https://www.cnblogs.com/dsj2016/p/9575712.html
@virtualsafety
Copy link
Author

An arithmetic expressions evaluator with Kotlin and ANTLR4
https://flavluc.github.io/blog/kotlin-antlr/

@virtualsafety
Copy link
Author

ANTLR4 Language Target, Runtime for Go
https://github.com/antlr/antlr4/blob/master/doc/go-target.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment