一. syntax error: ‘<’ came as a complete surprise to me while matching alternative
参考这个issue,antlr版本必须得是4.6
下载链接:http://www.antlr.org/download/antlr-4.6-complete.jar
二.org.antlr.v4.analysis.LeftRecursiveRuleTransformer.setAltASTPointers(LeftRecursiveRuleTransformer.java:241)
参考这个issue,Java版本必须得是Java6/7
三. antlr4运行命令
- antlr4和grun永久配置别名
echo "alias antlr4='java -jar /usr/local/lib/antlr-4.0-complete.jar'" >> ~/.bashrc
echo "alias grun='java org.antlr.v4.runtime.misc.TestRig'" >> ~/.bashrc
- 使用antlr4生成语法分析器和词法分析器
antlr4 test.g4
- 编译生成的Java文件
javac *.java
- 使用TestRig调试
grun [Grammar] [Rule] -optionseg. grun test r -tokens
四. 各种语言的.g4文件
https://github.com/antlr/grammars-v4/tree/master