Antlr4 安装
linux中安装:
我是在ubuntu-22.04-live-server-amd64中安装的
使用命令行工具下载antlr-4.7.1-complete.jar:
$ curl -O https://www.antlr.org/download/antlr-4.7.1-complete.jar
测试下ANTLR工具是否工作正常:
$ java -jar antlr-4.7.1-complete.jar
如果正常的话会看到以下帮助信息:
ANTLR Parser Generator Version 4.7.1
-o ___ specify output directory where all output is generated
-lib ___ specify location of grammars, tokens files
-atn generate rule augmented transition network diagrams
-encoding ___ specify grammar file encoding; e.g., euc-jp
-message-format ___ specify output style for messages in antlr, gnu, vs2005
-long-messages show exception details when available for errors and warnings
-listener generate parse tree listener (default)
-no-listener don't generate parse tree listener
-visitor generate parse tree visitor
-no-visitor don't generate parse tree visitor (default)
-package ___ specify a package/namespace for the generated code
-depend generate file dependencies
-D<option>=value set/override a grammar-level option
-Werror treat warnings as errors
-XdbgST launch StringTemplate visualizer on generated code
-XdbgSTWait wait for STViz to close before continuing
-Xforce-atn use the ATN simulator for all predictions
-Xlog dump lots of logging info to antlr-timestamp.log
-Xexact-output-dir all output goes into -o dir regardless of paths/package
之后简明教程中写个脚本来避免每次运行都要写这一长串代码
$ vim antlr
#!/bin/sh
java -cp antlr-4.7.1-complete.jar org.antlr.v4.Tool $*
运行
$ ./antlr
但这里antlr没有执行的权限,会告诉你Permission denied
我们也可以
使用
$ ls -al
查看文件的权限
所以要给他执行权限
使用
chmod +777 antlr
777代表,user,group ,others ,都有读写和可执行权限。
也可以+755
755 代表用户对该文件拥有读,写,执行的权限,同组其他人员拥有执行和读的权限,没有写的权限,其他用户的权限和同组人员权限一样。
windows安装Antlr4
windows安装比较方便,我是在IDEA2022.1.3中安装的,在在File—Settings—Plugins中直接就有对应的插件,安装即可
参考Antlr4的简明教程(linux安装参考):安装ANTLR