语法分析程序自动生成工具JavaCUP是一个LALR Parser Generator。JavaCUP是一个类似Unix平台上yacc程序的开源软件工具,遵循GPL。JavaCUP本身采用Java编写,并且生成Java语言的分析程序源代码。(下载地址:http://www2.cs.tum.edu/projects/cup/)
笔者下载的文件是:java-cup-bin-11b-20160615.tar.gz
解压后为:java-cup-11b-runtime.jar 和 java-cup-11b.jar 两个文件
然后我就不会了,码的
将java-cup-11b.jar文件放到工作区work。
1、先写一个scanner.flex
2、再写一个parser.cup
3、CD到work工作区,使用命令:java -jar java-cup-11b.jar parser.cup
4、窗口显示:
------- CUP v0.11b 20160615 (GIT 4ac7450) Parser Generation Summary -------
0 errors and 0 warnings
12 terminals, 4 non-terminals, and 13 productions declared,
producing 24 unique parse states.
0 terminals declared but not used.
0 non-terminals declared but not used.
0 productions never reduced.
0 conflicts detected (0 expected).
Code written to "parser.java", and "sym.java".
---------------------------------------------------- (CUP v0.11b 20160615 (GIT 4ac7450))
5、写一个主函数Calc.java
6、测试用例:test.txt
7、命令:java Calc test.txt