├── docus ├── lab0.md ├── LLVM.pdf ├── SysY语言定义.pdf ├── lab4及后续实验环境搭建.pdf ├── IDEA导入ANTLR包的方式.pdf ├── images │ ├── Lab5-Scope.png │ ├── Lab5-Scpoe.png │ ├── image-20221219201711996.png │ └── Lab5-Scope-1672913283336-4.png ├── lab5 │ └── Lab5-Scope-1672913283336-4.png ├── lab5.md ├── lab6.md ├── lab1.md ├── lab4.md ├── lab8.md ├── lab7.md ├── lab2.md └── lab3.md ├── tests ├── lab4-test2.sysy ├── lab1-test2.sysy ├── lab4-test1.sysy ├── lab2-test2.sysy ├── lab5-test2.sysy ├── lab2-test1.sysy ├── lab1-test1.sysy ├── lab7-test2.sysy ├── lab6-test2.sysy ├── lab6-test1.sysy ├── lab3-rename-test.sysy ├── lab5-test1.sysy ├── lab8-test1.sysy ├── lab3-type-test1.sysy ├── lab7-test1.sysy ├── lab8-test2.sysy ├── lab3-type-test2.sysy ├── lab8-test1.out └── lab8-test2.out ├── src ├── Type │ ├── Type.java │ ├── ArrayType.java │ └── FunctionType.java ├── Scope │ ├── LocalScope.java │ ├── GlobalScope.java │ ├── Scope.java │ ├── FunctionScope.java │ └── BaseScope.java ├── Symbol │ ├── BasicTypeSymbol.java │ ├── VariableSymbol.java │ ├── Symbol.java │ └── BaseSymbol.java ├── SysYLexer.tokens ├── SysYParser.tokens ├── gen │ ├── SysYLexer.tokens │ └── SysYLexer.interp ├── SysYLexer.g4 ├── Main.java ├── SysYParser.g4 ├── SysYLexer.interp ├── SysYParserVisitor.java ├── SysYParser.interp ├── SysYLexer.java ├── SysYParserBaseVisitor.java └── SysYParserBaseListener.java ├── .metals ├── metals.log ├── metals.mv.db └── metals.lock.db ├── classes ├── Main.class ├── Type.class ├── Scope.class ├── Symbol.class ├── ArrayType.class ├── BaseScope.class ├── SysYLexer.class ├── Visitor.class ├── BaseSymbol.class ├── GlobalScope.class ├── LocalScope.class ├── SysYParser.class ├── FunctionSymbol.class ├── FunctionType.class ├── VariableSymbol.class ├── BasicTypeSymbol.class ├── SysYParserListener.class ├── SysYParserVisitor.class ├── MyLexerErrorListener.class ├── MyParserErrorListener.class ├── SysYParser$ExpContext.class ├── SysYParserBaseVisitor.class ├── SysYParser$BTypeContext.class ├── SysYParser$BlockContext.class ├── SysYParser$CondContext.class ├── SysYParser$DeclContext.class ├── SysYParser$LValContext.class ├── SysYParser$NumberContext.class ├── SysYParser$ParamContext.class ├── SysYParser$StmtContext.class ├── SysYParser$VarDefContext.class ├── SysYParserBaseListener.class ├── SysYParser$CompUnitContext.class ├── SysYParser$ConstDefContext.class ├── SysYParser$ConstExpContext.class ├── SysYParser$FuncDefContext.class ├── SysYParser$FuncTypeContext.class ├── SysYParser$InitValContext.class ├── SysYParser$ProgramContext.class ├── SysYParser$UnaryOpContext.class ├── SysYParser$VarDeclContext.class ├── SysYParser$BlockItemContext.class ├── SysYParser$ConstDeclContext.class ├── SysYParser$FuncFParamContext.class ├── SysYParser$FuncFParamsContext.class ├── SysYParser$FuncRParamsContext.class └── SysYParser$ConstInitValContext.class ├── nohup.out ├── .vscode └── settings.json ├── target └── classes │ ├── Main.class │ ├── Visitor.class │ ├── SysYLexer.class │ ├── Type │ ├── Type.class │ ├── ArrayType.class │ └── FunctionType.class │ ├── Scope │ ├── Scope.class │ ├── BaseScope.class │ ├── GlobalScope.class │ ├── LocalScope.class │ └── FunctionScope.class │ ├── SysYParser.class │ ├── LLVMIRVisitor.class │ ├── Symbol │ ├── Symbol.class │ ├── BaseSymbol.class │ ├── BasicTypeSymbol.class │ └── VariableSymbol.class │ ├── SysYParserVisitor.class │ ├── SysYParserListener.class │ ├── SysYParser$CondContext.class │ ├── SysYParser$DeclContext.class │ ├── SysYParser$ExpContext.class │ ├── SysYParser$LValContext.class │ ├── SysYParser$StmtContext.class │ ├── SysYParserBaseListener.class │ ├── SysYParserBaseVisitor.class │ ├── SysYParser$AddExpContext.class │ ├── SysYParser$AndExpContext.class │ ├── SysYParser$BTypeContext.class │ ├── SysYParser$BlockContext.class │ ├── SysYParser$IfStmtContext.class │ ├── SysYParser$MulExpContext.class │ ├── SysYParser$NumExpContext.class │ ├── SysYParser$NumberContext.class │ ├── SysYParser$OrExpContext.class │ ├── SysYParser$ParamContext.class │ ├── SysYParser$VarDefContext.class │ ├── SysYParser$BlockItemContext.class │ ├── SysYParser$BlockStmtContext.class │ ├── SysYParser$BreakStmtContext.class │ ├── SysYParser$CompUnitContext.class │ ├── SysYParser$CondExpContext.class │ ├── SysYParser$ConstDeclContext.class │ ├── SysYParser$ConstDefContext.class │ ├── SysYParser$ConstExpContext.class │ ├── SysYParser$FuncDefContext.class │ ├── SysYParser$FuncTypeContext.class │ ├── SysYParser$InitValContext.class │ ├── SysYParser$LValExpContext.class │ ├── SysYParser$ParenExpContext.class │ ├── SysYParser$ProgramContext.class │ ├── SysYParser$UnaryExpContext.class │ ├── SysYParser$UnaryOpContext.class │ ├── SysYParser$VarDeclContext.class │ ├── SysYParser$WhileStmtContext.class │ ├── SysYParser$AssignmentContext.class │ ├── SysYParser$CompareExpContext.class │ ├── SysYParser$FuncCallExpContext.class │ ├── SysYParser$FuncFParamContext.class │ ├── SysYParser$FuncFParamsContext.class │ ├── SysYParser$FuncRParamsContext.class │ ├── SysYParser$PossibleExpContext.class │ ├── SysYParser$RelationExpContext.class │ ├── SysYParser$ReturnStmtContext.class │ ├── SysYParser$ConstInitValContext.class │ └── SysYParser$ContinueStmtContext.class ├── .idea ├── .idea │ ├── codeStyles │ │ ├── codeStyleConfig.xml │ │ └── Project.xml │ ├── misc.xml │ ├── .gitignore │ ├── modules.xml │ ├── .idea.iml │ └── workspace.xml ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── .gitignore ├── markdown.xml ├── modules.xml ├── encodings.xml ├── libraries │ ├── antlr_4_9_1_complete.xml │ ├── Maven__org_bytedeco_javacpp_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_ios_arm64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_linux_x86_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_ios_x86_64_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_android_arm_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_android_x86_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_linux_arm64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_linux_armhf_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_linux_x86_64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_macosx_arm64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_windows_x86_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_android_arm64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_android_x86_64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_linux_ppc64le_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_macosx_x86_64_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_windows_x86_64_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_linux_x86_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_linux_arm64_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_linux_armhf_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_windows_x86_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_javacpp_platform_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_linux_ppc64le_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_linux_x86_64_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_macosx_arm64_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_macosx_x86_64_13_0_1_1_5_7.xml │ ├── Maven__org_bytedeco_llvm_windows_x86_64_13_0_1_1_5_7.xml │ └── Maven__org_bytedeco_llvm_platform_13_0_1_1_5_7.xml ├── misc.xml ├── remote-targets.xml ├── compiler.xml ├── inspectionProfiles │ └── Project_Default.xml ├── jarRepositories.xml └── uiDesigner.xml ├── .gitignore ├── Makefile.git ├── pom.xml ├── README.md ├── LICENSE ├── submit.sh ├── Makefile └── Lab.iml /docus/lab0.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab0 实验报告 2 | -------------------------------------------------------------------------------- /tests/lab4-test2.sysy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | return 3+2*5; 3 | } 4 | -------------------------------------------------------------------------------- /src/Type/Type.java: -------------------------------------------------------------------------------- 1 | package Type; 2 | 3 | public interface Type { 4 | } -------------------------------------------------------------------------------- /tests/lab1-test2.sysy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int i = 1; 3 | int j = ~i; 4 | } 5 | -------------------------------------------------------------------------------- /tests/lab4-test1.sysy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | return -2147483647 / -1; 3 | } 4 | -------------------------------------------------------------------------------- /tests/lab2-test2.sysy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int a[]; 3 | return a][; 4 | } 5 | -------------------------------------------------------------------------------- /docus/LLVM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/LLVM.pdf -------------------------------------------------------------------------------- /tests/lab5-test2.sysy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int a[3] = {1,2,3}; 3 | return a[1]; 4 | } 5 | -------------------------------------------------------------------------------- /.metals/metals.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/.metals/metals.log -------------------------------------------------------------------------------- /classes/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/Main.class -------------------------------------------------------------------------------- /classes/Type.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/Type.class -------------------------------------------------------------------------------- /docus/SysY语言定义.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/SysY语言定义.pdf -------------------------------------------------------------------------------- /nohup.out: -------------------------------------------------------------------------------- 1 | Error type B at Line 5: mismatched input '' expecting {'const', 'int', 'void'} 2 | -------------------------------------------------------------------------------- /.metals/metals.mv.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/.metals/metals.mv.db -------------------------------------------------------------------------------- /classes/Scope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/Scope.class -------------------------------------------------------------------------------- /classes/Symbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/Symbol.class -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.watcherExclude": { 3 | "**/target": true 4 | } 5 | } -------------------------------------------------------------------------------- /classes/ArrayType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/ArrayType.class -------------------------------------------------------------------------------- /classes/BaseScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/BaseScope.class -------------------------------------------------------------------------------- /classes/SysYLexer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYLexer.class -------------------------------------------------------------------------------- /classes/Visitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/Visitor.class -------------------------------------------------------------------------------- /docus/lab4及后续实验环境搭建.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/lab4及后续实验环境搭建.pdf -------------------------------------------------------------------------------- /classes/BaseSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/BaseSymbol.class -------------------------------------------------------------------------------- /classes/GlobalScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/GlobalScope.class -------------------------------------------------------------------------------- /classes/LocalScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/LocalScope.class -------------------------------------------------------------------------------- /classes/SysYParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser.class -------------------------------------------------------------------------------- /docus/IDEA导入ANTLR包的方式.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/IDEA导入ANTLR包的方式.pdf -------------------------------------------------------------------------------- /target/classes/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Main.class -------------------------------------------------------------------------------- /classes/FunctionSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/FunctionSymbol.class -------------------------------------------------------------------------------- /classes/FunctionType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/FunctionType.class -------------------------------------------------------------------------------- /classes/VariableSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/VariableSymbol.class -------------------------------------------------------------------------------- /docus/images/Lab5-Scope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/images/Lab5-Scope.png -------------------------------------------------------------------------------- /docus/images/Lab5-Scpoe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/images/Lab5-Scpoe.png -------------------------------------------------------------------------------- /target/classes/Visitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Visitor.class -------------------------------------------------------------------------------- /classes/BasicTypeSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/BasicTypeSymbol.class -------------------------------------------------------------------------------- /target/classes/SysYLexer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYLexer.class -------------------------------------------------------------------------------- /target/classes/Type/Type.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Type/Type.class -------------------------------------------------------------------------------- /classes/SysYParserListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParserListener.class -------------------------------------------------------------------------------- /classes/SysYParserVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParserVisitor.class -------------------------------------------------------------------------------- /target/classes/Scope/Scope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Scope/Scope.class -------------------------------------------------------------------------------- /target/classes/SysYParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser.class -------------------------------------------------------------------------------- /classes/MyLexerErrorListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/MyLexerErrorListener.class -------------------------------------------------------------------------------- /classes/MyParserErrorListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/MyParserErrorListener.class -------------------------------------------------------------------------------- /classes/SysYParser$ExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ExpContext.class -------------------------------------------------------------------------------- /classes/SysYParserBaseVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParserBaseVisitor.class -------------------------------------------------------------------------------- /target/classes/LLVMIRVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/LLVMIRVisitor.class -------------------------------------------------------------------------------- /target/classes/Symbol/Symbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Symbol/Symbol.class -------------------------------------------------------------------------------- /target/classes/Type/ArrayType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Type/ArrayType.class -------------------------------------------------------------------------------- /tests/lab2-test1.sysy: -------------------------------------------------------------------------------- 1 | const int c = 10; 2 | int main() { 3 | int a = 0x10; 4 | const int b = 9; 5 | return a; 6 | } 7 | -------------------------------------------------------------------------------- /classes/SysYParser$BTypeContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$BTypeContext.class -------------------------------------------------------------------------------- /classes/SysYParser$BlockContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$BlockContext.class -------------------------------------------------------------------------------- /classes/SysYParser$CondContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$CondContext.class -------------------------------------------------------------------------------- /classes/SysYParser$DeclContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$DeclContext.class -------------------------------------------------------------------------------- /classes/SysYParser$LValContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$LValContext.class -------------------------------------------------------------------------------- /classes/SysYParser$NumberContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$NumberContext.class -------------------------------------------------------------------------------- /classes/SysYParser$ParamContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ParamContext.class -------------------------------------------------------------------------------- /classes/SysYParser$StmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$StmtContext.class -------------------------------------------------------------------------------- /classes/SysYParser$VarDefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$VarDefContext.class -------------------------------------------------------------------------------- /classes/SysYParserBaseListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParserBaseListener.class -------------------------------------------------------------------------------- /target/classes/Scope/BaseScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Scope/BaseScope.class -------------------------------------------------------------------------------- /target/classes/Scope/GlobalScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Scope/GlobalScope.class -------------------------------------------------------------------------------- /target/classes/Scope/LocalScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Scope/LocalScope.class -------------------------------------------------------------------------------- /target/classes/Symbol/BaseSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Symbol/BaseSymbol.class -------------------------------------------------------------------------------- /target/classes/SysYParserVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParserVisitor.class -------------------------------------------------------------------------------- /target/classes/Type/FunctionType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Type/FunctionType.class -------------------------------------------------------------------------------- /tests/lab1-test1.sysy: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | // line comment 4 | /* 5 | block comment 6 | */ 7 | int i = 0x1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/lab7-test2.sysy: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | while (2 || 3 && 4 || !0) { 4 | break; 5 | continue; 6 | } 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /classes/SysYParser$CompUnitContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$CompUnitContext.class -------------------------------------------------------------------------------- /classes/SysYParser$ConstDefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ConstDefContext.class -------------------------------------------------------------------------------- /classes/SysYParser$ConstExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ConstExpContext.class -------------------------------------------------------------------------------- /classes/SysYParser$FuncDefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$FuncDefContext.class -------------------------------------------------------------------------------- /classes/SysYParser$FuncTypeContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$FuncTypeContext.class -------------------------------------------------------------------------------- /classes/SysYParser$InitValContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$InitValContext.class -------------------------------------------------------------------------------- /classes/SysYParser$ProgramContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ProgramContext.class -------------------------------------------------------------------------------- /classes/SysYParser$UnaryOpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$UnaryOpContext.class -------------------------------------------------------------------------------- /classes/SysYParser$VarDeclContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$VarDeclContext.class -------------------------------------------------------------------------------- /docus/images/image-20221219201711996.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/images/image-20221219201711996.png -------------------------------------------------------------------------------- /target/classes/Scope/FunctionScope.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Scope/FunctionScope.class -------------------------------------------------------------------------------- /target/classes/SysYParserListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParserListener.class -------------------------------------------------------------------------------- /classes/SysYParser$BlockItemContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$BlockItemContext.class -------------------------------------------------------------------------------- /classes/SysYParser$ConstDeclContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ConstDeclContext.class -------------------------------------------------------------------------------- /classes/SysYParser$FuncFParamContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$FuncFParamContext.class -------------------------------------------------------------------------------- /classes/SysYParser$FuncFParamsContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$FuncFParamsContext.class -------------------------------------------------------------------------------- /classes/SysYParser$FuncRParamsContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$FuncRParamsContext.class -------------------------------------------------------------------------------- /docus/images/Lab5-Scope-1672913283336-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/images/Lab5-Scope-1672913283336-4.png -------------------------------------------------------------------------------- /docus/lab5/Lab5-Scope-1672913283336-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/docus/lab5/Lab5-Scope-1672913283336-4.png -------------------------------------------------------------------------------- /target/classes/Symbol/BasicTypeSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Symbol/BasicTypeSymbol.class -------------------------------------------------------------------------------- /target/classes/Symbol/VariableSymbol.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/Symbol/VariableSymbol.class -------------------------------------------------------------------------------- /target/classes/SysYParser$CondContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$CondContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$DeclContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$DeclContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$LValContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$LValContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$StmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$StmtContext.class -------------------------------------------------------------------------------- /target/classes/SysYParserBaseListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParserBaseListener.class -------------------------------------------------------------------------------- /target/classes/SysYParserBaseVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParserBaseVisitor.class -------------------------------------------------------------------------------- /classes/SysYParser$ConstInitValContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/classes/SysYParser$ConstInitValContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$AddExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$AddExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$AndExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$AndExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$BTypeContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$BTypeContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$BlockContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$BlockContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$IfStmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$IfStmtContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$MulExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$MulExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$NumExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$NumExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$NumberContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$NumberContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$OrExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$OrExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ParamContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ParamContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$VarDefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$VarDefContext.class -------------------------------------------------------------------------------- /tests/lab6-test2.sysy: -------------------------------------------------------------------------------- 1 | int a[10] = {}; 2 | 3 | int f(int a) { 4 | return 0; 5 | } 6 | 7 | int main() { 8 | a[1] = 1; 9 | return 0; 10 | } -------------------------------------------------------------------------------- /target/classes/SysYParser$BlockItemContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$BlockItemContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$BlockStmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$BlockStmtContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$BreakStmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$BreakStmtContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$CompUnitContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$CompUnitContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$CondExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$CondExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ConstDeclContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ConstDeclContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ConstDefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ConstDefContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ConstExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ConstExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$FuncDefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$FuncDefContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$FuncTypeContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$FuncTypeContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$InitValContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$InitValContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$LValExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$LValExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ParenExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ParenExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ProgramContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ProgramContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$UnaryExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$UnaryExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$UnaryOpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$UnaryOpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$VarDeclContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$VarDeclContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$WhileStmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$WhileStmtContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$AssignmentContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$AssignmentContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$CompareExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$CompareExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$FuncCallExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$FuncCallExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$FuncFParamContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$FuncFParamContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$FuncFParamsContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$FuncFParamsContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$FuncRParamsContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$FuncRParamsContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$PossibleExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$PossibleExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$RelationExpContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$RelationExpContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ReturnStmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ReturnStmtContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ConstInitValContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ConstInitValContext.class -------------------------------------------------------------------------------- /target/classes/SysYParser$ContinueStmtContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/HEAD/target/classes/SysYParser$ContinueStmtContext.class -------------------------------------------------------------------------------- /tests/lab6-test1.sysy: -------------------------------------------------------------------------------- 1 | int a[3] = { 0,1,1 }; 2 | int main() { 3 | a[0] = !a[0]; 4 | if (a[0]) { 5 | a[1] = 2; 6 | } 7 | return a[1]; 8 | } 9 | -------------------------------------------------------------------------------- /tests/lab3-rename-test.sysy: -------------------------------------------------------------------------------- 1 | int a() { 2 | return 10; 3 | } 4 | 5 | int main() { 6 | int a = 3; 7 | int b = 4; 8 | a = 5; 9 | return a; 10 | } 11 | -------------------------------------------------------------------------------- /.metals/metals.lock.db: -------------------------------------------------------------------------------- 1 | #FileLock 2 | #Sat Dec 17 21:21:00 CST 2022 3 | server=localhost\:7811 4 | hostName=localhost 5 | method=file 6 | id=185203ebdccf1242df8951ff89375be88921aaf346a 7 | -------------------------------------------------------------------------------- /.idea/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Scope/LocalScope.java: -------------------------------------------------------------------------------- 1 | package Scope; 2 | 3 | public class LocalScope extends BaseScope { 4 | public LocalScope(Scope enclosingScope) { 5 | super("Scope.Scope.LocalScope", enclosingScope); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /src/Scope/GlobalScope.java: -------------------------------------------------------------------------------- 1 | package Scope; 2 | 3 | import Symbol.BasicTypeSymbol; 4 | 5 | public class GlobalScope extends BaseScope { 6 | public GlobalScope(Scope enclosingScope) { 7 | super("Scope.Scope.GlobalScope", enclosingScope); 8 | } 9 | } -------------------------------------------------------------------------------- /.idea/markdown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /src/SysYLexer.java 2 | /src/SysYParser.java 3 | /src/SysYParserBaseListener.java 4 | /src/SysYParserBaseVisitor.java 5 | /src/SysYParserListener.java 6 | /src/SysYParserVisitor.java 7 | /classes 8 | /target 9 | .DS_Store 10 | /out 11 | /pom.xml 12 | /tests 13 | *.log -------------------------------------------------------------------------------- /.idea/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/libraries/antlr_4_9_1_complete.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Symbol/BasicTypeSymbol.java: -------------------------------------------------------------------------------- 1 | package Symbol; 2 | import Type.*; 3 | 4 | public class BasicTypeSymbol extends BaseSymbol implements Type { 5 | public BasicTypeSymbol(String name) { 6 | super(name, null); 7 | } 8 | 9 | @Override 10 | public String toString() { 11 | return name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/lab5-test1.sysy: -------------------------------------------------------------------------------- 1 | int f(int i){ 2 | return i; 3 | } 4 | 5 | void g() { 6 | int j = 1 + 5; 7 | return; 8 | } 9 | 10 | void func() { 11 | } 12 | 13 | int main(){ 14 | int a = 1; 15 | int array[5] = {1, 2, 3}; 16 | array[3] = a; 17 | array[4] = a + 5; 18 | g(); 19 | return f(a * array[4]); 20 | } 21 | -------------------------------------------------------------------------------- /src/Symbol/VariableSymbol.java: -------------------------------------------------------------------------------- 1 | package Symbol; 2 | 3 | import Symbol.BaseSymbol; 4 | import org.bytedeco.llvm.LLVM.LLVMTypeRef; 5 | import org.bytedeco.llvm.LLVM.LLVMValueRef; 6 | 7 | public class VariableSymbol extends BaseSymbol { 8 | public VariableSymbol(String name, LLVMTypeRef type) { 9 | super(name, type); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/lab8-test1.sysy: -------------------------------------------------------------------------------- 1 | int global_arr[20] = {1, 2, 3}; 2 | const int const_global_arr[5] = {0}; 3 | 4 | void g(int a[]) { 5 | } 6 | 7 | int f(int a[]) { 8 | if (a[0] == 0) { 9 | return 1; 10 | } else { 11 | return 2; 12 | } 13 | } 14 | 15 | int main() { 16 | int local_arr[5] = {f(global_arr), f(const_global_arr)}; 17 | return f(local_arr); 18 | } 19 | -------------------------------------------------------------------------------- /tests/lab3-type-test1.sysy: -------------------------------------------------------------------------------- 1 | int a(){ 2 | return 1; 3 | } 4 | 5 | int a(){ 6 | return 0; 7 | } 8 | 9 | int main(){ 10 | b = c(); 11 | int test1; 12 | int test1; 13 | int array[2] = {0,0}; 14 | test1 = array; 15 | test1 = a + array; 16 | test1 = a(1); 17 | test1 = test1[0]; 18 | test1(); 19 | a = 1; 20 | return a; 21 | } 22 | -------------------------------------------------------------------------------- /.idea/.idea/.idea.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Type/ArrayType.java: -------------------------------------------------------------------------------- 1 | package Type; 2 | 3 | public class ArrayType implements Type { 4 | public Type elementType; 5 | int elementCount; 6 | 7 | public ArrayType(int elementCount, Type elementType) { 8 | this.elementCount = elementCount; 9 | this.elementType = elementType; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return "array(" + elementType + ")"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docus/lab5.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab5 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 函数定义与调用 8 | 1. 局部变量 9 | 10 | ## 实验设计 11 | 12 | 本次实验参照助教在文档中的提示,对符号表做了如下设计。注意本次实验中符号表不再依赖 `Symbol` 和 `Type` 包,而是直接存储 `String` 对 `LLVMValueRef` 的映射。 13 | 14 | ![](lab5/Lab5-Scope-1672913283336-4.png) 15 | 16 | 本次实验重新设计了 `LLVMVisitor` 类。 17 | 18 | ## 实验困难 19 | 20 | 试验过程中笔者通过和王星云同学交流掌握了部分 API 的使用方法。笔者向助教求助解决了 `expected instruction opcode` 的测试用例报错问题。 21 | -------------------------------------------------------------------------------- /src/Symbol/Symbol.java: -------------------------------------------------------------------------------- 1 | package Symbol; 2 | 3 | import org.antlr.v4.runtime.misc.Pair; 4 | import org.bytedeco.llvm.LLVM.LLVMTypeRef; 5 | import org.bytedeco.llvm.LLVM.LLVMValueRef; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public interface Symbol { 11 | 12 | String getName(); 13 | 14 | void addUsage(int lineNo, int columnNo); 15 | 16 | boolean findUsage(int lineNo, int columnNo); 17 | 18 | LLVMTypeRef getType(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/lab7-test1.sysy: -------------------------------------------------------------------------------- 1 | int a[10]={5,4,3,2,1,8,6,2,4,7}; 2 | 3 | int main(){ 4 | int i=0,j=0; 5 | int min=0; 6 | while(i<9){ 7 | j=i; 8 | min=i; 9 | while(j<9){ 10 | if(a[j] 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Makefile.git: -------------------------------------------------------------------------------- 1 | STUID = 201250172 2 | STUNAME = 熊丘桓 3 | 4 | # DO NOT modify the following code!!! 5 | 6 | GITFLAGS = -q --author='tracer-compiler2022 ' --no-verify --allow-empty 7 | 8 | # prototype: git_commit(msg) 9 | define git_commit 10 | -@git add . -A --ignore-errors 11 | -@while (test -e .git/index.lock); do sleep 0.1; done 12 | -@(echo "> $(1)" && echo $(STUID) && id -un && uname -a && uptime && (head -c 20 /dev/urandom | hexdump -v -e '"%02x"') && echo) | git commit -F - $(GITFLAGS) 13 | -@sync 14 | endef 15 | -------------------------------------------------------------------------------- /src/Scope/Scope.java: -------------------------------------------------------------------------------- 1 | package Scope; 2 | 3 | import java.util.Map; 4 | 5 | import org.bytedeco.llvm.LLVM.LLVMTypeRef; 6 | import org.bytedeco.llvm.LLVM.LLVMValueRef; 7 | 8 | public interface Scope { 9 | String getScopeName(); 10 | 11 | void setScopeName(String scopeName); 12 | 13 | Scope getEnclosingScope(); 14 | 15 | Map getValueRef(); 16 | 17 | void define(String name, LLVMValueRef llvmValueRef, LLVMTypeRef llvmTypeRef); 18 | 19 | LLVMValueRef resolve(String name); 20 | 21 | LLVMTypeRef getType(String name); 22 | } 23 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_ios_arm64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_linux_x86_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_ios_x86_64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_android_arm_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_android_x86_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_linux_arm64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_linux_armhf_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_linux_x86_64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_macosx_arm64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_windows_x86_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_android_arm64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_android_x86_64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_linux_ppc64le_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_macosx_x86_64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_windows_x86_64_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_linux_x86_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_linux_arm64_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_linux_armhf_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_windows_x86_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_javacpp_platform_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_linux_ppc64le_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_linux_x86_64_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_macosx_arm64_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_macosx_x86_64_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_windows_x86_64_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /docus/lab6.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab6 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 全局变量声明和使用 8 | 1. 条件语句 9 | 10 | ## 实验设计 11 | 12 | 本次实验重新设计了 `LLVMVisitor` 类,其中全局变量相关内容主要是对 `visitVarDecl` 方法的修改。 13 | 14 | ## 实验困难 15 | 16 | 笔者实验过程中被三个困难的测试用例,报错信息如下: 17 | 18 | ``` 19 | hardtest1.sy:0(Aborted (core dumped) ) 20 | hardtest2.sy:0(Aborted (core dumped) ) 21 | hardtest3.sy:0(Aborted (core dumped) ) 22 | ``` 23 | 24 | 和顾龙助教沟通后,构建了引发错误的测试用例: 25 | 26 | ``` 27 | int a[10] = {}; 28 | 29 | int f(int a) { 30 | return 0; 31 | } 32 | 33 | int main() { 34 | a[1] = 1; 35 | return 0; 36 | } 37 | ``` 38 | 39 | 通过输出日志发现,函数参数 `a` 被定义在了全局作用域内,这是 `visitFuncDef` 方法当中的疏忽所致,修复了该 bug 后完成了本次实验。 40 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bytedeco_llvm_platform_13_0_1_1_5_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Type/FunctionType.java: -------------------------------------------------------------------------------- 1 | package Type; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class FunctionType implements Type { 6 | Type retType; 7 | ArrayList paramsType; 8 | 9 | public FunctionType(Type retType, ArrayList paramsType) { 10 | this.retType = retType; 11 | this.paramsType = paramsType; 12 | } 13 | 14 | public Type getRetType() { 15 | return retType; 16 | } 17 | 18 | public ArrayList getParamsType() { 19 | return paramsType; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | StringBuilder ret = new StringBuilder(retType + "("); 25 | for (Type type : paramsType) { 26 | ret.append(type.toString()); 27 | } 28 | ret.append(")"); 29 | return ret.toString(); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /docus/lab1.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab1 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 对 SysY 语言进行词法分析并报告错误的词法单元位置 8 | 2. 对不同进制的字面整型值进行转换 9 | 10 | ## 实验困难 11 | 12 | 实验所遇到的最大困难是使用 `make antlr` 时报错: 13 | 14 | ```bash 15 | eaglebear2002@EagleBear2002-HP:/mnt/c/Users/37756/Documents/NJU/2022Fall/Compilers/Lab$ make antlr 16 | java -jar /usr/local/lib/antlr-*-complete.jar -listener -visitor -long-messages ./src/SysYLexer.g4 17 | error(99): ./src/SysYLexer.g4::: grammar SysYLexer has no non-fragment rules 18 | make: *** [Makefile:32: antlr] Error 1 19 | ``` 20 | 21 | 笔者不理解该报错信息,反复检查词法规约,确认无误后在 Google 等搜索引擎需求帮助,未果。 22 | 23 | 笔者在检查项目目录时发现了问题所在: 24 | 25 | 笔者使用命令行编译项目在 `out` 目录中得到了 `SysYLexer.g4` 文件,并无意中注释掉该文件中所有词法规约内容。笔者之后未更改 `out/SysYLexer.g4` 内容,而是在修改 `src/SysYLexer.g4`。后面使用命令行编译时,系统总是默认先对 `out/SysYLexer.g4` 进行编译。 26 | 27 | 笔者删掉 `./out` 目录后解决了这一困难。 -------------------------------------------------------------------------------- /.idea/remote-targets.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | -------------------------------------------------------------------------------- /src/SysYLexer.tokens: -------------------------------------------------------------------------------- 1 | CONST=1 2 | INT=2 3 | VOID=3 4 | IF=4 5 | ELSE=5 6 | WHILE=6 7 | BREAK=7 8 | CONTINUE=8 9 | RETURN=9 10 | PLUS=10 11 | MINUS=11 12 | MUL=12 13 | DIV=13 14 | MOD=14 15 | ASSIGN=15 16 | EQ=16 17 | NEQ=17 18 | LT=18 19 | GT=19 20 | LE=20 21 | GE=21 22 | NOT=22 23 | AND=23 24 | OR=24 25 | L_PAREN=25 26 | R_PAREN=26 27 | L_BRACE=27 28 | R_BRACE=28 29 | L_BRACKT=29 30 | R_BRACKT=30 31 | COMMA=31 32 | SEMICOLON=32 33 | IDENT=33 34 | INTEGR_CONST=34 35 | WS=35 36 | SL_COMMENT=36 37 | ML_COMMENT=37 38 | 'const'=1 39 | 'int'=2 40 | 'void'=3 41 | 'if'=4 42 | 'else'=5 43 | 'while'=6 44 | 'break'=7 45 | 'continue'=8 46 | 'return'=9 47 | '+'=10 48 | '-'=11 49 | '*'=12 50 | '/'=13 51 | '%'=14 52 | '='=15 53 | '=='=16 54 | '!='=17 55 | '<'=18 56 | '>'=19 57 | '<='=20 58 | '>='=21 59 | '!'=22 60 | '&&'=23 61 | '||'=24 62 | '('=25 63 | ')'=26 64 | '{'=27 65 | '}'=28 66 | '['=29 67 | ']'=30 68 | ','=31 69 | ';'=32 70 | -------------------------------------------------------------------------------- /src/SysYParser.tokens: -------------------------------------------------------------------------------- 1 | CONST=1 2 | INT=2 3 | VOID=3 4 | IF=4 5 | ELSE=5 6 | WHILE=6 7 | BREAK=7 8 | CONTINUE=8 9 | RETURN=9 10 | PLUS=10 11 | MINUS=11 12 | MUL=12 13 | DIV=13 14 | MOD=14 15 | ASSIGN=15 16 | EQ=16 17 | NEQ=17 18 | LT=18 19 | GT=19 20 | LE=20 21 | GE=21 22 | NOT=22 23 | AND=23 24 | OR=24 25 | L_PAREN=25 26 | R_PAREN=26 27 | L_BRACE=27 28 | R_BRACE=28 29 | L_BRACKT=29 30 | R_BRACKT=30 31 | COMMA=31 32 | SEMICOLON=32 33 | IDENT=33 34 | INTEGR_CONST=34 35 | WS=35 36 | SL_COMMENT=36 37 | ML_COMMENT=37 38 | 'const'=1 39 | 'int'=2 40 | 'void'=3 41 | 'if'=4 42 | 'else'=5 43 | 'while'=6 44 | 'break'=7 45 | 'continue'=8 46 | 'return'=9 47 | '+'=10 48 | '-'=11 49 | '*'=12 50 | '/'=13 51 | '%'=14 52 | '='=15 53 | '=='=16 54 | '!='=17 55 | '<'=18 56 | '>'=19 57 | '<='=20 58 | '>='=21 59 | '!'=22 60 | '&&'=23 61 | '||'=24 62 | '('=25 63 | ')'=26 64 | '{'=27 65 | '}'=28 66 | '['=29 67 | ']'=30 68 | ','=31 69 | ';'=32 70 | -------------------------------------------------------------------------------- /src/gen/SysYLexer.tokens: -------------------------------------------------------------------------------- 1 | CONST=1 2 | INT=2 3 | VOID=3 4 | IF=4 5 | ELSE=5 6 | WHILE=6 7 | BREAK=7 8 | CONTINUE=8 9 | RETURN=9 10 | PLUS=10 11 | MINUS=11 12 | MUL=12 13 | DIV=13 14 | MOD=14 15 | ASSIGN=15 16 | EQ=16 17 | NEQ=17 18 | LT=18 19 | GT=19 20 | LE=20 21 | GE=21 22 | NOT=22 23 | AND=23 24 | OR=24 25 | L_PAREN=25 26 | R_PAREN=26 27 | L_BRACE=27 28 | R_BRACE=28 29 | L_BRACKT=29 30 | R_BRACKT=30 31 | COMMA=31 32 | SEMICOLON=32 33 | IDENT=33 34 | INTEGR_CONST=34 35 | WS=35 36 | SL_COMMENT=36 37 | ML_COMMENT=37 38 | 'const'=1 39 | 'int'=2 40 | 'void'=3 41 | 'if'=4 42 | 'else'=5 43 | 'while'=6 44 | 'break'=7 45 | 'continue'=8 46 | 'return'=9 47 | '+'=10 48 | '-'=11 49 | '*'=12 50 | '/'=13 51 | '%'=14 52 | '='=15 53 | '=='=16 54 | '!='=17 55 | '<'=18 56 | '>'=19 57 | '<='=20 58 | '>='=21 59 | '!'=22 60 | '&&'=23 61 | '||'=24 62 | '('=25 63 | ')'=26 64 | '{'=27 65 | '}'=28 66 | '['=29 67 | ']'=30 68 | ','=31 69 | ';'=32 70 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | groupId 8 | Lab 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 15 13 | 15 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.bytedeco 21 | llvm-platform 22 | 13.0.1-1.5.7 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/lab8-test2.sysy: -------------------------------------------------------------------------------- 1 | int sort_arr[5]; 2 | int combine(int arr1[], int arr1_length, int arr2[], int arr2_length) { 3 | int i = 0; 4 | int j = 0; 5 | int k = 0; 6 | while (i < arr1_length && j < arr2_length) { 7 | if (arr1[i] < arr2[j]) { 8 | sort_arr[k] = arr1[i]; 9 | i = i + 1; 10 | } 11 | else { 12 | sort_arr[k] = arr2[j]; 13 | j = j + 1; 14 | } 15 | k = k + 1; 16 | } 17 | if (i == arr1_length) { 18 | while (j < arr2_length) { 19 | sort_arr[k] = arr2[j]; 20 | k = k + 1; 21 | j = j + 1; 22 | } 23 | } 24 | else { 25 | while (i < arr1_length) { 26 | sort_arr[k] = arr2[i]; 27 | k = k + 1; 28 | i = i + 1; 29 | } 30 | } 31 | return sort_arr[arr1_length + arr2_length - 1]; 32 | } 33 | 34 | int main() { 35 | int a[2] = { 1,5 }; 36 | int b[3] = { 1,4,14 }; 37 | return combine(a, 2, b, 3); 38 | } 39 | -------------------------------------------------------------------------------- /src/Scope/FunctionScope.java: -------------------------------------------------------------------------------- 1 | package Scope; 2 | 3 | import org.antlr.v4.runtime.misc.Pair; 4 | 5 | import Symbol.*; 6 | import org.bytedeco.llvm.LLVM.LLVMTypeRef; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class FunctionScope extends BaseScope implements Symbol { 12 | public LLVMTypeRef type; 13 | public List> usagePosition; 14 | 15 | @Override 16 | public LLVMTypeRef getType() { 17 | return type; 18 | } 19 | 20 | public FunctionScope(String name, Scope enclosingScope, LLVMTypeRef type) { 21 | super(name, enclosingScope); 22 | this.usagePosition = new ArrayList<>(); 23 | this.type = type; 24 | } 25 | 26 | @Override 27 | public String getName() { 28 | return null; 29 | } 30 | 31 | public void addUsage(int lineNo, int columnNo) { 32 | usagePosition.add(new Pair<>(lineNo, columnNo)); 33 | } 34 | 35 | public boolean findUsage(int lineNo, int columnNo) { 36 | return usagePosition.contains(new Pair<>(lineNo, columnNo)); 37 | } 38 | } -------------------------------------------------------------------------------- /src/Symbol/BaseSymbol.java: -------------------------------------------------------------------------------- 1 | package Symbol;//import com.google.common.base.MoreObjects; 2 | 3 | import org.antlr.v4.runtime.misc.Pair; 4 | import org.bytedeco.llvm.LLVM.LLVMTypeRef; 5 | import org.bytedeco.llvm.LLVM.LLVMValueRef; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | public class BaseSymbol implements Symbol { 10 | final String name; 11 | final LLVMTypeRef type; 12 | public List> usagePosition; 13 | 14 | public BaseSymbol(String name, LLVMTypeRef type) { 15 | this.name = name; 16 | this.type = type; 17 | this.usagePosition = new ArrayList<>(); 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public LLVMTypeRef getType() { 25 | return type; 26 | } 27 | 28 | public void addUsage(int lineNo, int columnNo) { 29 | usagePosition.add(new Pair(lineNo, columnNo)); 30 | } 31 | 32 | public boolean findUsage(int lineNo, int columnNo) { 33 | boolean ret = usagePosition.contains(new Pair(lineNo, columnNo)); 34 | return ret; 35 | } 36 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 《编译原理》课程实验 2 | 3 | ## 项目功能 4 | 5 | 该项目完成了从 SysY 语言的子集到 LLVMIR 的编译过程。 6 | 7 | SysY 语言的介绍参考 [SysY语言定义](docus/SysY语言定义.pdf)。 8 | 9 | ## 实验报告 10 | 11 | 8 个实验的实验报告在 `/docus` 目录中,包含每个实验的功能、设计和问题解决。 12 | 13 | ## 运行说明 14 | 15 | ### 操作系统 16 | 17 | 使用 Windows + WSL2(Ubuntu 20.04)完成项目开发。 18 | 19 | 在 Windows 系统中,使用 IDEA 也可运行。 20 | 21 | 使用 JDK 11 完成实验。 22 | 23 | ### 配置 Antlr4 24 | 25 | 若使用 IDE,仅需安装 Antlr 的插件即可,以 IDEA 为例,在左上角,文件->设置->插件,搜索 ANTLR4 即可找到插件,下载后重启即可,之后可通过该插件处理 `.g4` 文件。 26 | 27 | 若文本编辑器则需自行安装 Antlr 28 | 29 | 前往 [Antlr 官网](https://www.antlr.org/download.html),下载 Complete ANTLR 4.9.X.jar,对于 Linux 也可以选择从命令行,使用: 30 | 31 | ```shell 32 | curl -O https://www.antlr.org/download/antlr-4.9.1-complete.jar 33 | ``` 34 | 35 | ### 配置 LLVM 36 | 37 | Linux 下安装: 38 | 39 | ```bash 40 | sudo apt-get install llvm 41 | sudo apt-get install clang 42 | ``` 43 | 44 | 安装后可通过如下命令测试,出现版本信息即为安装成功: 45 | 46 | ```bash 47 | clang -v 48 | lli --version 49 | ``` 50 | 51 | ### 问题解决 52 | 53 | 配置过程中遇到的问题解决方案参见: 54 | 55 | 1. [IDEA导入ANTLR包的方式](IDEA导入ANTLR包的方式.pdf) 56 | 2. [lab4及后续实验环境搭建](lab4及后续实验环境搭建.pdf) 57 | 3. [LLVM](LLVM.pdf) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 EagleBear2002 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/SysYLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar SysYLexer; 2 | 3 | //expr: expr ('*' | '/') expr | expr ('+' | '-') expr | IDENT | INT; 4 | CONST : 'const'; 5 | INT : 'int'; 6 | VOID : 'void'; 7 | IF : 'if'; 8 | ELSE : 'else'; 9 | WHILE : 'while'; 10 | BREAK : 'break'; 11 | CONTINUE : 'continue'; 12 | RETURN : 'return'; 13 | 14 | PLUS : '+'; 15 | MINUS : '-'; 16 | MUL : '*'; 17 | DIV : '/'; 18 | MOD : '%'; 19 | ASSIGN : '='; 20 | EQ : '=='; 21 | NEQ : '!='; 22 | LT : '<'; 23 | GT : '>'; 24 | LE : '<='; 25 | GE : '>='; 26 | NOT : '!'; 27 | AND : '&&'; 28 | OR : '||'; 29 | 30 | L_PAREN : '('; 31 | R_PAREN : ')'; 32 | L_BRACE : '{'; 33 | R_BRACE : '}'; 34 | L_BRACKT : '['; 35 | R_BRACKT : ']'; 36 | COMMA : ','; 37 | SEMICOLON : ';'; 38 | 39 | IDENT: (LETTER | '_') (LETTER | DIGIT | '_')* ; 40 | 41 | INTEGR_CONST: OCTAL | HEXADECIMAL | DECIMAL; 42 | fragment DECIMAL: '0' | [1-9] [0-9]*; 43 | fragment OCTAL: '0' [0-7]+; 44 | fragment HEXADECIMAL: ('0x' | '0X') (DIGIT | [a-fA-F])+ ; 45 | WS: [ \t\r\n]+ -> skip; 46 | SL_COMMENT: '//' .*? '\n' -> skip; 47 | ML_COMMENT: '/*' .*? '*/' -> skip; 48 | fragment LETTER: [a-zA-Z]; 49 | fragment DIGIT: [0-9]; -------------------------------------------------------------------------------- /.idea/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 12 | 13 | 14 | 18 | 19 | 20 | 21 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 12 | 13 | 14 | 18 | 19 | 20 | 21 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | import org.antlr.v4.runtime.CharStream; 2 | import org.antlr.v4.runtime.CharStreams; 3 | import org.antlr.v4.runtime.CommonTokenStream; 4 | import org.antlr.v4.runtime.tree.ParseTree; 5 | import org.bytedeco.javacpp.BytePointer; 6 | 7 | import static org.bytedeco.llvm.global.LLVM.*; 8 | 9 | import java.io.IOException; 10 | 11 | public class Main { 12 | 13 | public static SysYLexer lexer(String sourcePath) throws IOException { 14 | CharStream input = CharStreams.fromFileName(sourcePath); 15 | return new SysYLexer(input); 16 | } 17 | 18 | public static SysYParser parser(SysYLexer sysYLexer) { 19 | CommonTokenStream tokens = new CommonTokenStream(sysYLexer); 20 | return new SysYParser(tokens); 21 | } 22 | 23 | public static void main(String[] args) throws IOException { 24 | if (args.length < 2) { 25 | System.err.println("input path is required"); 26 | return; 27 | } 28 | 29 | String srcPath = args[0]; 30 | String destPath = args[1]; 31 | SysYLexer sysYLexer = lexer(srcPath); 32 | SysYParser sysYParser = parser(sysYLexer); 33 | ParseTree tree = sysYParser.program(); 34 | 35 | LLVMIRVisitor llvmirVisitor = new LLVMIRVisitor(); 36 | llvmirVisitor.visit(tree); 37 | 38 | final BytePointer error = new BytePointer(); 39 | if (LLVMPrintModuleToFile(llvmirVisitor.getModule(), destPath, error) != 0) { // moudle 是你自定义的 LLVMModuleRef 对象 40 | LLVMDisposeMessage(error); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/lab3-type-test2.sysy: -------------------------------------------------------------------------------- 1 | int globalVar; 2 | int globalArray[2]; 3 | 4 | void voidFunc1() { 5 | return; 6 | } 7 | 8 | void voidFunc2(int param1) { 9 | return 1; // type 7 10 | } 11 | 12 | void voidFunc3(int param1, int param2[]) { 13 | return param1; // type 7 14 | } 15 | 16 | int intFunc1() { 17 | return 1; 18 | } 19 | 20 | int intFunc1(int param) { // type 4 21 | return intFunc1(); // valid 22 | } 23 | 24 | int intFunc2(int param1) { 25 | return intFunc2(param1); // valid 26 | } 27 | 28 | int intFunc3(int param1, int param2[]) { 29 | return param2; // type 7 30 | } 31 | 32 | int voidFunc1() { // type 4 33 | 34 | } 35 | 36 | int test(int i, int i){ // type 3 37 | return test(i + 1); // valid 38 | } 39 | 40 | int main(){ 41 | a = 3; // type 1 42 | int b = func(); // type 2 43 | int b; // type 3 44 | 45 | int c[3][3][3]; 46 | int d[2][2]; 47 | c[1] = d; // valid 48 | c[1][1] = d; // type 5 49 | c[1][1] = d; // type 5 50 | int f = voidFunc1() + intFunc1(); // type 6 51 | int g = intFunc3(b); // type 8 52 | int h = intFunc3(b, globalArray); // valid 53 | 54 | int i = b[5]; // type 9 55 | int j = c(); // type 10 56 | c = 6; // type 5 57 | voidFunc1 = 6; // type 11 58 | 59 | if (1 || globalArray || 2 || d) { // type 6 for 3 times 60 | 61 | } 62 | 63 | int k = voidFunc1(); // type 5 64 | int l = voidFunc(); // type 2 65 | int m = k; 66 | return z(); // type 2 67 | } -------------------------------------------------------------------------------- /docus/lab4.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab4 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 翻译主函数的定义为中间代码 8 | 1. 翻译返回语句为中间代码 9 | 1. 计算整形字面常量表达式并翻译为中间代码 10 | 11 | ## 实验设计 12 | 13 | ```java 14 | @Override 15 | public LLVMValueRef visitFuncDef(SysYParser.FuncDefContext ctx) { 16 | LLVMTypeRef functionType = LLVMFunctionType(i32Type, LLVMVoidType(), 0, 0); 17 | String functionName = ctx.IDENT().getText(); 18 | LLVMValueRef function = LLVMAddFunction(module, functionName, functionType); 19 | LLVMBasicBlockRef mainEntry = LLVMAppendBasicBlock(function, "mainEntry"); 20 | LLVMPositionBuilderAtEnd(builder, mainEntry); 21 | super.visitFuncDef(ctx); 22 | 23 | return function; 24 | } 25 | ``` 26 | 27 | 笔者按照实验文档设计了 `visitFuncDef` 方法,并根据语法规则设计了 `visitUnaryExp, visitParenExp, visitAddExp, visitMulExp, visitReturnStmt` 等方法。 28 | 29 | ## 实验困难 30 | 31 | 笔者初始设计方案是将整形字面常量取值并在 java 中计算表达式求值,但该方案在 OJ 上仅得到了 1300 分(满分 3100)。 32 | 33 | 修改为调用 `LLVMBuildSDiv` 等 API 计算代替算术计算后得到了满分。 34 | 35 | ```java 36 | @Override 37 | public LLVMValueRef visitMulExp(SysYParser.MulExpContext ctx) { 38 | LLVMValueRef valueRef1 = visit(ctx.exp(0)); 39 | LLVMValueRef valueRef2 = visit(ctx.exp(1)); 40 | if (ctx.MUL() != null) { 41 | return LLVMBuildMul(builder, valueRef1, valueRef2, "tmp_"); 42 | } else if (ctx.DIV() != null) { 43 | return LLVMBuildSDiv(builder, valueRef1, valueRef2, "tmp_"); 44 | } else { 45 | return LLVMBuildSRem(builder, valueRef1, valueRef2, "tmp_"); 46 | } 47 | } 48 | ``` 49 | 50 | -------------------------------------------------------------------------------- /.idea/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 13 | 14 | 16 | 17 | 18 | 21 | 29 | 30 | 31 | 32 | 33 | 1674907290102 34 | 39 | 40 | 41 | 42 | 44 | -------------------------------------------------------------------------------- /src/Scope/BaseScope.java: -------------------------------------------------------------------------------- 1 | package Scope;//import com.google.common.base.MoreObjects; 2 | 3 | import org.bytedeco.llvm.LLVM.LLVMTypeRef; 4 | import org.bytedeco.llvm.LLVM.LLVMValueRef; 5 | 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | public class BaseScope implements Scope { 10 | private final Scope enclosingScope; 11 | private final Map valueRefs = new LinkedHashMap<>(); 12 | private final Map valueTypes = new LinkedHashMap<>(); 13 | private String scopeName; 14 | 15 | public BaseScope(String name, Scope enclosingScope) { 16 | this.scopeName = name; 17 | this.enclosingScope = enclosingScope; 18 | } 19 | 20 | @Override 21 | public String getScopeName() { 22 | return this.scopeName; 23 | } 24 | 25 | @Override 26 | public void setScopeName(String scopeName) { 27 | this.scopeName = scopeName; 28 | } 29 | 30 | @Override 31 | public Scope getEnclosingScope() { 32 | return this.enclosingScope; 33 | } 34 | 35 | public Map getValueRef() { 36 | return this.valueRefs; 37 | } 38 | 39 | @Override 40 | public void define(String name, LLVMValueRef llvmValueRef, LLVMTypeRef llvmTypeRef) { 41 | valueRefs.put(name, llvmValueRef); 42 | valueTypes.put(name, llvmTypeRef); 43 | // System.out.println(this.scopeName + "+(" + name + ", " + llvmValueRef + "," + llvmTypeRef + ")"); 44 | } 45 | 46 | @Override 47 | public LLVMValueRef resolve(String name) { 48 | LLVMValueRef symbol = valueRefs.get(name); 49 | if (symbol != null) { 50 | return symbol; 51 | } 52 | 53 | if (enclosingScope != null) { 54 | return enclosingScope.resolve(name); 55 | } 56 | 57 | // System.out.println("can not resolve: " + name); 58 | return null; 59 | } 60 | 61 | @Override 62 | public LLVMTypeRef getType(String name) { 63 | LLVMTypeRef typeRef = valueTypes.get(name); 64 | if (typeRef != null) { 65 | return typeRef; 66 | } 67 | 68 | if (enclosingScope != null) { 69 | return enclosingScope.getType(name); 70 | } 71 | 72 | return null; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /docus/lab8.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab8 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 一维数组作为函数参数 8 | 9 | ## 实验设计 10 | 11 | 本次实验主要修改了 `visitLVal()` 和 `visitLValExp()` 等方法。 12 | 13 | ```java 14 | @Override 15 | public LLVMValueRef visitLValExp(SysYParser.LValExpContext ctx) { 16 | LLVMValueRef lValPointer = this.visitLVal(ctx.lVal()); 17 | if (arrayAddr) { 18 | arrayAddr = false; 19 | return lValPointer; 20 | } 21 | return LLVMBuildLoad(builder, lValPointer, ctx.lVal().getText()); 22 | } 23 | 24 | @Override 25 | public LLVMValueRef visitLVal(SysYParser.LValContext ctx) { 26 | String lValName = ctx.IDENT().getText(); 27 | LLVMValueRef varPointer = currentScope.resolve(lValName); 28 | LLVMTypeRef varType = currentScope.getType(lValName); 29 | if (varType.equals(i32Type)) { 30 | return varPointer; 31 | } else if (varType.equals(intPointerType)) { 32 | if (ctx.exp().size() > 0) { 33 | LLVMValueRef[] arrayPointer = new LLVMValueRef[1]; 34 | arrayPointer[0] = this.visit(ctx.exp(0)); 35 | PointerPointer indexPointer = new PointerPointer<>(arrayPointer); 36 | LLVMValueRef pointer = LLVMBuildLoad(builder, varPointer, lValName); 37 | return LLVMBuildGEP(builder, pointer, indexPointer, 1, "&" + lValName); 38 | } else { 39 | return varPointer; 40 | } 41 | } else { 42 | LLVMValueRef[] arrayPointer = new LLVMValueRef[2]; 43 | arrayPointer[0] = zero; 44 | if (ctx.exp().size() > 0) { 45 | arrayPointer[1] = this.visit(ctx.exp(0)); 46 | } else { 47 | arrayAddr = true; 48 | arrayPointer[1] = zero; 49 | } 50 | PointerPointer indexPointer = new PointerPointer<>(arrayPointer); 51 | return LLVMBuildGEP(builder, varPointer, indexPointer, 2, "&" + lValName); 52 | } 53 | } 54 | ``` 55 | 56 | ## 实验困难 57 | 58 | 笔者完成实验代码编写后,遇到了 OJ 的报错: 59 | 60 | ``` 61 | lli-13: lli: out.ir:44:1: error: expected instruction opcode } ^ 62 | ``` 63 | 64 | 笔者与同学交流发现,在返回值为 `int` 的函数末尾添加 `ret i32 0` 语句即可通过 OJ 的所有测试用例。笔者推测测试用例中存在没有正确返回返回值的函数。 65 | 66 | -------------------------------------------------------------------------------- /docus/lab7.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab7 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. `while` 循环 8 | 1. 循环控制 9 | 10 | ## 实验设计 11 | 12 | 本次实验新增了 `visitWhileStmt` 等方法,使用栈属性维护当前最内层的循环对应的 `block`。核心代码如下: 13 | 14 | ```java 15 | @Override 16 | public LLVMValueRef visitWhileStmt(SysYParser.WhileStmtContext ctx) { 17 | LLVMBasicBlockRef whileCondition = LLVMAppendBasicBlock(currentFunction, "whileCondition"); 18 | LLVMBasicBlockRef whileBody = LLVMAppendBasicBlock(currentFunction, "whileBody"); 19 | LLVMBasicBlockRef afterWhile = LLVMAppendBasicBlock(currentFunction, "afterWhile"); 20 | 21 | LLVMBuildBr(builder, whileCondition); 22 | 23 | LLVMPositionBuilderAtEnd(builder, whileCondition); 24 | LLVMValueRef condVal = this.visit(ctx.cond()); 25 | LLVMValueRef cmpResult = LLVMBuildICmp(builder, LLVMIntNE, zero, condVal, "cmp_result"); 26 | LLVMBuildCondBr(builder, cmpResult, whileBody, afterWhile); 27 | 28 | LLVMPositionBuilderAtEnd(builder, whileBody); 29 | whileConditionStack.push(whileCondition); 30 | afterWhileStack.push(afterWhile); 31 | this.visit(ctx.stmt()); 32 | LLVMBuildBr(builder, whileCondition); 33 | whileConditionStack.pop(); 34 | afterWhileStack.pop(); 35 | LLVMBuildBr(builder, afterWhile); 36 | 37 | LLVMPositionBuilderAtEnd(builder, afterWhile); 38 | return null; 39 | } 40 | 41 | @Override 42 | public LLVMValueRef visitBreakStmt(SysYParser.BreakStmtContext ctx) { 43 | return LLVMBuildBr(builder, afterWhileStack.peek()); 44 | } 45 | 46 | @Override 47 | public LLVMValueRef visitContinueStmt(SysYParser.ContinueStmtContext ctx) { 48 | return LLVMBuildBr(builder, whileConditionStack.peek()); 49 | } 50 | ``` 51 | 52 | ## 实验困难 53 | 54 | 笔者实验过程中遇到了 OJ 的报错: 55 | 56 | ``` 57 | lli-13: lli: out.ir:67:3: error: instruction expected to be numbered '%3' %2 = call i32 @get_one(i32 0) ^ 58 | ``` 59 | 60 | 笔者分析发现 OJ 会检查以纯数字命名的变量。在代码中,只有函数调用的返回值用纯数字作为序号命名,且 OJ 还要求返回值为空类型的函数调用不应当有变量名。 61 | 62 | 笔者根据函数的返回值类型生成变量名: 63 | 64 | ```java 65 | if (retTypeMap.get(functionName).equals("void")) { 66 | functionName = ""; 67 | } 68 | return LLVMBuildCall(builder, function, args, argsCount, functionName); 69 | ``` 70 | 71 | -------------------------------------------------------------------------------- /submit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Change USERNAME, PASSWORD 5 | USERNAME="201250172" 6 | PASSWORD="123456" 7 | 8 | echo "--------Begin to Submit--------" 9 | 10 | if [[ $USERNAME == "20xxxxxxx" || $PASSWORD == "xxxxxxxxx" ]]; then 11 | echo "Fail. You need to change USERNAME and PASSWORD" 12 | exit -1 13 | fi 14 | 15 | COURSE=PTC2022 16 | MODULE=$(git rev-parse --abbrev-ref HEAD | tr '[a-z]' '[A-Z]') 17 | WORKSPACE=$(basename $(realpath .)) 18 | FILE=submit.zip 19 | 20 | #if [[ $(git status --porcelain) ]]; then 21 | # echo "Error: Git repository is dirty." 22 | # echo "Commit all your changes before submitting." 23 | # echo "Hint: run 'git status' to show changed files." 24 | # exit -1 25 | #fi 26 | 27 | # Construct assignmentId 28 | ANTLRTMP="labN" 29 | 30 | BRANCH=$(git symbolic-ref --short -q HEAD) 31 | NUMBER=$(echo $BRANCH | tr -cd "[0-9]") 32 | ID=$(echo $ANTLRTMP | sed "s/N/${NUMBER}/g") 33 | 34 | echo "In branch: $BRANCH " 35 | echo "Submit to assignment: $ID" 36 | 37 | 38 | # Compress the whole folder instead of git storage only. 39 | cd .. 40 | rm -f $FILE 41 | zip -r "$FILE" $(ls -d "$WORKSPACE/.git" 2>/dev/null) > /dev/null 42 | if [ $? -ne 0 ]; then 43 | echo "" 44 | echo "Fail to zip for submit.zip!" 45 | else 46 | echo "" 47 | echo "generate submit.zip" 48 | fi 49 | 50 | 51 | # construct json for cul 52 | TMPRAW='{"username":"XXXUSERXXX","password":"YYYPWDYYY"}' 53 | DATARAW=$(echo $TMPRAW | sed "s/XXXUSERXXX/$USERNAME/g" | sed "s/YYYPWDYYY/$PASSWORD/g") 54 | URL=http://47.122.3.40:28300 55 | 56 | # extract token 57 | RAW=$(curl "$URL/auth/login" \ 58 | -H 'Content-Type: application/json' \ 59 | --data-raw $DATARAW ) 60 | TOKEN=$(echo $RAW | sed 's/,/\n/g' | grep "token" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/\"//g') 61 | 62 | RES=$(curl "$URL/submissions" \ 63 | -H "Authorization: Bearer $TOKEN" \ 64 | -F "assignmentId=$ID" \ 65 | -F "file=@$FILE" ) 66 | 67 | FLAG0=$? 68 | 69 | TIME=$(echo $RES | sed 's/,/\n/g' | grep "createdAt" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/\"//g') 70 | 71 | if [[ $FLAG0 -ne 0 || -z $TIME ]]; then 72 | echo "" 73 | echo "T_T Commit Fail! T_T" 74 | else 75 | echo "" 76 | echo "^v^ Commit Success! ^v^ " 77 | fi 78 | 79 | -------------------------------------------------------------------------------- /tests/lab8-test1.out: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'moudle' 2 | source_filename = "moudle" 3 | 4 | @global_arr = global [20 x i32] [i32 1, i32 2, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0] 5 | @global_const_global_arr = global [5 x i32] zeroinitializer 6 | 7 | define void @g(i32* %0) { 8 | g_entry: 9 | %"&a" = alloca i32*, align 8 10 | store i32* %0, i32** %"&a", align 8 11 | ret void 12 | } 13 | 14 | define i32 @f(i32* %0) { 15 | f_entry: 16 | %"&a" = alloca i32*, align 8 17 | store i32* %0, i32** %"&a", align 8 18 | %a = load i32*, i32** %"&a", align 8 19 | %"&a1" = getelementptr i32, i32* %a, i32 0 20 | %"a[0]" = load i32, i32* %"&a1", align 4 21 | %eq_ = icmp eq i32 %"a[0]", 0 22 | %zext_ = zext i1 %eq_ to i32 23 | %icmp_ = icmp ne i32 0, %zext_ 24 | br i1 %icmp_, label %true_block, label %false_block 25 | 26 | true_block: ; preds = %f_entry 27 | ret i32 1 28 | br label %after_if_block 29 | 30 | false_block: ; preds = %f_entry 31 | ret i32 2 32 | br label %after_if_block 33 | 34 | after_if_block: ; preds = %false_block, %true_block 35 | ret i32 0 36 | } 37 | 38 | define i32 @main() { 39 | main_entry: 40 | %local_arr = alloca [5 x i32], align 4 41 | %f = call i32 @f(i32* getelementptr inbounds ([20 x i32], [20 x i32]* @global_arr, i32 0, i32 0)) 42 | %f1 = call i32 @f(i32* getelementptr inbounds ([5 x i32], [5 x i32]* @global_const_global_arr, i32 0, i32 0)) 43 | %"&0" = getelementptr [5 x i32], [5 x i32]* %local_arr, i32 0, i32 0 44 | store i32 %f, i32* %"&0", align 4 45 | %"&1" = getelementptr [5 x i32], [5 x i32]* %local_arr, i32 0, i32 1 46 | store i32 %f1, i32* %"&1", align 4 47 | %"&2" = getelementptr [5 x i32], [5 x i32]* %local_arr, i32 0, i32 2 48 | store i32 0, i32* %"&2", align 4 49 | %"&3" = getelementptr [5 x i32], [5 x i32]* %local_arr, i32 0, i32 3 50 | store i32 0, i32* %"&3", align 4 51 | %"&4" = getelementptr [5 x i32], [5 x i32]* %local_arr, i32 0, i32 4 52 | store i32 0, i32* %"&4", align 4 53 | %"&local_arr" = getelementptr [5 x i32], [5 x i32]* %local_arr, i32 0, i32 0 54 | %f2 = call i32 @f(i32* %"&local_arr") 55 | ret i32 %f2 56 | ret i32 0 57 | } 58 | -------------------------------------------------------------------------------- /docus/lab2.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab2 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 对 SysY 语言进行语法分析 8 | 2. 输出语法树和语法高亮 9 | 3. 报告语法错误并提供提示信息 10 | 11 | ## 实验困难 12 | 13 | 实验所遇到的最大困难是测试样例时报错: 14 | 15 | ```bash 16 | eaglebear2002@EagleBear2002-HP:/mnt/c/Users/37756/Documents/NJU/2022Fall/Compilers/Lab$ make parser-test1 17 | java -jar /usr/local/lib/antlr-*-complete.jar -listener -visitor -long-messages ./src/SysYParser.g4 ./src/SysYLexer.g4 18 | mkdir -p classes 19 | javac -g -classpath /usr/local/lib/antlr-4.9.1-complete.jar ./src/Main.java ./src/MyLexerErrorListener.java ./src/MyParserErrorListener.java ./src/S 20 | ysYLexer.java ./src/SysYParser.java ./src/SysYParserBaseListener.java ./src/SysYParserBaseVisitor.java ./src/SysYParserListener.java ./src/SysYParse 21 | rVisitor.java ./src/Visitor.java -d classes 22 | java -classpath ./classes:/usr/local/lib/antlr-4.9.1-complete.jar Main tests/parser-test1.sysy 23 | Error type B at Line 7: mismatched input '' expecting {'const', 'int', 'void'} 24 | ``` 25 | 26 | 笔者不理解该报错的原因,后来无意中注释掉词法分析过程后消除了该报错: 27 | 28 | ```java 29 | public class Main { 30 | public static SysYLexer lexer(String sourcePath) throws IOException { 31 | CharStream input = CharStreams.fromFileName(sourcePath); 32 | SysYLexer sysYLexer = new SysYLexer(input); 33 | 34 | // MyLexerErrorListener myLexerErrorListener = new MyLexerErrorListener(); 35 | // sysYLexer.removeErrorListeners(); 36 | // sysYLexer.addErrorListener(myLexerErrorListener); 37 | // List tokenList = sysYLexer.getAllTokens(); 38 | // 39 | // if (myLexerErrorListener.listenError()) { 40 | // return sysYLexer; 41 | // } 42 | // 43 | // String[] ruleNames = sysYLexer.getRuleNames(); 44 | // for (Token token : tokenList) { 45 | // String tokenText = token.getText(); 46 | // int ruleNum = token.getType(); 47 | // int lineNum = token.getLine(); 48 | // if (ruleNum == 34) { 49 | // if (tokenText.startsWith("0x") || tokenText.startsWith("0X")) { 50 | // tokenText = String.valueOf(Integer.parseInt(tokenText.substring(2), 16)); 51 | // } else if (tokenText.startsWith("0")) { 52 | // tokenText = String.valueOf(Integer.parseInt(tokenText, 8)); 53 | // } 54 | // } 55 | // 56 | //// System.err.printf("%s %s at Line %d.\n", ruleNames[ruleNum - 1], tokenText, lineNum); 57 | // } 58 | 59 | return sysYLexer; 60 | } 61 | } 62 | ``` 63 | 64 | 笔者和助教沟通后,找到了问题所在:`sysYLexer.getAllTokens()` 方法分析了所有词法单元后指针移动到了最后,再调用词法单元时只能从 `` 处开始读取。 -------------------------------------------------------------------------------- /docus/lab3.md: -------------------------------------------------------------------------------- 1 | # 编译原理 Lab3 实验报告 2 | 3 | ## 实现功能 4 | 5 | 本次实验完成了以下功能: 6 | 7 | 1. 类型检查 8 | 2. 重命名 9 | 10 | ## 实验设计 11 | 12 | 笔者参考老师上课的演示代码和助教在文档中的提示,做出如下类设计。该设计采取了依赖倒置原则。 13 | 14 | ![](images/image-20221219201711996.png) 15 | 16 | 在实现功能方面,笔者采用了如下思路: 17 | 18 | 1. 通过 `Visitor` 对语法树进行遍历,遍历过程中输出语义错误; 19 | 2. 在 `visitTerminal` 方法中,对每个 `Symbol` 记录变量名、函数名的出现位置,并存储待输出语法树内容; 20 | 3. 如果语法树中无语义错误,则输出语法树的内容,输出过程中对待重命名的变量、函数进行重命名。 21 | 22 | 整个过程总共遍历语法树一遍。 23 | 24 | ## 实验困难 25 | 26 | 实验主要困难在于上述设计,特别是对 `getLValType`,`getExpType` 和 `getCondType` 等递归方法的独立设计。 27 | 28 | 在此以 `getExpType` 为例给出代码: 29 | 30 | ```java 31 | private Type getExpType(SysYParser.ExpContext ctx) { 32 | if (ctx.IDENT() != null) { // IDENT L_PAREN funcRParams? R_PAREN 33 | String funcName = ctx.IDENT().getText(); 34 | Symbol symbol = currentScope.resolve(funcName); 35 | if (symbol != null && symbol.getType() instanceof FunctionType) { 36 | FunctionType functionType = (FunctionType) currentScope.resolve(funcName).getType(); 37 | ArrayList paramsType = functionType.getParamsType(), argsType = new ArrayList<>(); 38 | if (ctx.funcRParams() != null) { 39 | for (SysYParser.ParamContext paramContext : ctx.funcRParams().param()) { 40 | argsType.add(getExpType(paramContext.exp())); 41 | } 42 | } 43 | if (paramsType.equals(argsType)) { 44 | return functionType.getRetType(); 45 | } 46 | } 47 | } else if (ctx.L_PAREN() != null) { // L_PAREN exp R_PAREN 48 | return getExpType(ctx.exp(0)); 49 | } else if (ctx.unaryOp() != null) { // unaryOp exp 50 | return getExpType(ctx.exp(0)); 51 | } else if (ctx.lVal() != null) { // lVal 52 | return getLValType(ctx.lVal()); 53 | } else if (ctx.number() != null) { // number 54 | return new BasicTypeSymbol("int"); 55 | } else if (ctx.MUL() != null || ctx.DIV() != null || ctx.MOD() != null || ctx.PLUS() != null || ctx.MINUS() != null) { 56 | Type op1Type = getExpType(ctx.exp(0)); 57 | Type op2Type = getExpType(ctx.exp(1)); 58 | if (op1Type.toString().equals("int") && op2Type.toString().equals("int")) { 59 | return op1Type; 60 | } 61 | } 62 | return new BasicTypeSymbol("noType"); 63 | } 64 | ``` 65 | 66 | 该方法用于计算某个 `ExpContext` 的类型,主要用于判断该表达式内部是否有语义错误和类型不兼容。利用递归的思想,笔者还设计了 `getLValType` 和 `getCondType`,分别用来计算左值的类型和条件子句的类型及其合法性。 -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.git 2 | 3 | export CLASSPATH=/usr/local/lib/antlr-*-complete.jar 4 | 5 | DOMAINNAME = 47.122.3.40:3000 6 | ANTLR = java -jar /usr/local/lib/antlr-*-complete.jar -listener -visitor -long-messages 7 | JAVAC = javac -g 8 | JAVA = java 9 | 10 | 11 | PFILE = $(shell find . -name "SysYParser.g4") 12 | LFILE = $(shell find . -name "SysYLexer.g4") 13 | JAVAFILE = $(shell find . -name "*.java") 14 | ANTLRPATH = $(shell find /usr/local/lib -name "antlr-*-complete.jar") 15 | 16 | compile: antlr 17 | $(call git_commit,"make") 18 | mkdir -p classes 19 | $(JAVAC) -classpath $(ANTLRPATH) $(JAVAFILE) -d classes 20 | 21 | lexer-test1: compile 22 | $(call git_commit, "lexer-test1") 23 | java -classpath ./classes:$(ANTLRPATH) Main tests/lexer-test1.sysy 24 | 25 | lexer-test2: compile 26 | $(call git_commit, "lexer-test2") 27 | java -classpath ./classes:$(ANTLRPATH) Main tests/lexer-test2.sysy 28 | 29 | parser-test1: compile 30 | $(call git_commit, "parser-test1") 31 | java -classpath ./classes:$(ANTLRPATH) Main tests/parser-test1.sysy 32 | 33 | parser-test2: compile 34 | $(call git_commit, "parser-test2") 35 | java -classpath ./classes:$(ANTLRPATH) Main tests/parser-test2.sysy 36 | 37 | type-test: compile 38 | $(call git_commit, "type-test") 39 | java -classpath ./classes:$(ANTLRPATH) Main tests/type-test.sysy 8 4 d 40 | 41 | type-test2: compile 42 | $(call git_commit, "type-test2") 43 | java -classpath ./classes:$(ANTLRPATH) Main tests/type-test2.sysy 8 4 d 44 | 45 | rename-test: compile 46 | $(call git_commit, "rename-test") 47 | java -classpath ./classes:$(ANTLRPATH) Main tests/rename-test.sysy 8 4 d 48 | 49 | llvm-ir-test1: compile 50 | $(call git_commit, "llvm-ir-test1") 51 | java -classpath ./classes:$(ANTLRPATH) Main tests/llvm-ir-test1.sysy tests/llvm-ir-test1.out 52 | 53 | llvm-ir-test2: compile 54 | $(call git_commit, "llvm-ir-test2") 55 | java -classpath ./classes:$(ANTLRPATH) Main tests/llvm-ir-test2.sysy tests/llvm-ir-test2.out 56 | 57 | antlr: $(LFILE) $(PFILE) 58 | $(ANTLR) $(PFILE) $(LFILE) 59 | 60 | test: compile 61 | $(call git_commit, "test") 62 | nohup java -classpath ./classes:$(ANTLRPATH) Main ./tests/test1.sysy & 63 | 64 | clean: 65 | rm -f src/*.tokens 66 | rm -f src/*.interp 67 | rm -f src/SysYLexer.java src/SysYParser.java src/SysYParserBaseListener.java src/SysYParserBaseVisitor.java src/SysYParserListener.java src/SysYParserVisitor.java 68 | rm -rf classes 69 | 70 | submit: 71 | git gc 72 | #bash -c "$$(curl -s $(DOMAINNAME)/scripts/submit-v2.sh)" 73 | bash submit.sh 74 | 75 | .PHONY: compile antlr test run clean submit -------------------------------------------------------------------------------- /src/SysYParser.g4: -------------------------------------------------------------------------------- 1 | parser grammar SysYParser; 2 | 3 | options { 4 | tokenVocab = SysYLexer; 5 | } 6 | 7 | program : compUnit; 8 | 9 | // 编译单元 10 | compUnit : (funcDef | decl)+ EOF; 11 | 12 | // 下面是其他的语法单元定义 13 | 14 | // 声明 15 | decl : constDecl | varDecl; 16 | 17 | // 常量声明 18 | constDecl : CONST bType constDef (COMMA constDef)* SEMICOLON; 19 | 20 | // 基本类型 21 | bType : INT; 22 | 23 | // 常数定义 24 | constDef : IDENT (L_BRACKT constExp R_BRACKT)* ASSIGN constInitVal; 25 | 26 | // 常量初值 27 | constInitVal : constExp | L_BRACE (constInitVal (COMMA constInitVal)*)? R_BRACE; 28 | 29 | // 变量声明 30 | varDecl : bType varDef (COMMA varDef)* SEMICOLON; 31 | 32 | // 变量定义 33 | varDef : IDENT (L_BRACKT constExp R_BRACKT)* (ASSIGN initVal)?; 34 | 35 | // 变量初值 36 | initVal : exp | L_BRACE (initVal (COMMA initVal)*)? R_BRACE; 37 | 38 | // 函数定义 39 | funcDef : funcType IDENT L_PAREN (funcFParams)? R_PAREN block; 40 | 41 | // 函数类型 42 | funcType : VOID | INT; 43 | 44 | // 函数形参表 45 | funcFParams : funcFParam (COMMA funcFParam)*; 46 | 47 | // 函数形参 48 | funcFParam : bType IDENT (L_BRACKT R_BRACKT (L_BRACKT exp R_BRACKT)*)?; 49 | 50 | // 语句块 51 | block : L_BRACE (blockItem)* R_BRACE; 52 | 53 | // 语句块项 54 | blockItem : decl | stmt; 55 | 56 | // 语句 57 | stmt : lVal ASSIGN exp SEMICOLON # assignment 58 | | (exp)? SEMICOLON # possibleExp 59 | | block # blockStmt 60 | | IF L_PAREN cond R_PAREN stmt (ELSE stmt)? # ifStmt 61 | | WHILE L_PAREN cond R_PAREN stmt # whileStmt 62 | | BREAK SEMICOLON # breakStmt 63 | | CONTINUE SEMICOLON # continueStmt 64 | | RETURN (exp)? SEMICOLON # returnStmt 65 | ; 66 | 67 | // 表达式 68 | exp: L_PAREN exp R_PAREN # parenExp 69 | | lVal # lValExp 70 | | number # numExp 71 | | IDENT L_PAREN funcRParams? R_PAREN # funcCallExp 72 | | unaryOp exp # unaryExp 73 | | exp (MUL | DIV | MOD) exp # mulExp 74 | | exp (PLUS | MINUS) exp # addExp 75 | ; 76 | 77 | 78 | // 条件表达式 79 | cond: exp # condExp 80 | | cond (LT | GT | LE | GE) cond # compareExp 81 | | cond (EQ | NEQ) cond # relationExp 82 | | cond AND cond # andExp 83 | | cond OR cond # orExp 84 | ; 85 | 86 | 87 | // 左值表达式 88 | lVal : IDENT (L_BRACKT exp R_BRACKT)*; 89 | 90 | // 基本表达式 91 | // primaryExp : L_PAREN exp R_PAREN | lVal | number; 92 | 93 | // 数值 94 | number : INTEGR_CONST; 95 | 96 | // 一元表达式 97 | //unaryExp : primaryExp | IDENT L_PAREN (funcRParams)? R_PAREN | unaryOp unaryExp; 98 | 99 | // 单目运算符 100 | unaryOp : PLUS | MINUS | NOT; 101 | 102 | // 函数实参表, from TA 103 | funcRParams : param (COMMA param)*; 104 | 105 | // from TA 106 | param : exp; 107 | 108 | //// 乘除模表达式 109 | //mulExp : unaryOp | mulExp (MUL | DIV | MOD) unaryExp; 110 | // 111 | //// 加减表达式 112 | //addExp : mulExp | addExp (PLUS | MINUS) mulExp; 113 | // 114 | //// 关系表达式 115 | //relExp : addExp | relExp (LT | GT | LE | GE) addExp; 116 | // 117 | //// 相等性表达式 118 | //eqExp : relExp | eqExp (EQ | NEQ) relExp; 119 | // 120 | //// 逻辑与表达式 121 | //lAndExp : eqExp | lAndExp LAND eqExp; 122 | // 123 | //// 逻辑或表达式 124 | //lOrExp : lAndExp | lOrExp LOR lAndExp; 125 | 126 | // 常量表达式 127 | constExp : exp; -------------------------------------------------------------------------------- /Lab.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /tests/lab8-test2.out: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'moudle' 2 | source_filename = "moudle" 3 | 4 | @sort_arr = global [5 x i32] zeroinitializer 5 | 6 | define i32 @combine(i32* %0, i32 %1, i32* %2, i32 %3) { 7 | combine_entry: 8 | %"&arr1" = alloca i32*, align 8 9 | store i32* %0, i32** %"&arr1", align 8 10 | %"&arr1_length" = alloca i32, align 4 11 | store i32 %1, i32* %"&arr1_length", align 4 12 | %"&arr2" = alloca i32*, align 8 13 | store i32* %2, i32** %"&arr2", align 8 14 | %"&arr2_length" = alloca i32, align 4 15 | store i32 %3, i32* %"&arr2_length", align 4 16 | %i = alloca i32, align 4 17 | store i32 0, i32* %i, align 4 18 | %j = alloca i32, align 4 19 | store i32 0, i32* %j, align 4 20 | %k = alloca i32, align 4 21 | store i32 0, i32* %k, align 4 22 | br label %while_condition 23 | 24 | while_condition: ; preds = %after_if_block, %combine_entry 25 | %i1 = load i32, i32* %i, align 4 26 | %arr1_length = load i32, i32* %"&arr1_length", align 4 27 | %slt_ = icmp slt i32 %i1, %arr1_length 28 | %zext_ = zext i1 %slt_ to i32 29 | %j2 = load i32, i32* %j, align 4 30 | %arr2_length = load i32, i32* %"&arr2_length", align 4 31 | %slt_3 = icmp slt i32 %j2, %arr2_length 32 | %zext_4 = zext i1 %slt_3 to i32 33 | %and_ = and i32 %zext_, %zext_4 34 | %icmp_ = icmp ne i32 0, %and_ 35 | br i1 %icmp_, label %while_body, label %after_while_block 36 | 37 | while_body: ; preds = %while_condition 38 | %i5 = load i32, i32* %i, align 4 39 | %arr1 = load i32*, i32** %"&arr1", align 8 40 | %"&arr16" = getelementptr i32, i32* %arr1, i32 %i5 41 | %"arr1[i]" = load i32, i32* %"&arr16", align 4 42 | %j7 = load i32, i32* %j, align 4 43 | %arr2 = load i32*, i32** %"&arr2", align 8 44 | %"&arr28" = getelementptr i32, i32* %arr2, i32 %j7 45 | %"arr2[j]" = load i32, i32* %"&arr28", align 4 46 | %slt_9 = icmp slt i32 %"arr1[i]", %"arr2[j]" 47 | %zext_10 = zext i1 %slt_9 to i32 48 | %icmp_11 = icmp ne i32 0, %zext_10 49 | br i1 %icmp_11, label %true_block, label %false_block 50 | 51 | after_while_block: ; preds = %after_if_block, %while_condition 52 | %i28 = load i32, i32* %i, align 4 53 | %arr1_length29 = load i32, i32* %"&arr1_length", align 4 54 | %eq_ = icmp eq i32 %i28, %arr1_length29 55 | %zext_30 = zext i1 %eq_ to i32 56 | %icmp_31 = icmp ne i32 0, %zext_30 57 | br i1 %icmp_31, label %true_block32, label %false_block33 58 | 59 | true_block: ; preds = %while_body 60 | %i12 = load i32, i32* %i, align 4 61 | %arr113 = load i32*, i32** %"&arr1", align 8 62 | %"&arr114" = getelementptr i32, i32* %arr113, i32 %i12 63 | %"arr1[i]15" = load i32, i32* %"&arr114", align 4 64 | %k16 = load i32, i32* %k, align 4 65 | %"&sort_arr" = getelementptr [5 x i32], [5 x i32]* @sort_arr, i32 0, i32 %k16 66 | store i32 %"arr1[i]15", i32* %"&sort_arr", align 4 67 | %i17 = load i32, i32* %i, align 4 68 | %add_ = add i32 %i17, 1 69 | store i32 %add_, i32* %i, align 4 70 | br label %after_if_block 71 | 72 | false_block: ; preds = %while_body 73 | %j18 = load i32, i32* %j, align 4 74 | %arr219 = load i32*, i32** %"&arr2", align 8 75 | %"&arr220" = getelementptr i32, i32* %arr219, i32 %j18 76 | %"arr2[j]21" = load i32, i32* %"&arr220", align 4 77 | %k22 = load i32, i32* %k, align 4 78 | %"&sort_arr23" = getelementptr [5 x i32], [5 x i32]* @sort_arr, i32 0, i32 %k22 79 | store i32 %"arr2[j]21", i32* %"&sort_arr23", align 4 80 | %j24 = load i32, i32* %j, align 4 81 | %add_25 = add i32 %j24, 1 82 | store i32 %add_25, i32* %j, align 4 83 | br label %after_if_block 84 | 85 | after_if_block: ; preds = %false_block, %true_block 86 | %k26 = load i32, i32* %k, align 4 87 | %add_27 = add i32 %k26, 1 88 | store i32 %add_27, i32* %k, align 4 89 | br label %while_condition 90 | br label %after_while_block 91 | 92 | true_block32: ; preds = %after_while_block 93 | br label %while_condition35 94 | 95 | false_block33: ; preds = %after_while_block 96 | br label %while_condition53 97 | 98 | after_if_block34: ; preds = %after_while_block55, %after_while_block37 99 | %arr1_length70 = load i32, i32* %"&arr1_length", align 4 100 | %arr2_length71 = load i32, i32* %"&arr2_length", align 4 101 | %add_72 = add i32 %arr1_length70, %arr2_length71 102 | %sub_ = sub i32 %add_72, 1 103 | %"&sort_arr73" = getelementptr [5 x i32], [5 x i32]* @sort_arr, i32 0, i32 %sub_ 104 | %"sort_arr[arr1_length+arr2_length-1]" = load i32, i32* %"&sort_arr73", align 4 105 | ret i32 %"sort_arr[arr1_length+arr2_length-1]" 106 | ret i32 0 107 | 108 | while_condition35: ; preds = %while_body36, %true_block32 109 | %j38 = load i32, i32* %j, align 4 110 | %arr2_length39 = load i32, i32* %"&arr2_length", align 4 111 | %slt_40 = icmp slt i32 %j38, %arr2_length39 112 | %zext_41 = zext i1 %slt_40 to i32 113 | %icmp_42 = icmp ne i32 0, %zext_41 114 | br i1 %icmp_42, label %while_body36, label %after_while_block37 115 | 116 | while_body36: ; preds = %while_condition35 117 | %j43 = load i32, i32* %j, align 4 118 | %arr244 = load i32*, i32** %"&arr2", align 8 119 | %"&arr245" = getelementptr i32, i32* %arr244, i32 %j43 120 | %"arr2[j]46" = load i32, i32* %"&arr245", align 4 121 | %k47 = load i32, i32* %k, align 4 122 | %"&sort_arr48" = getelementptr [5 x i32], [5 x i32]* @sort_arr, i32 0, i32 %k47 123 | store i32 %"arr2[j]46", i32* %"&sort_arr48", align 4 124 | %k49 = load i32, i32* %k, align 4 125 | %add_50 = add i32 %k49, 1 126 | store i32 %add_50, i32* %k, align 4 127 | %j51 = load i32, i32* %j, align 4 128 | %add_52 = add i32 %j51, 1 129 | store i32 %add_52, i32* %j, align 4 130 | br label %while_condition35 131 | br label %after_while_block37 132 | 133 | after_while_block37: ; preds = %while_body36, %while_condition35 134 | br label %after_if_block34 135 | 136 | while_condition53: ; preds = %while_body54, %false_block33 137 | %i56 = load i32, i32* %i, align 4 138 | %arr1_length57 = load i32, i32* %"&arr1_length", align 4 139 | %slt_58 = icmp slt i32 %i56, %arr1_length57 140 | %zext_59 = zext i1 %slt_58 to i32 141 | %icmp_60 = icmp ne i32 0, %zext_59 142 | br i1 %icmp_60, label %while_body54, label %after_while_block55 143 | 144 | while_body54: ; preds = %while_condition53 145 | %i61 = load i32, i32* %i, align 4 146 | %arr262 = load i32*, i32** %"&arr2", align 8 147 | %"&arr263" = getelementptr i32, i32* %arr262, i32 %i61 148 | %"arr2[i]" = load i32, i32* %"&arr263", align 4 149 | %k64 = load i32, i32* %k, align 4 150 | %"&sort_arr65" = getelementptr [5 x i32], [5 x i32]* @sort_arr, i32 0, i32 %k64 151 | store i32 %"arr2[i]", i32* %"&sort_arr65", align 4 152 | %k66 = load i32, i32* %k, align 4 153 | %add_67 = add i32 %k66, 1 154 | store i32 %add_67, i32* %k, align 4 155 | %i68 = load i32, i32* %i, align 4 156 | %add_69 = add i32 %i68, 1 157 | store i32 %add_69, i32* %i, align 4 158 | br label %while_condition53 159 | br label %after_while_block55 160 | 161 | after_while_block55: ; preds = %while_body54, %while_condition53 162 | br label %after_if_block34 163 | } 164 | 165 | define i32 @main() { 166 | main_entry: 167 | %a = alloca [2 x i32], align 4 168 | %"&0" = getelementptr [2 x i32], [2 x i32]* %a, i32 0, i32 0 169 | store i32 1, i32* %"&0", align 4 170 | %"&1" = getelementptr [2 x i32], [2 x i32]* %a, i32 0, i32 1 171 | store i32 5, i32* %"&1", align 4 172 | %b = alloca [3 x i32], align 4 173 | %"&01" = getelementptr [3 x i32], [3 x i32]* %b, i32 0, i32 0 174 | store i32 1, i32* %"&01", align 4 175 | %"&12" = getelementptr [3 x i32], [3 x i32]* %b, i32 0, i32 1 176 | store i32 4, i32* %"&12", align 4 177 | %"&2" = getelementptr [3 x i32], [3 x i32]* %b, i32 0, i32 2 178 | store i32 14, i32* %"&2", align 4 179 | %"&a" = getelementptr [2 x i32], [2 x i32]* %a, i32 0, i32 0 180 | %"&b" = getelementptr [3 x i32], [3 x i32]* %b, i32 0, i32 0 181 | %combine = call i32 @combine(i32* %"&a", i32 2, i32* %"&b", i32 3) 182 | ret i32 %combine 183 | ret i32 0 184 | } 185 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/gen/SysYLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | 'const' 4 | 'int' 5 | 'void' 6 | 'if' 7 | 'else' 8 | 'while' 9 | 'break' 10 | 'continue' 11 | 'return' 12 | '+' 13 | '-' 14 | '*' 15 | '/' 16 | '%' 17 | '=' 18 | '==' 19 | '!=' 20 | '<' 21 | '>' 22 | '<=' 23 | '>=' 24 | '!' 25 | '&&' 26 | '||' 27 | '(' 28 | ')' 29 | '{' 30 | '}' 31 | '[' 32 | ']' 33 | ',' 34 | ';' 35 | null 36 | null 37 | null 38 | null 39 | null 40 | 41 | token symbolic names: 42 | null 43 | CONST 44 | INT 45 | VOID 46 | IF 47 | ELSE 48 | WHILE 49 | BREAK 50 | CONTINUE 51 | RETURN 52 | PLUS 53 | MINUS 54 | MUL 55 | DIV 56 | MOD 57 | ASSIGN 58 | EQ 59 | NEQ 60 | LT 61 | GT 62 | LE 63 | GE 64 | NOT 65 | AND 66 | OR 67 | L_PAREN 68 | R_PAREN 69 | L_BRACE 70 | R_BRACE 71 | L_BRACKT 72 | R_BRACKT 73 | COMMA 74 | SEMICOLON 75 | IDENT 76 | INTEGR_CONST 77 | WS 78 | SL_COMMENT 79 | ML_COMMENT 80 | 81 | rule names: 82 | CONST 83 | INT 84 | VOID 85 | IF 86 | ELSE 87 | WHILE 88 | BREAK 89 | CONTINUE 90 | RETURN 91 | PLUS 92 | MINUS 93 | MUL 94 | DIV 95 | MOD 96 | ASSIGN 97 | EQ 98 | NEQ 99 | LT 100 | GT 101 | LE 102 | GE 103 | NOT 104 | AND 105 | OR 106 | L_PAREN 107 | R_PAREN 108 | L_BRACE 109 | R_BRACE 110 | L_BRACKT 111 | R_BRACKT 112 | COMMA 113 | SEMICOLON 114 | IDENT 115 | INTEGR_CONST 116 | DECIMAL 117 | OCTAL 118 | HEXADECIMAL 119 | WS 120 | SL_COMMENT 121 | ML_COMMENT 122 | LETTER 123 | DIGIT 124 | 125 | channel names: 126 | DEFAULT_TOKEN_CHANNEL 127 | HIDDEN 128 | 129 | mode names: 130 | DEFAULT_MODE 131 | 132 | atn: 133 | [4, 0, 37, 271, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 3, 32, 191, 8, 32, 1, 32, 1, 32, 1, 32, 5, 32, 196, 8, 32, 10, 32, 12, 32, 199, 9, 32, 1, 33, 1, 33, 1, 33, 3, 33, 204, 8, 33, 1, 34, 1, 34, 1, 34, 5, 34, 209, 8, 34, 10, 34, 12, 34, 212, 9, 34, 3, 34, 214, 8, 34, 1, 35, 1, 35, 4, 35, 218, 8, 35, 11, 35, 12, 35, 219, 1, 36, 1, 36, 1, 36, 1, 36, 3, 36, 226, 8, 36, 1, 36, 1, 36, 4, 36, 230, 8, 36, 11, 36, 12, 36, 231, 1, 37, 4, 37, 235, 8, 37, 11, 37, 12, 37, 236, 1, 37, 1, 37, 1, 38, 1, 38, 1, 38, 1, 38, 5, 38, 245, 8, 38, 10, 38, 12, 38, 248, 9, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 39, 5, 39, 258, 8, 39, 10, 39, 12, 39, 261, 9, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 41, 1, 41, 2, 246, 259, 0, 42, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 0, 71, 0, 73, 0, 75, 35, 77, 36, 79, 37, 81, 0, 83, 0, 1, 0, 6, 1, 0, 49, 57, 1, 0, 48, 57, 1, 0, 48, 55, 2, 0, 65, 70, 97, 102, 3, 0, 9, 10, 13, 13, 32, 32, 2, 0, 65, 90, 97, 122, 280, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 1, 85, 1, 0, 0, 0, 3, 91, 1, 0, 0, 0, 5, 95, 1, 0, 0, 0, 7, 100, 1, 0, 0, 0, 9, 103, 1, 0, 0, 0, 11, 108, 1, 0, 0, 0, 13, 114, 1, 0, 0, 0, 15, 120, 1, 0, 0, 0, 17, 129, 1, 0, 0, 0, 19, 136, 1, 0, 0, 0, 21, 138, 1, 0, 0, 0, 23, 140, 1, 0, 0, 0, 25, 142, 1, 0, 0, 0, 27, 144, 1, 0, 0, 0, 29, 146, 1, 0, 0, 0, 31, 148, 1, 0, 0, 0, 33, 151, 1, 0, 0, 0, 35, 154, 1, 0, 0, 0, 37, 156, 1, 0, 0, 0, 39, 158, 1, 0, 0, 0, 41, 161, 1, 0, 0, 0, 43, 164, 1, 0, 0, 0, 45, 166, 1, 0, 0, 0, 47, 169, 1, 0, 0, 0, 49, 172, 1, 0, 0, 0, 51, 174, 1, 0, 0, 0, 53, 176, 1, 0, 0, 0, 55, 178, 1, 0, 0, 0, 57, 180, 1, 0, 0, 0, 59, 182, 1, 0, 0, 0, 61, 184, 1, 0, 0, 0, 63, 186, 1, 0, 0, 0, 65, 190, 1, 0, 0, 0, 67, 203, 1, 0, 0, 0, 69, 213, 1, 0, 0, 0, 71, 215, 1, 0, 0, 0, 73, 225, 1, 0, 0, 0, 75, 234, 1, 0, 0, 0, 77, 240, 1, 0, 0, 0, 79, 253, 1, 0, 0, 0, 81, 267, 1, 0, 0, 0, 83, 269, 1, 0, 0, 0, 85, 86, 5, 99, 0, 0, 86, 87, 5, 111, 0, 0, 87, 88, 5, 110, 0, 0, 88, 89, 5, 115, 0, 0, 89, 90, 5, 116, 0, 0, 90, 2, 1, 0, 0, 0, 91, 92, 5, 105, 0, 0, 92, 93, 5, 110, 0, 0, 93, 94, 5, 116, 0, 0, 94, 4, 1, 0, 0, 0, 95, 96, 5, 118, 0, 0, 96, 97, 5, 111, 0, 0, 97, 98, 5, 105, 0, 0, 98, 99, 5, 100, 0, 0, 99, 6, 1, 0, 0, 0, 100, 101, 5, 105, 0, 0, 101, 102, 5, 102, 0, 0, 102, 8, 1, 0, 0, 0, 103, 104, 5, 101, 0, 0, 104, 105, 5, 108, 0, 0, 105, 106, 5, 115, 0, 0, 106, 107, 5, 101, 0, 0, 107, 10, 1, 0, 0, 0, 108, 109, 5, 119, 0, 0, 109, 110, 5, 104, 0, 0, 110, 111, 5, 105, 0, 0, 111, 112, 5, 108, 0, 0, 112, 113, 5, 101, 0, 0, 113, 12, 1, 0, 0, 0, 114, 115, 5, 98, 0, 0, 115, 116, 5, 114, 0, 0, 116, 117, 5, 101, 0, 0, 117, 118, 5, 97, 0, 0, 118, 119, 5, 107, 0, 0, 119, 14, 1, 0, 0, 0, 120, 121, 5, 99, 0, 0, 121, 122, 5, 111, 0, 0, 122, 123, 5, 110, 0, 0, 123, 124, 5, 116, 0, 0, 124, 125, 5, 105, 0, 0, 125, 126, 5, 110, 0, 0, 126, 127, 5, 117, 0, 0, 127, 128, 5, 101, 0, 0, 128, 16, 1, 0, 0, 0, 129, 130, 5, 114, 0, 0, 130, 131, 5, 101, 0, 0, 131, 132, 5, 116, 0, 0, 132, 133, 5, 117, 0, 0, 133, 134, 5, 114, 0, 0, 134, 135, 5, 110, 0, 0, 135, 18, 1, 0, 0, 0, 136, 137, 5, 43, 0, 0, 137, 20, 1, 0, 0, 0, 138, 139, 5, 45, 0, 0, 139, 22, 1, 0, 0, 0, 140, 141, 5, 42, 0, 0, 141, 24, 1, 0, 0, 0, 142, 143, 5, 47, 0, 0, 143, 26, 1, 0, 0, 0, 144, 145, 5, 37, 0, 0, 145, 28, 1, 0, 0, 0, 146, 147, 5, 61, 0, 0, 147, 30, 1, 0, 0, 0, 148, 149, 5, 61, 0, 0, 149, 150, 5, 61, 0, 0, 150, 32, 1, 0, 0, 0, 151, 152, 5, 33, 0, 0, 152, 153, 5, 61, 0, 0, 153, 34, 1, 0, 0, 0, 154, 155, 5, 60, 0, 0, 155, 36, 1, 0, 0, 0, 156, 157, 5, 62, 0, 0, 157, 38, 1, 0, 0, 0, 158, 159, 5, 60, 0, 0, 159, 160, 5, 61, 0, 0, 160, 40, 1, 0, 0, 0, 161, 162, 5, 62, 0, 0, 162, 163, 5, 61, 0, 0, 163, 42, 1, 0, 0, 0, 164, 165, 5, 33, 0, 0, 165, 44, 1, 0, 0, 0, 166, 167, 5, 38, 0, 0, 167, 168, 5, 38, 0, 0, 168, 46, 1, 0, 0, 0, 169, 170, 5, 124, 0, 0, 170, 171, 5, 124, 0, 0, 171, 48, 1, 0, 0, 0, 172, 173, 5, 40, 0, 0, 173, 50, 1, 0, 0, 0, 174, 175, 5, 41, 0, 0, 175, 52, 1, 0, 0, 0, 176, 177, 5, 123, 0, 0, 177, 54, 1, 0, 0, 0, 178, 179, 5, 125, 0, 0, 179, 56, 1, 0, 0, 0, 180, 181, 5, 91, 0, 0, 181, 58, 1, 0, 0, 0, 182, 183, 5, 93, 0, 0, 183, 60, 1, 0, 0, 0, 184, 185, 5, 44, 0, 0, 185, 62, 1, 0, 0, 0, 186, 187, 5, 59, 0, 0, 187, 64, 1, 0, 0, 0, 188, 191, 3, 81, 40, 0, 189, 191, 5, 95, 0, 0, 190, 188, 1, 0, 0, 0, 190, 189, 1, 0, 0, 0, 191, 197, 1, 0, 0, 0, 192, 196, 3, 81, 40, 0, 193, 196, 3, 83, 41, 0, 194, 196, 5, 95, 0, 0, 195, 192, 1, 0, 0, 0, 195, 193, 1, 0, 0, 0, 195, 194, 1, 0, 0, 0, 196, 199, 1, 0, 0, 0, 197, 195, 1, 0, 0, 0, 197, 198, 1, 0, 0, 0, 198, 66, 1, 0, 0, 0, 199, 197, 1, 0, 0, 0, 200, 204, 3, 71, 35, 0, 201, 204, 3, 73, 36, 0, 202, 204, 3, 69, 34, 0, 203, 200, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 203, 202, 1, 0, 0, 0, 204, 68, 1, 0, 0, 0, 205, 214, 5, 48, 0, 0, 206, 210, 7, 0, 0, 0, 207, 209, 7, 1, 0, 0, 208, 207, 1, 0, 0, 0, 209, 212, 1, 0, 0, 0, 210, 208, 1, 0, 0, 0, 210, 211, 1, 0, 0, 0, 211, 214, 1, 0, 0, 0, 212, 210, 1, 0, 0, 0, 213, 205, 1, 0, 0, 0, 213, 206, 1, 0, 0, 0, 214, 70, 1, 0, 0, 0, 215, 217, 5, 48, 0, 0, 216, 218, 7, 2, 0, 0, 217, 216, 1, 0, 0, 0, 218, 219, 1, 0, 0, 0, 219, 217, 1, 0, 0, 0, 219, 220, 1, 0, 0, 0, 220, 72, 1, 0, 0, 0, 221, 222, 5, 48, 0, 0, 222, 226, 5, 120, 0, 0, 223, 224, 5, 48, 0, 0, 224, 226, 5, 88, 0, 0, 225, 221, 1, 0, 0, 0, 225, 223, 1, 0, 0, 0, 226, 229, 1, 0, 0, 0, 227, 230, 3, 83, 41, 0, 228, 230, 7, 3, 0, 0, 229, 227, 1, 0, 0, 0, 229, 228, 1, 0, 0, 0, 230, 231, 1, 0, 0, 0, 231, 229, 1, 0, 0, 0, 231, 232, 1, 0, 0, 0, 232, 74, 1, 0, 0, 0, 233, 235, 7, 4, 0, 0, 234, 233, 1, 0, 0, 0, 235, 236, 1, 0, 0, 0, 236, 234, 1, 0, 0, 0, 236, 237, 1, 0, 0, 0, 237, 238, 1, 0, 0, 0, 238, 239, 6, 37, 0, 0, 239, 76, 1, 0, 0, 0, 240, 241, 5, 47, 0, 0, 241, 242, 5, 47, 0, 0, 242, 246, 1, 0, 0, 0, 243, 245, 9, 0, 0, 0, 244, 243, 1, 0, 0, 0, 245, 248, 1, 0, 0, 0, 246, 247, 1, 0, 0, 0, 246, 244, 1, 0, 0, 0, 247, 249, 1, 0, 0, 0, 248, 246, 1, 0, 0, 0, 249, 250, 5, 10, 0, 0, 250, 251, 1, 0, 0, 0, 251, 252, 6, 38, 0, 0, 252, 78, 1, 0, 0, 0, 253, 254, 5, 47, 0, 0, 254, 255, 5, 42, 0, 0, 255, 259, 1, 0, 0, 0, 256, 258, 9, 0, 0, 0, 257, 256, 1, 0, 0, 0, 258, 261, 1, 0, 0, 0, 259, 260, 1, 0, 0, 0, 259, 257, 1, 0, 0, 0, 260, 262, 1, 0, 0, 0, 261, 259, 1, 0, 0, 0, 262, 263, 5, 42, 0, 0, 263, 264, 5, 47, 0, 0, 264, 265, 1, 0, 0, 0, 265, 266, 6, 39, 0, 0, 266, 80, 1, 0, 0, 0, 267, 268, 7, 5, 0, 0, 268, 82, 1, 0, 0, 0, 269, 270, 7, 1, 0, 0, 270, 84, 1, 0, 0, 0, 14, 0, 190, 195, 197, 203, 210, 213, 219, 225, 229, 231, 236, 246, 259, 1, 6, 0, 0] -------------------------------------------------------------------------------- /src/SysYLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | 'const' 4 | 'int' 5 | 'void' 6 | 'if' 7 | 'else' 8 | 'while' 9 | 'break' 10 | 'continue' 11 | 'return' 12 | '+' 13 | '-' 14 | '*' 15 | '/' 16 | '%' 17 | '=' 18 | '==' 19 | '!=' 20 | '<' 21 | '>' 22 | '<=' 23 | '>=' 24 | '!' 25 | '&&' 26 | '||' 27 | '(' 28 | ')' 29 | '{' 30 | '}' 31 | '[' 32 | ']' 33 | ',' 34 | ';' 35 | null 36 | null 37 | null 38 | null 39 | null 40 | 41 | token symbolic names: 42 | null 43 | CONST 44 | INT 45 | VOID 46 | IF 47 | ELSE 48 | WHILE 49 | BREAK 50 | CONTINUE 51 | RETURN 52 | PLUS 53 | MINUS 54 | MUL 55 | DIV 56 | MOD 57 | ASSIGN 58 | EQ 59 | NEQ 60 | LT 61 | GT 62 | LE 63 | GE 64 | NOT 65 | AND 66 | OR 67 | L_PAREN 68 | R_PAREN 69 | L_BRACE 70 | R_BRACE 71 | L_BRACKT 72 | R_BRACKT 73 | COMMA 74 | SEMICOLON 75 | IDENT 76 | INTEGR_CONST 77 | WS 78 | SL_COMMENT 79 | ML_COMMENT 80 | 81 | rule names: 82 | CONST 83 | INT 84 | VOID 85 | IF 86 | ELSE 87 | WHILE 88 | BREAK 89 | CONTINUE 90 | RETURN 91 | PLUS 92 | MINUS 93 | MUL 94 | DIV 95 | MOD 96 | ASSIGN 97 | EQ 98 | NEQ 99 | LT 100 | GT 101 | LE 102 | GE 103 | NOT 104 | AND 105 | OR 106 | L_PAREN 107 | R_PAREN 108 | L_BRACE 109 | R_BRACE 110 | L_BRACKT 111 | R_BRACKT 112 | COMMA 113 | SEMICOLON 114 | IDENT 115 | INTEGR_CONST 116 | DECIMAL 117 | OCTAL 118 | HEXADECIMAL 119 | WS 120 | SL_COMMENT 121 | ML_COMMENT 122 | LETTER 123 | DIGIT 124 | 125 | channel names: 126 | DEFAULT_TOKEN_CHANNEL 127 | HIDDEN 128 | 129 | mode names: 130 | DEFAULT_MODE 131 | 132 | atn: 133 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 39, 273, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 4, 30, 9, 30, 4, 31, 9, 31, 4, 32, 9, 32, 4, 33, 9, 33, 4, 34, 9, 34, 4, 35, 9, 35, 4, 36, 9, 36, 4, 37, 9, 37, 4, 38, 9, 38, 4, 39, 9, 39, 4, 40, 9, 40, 4, 41, 9, 41, 4, 42, 9, 42, 4, 43, 9, 43, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 13, 3, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 3, 25, 3, 25, 3, 25, 3, 26, 3, 26, 3, 27, 3, 27, 3, 28, 3, 28, 3, 29, 3, 29, 3, 30, 3, 30, 3, 31, 3, 31, 3, 32, 3, 32, 3, 33, 3, 33, 3, 34, 3, 34, 5, 34, 193, 10, 34, 3, 34, 3, 34, 3, 34, 7, 34, 198, 10, 34, 12, 34, 14, 34, 201, 11, 34, 3, 35, 3, 35, 3, 35, 5, 35, 206, 10, 35, 3, 36, 3, 36, 3, 36, 7, 36, 211, 10, 36, 12, 36, 14, 36, 214, 11, 36, 5, 36, 216, 10, 36, 3, 37, 3, 37, 6, 37, 220, 10, 37, 13, 37, 14, 37, 221, 3, 38, 3, 38, 3, 38, 3, 38, 5, 38, 228, 10, 38, 3, 38, 3, 38, 6, 38, 232, 10, 38, 13, 38, 14, 38, 233, 3, 39, 6, 39, 237, 10, 39, 13, 39, 14, 39, 238, 3, 39, 3, 39, 3, 40, 3, 40, 3, 40, 3, 40, 7, 40, 247, 10, 40, 12, 40, 14, 40, 250, 11, 40, 3, 40, 3, 40, 3, 40, 3, 40, 3, 41, 3, 41, 3, 41, 3, 41, 7, 41, 260, 10, 41, 12, 41, 14, 41, 263, 11, 41, 3, 41, 3, 41, 3, 41, 3, 41, 3, 41, 3, 42, 3, 42, 3, 43, 3, 43, 4, 248, 261, 2, 44, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 20, 39, 21, 41, 22, 43, 23, 45, 24, 47, 25, 49, 26, 51, 27, 53, 28, 55, 29, 57, 30, 59, 31, 61, 32, 63, 33, 65, 34, 67, 35, 69, 36, 71, 2, 73, 2, 75, 2, 77, 37, 79, 38, 81, 39, 83, 2, 85, 2, 3, 2, 8, 3, 2, 51, 59, 3, 2, 50, 59, 3, 2, 50, 57, 4, 2, 67, 72, 99, 104, 5, 2, 11, 12, 15, 15, 34, 34, 4, 2, 67, 92, 99, 124, 2, 282, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 45, 3, 2, 2, 2, 2, 47, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 2, 57, 3, 2, 2, 2, 2, 59, 3, 2, 2, 2, 2, 61, 3, 2, 2, 2, 2, 63, 3, 2, 2, 2, 2, 65, 3, 2, 2, 2, 2, 67, 3, 2, 2, 2, 2, 69, 3, 2, 2, 2, 2, 77, 3, 2, 2, 2, 2, 79, 3, 2, 2, 2, 2, 81, 3, 2, 2, 2, 3, 87, 3, 2, 2, 2, 5, 93, 3, 2, 2, 2, 7, 97, 3, 2, 2, 2, 9, 102, 3, 2, 2, 2, 11, 105, 3, 2, 2, 2, 13, 110, 3, 2, 2, 2, 15, 116, 3, 2, 2, 2, 17, 122, 3, 2, 2, 2, 19, 131, 3, 2, 2, 2, 21, 138, 3, 2, 2, 2, 23, 140, 3, 2, 2, 2, 25, 142, 3, 2, 2, 2, 27, 144, 3, 2, 2, 2, 29, 146, 3, 2, 2, 2, 31, 148, 3, 2, 2, 2, 33, 150, 3, 2, 2, 2, 35, 153, 3, 2, 2, 2, 37, 156, 3, 2, 2, 2, 39, 158, 3, 2, 2, 2, 41, 160, 3, 2, 2, 2, 43, 163, 3, 2, 2, 2, 45, 166, 3, 2, 2, 2, 47, 168, 3, 2, 2, 2, 49, 171, 3, 2, 2, 2, 51, 174, 3, 2, 2, 2, 53, 176, 3, 2, 2, 2, 55, 178, 3, 2, 2, 2, 57, 180, 3, 2, 2, 2, 59, 182, 3, 2, 2, 2, 61, 184, 3, 2, 2, 2, 63, 186, 3, 2, 2, 2, 65, 188, 3, 2, 2, 2, 67, 192, 3, 2, 2, 2, 69, 205, 3, 2, 2, 2, 71, 215, 3, 2, 2, 2, 73, 217, 3, 2, 2, 2, 75, 227, 3, 2, 2, 2, 77, 236, 3, 2, 2, 2, 79, 242, 3, 2, 2, 2, 81, 255, 3, 2, 2, 2, 83, 269, 3, 2, 2, 2, 85, 271, 3, 2, 2, 2, 87, 88, 7, 101, 2, 2, 88, 89, 7, 113, 2, 2, 89, 90, 7, 112, 2, 2, 90, 91, 7, 117, 2, 2, 91, 92, 7, 118, 2, 2, 92, 4, 3, 2, 2, 2, 93, 94, 7, 107, 2, 2, 94, 95, 7, 112, 2, 2, 95, 96, 7, 118, 2, 2, 96, 6, 3, 2, 2, 2, 97, 98, 7, 120, 2, 2, 98, 99, 7, 113, 2, 2, 99, 100, 7, 107, 2, 2, 100, 101, 7, 102, 2, 2, 101, 8, 3, 2, 2, 2, 102, 103, 7, 107, 2, 2, 103, 104, 7, 104, 2, 2, 104, 10, 3, 2, 2, 2, 105, 106, 7, 103, 2, 2, 106, 107, 7, 110, 2, 2, 107, 108, 7, 117, 2, 2, 108, 109, 7, 103, 2, 2, 109, 12, 3, 2, 2, 2, 110, 111, 7, 121, 2, 2, 111, 112, 7, 106, 2, 2, 112, 113, 7, 107, 2, 2, 113, 114, 7, 110, 2, 2, 114, 115, 7, 103, 2, 2, 115, 14, 3, 2, 2, 2, 116, 117, 7, 100, 2, 2, 117, 118, 7, 116, 2, 2, 118, 119, 7, 103, 2, 2, 119, 120, 7, 99, 2, 2, 120, 121, 7, 109, 2, 2, 121, 16, 3, 2, 2, 2, 122, 123, 7, 101, 2, 2, 123, 124, 7, 113, 2, 2, 124, 125, 7, 112, 2, 2, 125, 126, 7, 118, 2, 2, 126, 127, 7, 107, 2, 2, 127, 128, 7, 112, 2, 2, 128, 129, 7, 119, 2, 2, 129, 130, 7, 103, 2, 2, 130, 18, 3, 2, 2, 2, 131, 132, 7, 116, 2, 2, 132, 133, 7, 103, 2, 2, 133, 134, 7, 118, 2, 2, 134, 135, 7, 119, 2, 2, 135, 136, 7, 116, 2, 2, 136, 137, 7, 112, 2, 2, 137, 20, 3, 2, 2, 2, 138, 139, 7, 45, 2, 2, 139, 22, 3, 2, 2, 2, 140, 141, 7, 47, 2, 2, 141, 24, 3, 2, 2, 2, 142, 143, 7, 44, 2, 2, 143, 26, 3, 2, 2, 2, 144, 145, 7, 49, 2, 2, 145, 28, 3, 2, 2, 2, 146, 147, 7, 39, 2, 2, 147, 30, 3, 2, 2, 2, 148, 149, 7, 63, 2, 2, 149, 32, 3, 2, 2, 2, 150, 151, 7, 63, 2, 2, 151, 152, 7, 63, 2, 2, 152, 34, 3, 2, 2, 2, 153, 154, 7, 35, 2, 2, 154, 155, 7, 63, 2, 2, 155, 36, 3, 2, 2, 2, 156, 157, 7, 62, 2, 2, 157, 38, 3, 2, 2, 2, 158, 159, 7, 64, 2, 2, 159, 40, 3, 2, 2, 2, 160, 161, 7, 62, 2, 2, 161, 162, 7, 63, 2, 2, 162, 42, 3, 2, 2, 2, 163, 164, 7, 64, 2, 2, 164, 165, 7, 63, 2, 2, 165, 44, 3, 2, 2, 2, 166, 167, 7, 35, 2, 2, 167, 46, 3, 2, 2, 2, 168, 169, 7, 40, 2, 2, 169, 170, 7, 40, 2, 2, 170, 48, 3, 2, 2, 2, 171, 172, 7, 126, 2, 2, 172, 173, 7, 126, 2, 2, 173, 50, 3, 2, 2, 2, 174, 175, 7, 42, 2, 2, 175, 52, 3, 2, 2, 2, 176, 177, 7, 43, 2, 2, 177, 54, 3, 2, 2, 2, 178, 179, 7, 125, 2, 2, 179, 56, 3, 2, 2, 2, 180, 181, 7, 127, 2, 2, 181, 58, 3, 2, 2, 2, 182, 183, 7, 93, 2, 2, 183, 60, 3, 2, 2, 2, 184, 185, 7, 95, 2, 2, 185, 62, 3, 2, 2, 2, 186, 187, 7, 46, 2, 2, 187, 64, 3, 2, 2, 2, 188, 189, 7, 61, 2, 2, 189, 66, 3, 2, 2, 2, 190, 193, 5, 83, 42, 2, 191, 193, 7, 97, 2, 2, 192, 190, 3, 2, 2, 2, 192, 191, 3, 2, 2, 2, 193, 199, 3, 2, 2, 2, 194, 198, 5, 83, 42, 2, 195, 198, 5, 85, 43, 2, 196, 198, 7, 97, 2, 2, 197, 194, 3, 2, 2, 2, 197, 195, 3, 2, 2, 2, 197, 196, 3, 2, 2, 2, 198, 201, 3, 2, 2, 2, 199, 197, 3, 2, 2, 2, 199, 200, 3, 2, 2, 2, 200, 68, 3, 2, 2, 2, 201, 199, 3, 2, 2, 2, 202, 206, 5, 73, 37, 2, 203, 206, 5, 75, 38, 2, 204, 206, 5, 71, 36, 2, 205, 202, 3, 2, 2, 2, 205, 203, 3, 2, 2, 2, 205, 204, 3, 2, 2, 2, 206, 70, 3, 2, 2, 2, 207, 216, 7, 50, 2, 2, 208, 212, 9, 2, 2, 2, 209, 211, 9, 3, 2, 2, 210, 209, 3, 2, 2, 2, 211, 214, 3, 2, 2, 2, 212, 210, 3, 2, 2, 2, 212, 213, 3, 2, 2, 2, 213, 216, 3, 2, 2, 2, 214, 212, 3, 2, 2, 2, 215, 207, 3, 2, 2, 2, 215, 208, 3, 2, 2, 2, 216, 72, 3, 2, 2, 2, 217, 219, 7, 50, 2, 2, 218, 220, 9, 4, 2, 2, 219, 218, 3, 2, 2, 2, 220, 221, 3, 2, 2, 2, 221, 219, 3, 2, 2, 2, 221, 222, 3, 2, 2, 2, 222, 74, 3, 2, 2, 2, 223, 224, 7, 50, 2, 2, 224, 228, 7, 122, 2, 2, 225, 226, 7, 50, 2, 2, 226, 228, 7, 90, 2, 2, 227, 223, 3, 2, 2, 2, 227, 225, 3, 2, 2, 2, 228, 231, 3, 2, 2, 2, 229, 232, 5, 85, 43, 2, 230, 232, 9, 5, 2, 2, 231, 229, 3, 2, 2, 2, 231, 230, 3, 2, 2, 2, 232, 233, 3, 2, 2, 2, 233, 231, 3, 2, 2, 2, 233, 234, 3, 2, 2, 2, 234, 76, 3, 2, 2, 2, 235, 237, 9, 6, 2, 2, 236, 235, 3, 2, 2, 2, 237, 238, 3, 2, 2, 2, 238, 236, 3, 2, 2, 2, 238, 239, 3, 2, 2, 2, 239, 240, 3, 2, 2, 2, 240, 241, 8, 39, 2, 2, 241, 78, 3, 2, 2, 2, 242, 243, 7, 49, 2, 2, 243, 244, 7, 49, 2, 2, 244, 248, 3, 2, 2, 2, 245, 247, 11, 2, 2, 2, 246, 245, 3, 2, 2, 2, 247, 250, 3, 2, 2, 2, 248, 249, 3, 2, 2, 2, 248, 246, 3, 2, 2, 2, 249, 251, 3, 2, 2, 2, 250, 248, 3, 2, 2, 2, 251, 252, 7, 12, 2, 2, 252, 253, 3, 2, 2, 2, 253, 254, 8, 40, 2, 2, 254, 80, 3, 2, 2, 2, 255, 256, 7, 49, 2, 2, 256, 257, 7, 44, 2, 2, 257, 261, 3, 2, 2, 2, 258, 260, 11, 2, 2, 2, 259, 258, 3, 2, 2, 2, 260, 263, 3, 2, 2, 2, 261, 262, 3, 2, 2, 2, 261, 259, 3, 2, 2, 2, 262, 264, 3, 2, 2, 2, 263, 261, 3, 2, 2, 2, 264, 265, 7, 44, 2, 2, 265, 266, 7, 49, 2, 2, 266, 267, 3, 2, 2, 2, 267, 268, 8, 41, 2, 2, 268, 82, 3, 2, 2, 2, 269, 270, 9, 7, 2, 2, 270, 84, 3, 2, 2, 2, 271, 272, 9, 3, 2, 2, 272, 86, 3, 2, 2, 2, 16, 2, 192, 197, 199, 205, 212, 215, 221, 227, 231, 233, 238, 248, 261, 3, 8, 2, 2] -------------------------------------------------------------------------------- /src/SysYParserVisitor.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/SysYParser.g4 by ANTLR 4.9.1 2 | import org.antlr.v4.runtime.tree.ParseTreeVisitor; 3 | 4 | /** 5 | * This interface defines a complete generic visitor for a parse tree produced 6 | * by {@link SysYParser}. 7 | * 8 | * @param The return type of the visit operation. Use {@link Void} for 9 | * operations with no return type. 10 | */ 11 | public interface SysYParserVisitor extends ParseTreeVisitor { 12 | /** 13 | * Visit a parse tree produced by {@link SysYParser#program}. 14 | * @param ctx the parse tree 15 | * @return the visitor result 16 | */ 17 | T visitProgram(SysYParser.ProgramContext ctx); 18 | /** 19 | * Visit a parse tree produced by {@link SysYParser#compUnit}. 20 | * @param ctx the parse tree 21 | * @return the visitor result 22 | */ 23 | T visitCompUnit(SysYParser.CompUnitContext ctx); 24 | /** 25 | * Visit a parse tree produced by {@link SysYParser#decl}. 26 | * @param ctx the parse tree 27 | * @return the visitor result 28 | */ 29 | T visitDecl(SysYParser.DeclContext ctx); 30 | /** 31 | * Visit a parse tree produced by {@link SysYParser#constDecl}. 32 | * @param ctx the parse tree 33 | * @return the visitor result 34 | */ 35 | T visitConstDecl(SysYParser.ConstDeclContext ctx); 36 | /** 37 | * Visit a parse tree produced by {@link SysYParser#bType}. 38 | * @param ctx the parse tree 39 | * @return the visitor result 40 | */ 41 | T visitBType(SysYParser.BTypeContext ctx); 42 | /** 43 | * Visit a parse tree produced by {@link SysYParser#constDef}. 44 | * @param ctx the parse tree 45 | * @return the visitor result 46 | */ 47 | T visitConstDef(SysYParser.ConstDefContext ctx); 48 | /** 49 | * Visit a parse tree produced by {@link SysYParser#constInitVal}. 50 | * @param ctx the parse tree 51 | * @return the visitor result 52 | */ 53 | T visitConstInitVal(SysYParser.ConstInitValContext ctx); 54 | /** 55 | * Visit a parse tree produced by {@link SysYParser#varDecl}. 56 | * @param ctx the parse tree 57 | * @return the visitor result 58 | */ 59 | T visitVarDecl(SysYParser.VarDeclContext ctx); 60 | /** 61 | * Visit a parse tree produced by {@link SysYParser#varDef}. 62 | * @param ctx the parse tree 63 | * @return the visitor result 64 | */ 65 | T visitVarDef(SysYParser.VarDefContext ctx); 66 | /** 67 | * Visit a parse tree produced by {@link SysYParser#initVal}. 68 | * @param ctx the parse tree 69 | * @return the visitor result 70 | */ 71 | T visitInitVal(SysYParser.InitValContext ctx); 72 | /** 73 | * Visit a parse tree produced by {@link SysYParser#funcDef}. 74 | * @param ctx the parse tree 75 | * @return the visitor result 76 | */ 77 | T visitFuncDef(SysYParser.FuncDefContext ctx); 78 | /** 79 | * Visit a parse tree produced by {@link SysYParser#funcType}. 80 | * @param ctx the parse tree 81 | * @return the visitor result 82 | */ 83 | T visitFuncType(SysYParser.FuncTypeContext ctx); 84 | /** 85 | * Visit a parse tree produced by {@link SysYParser#funcFParams}. 86 | * @param ctx the parse tree 87 | * @return the visitor result 88 | */ 89 | T visitFuncFParams(SysYParser.FuncFParamsContext ctx); 90 | /** 91 | * Visit a parse tree produced by {@link SysYParser#funcFParam}. 92 | * @param ctx the parse tree 93 | * @return the visitor result 94 | */ 95 | T visitFuncFParam(SysYParser.FuncFParamContext ctx); 96 | /** 97 | * Visit a parse tree produced by {@link SysYParser#block}. 98 | * @param ctx the parse tree 99 | * @return the visitor result 100 | */ 101 | T visitBlock(SysYParser.BlockContext ctx); 102 | /** 103 | * Visit a parse tree produced by {@link SysYParser#blockItem}. 104 | * @param ctx the parse tree 105 | * @return the visitor result 106 | */ 107 | T visitBlockItem(SysYParser.BlockItemContext ctx); 108 | /** 109 | * Visit a parse tree produced by the {@code assignment} 110 | * labeled alternative in {@link SysYParser#stmt}. 111 | * @param ctx the parse tree 112 | * @return the visitor result 113 | */ 114 | T visitAssignment(SysYParser.AssignmentContext ctx); 115 | /** 116 | * Visit a parse tree produced by the {@code possibleExp} 117 | * labeled alternative in {@link SysYParser#stmt}. 118 | * @param ctx the parse tree 119 | * @return the visitor result 120 | */ 121 | T visitPossibleExp(SysYParser.PossibleExpContext ctx); 122 | /** 123 | * Visit a parse tree produced by the {@code blockStmt} 124 | * labeled alternative in {@link SysYParser#stmt}. 125 | * @param ctx the parse tree 126 | * @return the visitor result 127 | */ 128 | T visitBlockStmt(SysYParser.BlockStmtContext ctx); 129 | /** 130 | * Visit a parse tree produced by the {@code ifStmt} 131 | * labeled alternative in {@link SysYParser#stmt}. 132 | * @param ctx the parse tree 133 | * @return the visitor result 134 | */ 135 | T visitIfStmt(SysYParser.IfStmtContext ctx); 136 | /** 137 | * Visit a parse tree produced by the {@code whileStmt} 138 | * labeled alternative in {@link SysYParser#stmt}. 139 | * @param ctx the parse tree 140 | * @return the visitor result 141 | */ 142 | T visitWhileStmt(SysYParser.WhileStmtContext ctx); 143 | /** 144 | * Visit a parse tree produced by the {@code breakStmt} 145 | * labeled alternative in {@link SysYParser#stmt}. 146 | * @param ctx the parse tree 147 | * @return the visitor result 148 | */ 149 | T visitBreakStmt(SysYParser.BreakStmtContext ctx); 150 | /** 151 | * Visit a parse tree produced by the {@code continueStmt} 152 | * labeled alternative in {@link SysYParser#stmt}. 153 | * @param ctx the parse tree 154 | * @return the visitor result 155 | */ 156 | T visitContinueStmt(SysYParser.ContinueStmtContext ctx); 157 | /** 158 | * Visit a parse tree produced by the {@code returnStmt} 159 | * labeled alternative in {@link SysYParser#stmt}. 160 | * @param ctx the parse tree 161 | * @return the visitor result 162 | */ 163 | T visitReturnStmt(SysYParser.ReturnStmtContext ctx); 164 | /** 165 | * Visit a parse tree produced by the {@code lValExp} 166 | * labeled alternative in {@link SysYParser#exp}. 167 | * @param ctx the parse tree 168 | * @return the visitor result 169 | */ 170 | T visitLValExp(SysYParser.LValExpContext ctx); 171 | /** 172 | * Visit a parse tree produced by the {@code unaryExp} 173 | * labeled alternative in {@link SysYParser#exp}. 174 | * @param ctx the parse tree 175 | * @return the visitor result 176 | */ 177 | T visitUnaryExp(SysYParser.UnaryExpContext ctx); 178 | /** 179 | * Visit a parse tree produced by the {@code parenExp} 180 | * labeled alternative in {@link SysYParser#exp}. 181 | * @param ctx the parse tree 182 | * @return the visitor result 183 | */ 184 | T visitParenExp(SysYParser.ParenExpContext ctx); 185 | /** 186 | * Visit a parse tree produced by the {@code addExp} 187 | * labeled alternative in {@link SysYParser#exp}. 188 | * @param ctx the parse tree 189 | * @return the visitor result 190 | */ 191 | T visitAddExp(SysYParser.AddExpContext ctx); 192 | /** 193 | * Visit a parse tree produced by the {@code mulExp} 194 | * labeled alternative in {@link SysYParser#exp}. 195 | * @param ctx the parse tree 196 | * @return the visitor result 197 | */ 198 | T visitMulExp(SysYParser.MulExpContext ctx); 199 | /** 200 | * Visit a parse tree produced by the {@code funcCallExp} 201 | * labeled alternative in {@link SysYParser#exp}. 202 | * @param ctx the parse tree 203 | * @return the visitor result 204 | */ 205 | T visitFuncCallExp(SysYParser.FuncCallExpContext ctx); 206 | /** 207 | * Visit a parse tree produced by the {@code numExp} 208 | * labeled alternative in {@link SysYParser#exp}. 209 | * @param ctx the parse tree 210 | * @return the visitor result 211 | */ 212 | T visitNumExp(SysYParser.NumExpContext ctx); 213 | /** 214 | * Visit a parse tree produced by the {@code compareExp} 215 | * labeled alternative in {@link SysYParser#cond}. 216 | * @param ctx the parse tree 217 | * @return the visitor result 218 | */ 219 | T visitCompareExp(SysYParser.CompareExpContext ctx); 220 | /** 221 | * Visit a parse tree produced by the {@code relationExp} 222 | * labeled alternative in {@link SysYParser#cond}. 223 | * @param ctx the parse tree 224 | * @return the visitor result 225 | */ 226 | T visitRelationExp(SysYParser.RelationExpContext ctx); 227 | /** 228 | * Visit a parse tree produced by the {@code condExp} 229 | * labeled alternative in {@link SysYParser#cond}. 230 | * @param ctx the parse tree 231 | * @return the visitor result 232 | */ 233 | T visitCondExp(SysYParser.CondExpContext ctx); 234 | /** 235 | * Visit a parse tree produced by the {@code andExp} 236 | * labeled alternative in {@link SysYParser#cond}. 237 | * @param ctx the parse tree 238 | * @return the visitor result 239 | */ 240 | T visitAndExp(SysYParser.AndExpContext ctx); 241 | /** 242 | * Visit a parse tree produced by the {@code orExp} 243 | * labeled alternative in {@link SysYParser#cond}. 244 | * @param ctx the parse tree 245 | * @return the visitor result 246 | */ 247 | T visitOrExp(SysYParser.OrExpContext ctx); 248 | /** 249 | * Visit a parse tree produced by {@link SysYParser#lVal}. 250 | * @param ctx the parse tree 251 | * @return the visitor result 252 | */ 253 | T visitLVal(SysYParser.LValContext ctx); 254 | /** 255 | * Visit a parse tree produced by {@link SysYParser#number}. 256 | * @param ctx the parse tree 257 | * @return the visitor result 258 | */ 259 | T visitNumber(SysYParser.NumberContext ctx); 260 | /** 261 | * Visit a parse tree produced by {@link SysYParser#unaryOp}. 262 | * @param ctx the parse tree 263 | * @return the visitor result 264 | */ 265 | T visitUnaryOp(SysYParser.UnaryOpContext ctx); 266 | /** 267 | * Visit a parse tree produced by {@link SysYParser#funcRParams}. 268 | * @param ctx the parse tree 269 | * @return the visitor result 270 | */ 271 | T visitFuncRParams(SysYParser.FuncRParamsContext ctx); 272 | /** 273 | * Visit a parse tree produced by {@link SysYParser#param}. 274 | * @param ctx the parse tree 275 | * @return the visitor result 276 | */ 277 | T visitParam(SysYParser.ParamContext ctx); 278 | /** 279 | * Visit a parse tree produced by {@link SysYParser#constExp}. 280 | * @param ctx the parse tree 281 | * @return the visitor result 282 | */ 283 | T visitConstExp(SysYParser.ConstExpContext ctx); 284 | } -------------------------------------------------------------------------------- /src/SysYParser.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | 'const' 4 | 'int' 5 | 'void' 6 | 'if' 7 | 'else' 8 | 'while' 9 | 'break' 10 | 'continue' 11 | 'return' 12 | '+' 13 | '-' 14 | '*' 15 | '/' 16 | '%' 17 | '=' 18 | '==' 19 | '!=' 20 | '<' 21 | '>' 22 | '<=' 23 | '>=' 24 | '!' 25 | '&&' 26 | '||' 27 | '(' 28 | ')' 29 | '{' 30 | '}' 31 | '[' 32 | ']' 33 | ',' 34 | ';' 35 | null 36 | null 37 | null 38 | null 39 | null 40 | 41 | token symbolic names: 42 | null 43 | CONST 44 | INT 45 | VOID 46 | IF 47 | ELSE 48 | WHILE 49 | BREAK 50 | CONTINUE 51 | RETURN 52 | PLUS 53 | MINUS 54 | MUL 55 | DIV 56 | MOD 57 | ASSIGN 58 | EQ 59 | NEQ 60 | LT 61 | GT 62 | LE 63 | GE 64 | NOT 65 | AND 66 | OR 67 | L_PAREN 68 | R_PAREN 69 | L_BRACE 70 | R_BRACE 71 | L_BRACKT 72 | R_BRACKT 73 | COMMA 74 | SEMICOLON 75 | IDENT 76 | INTEGR_CONST 77 | WS 78 | SL_COMMENT 79 | ML_COMMENT 80 | 81 | rule names: 82 | program 83 | compUnit 84 | decl 85 | constDecl 86 | bType 87 | constDef 88 | constInitVal 89 | varDecl 90 | varDef 91 | initVal 92 | funcDef 93 | funcType 94 | funcFParams 95 | funcFParam 96 | block 97 | blockItem 98 | stmt 99 | exp 100 | cond 101 | lVal 102 | number 103 | unaryOp 104 | funcRParams 105 | param 106 | constExp 107 | 108 | 109 | atn: 110 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 39, 307, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 3, 2, 3, 2, 3, 3, 3, 3, 6, 3, 57, 10, 3, 13, 3, 14, 3, 58, 3, 3, 3, 3, 3, 4, 3, 4, 5, 4, 65, 10, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 7, 5, 72, 10, 5, 12, 5, 14, 5, 75, 11, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 86, 10, 7, 12, 7, 14, 7, 89, 11, 7, 3, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 7, 8, 99, 10, 8, 12, 8, 14, 8, 102, 11, 8, 5, 8, 104, 10, 8, 3, 8, 5, 8, 107, 10, 8, 3, 9, 3, 9, 3, 9, 3, 9, 7, 9, 113, 10, 9, 12, 9, 14, 9, 116, 11, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 7, 10, 125, 10, 10, 12, 10, 14, 10, 128, 11, 10, 3, 10, 3, 10, 5, 10, 132, 10, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 7, 11, 139, 10, 11, 12, 11, 14, 11, 142, 11, 11, 5, 11, 144, 10, 11, 3, 11, 5, 11, 147, 10, 11, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 153, 10, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 7, 14, 163, 10, 14, 12, 14, 14, 14, 166, 11, 14, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 7, 15, 176, 10, 15, 12, 15, 14, 15, 179, 11, 15, 5, 15, 181, 10, 15, 3, 16, 3, 16, 7, 16, 185, 10, 16, 12, 16, 14, 16, 188, 11, 16, 3, 16, 3, 16, 3, 17, 3, 17, 5, 17, 194, 10, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 202, 10, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 213, 10, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 227, 10, 18, 3, 18, 5, 18, 230, 10, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 5, 19, 242, 10, 19, 3, 19, 3, 19, 3, 19, 3, 19, 5, 19, 248, 10, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 7, 19, 256, 10, 19, 12, 19, 14, 19, 259, 11, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 7, 20, 276, 10, 20, 12, 20, 14, 20, 279, 11, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 7, 21, 286, 10, 21, 12, 21, 14, 21, 289, 11, 21, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 7, 24, 298, 10, 24, 12, 24, 14, 24, 301, 11, 24, 3, 25, 3, 25, 3, 26, 3, 26, 3, 26, 2, 4, 36, 38, 27, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 2, 8, 3, 2, 4, 5, 3, 2, 14, 16, 3, 2, 12, 13, 3, 2, 20, 23, 3, 2, 18, 19, 4, 2, 12, 13, 24, 24, 2, 324, 2, 52, 3, 2, 2, 2, 4, 56, 3, 2, 2, 2, 6, 64, 3, 2, 2, 2, 8, 66, 3, 2, 2, 2, 10, 78, 3, 2, 2, 2, 12, 80, 3, 2, 2, 2, 14, 106, 3, 2, 2, 2, 16, 108, 3, 2, 2, 2, 18, 119, 3, 2, 2, 2, 20, 146, 3, 2, 2, 2, 22, 148, 3, 2, 2, 2, 24, 157, 3, 2, 2, 2, 26, 159, 3, 2, 2, 2, 28, 167, 3, 2, 2, 2, 30, 182, 3, 2, 2, 2, 32, 193, 3, 2, 2, 2, 34, 229, 3, 2, 2, 2, 36, 247, 3, 2, 2, 2, 38, 260, 3, 2, 2, 2, 40, 280, 3, 2, 2, 2, 42, 290, 3, 2, 2, 2, 44, 292, 3, 2, 2, 2, 46, 294, 3, 2, 2, 2, 48, 302, 3, 2, 2, 2, 50, 304, 3, 2, 2, 2, 52, 53, 5, 4, 3, 2, 53, 3, 3, 2, 2, 2, 54, 57, 5, 22, 12, 2, 55, 57, 5, 6, 4, 2, 56, 54, 3, 2, 2, 2, 56, 55, 3, 2, 2, 2, 57, 58, 3, 2, 2, 2, 58, 56, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 60, 3, 2, 2, 2, 60, 61, 7, 2, 2, 3, 61, 5, 3, 2, 2, 2, 62, 65, 5, 8, 5, 2, 63, 65, 5, 16, 9, 2, 64, 62, 3, 2, 2, 2, 64, 63, 3, 2, 2, 2, 65, 7, 3, 2, 2, 2, 66, 67, 7, 3, 2, 2, 67, 68, 5, 10, 6, 2, 68, 73, 5, 12, 7, 2, 69, 70, 7, 33, 2, 2, 70, 72, 5, 12, 7, 2, 71, 69, 3, 2, 2, 2, 72, 75, 3, 2, 2, 2, 73, 71, 3, 2, 2, 2, 73, 74, 3, 2, 2, 2, 74, 76, 3, 2, 2, 2, 75, 73, 3, 2, 2, 2, 76, 77, 7, 34, 2, 2, 77, 9, 3, 2, 2, 2, 78, 79, 7, 4, 2, 2, 79, 11, 3, 2, 2, 2, 80, 87, 7, 35, 2, 2, 81, 82, 7, 31, 2, 2, 82, 83, 5, 50, 26, 2, 83, 84, 7, 32, 2, 2, 84, 86, 3, 2, 2, 2, 85, 81, 3, 2, 2, 2, 86, 89, 3, 2, 2, 2, 87, 85, 3, 2, 2, 2, 87, 88, 3, 2, 2, 2, 88, 90, 3, 2, 2, 2, 89, 87, 3, 2, 2, 2, 90, 91, 7, 17, 2, 2, 91, 92, 5, 14, 8, 2, 92, 13, 3, 2, 2, 2, 93, 107, 5, 50, 26, 2, 94, 103, 7, 29, 2, 2, 95, 100, 5, 14, 8, 2, 96, 97, 7, 33, 2, 2, 97, 99, 5, 14, 8, 2, 98, 96, 3, 2, 2, 2, 99, 102, 3, 2, 2, 2, 100, 98, 3, 2, 2, 2, 100, 101, 3, 2, 2, 2, 101, 104, 3, 2, 2, 2, 102, 100, 3, 2, 2, 2, 103, 95, 3, 2, 2, 2, 103, 104, 3, 2, 2, 2, 104, 105, 3, 2, 2, 2, 105, 107, 7, 30, 2, 2, 106, 93, 3, 2, 2, 2, 106, 94, 3, 2, 2, 2, 107, 15, 3, 2, 2, 2, 108, 109, 5, 10, 6, 2, 109, 114, 5, 18, 10, 2, 110, 111, 7, 33, 2, 2, 111, 113, 5, 18, 10, 2, 112, 110, 3, 2, 2, 2, 113, 116, 3, 2, 2, 2, 114, 112, 3, 2, 2, 2, 114, 115, 3, 2, 2, 2, 115, 117, 3, 2, 2, 2, 116, 114, 3, 2, 2, 2, 117, 118, 7, 34, 2, 2, 118, 17, 3, 2, 2, 2, 119, 126, 7, 35, 2, 2, 120, 121, 7, 31, 2, 2, 121, 122, 5, 50, 26, 2, 122, 123, 7, 32, 2, 2, 123, 125, 3, 2, 2, 2, 124, 120, 3, 2, 2, 2, 125, 128, 3, 2, 2, 2, 126, 124, 3, 2, 2, 2, 126, 127, 3, 2, 2, 2, 127, 131, 3, 2, 2, 2, 128, 126, 3, 2, 2, 2, 129, 130, 7, 17, 2, 2, 130, 132, 5, 20, 11, 2, 131, 129, 3, 2, 2, 2, 131, 132, 3, 2, 2, 2, 132, 19, 3, 2, 2, 2, 133, 147, 5, 36, 19, 2, 134, 143, 7, 29, 2, 2, 135, 140, 5, 20, 11, 2, 136, 137, 7, 33, 2, 2, 137, 139, 5, 20, 11, 2, 138, 136, 3, 2, 2, 2, 139, 142, 3, 2, 2, 2, 140, 138, 3, 2, 2, 2, 140, 141, 3, 2, 2, 2, 141, 144, 3, 2, 2, 2, 142, 140, 3, 2, 2, 2, 143, 135, 3, 2, 2, 2, 143, 144, 3, 2, 2, 2, 144, 145, 3, 2, 2, 2, 145, 147, 7, 30, 2, 2, 146, 133, 3, 2, 2, 2, 146, 134, 3, 2, 2, 2, 147, 21, 3, 2, 2, 2, 148, 149, 5, 24, 13, 2, 149, 150, 7, 35, 2, 2, 150, 152, 7, 27, 2, 2, 151, 153, 5, 26, 14, 2, 152, 151, 3, 2, 2, 2, 152, 153, 3, 2, 2, 2, 153, 154, 3, 2, 2, 2, 154, 155, 7, 28, 2, 2, 155, 156, 5, 30, 16, 2, 156, 23, 3, 2, 2, 2, 157, 158, 9, 2, 2, 2, 158, 25, 3, 2, 2, 2, 159, 164, 5, 28, 15, 2, 160, 161, 7, 33, 2, 2, 161, 163, 5, 28, 15, 2, 162, 160, 3, 2, 2, 2, 163, 166, 3, 2, 2, 2, 164, 162, 3, 2, 2, 2, 164, 165, 3, 2, 2, 2, 165, 27, 3, 2, 2, 2, 166, 164, 3, 2, 2, 2, 167, 168, 5, 10, 6, 2, 168, 180, 7, 35, 2, 2, 169, 170, 7, 31, 2, 2, 170, 177, 7, 32, 2, 2, 171, 172, 7, 31, 2, 2, 172, 173, 5, 36, 19, 2, 173, 174, 7, 32, 2, 2, 174, 176, 3, 2, 2, 2, 175, 171, 3, 2, 2, 2, 176, 179, 3, 2, 2, 2, 177, 175, 3, 2, 2, 2, 177, 178, 3, 2, 2, 2, 178, 181, 3, 2, 2, 2, 179, 177, 3, 2, 2, 2, 180, 169, 3, 2, 2, 2, 180, 181, 3, 2, 2, 2, 181, 29, 3, 2, 2, 2, 182, 186, 7, 29, 2, 2, 183, 185, 5, 32, 17, 2, 184, 183, 3, 2, 2, 2, 185, 188, 3, 2, 2, 2, 186, 184, 3, 2, 2, 2, 186, 187, 3, 2, 2, 2, 187, 189, 3, 2, 2, 2, 188, 186, 3, 2, 2, 2, 189, 190, 7, 30, 2, 2, 190, 31, 3, 2, 2, 2, 191, 194, 5, 6, 4, 2, 192, 194, 5, 34, 18, 2, 193, 191, 3, 2, 2, 2, 193, 192, 3, 2, 2, 2, 194, 33, 3, 2, 2, 2, 195, 196, 5, 40, 21, 2, 196, 197, 7, 17, 2, 2, 197, 198, 5, 36, 19, 2, 198, 199, 7, 34, 2, 2, 199, 230, 3, 2, 2, 2, 200, 202, 5, 36, 19, 2, 201, 200, 3, 2, 2, 2, 201, 202, 3, 2, 2, 2, 202, 203, 3, 2, 2, 2, 203, 230, 7, 34, 2, 2, 204, 230, 5, 30, 16, 2, 205, 206, 7, 6, 2, 2, 206, 207, 7, 27, 2, 2, 207, 208, 5, 38, 20, 2, 208, 209, 7, 28, 2, 2, 209, 212, 5, 34, 18, 2, 210, 211, 7, 7, 2, 2, 211, 213, 5, 34, 18, 2, 212, 210, 3, 2, 2, 2, 212, 213, 3, 2, 2, 2, 213, 230, 3, 2, 2, 2, 214, 215, 7, 8, 2, 2, 215, 216, 7, 27, 2, 2, 216, 217, 5, 38, 20, 2, 217, 218, 7, 28, 2, 2, 218, 219, 5, 34, 18, 2, 219, 230, 3, 2, 2, 2, 220, 221, 7, 9, 2, 2, 221, 230, 7, 34, 2, 2, 222, 223, 7, 10, 2, 2, 223, 230, 7, 34, 2, 2, 224, 226, 7, 11, 2, 2, 225, 227, 5, 36, 19, 2, 226, 225, 3, 2, 2, 2, 226, 227, 3, 2, 2, 2, 227, 228, 3, 2, 2, 2, 228, 230, 7, 34, 2, 2, 229, 195, 3, 2, 2, 2, 229, 201, 3, 2, 2, 2, 229, 204, 3, 2, 2, 2, 229, 205, 3, 2, 2, 2, 229, 214, 3, 2, 2, 2, 229, 220, 3, 2, 2, 2, 229, 222, 3, 2, 2, 2, 229, 224, 3, 2, 2, 2, 230, 35, 3, 2, 2, 2, 231, 232, 8, 19, 1, 2, 232, 233, 7, 27, 2, 2, 233, 234, 5, 36, 19, 2, 234, 235, 7, 28, 2, 2, 235, 248, 3, 2, 2, 2, 236, 248, 5, 40, 21, 2, 237, 248, 5, 42, 22, 2, 238, 239, 7, 35, 2, 2, 239, 241, 7, 27, 2, 2, 240, 242, 5, 46, 24, 2, 241, 240, 3, 2, 2, 2, 241, 242, 3, 2, 2, 2, 242, 243, 3, 2, 2, 2, 243, 248, 7, 28, 2, 2, 244, 245, 5, 44, 23, 2, 245, 246, 5, 36, 19, 5, 246, 248, 3, 2, 2, 2, 247, 231, 3, 2, 2, 2, 247, 236, 3, 2, 2, 2, 247, 237, 3, 2, 2, 2, 247, 238, 3, 2, 2, 2, 247, 244, 3, 2, 2, 2, 248, 257, 3, 2, 2, 2, 249, 250, 12, 4, 2, 2, 250, 251, 9, 3, 2, 2, 251, 256, 5, 36, 19, 5, 252, 253, 12, 3, 2, 2, 253, 254, 9, 4, 2, 2, 254, 256, 5, 36, 19, 4, 255, 249, 3, 2, 2, 2, 255, 252, 3, 2, 2, 2, 256, 259, 3, 2, 2, 2, 257, 255, 3, 2, 2, 2, 257, 258, 3, 2, 2, 2, 258, 37, 3, 2, 2, 2, 259, 257, 3, 2, 2, 2, 260, 261, 8, 20, 1, 2, 261, 262, 5, 36, 19, 2, 262, 277, 3, 2, 2, 2, 263, 264, 12, 6, 2, 2, 264, 265, 9, 5, 2, 2, 265, 276, 5, 38, 20, 7, 266, 267, 12, 5, 2, 2, 267, 268, 9, 6, 2, 2, 268, 276, 5, 38, 20, 6, 269, 270, 12, 4, 2, 2, 270, 271, 7, 25, 2, 2, 271, 276, 5, 38, 20, 5, 272, 273, 12, 3, 2, 2, 273, 274, 7, 26, 2, 2, 274, 276, 5, 38, 20, 4, 275, 263, 3, 2, 2, 2, 275, 266, 3, 2, 2, 2, 275, 269, 3, 2, 2, 2, 275, 272, 3, 2, 2, 2, 276, 279, 3, 2, 2, 2, 277, 275, 3, 2, 2, 2, 277, 278, 3, 2, 2, 2, 278, 39, 3, 2, 2, 2, 279, 277, 3, 2, 2, 2, 280, 287, 7, 35, 2, 2, 281, 282, 7, 31, 2, 2, 282, 283, 5, 36, 19, 2, 283, 284, 7, 32, 2, 2, 284, 286, 3, 2, 2, 2, 285, 281, 3, 2, 2, 2, 286, 289, 3, 2, 2, 2, 287, 285, 3, 2, 2, 2, 287, 288, 3, 2, 2, 2, 288, 41, 3, 2, 2, 2, 289, 287, 3, 2, 2, 2, 290, 291, 7, 36, 2, 2, 291, 43, 3, 2, 2, 2, 292, 293, 9, 7, 2, 2, 293, 45, 3, 2, 2, 2, 294, 299, 5, 48, 25, 2, 295, 296, 7, 33, 2, 2, 296, 298, 5, 48, 25, 2, 297, 295, 3, 2, 2, 2, 298, 301, 3, 2, 2, 2, 299, 297, 3, 2, 2, 2, 299, 300, 3, 2, 2, 2, 300, 47, 3, 2, 2, 2, 301, 299, 3, 2, 2, 2, 302, 303, 5, 36, 19, 2, 303, 49, 3, 2, 2, 2, 304, 305, 5, 36, 19, 2, 305, 51, 3, 2, 2, 2, 34, 56, 58, 64, 73, 87, 100, 103, 106, 114, 126, 131, 140, 143, 146, 152, 164, 177, 180, 186, 193, 201, 212, 226, 229, 241, 247, 255, 257, 275, 277, 287, 299] -------------------------------------------------------------------------------- /src/SysYLexer.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/SysYLexer.g4 by ANTLR 4.9.1 2 | import org.antlr.v4.runtime.Lexer; 3 | import org.antlr.v4.runtime.CharStream; 4 | import org.antlr.v4.runtime.Token; 5 | import org.antlr.v4.runtime.TokenStream; 6 | import org.antlr.v4.runtime.*; 7 | import org.antlr.v4.runtime.atn.*; 8 | import org.antlr.v4.runtime.dfa.DFA; 9 | import org.antlr.v4.runtime.misc.*; 10 | 11 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) 12 | public class SysYLexer extends Lexer { 13 | static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); } 14 | 15 | protected static final DFA[] _decisionToDFA; 16 | protected static final PredictionContextCache _sharedContextCache = 17 | new PredictionContextCache(); 18 | public static final int 19 | CONST=1, INT=2, VOID=3, IF=4, ELSE=5, WHILE=6, BREAK=7, CONTINUE=8, RETURN=9, 20 | PLUS=10, MINUS=11, MUL=12, DIV=13, MOD=14, ASSIGN=15, EQ=16, NEQ=17, LT=18, 21 | GT=19, LE=20, GE=21, NOT=22, AND=23, OR=24, L_PAREN=25, R_PAREN=26, L_BRACE=27, 22 | R_BRACE=28, L_BRACKT=29, R_BRACKT=30, COMMA=31, SEMICOLON=32, IDENT=33, 23 | INTEGR_CONST=34, WS=35, SL_COMMENT=36, ML_COMMENT=37; 24 | public static String[] channelNames = { 25 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN" 26 | }; 27 | 28 | public static String[] modeNames = { 29 | "DEFAULT_MODE" 30 | }; 31 | 32 | private static String[] makeRuleNames() { 33 | return new String[] { 34 | "CONST", "INT", "VOID", "IF", "ELSE", "WHILE", "BREAK", "CONTINUE", "RETURN", 35 | "PLUS", "MINUS", "MUL", "DIV", "MOD", "ASSIGN", "EQ", "NEQ", "LT", "GT", 36 | "LE", "GE", "NOT", "AND", "OR", "L_PAREN", "R_PAREN", "L_BRACE", "R_BRACE", 37 | "L_BRACKT", "R_BRACKT", "COMMA", "SEMICOLON", "IDENT", "INTEGR_CONST", 38 | "DECIMAL", "OCTAL", "HEXADECIMAL", "WS", "SL_COMMENT", "ML_COMMENT", 39 | "LETTER", "DIGIT" 40 | }; 41 | } 42 | public static final String[] ruleNames = makeRuleNames(); 43 | 44 | private static String[] makeLiteralNames() { 45 | return new String[] { 46 | null, "'const'", "'int'", "'void'", "'if'", "'else'", "'while'", "'break'", 47 | "'continue'", "'return'", "'+'", "'-'", "'*'", "'/'", "'%'", "'='", "'=='", 48 | "'!='", "'<'", "'>'", "'<='", "'>='", "'!'", "'&&'", "'||'", "'('", "')'", 49 | "'{'", "'}'", "'['", "']'", "','", "';'" 50 | }; 51 | } 52 | private static final String[] _LITERAL_NAMES = makeLiteralNames(); 53 | private static String[] makeSymbolicNames() { 54 | return new String[] { 55 | null, "CONST", "INT", "VOID", "IF", "ELSE", "WHILE", "BREAK", "CONTINUE", 56 | "RETURN", "PLUS", "MINUS", "MUL", "DIV", "MOD", "ASSIGN", "EQ", "NEQ", 57 | "LT", "GT", "LE", "GE", "NOT", "AND", "OR", "L_PAREN", "R_PAREN", "L_BRACE", 58 | "R_BRACE", "L_BRACKT", "R_BRACKT", "COMMA", "SEMICOLON", "IDENT", "INTEGR_CONST", 59 | "WS", "SL_COMMENT", "ML_COMMENT" 60 | }; 61 | } 62 | private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); 63 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); 64 | 65 | /** 66 | * @deprecated Use {@link #VOCABULARY} instead. 67 | */ 68 | @Deprecated 69 | public static final String[] tokenNames; 70 | static { 71 | tokenNames = new String[_SYMBOLIC_NAMES.length]; 72 | for (int i = 0; i < tokenNames.length; i++) { 73 | tokenNames[i] = VOCABULARY.getLiteralName(i); 74 | if (tokenNames[i] == null) { 75 | tokenNames[i] = VOCABULARY.getSymbolicName(i); 76 | } 77 | 78 | if (tokenNames[i] == null) { 79 | tokenNames[i] = ""; 80 | } 81 | } 82 | } 83 | 84 | @Override 85 | @Deprecated 86 | public String[] getTokenNames() { 87 | return tokenNames; 88 | } 89 | 90 | @Override 91 | 92 | public Vocabulary getVocabulary() { 93 | return VOCABULARY; 94 | } 95 | 96 | 97 | public SysYLexer(CharStream input) { 98 | super(input); 99 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); 100 | } 101 | 102 | @Override 103 | public String getGrammarFileName() { return "SysYLexer.g4"; } 104 | 105 | @Override 106 | public String[] getRuleNames() { return ruleNames; } 107 | 108 | @Override 109 | public String getSerializedATN() { return _serializedATN; } 110 | 111 | @Override 112 | public String[] getChannelNames() { return channelNames; } 113 | 114 | @Override 115 | public String[] getModeNames() { return modeNames; } 116 | 117 | @Override 118 | public ATN getATN() { return _ATN; } 119 | 120 | public static final String _serializedATN = 121 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\'\u0111\b\1\4\2\t"+ 122 | "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+ 123 | "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+ 124 | "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+ 125 | "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+ 126 | "\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t+\3"+ 127 | "\2\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\4\3\4\3\4\3\4\3\4\3\5\3\5\3\5"+ 128 | "\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3"+ 129 | "\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3"+ 130 | "\13\3\f\3\f\3\r\3\r\3\16\3\16\3\17\3\17\3\20\3\20\3\21\3\21\3\21\3\22"+ 131 | "\3\22\3\22\3\23\3\23\3\24\3\24\3\25\3\25\3\25\3\26\3\26\3\26\3\27\3\27"+ 132 | "\3\30\3\30\3\30\3\31\3\31\3\31\3\32\3\32\3\33\3\33\3\34\3\34\3\35\3\35"+ 133 | "\3\36\3\36\3\37\3\37\3 \3 \3!\3!\3\"\3\"\5\"\u00c1\n\"\3\"\3\"\3\"\7\""+ 134 | "\u00c6\n\"\f\"\16\"\u00c9\13\"\3#\3#\3#\5#\u00ce\n#\3$\3$\3$\7$\u00d3"+ 135 | "\n$\f$\16$\u00d6\13$\5$\u00d8\n$\3%\3%\6%\u00dc\n%\r%\16%\u00dd\3&\3&"+ 136 | "\3&\3&\5&\u00e4\n&\3&\3&\6&\u00e8\n&\r&\16&\u00e9\3\'\6\'\u00ed\n\'\r"+ 137 | "\'\16\'\u00ee\3\'\3\'\3(\3(\3(\3(\7(\u00f7\n(\f(\16(\u00fa\13(\3(\3(\3"+ 138 | "(\3(\3)\3)\3)\3)\7)\u0104\n)\f)\16)\u0107\13)\3)\3)\3)\3)\3)\3*\3*\3+"+ 139 | "\3+\4\u00f8\u0105\2,\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27"+ 140 | "\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\25)\26+\27-\30/\31\61\32\63\33"+ 141 | "\65\34\67\359\36;\37= ?!A\"C#E$G\2I\2K\2M%O&Q\'S\2U\2\3\2\b\3\2\63;\3"+ 142 | "\2\62;\3\2\629\4\2CHch\5\2\13\f\17\17\"\"\4\2C\\c|\2\u011a\2\3\3\2\2\2"+ 143 | "\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2"+ 144 | "\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2"+ 145 | "\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2"+ 146 | "\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2/\3\2\2\2\2\61\3\2\2"+ 147 | "\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2\2\2\2;\3\2\2\2\2=\3\2"+ 148 | "\2\2\2?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2\2M\3\2\2\2\2O\3\2\2\2"+ 149 | "\2Q\3\2\2\2\3W\3\2\2\2\5]\3\2\2\2\7a\3\2\2\2\tf\3\2\2\2\13i\3\2\2\2\r"+ 150 | "n\3\2\2\2\17t\3\2\2\2\21z\3\2\2\2\23\u0083\3\2\2\2\25\u008a\3\2\2\2\27"+ 151 | "\u008c\3\2\2\2\31\u008e\3\2\2\2\33\u0090\3\2\2\2\35\u0092\3\2\2\2\37\u0094"+ 152 | "\3\2\2\2!\u0096\3\2\2\2#\u0099\3\2\2\2%\u009c\3\2\2\2\'\u009e\3\2\2\2"+ 153 | ")\u00a0\3\2\2\2+\u00a3\3\2\2\2-\u00a6\3\2\2\2/\u00a8\3\2\2\2\61\u00ab"+ 154 | "\3\2\2\2\63\u00ae\3\2\2\2\65\u00b0\3\2\2\2\67\u00b2\3\2\2\29\u00b4\3\2"+ 155 | "\2\2;\u00b6\3\2\2\2=\u00b8\3\2\2\2?\u00ba\3\2\2\2A\u00bc\3\2\2\2C\u00c0"+ 156 | "\3\2\2\2E\u00cd\3\2\2\2G\u00d7\3\2\2\2I\u00d9\3\2\2\2K\u00e3\3\2\2\2M"+ 157 | "\u00ec\3\2\2\2O\u00f2\3\2\2\2Q\u00ff\3\2\2\2S\u010d\3\2\2\2U\u010f\3\2"+ 158 | "\2\2WX\7e\2\2XY\7q\2\2YZ\7p\2\2Z[\7u\2\2[\\\7v\2\2\\\4\3\2\2\2]^\7k\2"+ 159 | "\2^_\7p\2\2_`\7v\2\2`\6\3\2\2\2ab\7x\2\2bc\7q\2\2cd\7k\2\2de\7f\2\2e\b"+ 160 | "\3\2\2\2fg\7k\2\2gh\7h\2\2h\n\3\2\2\2ij\7g\2\2jk\7n\2\2kl\7u\2\2lm\7g"+ 161 | "\2\2m\f\3\2\2\2no\7y\2\2op\7j\2\2pq\7k\2\2qr\7n\2\2rs\7g\2\2s\16\3\2\2"+ 162 | "\2tu\7d\2\2uv\7t\2\2vw\7g\2\2wx\7c\2\2xy\7m\2\2y\20\3\2\2\2z{\7e\2\2{"+ 163 | "|\7q\2\2|}\7p\2\2}~\7v\2\2~\177\7k\2\2\177\u0080\7p\2\2\u0080\u0081\7"+ 164 | "w\2\2\u0081\u0082\7g\2\2\u0082\22\3\2\2\2\u0083\u0084\7t\2\2\u0084\u0085"+ 165 | "\7g\2\2\u0085\u0086\7v\2\2\u0086\u0087\7w\2\2\u0087\u0088\7t\2\2\u0088"+ 166 | "\u0089\7p\2\2\u0089\24\3\2\2\2\u008a\u008b\7-\2\2\u008b\26\3\2\2\2\u008c"+ 167 | "\u008d\7/\2\2\u008d\30\3\2\2\2\u008e\u008f\7,\2\2\u008f\32\3\2\2\2\u0090"+ 168 | "\u0091\7\61\2\2\u0091\34\3\2\2\2\u0092\u0093\7\'\2\2\u0093\36\3\2\2\2"+ 169 | "\u0094\u0095\7?\2\2\u0095 \3\2\2\2\u0096\u0097\7?\2\2\u0097\u0098\7?\2"+ 170 | "\2\u0098\"\3\2\2\2\u0099\u009a\7#\2\2\u009a\u009b\7?\2\2\u009b$\3\2\2"+ 171 | "\2\u009c\u009d\7>\2\2\u009d&\3\2\2\2\u009e\u009f\7@\2\2\u009f(\3\2\2\2"+ 172 | "\u00a0\u00a1\7>\2\2\u00a1\u00a2\7?\2\2\u00a2*\3\2\2\2\u00a3\u00a4\7@\2"+ 173 | "\2\u00a4\u00a5\7?\2\2\u00a5,\3\2\2\2\u00a6\u00a7\7#\2\2\u00a7.\3\2\2\2"+ 174 | "\u00a8\u00a9\7(\2\2\u00a9\u00aa\7(\2\2\u00aa\60\3\2\2\2\u00ab\u00ac\7"+ 175 | "~\2\2\u00ac\u00ad\7~\2\2\u00ad\62\3\2\2\2\u00ae\u00af\7*\2\2\u00af\64"+ 176 | "\3\2\2\2\u00b0\u00b1\7+\2\2\u00b1\66\3\2\2\2\u00b2\u00b3\7}\2\2\u00b3"+ 177 | "8\3\2\2\2\u00b4\u00b5\7\177\2\2\u00b5:\3\2\2\2\u00b6\u00b7\7]\2\2\u00b7"+ 178 | "<\3\2\2\2\u00b8\u00b9\7_\2\2\u00b9>\3\2\2\2\u00ba\u00bb\7.\2\2\u00bb@"+ 179 | "\3\2\2\2\u00bc\u00bd\7=\2\2\u00bdB\3\2\2\2\u00be\u00c1\5S*\2\u00bf\u00c1"+ 180 | "\7a\2\2\u00c0\u00be\3\2\2\2\u00c0\u00bf\3\2\2\2\u00c1\u00c7\3\2\2\2\u00c2"+ 181 | "\u00c6\5S*\2\u00c3\u00c6\5U+\2\u00c4\u00c6\7a\2\2\u00c5\u00c2\3\2\2\2"+ 182 | "\u00c5\u00c3\3\2\2\2\u00c5\u00c4\3\2\2\2\u00c6\u00c9\3\2\2\2\u00c7\u00c5"+ 183 | "\3\2\2\2\u00c7\u00c8\3\2\2\2\u00c8D\3\2\2\2\u00c9\u00c7\3\2\2\2\u00ca"+ 184 | "\u00ce\5I%\2\u00cb\u00ce\5K&\2\u00cc\u00ce\5G$\2\u00cd\u00ca\3\2\2\2\u00cd"+ 185 | "\u00cb\3\2\2\2\u00cd\u00cc\3\2\2\2\u00ceF\3\2\2\2\u00cf\u00d8\7\62\2\2"+ 186 | "\u00d0\u00d4\t\2\2\2\u00d1\u00d3\t\3\2\2\u00d2\u00d1\3\2\2\2\u00d3\u00d6"+ 187 | "\3\2\2\2\u00d4\u00d2\3\2\2\2\u00d4\u00d5\3\2\2\2\u00d5\u00d8\3\2\2\2\u00d6"+ 188 | "\u00d4\3\2\2\2\u00d7\u00cf\3\2\2\2\u00d7\u00d0\3\2\2\2\u00d8H\3\2\2\2"+ 189 | "\u00d9\u00db\7\62\2\2\u00da\u00dc\t\4\2\2\u00db\u00da\3\2\2\2\u00dc\u00dd"+ 190 | "\3\2\2\2\u00dd\u00db\3\2\2\2\u00dd\u00de\3\2\2\2\u00deJ\3\2\2\2\u00df"+ 191 | "\u00e0\7\62\2\2\u00e0\u00e4\7z\2\2\u00e1\u00e2\7\62\2\2\u00e2\u00e4\7"+ 192 | "Z\2\2\u00e3\u00df\3\2\2\2\u00e3\u00e1\3\2\2\2\u00e4\u00e7\3\2\2\2\u00e5"+ 193 | "\u00e8\5U+\2\u00e6\u00e8\t\5\2\2\u00e7\u00e5\3\2\2\2\u00e7\u00e6\3\2\2"+ 194 | "\2\u00e8\u00e9\3\2\2\2\u00e9\u00e7\3\2\2\2\u00e9\u00ea\3\2\2\2\u00eaL"+ 195 | "\3\2\2\2\u00eb\u00ed\t\6\2\2\u00ec\u00eb\3\2\2\2\u00ed\u00ee\3\2\2\2\u00ee"+ 196 | "\u00ec\3\2\2\2\u00ee\u00ef\3\2\2\2\u00ef\u00f0\3\2\2\2\u00f0\u00f1\b\'"+ 197 | "\2\2\u00f1N\3\2\2\2\u00f2\u00f3\7\61\2\2\u00f3\u00f4\7\61\2\2\u00f4\u00f8"+ 198 | "\3\2\2\2\u00f5\u00f7\13\2\2\2\u00f6\u00f5\3\2\2\2\u00f7\u00fa\3\2\2\2"+ 199 | "\u00f8\u00f9\3\2\2\2\u00f8\u00f6\3\2\2\2\u00f9\u00fb\3\2\2\2\u00fa\u00f8"+ 200 | "\3\2\2\2\u00fb\u00fc\7\f\2\2\u00fc\u00fd\3\2\2\2\u00fd\u00fe\b(\2\2\u00fe"+ 201 | "P\3\2\2\2\u00ff\u0100\7\61\2\2\u0100\u0101\7,\2\2\u0101\u0105\3\2\2\2"+ 202 | "\u0102\u0104\13\2\2\2\u0103\u0102\3\2\2\2\u0104\u0107\3\2\2\2\u0105\u0106"+ 203 | "\3\2\2\2\u0105\u0103\3\2\2\2\u0106\u0108\3\2\2\2\u0107\u0105\3\2\2\2\u0108"+ 204 | "\u0109\7,\2\2\u0109\u010a\7\61\2\2\u010a\u010b\3\2\2\2\u010b\u010c\b)"+ 205 | "\2\2\u010cR\3\2\2\2\u010d\u010e\t\7\2\2\u010eT\3\2\2\2\u010f\u0110\t\3"+ 206 | "\2\2\u0110V\3\2\2\2\20\2\u00c0\u00c5\u00c7\u00cd\u00d4\u00d7\u00dd\u00e3"+ 207 | "\u00e7\u00e9\u00ee\u00f8\u0105\3\b\2\2"; 208 | public static final ATN _ATN = 209 | new ATNDeserializer().deserialize(_serializedATN.toCharArray()); 210 | static { 211 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; 212 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { 213 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); 214 | } 215 | } 216 | } -------------------------------------------------------------------------------- /src/SysYParserBaseVisitor.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/SysYParser.g4 by ANTLR 4.9.1 2 | import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; 3 | 4 | /** 5 | * This class provides an empty implementation of {@link SysYParserVisitor}, 6 | * which can be extended to create a visitor which only needs to handle a subset 7 | * of the available methods. 8 | * 9 | * @param The return type of the visit operation. Use {@link Void} for 10 | * operations with no return type. 11 | */ 12 | public class SysYParserBaseVisitor extends AbstractParseTreeVisitor implements SysYParserVisitor { 13 | /** 14 | * {@inheritDoc} 15 | * 16 | *

