-
-
Save virtualsafety/9d27a62ab615c9425d830fb35a4d5b76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(一)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 |
WS
: [ \t\r\n] + -> channel(HIDDEN)
;
将词法符号送入不同通道
https://blog.csdn.net/pourtheworld/article/details/108293630
https://blog.csdn.net/pourtheworld/article/details/108430250
An arithmetic expressions evaluator with Kotlin and ANTLR4
https://flavluc.github.io/blog/kotlin-antlr/
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
https://stackoverflow.com/questions/41180399/modify-expressions-generated-by-antlr
https://stackoverflow.com/questions/2228810/how-can-i-modify-the-text-of-tokens-in-a-commontokenstream-with-antlr
重写输入流
https://www.bookstack.cn/read/antlr4-short-course/rewriting-input-stream.md
https://www.antlr.org/api/Java/org/antlr/v4/runtime/TokenStreamRewriter.html