The default implementation returns the result of calling 17 | * {@link #visitChildren} on {@code ctx}.

18 | */ 19 | @Override public T visitProgram(SysYParser.ProgramContext ctx) { return visitChildren(ctx); } 20 | /** 21 | * {@inheritDoc} 22 | * 23 | *

The default implementation returns the result of calling 24 | * {@link #visitChildren} on {@code ctx}.

25 | */ 26 | @Override public T visitCompUnit(SysYParser.CompUnitContext ctx) { return visitChildren(ctx); } 27 | /** 28 | * {@inheritDoc} 29 | * 30 | *

The default implementation returns the result of calling 31 | * {@link #visitChildren} on {@code ctx}.

32 | */ 33 | @Override public T visitDecl(SysYParser.DeclContext ctx) { return visitChildren(ctx); } 34 | /** 35 | * {@inheritDoc} 36 | * 37 | *

The default implementation returns the result of calling 38 | * {@link #visitChildren} on {@code ctx}.

39 | */ 40 | @Override public T visitConstDecl(SysYParser.ConstDeclContext ctx) { return visitChildren(ctx); } 41 | /** 42 | * {@inheritDoc} 43 | * 44 | *

The default implementation returns the result of calling 45 | * {@link #visitChildren} on {@code ctx}.

46 | */ 47 | @Override public T visitBType(SysYParser.BTypeContext ctx) { return visitChildren(ctx); } 48 | /** 49 | * {@inheritDoc} 50 | * 51 | *

The default implementation returns the result of calling 52 | * {@link #visitChildren} on {@code ctx}.

53 | */ 54 | @Override public T visitConstDef(SysYParser.ConstDefContext ctx) { return visitChildren(ctx); } 55 | /** 56 | * {@inheritDoc} 57 | * 58 | *

The default implementation returns the result of calling 59 | * {@link #visitChildren} on {@code ctx}.

60 | */ 61 | @Override public T visitConstInitVal(SysYParser.ConstInitValContext ctx) { return visitChildren(ctx); } 62 | /** 63 | * {@inheritDoc} 64 | * 65 | *

The default implementation returns the result of calling 66 | * {@link #visitChildren} on {@code ctx}.

67 | */ 68 | @Override public T visitVarDecl(SysYParser.VarDeclContext ctx) { return visitChildren(ctx); } 69 | /** 70 | * {@inheritDoc} 71 | * 72 | *

The default implementation returns the result of calling 73 | * {@link #visitChildren} on {@code ctx}.

74 | */ 75 | @Override public T visitVarDef(SysYParser.VarDefContext ctx) { return visitChildren(ctx); } 76 | /** 77 | * {@inheritDoc} 78 | * 79 | *

The default implementation returns the result of calling 80 | * {@link #visitChildren} on {@code ctx}.

81 | */ 82 | @Override public T visitInitVal(SysYParser.InitValContext ctx) { return visitChildren(ctx); } 83 | /** 84 | * {@inheritDoc} 85 | * 86 | *

The default implementation returns the result of calling 87 | * {@link #visitChildren} on {@code ctx}.

88 | */ 89 | @Override public T visitFuncDef(SysYParser.FuncDefContext ctx) { return visitChildren(ctx); } 90 | /** 91 | * {@inheritDoc} 92 | * 93 | *

The default implementation returns the result of calling 94 | * {@link #visitChildren} on {@code ctx}.

95 | */ 96 | @Override public T visitFuncType(SysYParser.FuncTypeContext ctx) { return visitChildren(ctx); } 97 | /** 98 | * {@inheritDoc} 99 | * 100 | *

The default implementation returns the result of calling 101 | * {@link #visitChildren} on {@code ctx}.

102 | */ 103 | @Override public T visitFuncFParams(SysYParser.FuncFParamsContext ctx) { return visitChildren(ctx); } 104 | /** 105 | * {@inheritDoc} 106 | * 107 | *

The default implementation returns the result of calling 108 | * {@link #visitChildren} on {@code ctx}.

109 | */ 110 | @Override public T visitFuncFParam(SysYParser.FuncFParamContext ctx) { return visitChildren(ctx); } 111 | /** 112 | * {@inheritDoc} 113 | * 114 | *

The default implementation returns the result of calling 115 | * {@link #visitChildren} on {@code ctx}.

116 | */ 117 | @Override public T visitBlock(SysYParser.BlockContext ctx) { return visitChildren(ctx); } 118 | /** 119 | * {@inheritDoc} 120 | * 121 | *

The default implementation returns the result of calling 122 | * {@link #visitChildren} on {@code ctx}.

123 | */ 124 | @Override public T visitBlockItem(SysYParser.BlockItemContext ctx) { return visitChildren(ctx); } 125 | /** 126 | * {@inheritDoc} 127 | * 128 | *

The default implementation returns the result of calling 129 | * {@link #visitChildren} on {@code ctx}.

130 | */ 131 | @Override public T visitAssignment(SysYParser.AssignmentContext ctx) { return visitChildren(ctx); } 132 | /** 133 | * {@inheritDoc} 134 | * 135 | *

The default implementation returns the result of calling 136 | * {@link #visitChildren} on {@code ctx}.

137 | */ 138 | @Override public T visitPossibleExp(SysYParser.PossibleExpContext ctx) { return visitChildren(ctx); } 139 | /** 140 | * {@inheritDoc} 141 | * 142 | *

The default implementation returns the result of calling 143 | * {@link #visitChildren} on {@code ctx}.

144 | */ 145 | @Override public T visitBlockStmt(SysYParser.BlockStmtContext ctx) { return visitChildren(ctx); } 146 | /** 147 | * {@inheritDoc} 148 | * 149 | *

The default implementation returns the result of calling 150 | * {@link #visitChildren} on {@code ctx}.

151 | */ 152 | @Override public T visitIfStmt(SysYParser.IfStmtContext ctx) { return visitChildren(ctx); } 153 | /** 154 | * {@inheritDoc} 155 | * 156 | *

The default implementation returns the result of calling 157 | * {@link #visitChildren} on {@code ctx}.

158 | */ 159 | @Override public T visitWhileStmt(SysYParser.WhileStmtContext ctx) { return visitChildren(ctx); } 160 | /** 161 | * {@inheritDoc} 162 | * 163 | *

The default implementation returns the result of calling 164 | * {@link #visitChildren} on {@code ctx}.

165 | */ 166 | @Override public T visitBreakStmt(SysYParser.BreakStmtContext ctx) { return visitChildren(ctx); } 167 | /** 168 | * {@inheritDoc} 169 | * 170 | *

The default implementation returns the result of calling 171 | * {@link #visitChildren} on {@code ctx}.

172 | */ 173 | @Override public T visitContinueStmt(SysYParser.ContinueStmtContext ctx) { return visitChildren(ctx); } 174 | /** 175 | * {@inheritDoc} 176 | * 177 | *

The default implementation returns the result of calling 178 | * {@link #visitChildren} on {@code ctx}.

179 | */ 180 | @Override public T visitReturnStmt(SysYParser.ReturnStmtContext ctx) { return visitChildren(ctx); } 181 | /** 182 | * {@inheritDoc} 183 | * 184 | *

The default implementation returns the result of calling 185 | * {@link #visitChildren} on {@code ctx}.

186 | */ 187 | @Override public T visitLValExp(SysYParser.LValExpContext ctx) { return visitChildren(ctx); } 188 | /** 189 | * {@inheritDoc} 190 | * 191 | *

The default implementation returns the result of calling 192 | * {@link #visitChildren} on {@code ctx}.

193 | */ 194 | @Override public T visitUnaryExp(SysYParser.UnaryExpContext ctx) { return visitChildren(ctx); } 195 | /** 196 | * {@inheritDoc} 197 | * 198 | *

The default implementation returns the result of calling 199 | * {@link #visitChildren} on {@code ctx}.

200 | */ 201 | @Override public T visitParenExp(SysYParser.ParenExpContext ctx) { return visitChildren(ctx); } 202 | /** 203 | * {@inheritDoc} 204 | * 205 | *

The default implementation returns the result of calling 206 | * {@link #visitChildren} on {@code ctx}.

207 | */ 208 | @Override public T visitAddExp(SysYParser.AddExpContext ctx) { return visitChildren(ctx); } 209 | /** 210 | * {@inheritDoc} 211 | * 212 | *

The default implementation returns the result of calling 213 | * {@link #visitChildren} on {@code ctx}.

214 | */ 215 | @Override public T visitMulExp(SysYParser.MulExpContext ctx) { return visitChildren(ctx); } 216 | /** 217 | * {@inheritDoc} 218 | * 219 | *

The default implementation returns the result of calling 220 | * {@link #visitChildren} on {@code ctx}.

221 | */ 222 | @Override public T visitFuncCallExp(SysYParser.FuncCallExpContext ctx) { return visitChildren(ctx); } 223 | /** 224 | * {@inheritDoc} 225 | * 226 | *

The default implementation returns the result of calling 227 | * {@link #visitChildren} on {@code ctx}.

228 | */ 229 | @Override public T visitNumExp(SysYParser.NumExpContext ctx) { return visitChildren(ctx); } 230 | /** 231 | * {@inheritDoc} 232 | * 233 | *

The default implementation returns the result of calling 234 | * {@link #visitChildren} on {@code ctx}.

235 | */ 236 | @Override public T visitCompareExp(SysYParser.CompareExpContext ctx) { return visitChildren(ctx); } 237 | /** 238 | * {@inheritDoc} 239 | * 240 | *

The default implementation returns the result of calling 241 | * {@link #visitChildren} on {@code ctx}.

242 | */ 243 | @Override public T visitRelationExp(SysYParser.RelationExpContext ctx) { return visitChildren(ctx); } 244 | /** 245 | * {@inheritDoc} 246 | * 247 | *

The default implementation returns the result of calling 248 | * {@link #visitChildren} on {@code ctx}.

249 | */ 250 | @Override public T visitCondExp(SysYParser.CondExpContext ctx) { return visitChildren(ctx); } 251 | /** 252 | * {@inheritDoc} 253 | * 254 | *

The default implementation returns the result of calling 255 | * {@link #visitChildren} on {@code ctx}.

256 | */ 257 | @Override public T visitAndExp(SysYParser.AndExpContext ctx) { return visitChildren(ctx); } 258 | /** 259 | * {@inheritDoc} 260 | * 261 | *

The default implementation returns the result of calling 262 | * {@link #visitChildren} on {@code ctx}.

263 | */ 264 | @Override public T visitOrExp(SysYParser.OrExpContext ctx) { return visitChildren(ctx); } 265 | /** 266 | * {@inheritDoc} 267 | * 268 | *

The default implementation returns the result of calling 269 | * {@link #visitChildren} on {@code ctx}.

270 | */ 271 | @Override public T visitLVal(SysYParser.LValContext ctx) { return visitChildren(ctx); } 272 | /** 273 | * {@inheritDoc} 274 | * 275 | *

The default implementation returns the result of calling 276 | * {@link #visitChildren} on {@code ctx}.

277 | */ 278 | @Override public T visitNumber(SysYParser.NumberContext ctx) { return visitChildren(ctx); } 279 | /** 280 | * {@inheritDoc} 281 | * 282 | *

The default implementation returns the result of calling 283 | * {@link #visitChildren} on {@code ctx}.

284 | */ 285 | @Override public T visitUnaryOp(SysYParser.UnaryOpContext ctx) { return visitChildren(ctx); } 286 | /** 287 | * {@inheritDoc} 288 | * 289 | *

The default implementation returns the result of calling 290 | * {@link #visitChildren} on {@code ctx}.

291 | */ 292 | @Override public T visitFuncRParams(SysYParser.FuncRParamsContext ctx) { return visitChildren(ctx); } 293 | /** 294 | * {@inheritDoc} 295 | * 296 | *

The default implementation returns the result of calling 297 | * {@link #visitChildren} on {@code ctx}.

298 | */ 299 | @Override public T visitParam(SysYParser.ParamContext ctx) { return visitChildren(ctx); } 300 | /** 301 | * {@inheritDoc} 302 | * 303 | *

The default implementation returns the result of calling 304 | * {@link #visitChildren} on {@code ctx}.

305 | */ 306 | @Override public T visitConstExp(SysYParser.ConstExpContext ctx) { return visitChildren(ctx); } 307 | } -------------------------------------------------------------------------------- /src/SysYParserBaseListener.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/SysYParser.g4 by ANTLR 4.9.1 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.tree.ErrorNode; 5 | import org.antlr.v4.runtime.tree.TerminalNode; 6 | 7 | /** 8 | * This class provides an empty implementation of {@link SysYParserListener}, 9 | * which can be extended to create a listener which only needs to handle a subset 10 | * of the available methods. 11 | */ 12 | public class SysYParserBaseListener implements SysYParserListener { 13 | /** 14 | * {@inheritDoc} 15 | * 16 | *

The default implementation does nothing.

17 | */ 18 | @Override public void enterProgram(SysYParser.ProgramContext ctx) { } 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

The default implementation does nothing.

23 | */ 24 | @Override public void exitProgram(SysYParser.ProgramContext ctx) { } 25 | /** 26 | * {@inheritDoc} 27 | * 28 | *

The default implementation does nothing.

29 | */ 30 | @Override public void enterCompUnit(SysYParser.CompUnitContext ctx) { } 31 | /** 32 | * {@inheritDoc} 33 | * 34 | *

The default implementation does nothing.

35 | */ 36 | @Override public void exitCompUnit(SysYParser.CompUnitContext ctx) { } 37 | /** 38 | * {@inheritDoc} 39 | * 40 | *

The default implementation does nothing.

41 | */ 42 | @Override public void enterDecl(SysYParser.DeclContext ctx) { } 43 | /** 44 | * {@inheritDoc} 45 | * 46 | *

The default implementation does nothing.

47 | */ 48 | @Override public void exitDecl(SysYParser.DeclContext ctx) { } 49 | /** 50 | * {@inheritDoc} 51 | * 52 | *

The default implementation does nothing.

53 | */ 54 | @Override public void enterConstDecl(SysYParser.ConstDeclContext ctx) { } 55 | /** 56 | * {@inheritDoc} 57 | * 58 | *

The default implementation does nothing.

59 | */ 60 | @Override public void exitConstDecl(SysYParser.ConstDeclContext ctx) { } 61 | /** 62 | * {@inheritDoc} 63 | * 64 | *

The default implementation does nothing.

65 | */ 66 | @Override public void enterBType(SysYParser.BTypeContext ctx) { } 67 | /** 68 | * {@inheritDoc} 69 | * 70 | *

The default implementation does nothing.

71 | */ 72 | @Override public void exitBType(SysYParser.BTypeContext ctx) { } 73 | /** 74 | * {@inheritDoc} 75 | * 76 | *

The default implementation does nothing.

77 | */ 78 | @Override public void enterConstDef(SysYParser.ConstDefContext ctx) { } 79 | /** 80 | * {@inheritDoc} 81 | * 82 | *

The default implementation does nothing.

83 | */ 84 | @Override public void exitConstDef(SysYParser.ConstDefContext ctx) { } 85 | /** 86 | * {@inheritDoc} 87 | * 88 | *

The default implementation does nothing.

89 | */ 90 | @Override public void enterConstInitVal(SysYParser.ConstInitValContext ctx) { } 91 | /** 92 | * {@inheritDoc} 93 | * 94 | *

The default implementation does nothing.

95 | */ 96 | @Override public void exitConstInitVal(SysYParser.ConstInitValContext ctx) { } 97 | /** 98 | * {@inheritDoc} 99 | * 100 | *

The default implementation does nothing.

101 | */ 102 | @Override public void enterVarDecl(SysYParser.VarDeclContext ctx) { } 103 | /** 104 | * {@inheritDoc} 105 | * 106 | *

The default implementation does nothing.

107 | */ 108 | @Override public void exitVarDecl(SysYParser.VarDeclContext ctx) { } 109 | /** 110 | * {@inheritDoc} 111 | * 112 | *

The default implementation does nothing.

113 | */ 114 | @Override public void enterVarDef(SysYParser.VarDefContext ctx) { } 115 | /** 116 | * {@inheritDoc} 117 | * 118 | *

The default implementation does nothing.

119 | */ 120 | @Override public void exitVarDef(SysYParser.VarDefContext ctx) { } 121 | /** 122 | * {@inheritDoc} 123 | * 124 | *

The default implementation does nothing.

125 | */ 126 | @Override public void enterInitVal(SysYParser.InitValContext ctx) { } 127 | /** 128 | * {@inheritDoc} 129 | * 130 | *

The default implementation does nothing.

131 | */ 132 | @Override public void exitInitVal(SysYParser.InitValContext ctx) { } 133 | /** 134 | * {@inheritDoc} 135 | * 136 | *

The default implementation does nothing.

137 | */ 138 | @Override public void enterFuncDef(SysYParser.FuncDefContext ctx) { } 139 | /** 140 | * {@inheritDoc} 141 | * 142 | *

The default implementation does nothing.

143 | */ 144 | @Override public void exitFuncDef(SysYParser.FuncDefContext ctx) { } 145 | /** 146 | * {@inheritDoc} 147 | * 148 | *

The default implementation does nothing.

149 | */ 150 | @Override public void enterFuncType(SysYParser.FuncTypeContext ctx) { } 151 | /** 152 | * {@inheritDoc} 153 | * 154 | *

The default implementation does nothing.

155 | */ 156 | @Override public void exitFuncType(SysYParser.FuncTypeContext ctx) { } 157 | /** 158 | * {@inheritDoc} 159 | * 160 | *

The default implementation does nothing.

161 | */ 162 | @Override public void enterFuncFParams(SysYParser.FuncFParamsContext ctx) { } 163 | /** 164 | * {@inheritDoc} 165 | * 166 | *

The default implementation does nothing.

167 | */ 168 | @Override public void exitFuncFParams(SysYParser.FuncFParamsContext ctx) { } 169 | /** 170 | * {@inheritDoc} 171 | * 172 | *

The default implementation does nothing.

173 | */ 174 | @Override public void enterFuncFParam(SysYParser.FuncFParamContext ctx) { } 175 | /** 176 | * {@inheritDoc} 177 | * 178 | *

The default implementation does nothing.

179 | */ 180 | @Override public void exitFuncFParam(SysYParser.FuncFParamContext ctx) { } 181 | /** 182 | * {@inheritDoc} 183 | * 184 | *

The default implementation does nothing.

185 | */ 186 | @Override public void enterBlock(SysYParser.BlockContext ctx) { } 187 | /** 188 | * {@inheritDoc} 189 | * 190 | *

The default implementation does nothing.

191 | */ 192 | @Override public void exitBlock(SysYParser.BlockContext ctx) { } 193 | /** 194 | * {@inheritDoc} 195 | * 196 | *

The default implementation does nothing.

197 | */ 198 | @Override public void enterBlockItem(SysYParser.BlockItemContext ctx) { } 199 | /** 200 | * {@inheritDoc} 201 | * 202 | *

The default implementation does nothing.

203 | */ 204 | @Override public void exitBlockItem(SysYParser.BlockItemContext ctx) { } 205 | /** 206 | * {@inheritDoc} 207 | * 208 | *

The default implementation does nothing.

209 | */ 210 | @Override public void enterAssignment(SysYParser.AssignmentContext ctx) { } 211 | /** 212 | * {@inheritDoc} 213 | * 214 | *

The default implementation does nothing.

215 | */ 216 | @Override public void exitAssignment(SysYParser.AssignmentContext ctx) { } 217 | /** 218 | * {@inheritDoc} 219 | * 220 | *

The default implementation does nothing.

221 | */ 222 | @Override public void enterPossibleExp(SysYParser.PossibleExpContext ctx) { } 223 | /** 224 | * {@inheritDoc} 225 | * 226 | *

The default implementation does nothing.

227 | */ 228 | @Override public void exitPossibleExp(SysYParser.PossibleExpContext ctx) { } 229 | /** 230 | * {@inheritDoc} 231 | * 232 | *

The default implementation does nothing.

233 | */ 234 | @Override public void enterBlockStmt(SysYParser.BlockStmtContext ctx) { } 235 | /** 236 | * {@inheritDoc} 237 | * 238 | *

The default implementation does nothing.

239 | */ 240 | @Override public void exitBlockStmt(SysYParser.BlockStmtContext ctx) { } 241 | /** 242 | * {@inheritDoc} 243 | * 244 | *

The default implementation does nothing.

245 | */ 246 | @Override public void enterIfStmt(SysYParser.IfStmtContext ctx) { } 247 | /** 248 | * {@inheritDoc} 249 | * 250 | *

The default implementation does nothing.

251 | */ 252 | @Override public void exitIfStmt(SysYParser.IfStmtContext ctx) { } 253 | /** 254 | * {@inheritDoc} 255 | * 256 | *

The default implementation does nothing.

257 | */ 258 | @Override public void enterWhileStmt(SysYParser.WhileStmtContext ctx) { } 259 | /** 260 | * {@inheritDoc} 261 | * 262 | *

The default implementation does nothing.

263 | */ 264 | @Override public void exitWhileStmt(SysYParser.WhileStmtContext ctx) { } 265 | /** 266 | * {@inheritDoc} 267 | * 268 | *

The default implementation does nothing.

269 | */ 270 | @Override public void enterBreakStmt(SysYParser.BreakStmtContext ctx) { } 271 | /** 272 | * {@inheritDoc} 273 | * 274 | *

The default implementation does nothing.

275 | */ 276 | @Override public void exitBreakStmt(SysYParser.BreakStmtContext ctx) { } 277 | /** 278 | * {@inheritDoc} 279 | * 280 | *

The default implementation does nothing.

281 | */ 282 | @Override public void enterContinueStmt(SysYParser.ContinueStmtContext ctx) { } 283 | /** 284 | * {@inheritDoc} 285 | * 286 | *

The default implementation does nothing.

287 | */ 288 | @Override public void exitContinueStmt(SysYParser.ContinueStmtContext ctx) { } 289 | /** 290 | * {@inheritDoc} 291 | * 292 | *

The default implementation does nothing.

293 | */ 294 | @Override public void enterReturnStmt(SysYParser.ReturnStmtContext ctx) { } 295 | /** 296 | * {@inheritDoc} 297 | * 298 | *

The default implementation does nothing.

299 | */ 300 | @Override public void exitReturnStmt(SysYParser.ReturnStmtContext ctx) { } 301 | /** 302 | * {@inheritDoc} 303 | * 304 | *

The default implementation does nothing.

305 | */ 306 | @Override public void enterLValExp(SysYParser.LValExpContext ctx) { } 307 | /** 308 | * {@inheritDoc} 309 | * 310 | *

The default implementation does nothing.

311 | */ 312 | @Override public void exitLValExp(SysYParser.LValExpContext ctx) { } 313 | /** 314 | * {@inheritDoc} 315 | * 316 | *

The default implementation does nothing.

317 | */ 318 | @Override public void enterUnaryExp(SysYParser.UnaryExpContext ctx) { } 319 | /** 320 | * {@inheritDoc} 321 | * 322 | *

The default implementation does nothing.

323 | */ 324 | @Override public void exitUnaryExp(SysYParser.UnaryExpContext ctx) { } 325 | /** 326 | * {@inheritDoc} 327 | * 328 | *

The default implementation does nothing.

329 | */ 330 | @Override public void enterParenExp(SysYParser.ParenExpContext ctx) { } 331 | /** 332 | * {@inheritDoc} 333 | * 334 | *

The default implementation does nothing.

335 | */ 336 | @Override public void exitParenExp(SysYParser.ParenExpContext ctx) { } 337 | /** 338 | * {@inheritDoc} 339 | * 340 | *

The default implementation does nothing.

341 | */ 342 | @Override public void enterAddExp(SysYParser.AddExpContext ctx) { } 343 | /** 344 | * {@inheritDoc} 345 | * 346 | *

The default implementation does nothing.

347 | */ 348 | @Override public void exitAddExp(SysYParser.AddExpContext ctx) { } 349 | /** 350 | * {@inheritDoc} 351 | * 352 | *

The default implementation does nothing.

353 | */ 354 | @Override public void enterMulExp(SysYParser.MulExpContext ctx) { } 355 | /** 356 | * {@inheritDoc} 357 | * 358 | *

The default implementation does nothing.

359 | */ 360 | @Override public void exitMulExp(SysYParser.MulExpContext ctx) { } 361 | /** 362 | * {@inheritDoc} 363 | * 364 | *

The default implementation does nothing.

365 | */ 366 | @Override public void enterFuncCallExp(SysYParser.FuncCallExpContext ctx) { } 367 | /** 368 | * {@inheritDoc} 369 | * 370 | *

The default implementation does nothing.

371 | */ 372 | @Override public void exitFuncCallExp(SysYParser.FuncCallExpContext ctx) { } 373 | /** 374 | * {@inheritDoc} 375 | * 376 | *

The default implementation does nothing.

377 | */ 378 | @Override public void enterNumExp(SysYParser.NumExpContext ctx) { } 379 | /** 380 | * {@inheritDoc} 381 | * 382 | *

The default implementation does nothing.

383 | */ 384 | @Override public void exitNumExp(SysYParser.NumExpContext ctx) { } 385 | /** 386 | * {@inheritDoc} 387 | * 388 | *

The default implementation does nothing.

389 | */ 390 | @Override public void enterCompareExp(SysYParser.CompareExpContext ctx) { } 391 | /** 392 | * {@inheritDoc} 393 | * 394 | *

The default implementation does nothing.

395 | */ 396 | @Override public void exitCompareExp(SysYParser.CompareExpContext ctx) { } 397 | /** 398 | * {@inheritDoc} 399 | * 400 | *

The default implementation does nothing.

401 | */ 402 | @Override public void enterRelationExp(SysYParser.RelationExpContext ctx) { } 403 | /** 404 | * {@inheritDoc} 405 | * 406 | *

The default implementation does nothing.

407 | */ 408 | @Override public void exitRelationExp(SysYParser.RelationExpContext ctx) { } 409 | /** 410 | * {@inheritDoc} 411 | * 412 | *

The default implementation does nothing.

413 | */ 414 | @Override public void enterCondExp(SysYParser.CondExpContext ctx) { } 415 | /** 416 | * {@inheritDoc} 417 | * 418 | *

The default implementation does nothing.

419 | */ 420 | @Override public void exitCondExp(SysYParser.CondExpContext ctx) { } 421 | /** 422 | * {@inheritDoc} 423 | * 424 | *

The default implementation does nothing.

425 | */ 426 | @Override public void enterAndExp(SysYParser.AndExpContext ctx) { } 427 | /** 428 | * {@inheritDoc} 429 | * 430 | *

The default implementation does nothing.

431 | */ 432 | @Override public void exitAndExp(SysYParser.AndExpContext ctx) { } 433 | /** 434 | * {@inheritDoc} 435 | * 436 | *

The default implementation does nothing.

437 | */ 438 | @Override public void enterOrExp(SysYParser.OrExpContext ctx) { } 439 | /** 440 | * {@inheritDoc} 441 | * 442 | *

The default implementation does nothing.

443 | */ 444 | @Override public void exitOrExp(SysYParser.OrExpContext ctx) { } 445 | /** 446 | * {@inheritDoc} 447 | * 448 | *

The default implementation does nothing.

449 | */ 450 | @Override public void enterLVal(SysYParser.LValContext ctx) { } 451 | /** 452 | * {@inheritDoc} 453 | * 454 | *

The default implementation does nothing.

455 | */ 456 | @Override public void exitLVal(SysYParser.LValContext ctx) { } 457 | /** 458 | * {@inheritDoc} 459 | * 460 | *

The default implementation does nothing.

461 | */ 462 | @Override public void enterNumber(SysYParser.NumberContext ctx) { } 463 | /** 464 | * {@inheritDoc} 465 | * 466 | *

The default implementation does nothing.

467 | */ 468 | @Override public void exitNumber(SysYParser.NumberContext ctx) { } 469 | /** 470 | * {@inheritDoc} 471 | * 472 | *

The default implementation does nothing.

473 | */ 474 | @Override public void enterUnaryOp(SysYParser.UnaryOpContext ctx) { } 475 | /** 476 | * {@inheritDoc} 477 | * 478 | *

The default implementation does nothing.

479 | */ 480 | @Override public void exitUnaryOp(SysYParser.UnaryOpContext ctx) { } 481 | /** 482 | * {@inheritDoc} 483 | * 484 | *

The default implementation does nothing.

485 | */ 486 | @Override public void enterFuncRParams(SysYParser.FuncRParamsContext ctx) { } 487 | /** 488 | * {@inheritDoc} 489 | * 490 | *

The default implementation does nothing.

491 | */ 492 | @Override public void exitFuncRParams(SysYParser.FuncRParamsContext ctx) { } 493 | /** 494 | * {@inheritDoc} 495 | * 496 | *

The default implementation does nothing.

497 | */ 498 | @Override public void enterParam(SysYParser.ParamContext ctx) { } 499 | /** 500 | * {@inheritDoc} 501 | * 502 | *

The default implementation does nothing.

503 | */ 504 | @Override public void exitParam(SysYParser.ParamContext ctx) { } 505 | /** 506 | * {@inheritDoc} 507 | * 508 | *

The default implementation does nothing.

509 | */ 510 | @Override public void enterConstExp(SysYParser.ConstExpContext ctx) { } 511 | /** 512 | * {@inheritDoc} 513 | * 514 | *

The default implementation does nothing.

515 | */ 516 | @Override public void exitConstExp(SysYParser.ConstExpContext ctx) { } 517 | 518 | /** 519 | * {@inheritDoc} 520 | * 521 | *

The default implementation does nothing.

522 | */ 523 | @Override public void enterEveryRule(ParserRuleContext ctx) { } 524 | /** 525 | * {@inheritDoc} 526 | * 527 | *

The default implementation does nothing.

528 | */ 529 | @Override public void exitEveryRule(ParserRuleContext ctx) { } 530 | /** 531 | * {@inheritDoc} 532 | * 533 | *

The default implementation does nothing.

534 | */ 535 | @Override public void visitTerminal(TerminalNode node) { } 536 | /** 537 | * {@inheritDoc} 538 | * 539 | *

The default implementation does nothing.

540 | */ 541 | @Override public void visitErrorNode(ErrorNode node) { } 542 | } --------------------------------------------------------------------------------