From d8c3f92eab94d36bfd4b47af0b37020974461dc0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 11 Nov 2025 04:50:08 +0000 Subject: [PATCH 1/5] Initial plan From 624520e8e00cefa81751687f30fd289e31811532 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 11 Nov 2025 05:11:55 +0000 Subject: [PATCH 2/5] Implement type system, symbol table, and semantic checking for Project 3 Co-authored-by: wuzhi456 <217564920+wuzhi456@users.noreply.github.com> --- Splc.g4 | 1 + out/Main.class | Bin 0 -> 712 bytes out/framework/AbstractCompiler.class | Bin 0 -> 381 bytes out/framework/AbstractGrader.class | Bin 0 -> 1798 bytes out/framework/lang/Type.class | Bin 0 -> 241 bytes out/framework/project3/Grader.class | Bin 0 -> 578 bytes ...nticError$DefinitionOfIncompleteType.class | Bin 0 -> 1105 bytes .../Project3SemanticError$MemberError.class | Bin 0 -> 1140 bytes ...ect3SemanticError$RedeclarationError.class | Bin 0 -> 1158 bytes ...ject3SemanticError$RedefinitionError.class | Bin 0 -> 1073 bytes ...ect3SemanticError$UndeclaredUseError.class | Bin 0 -> 1077 bytes .../project3/Project3SemanticError.class | Bin 0 -> 1550 bytes out/generated/Splc/SplcBaseVisitor.class | Bin 0 -> 3672 bytes out/generated/Splc/SplcLexer.class | Bin 0 -> 8795 bytes out/generated/Splc/SplcListener.class | Bin 0 -> 2268 bytes .../Splc/SplcParser$BracketContext.class | Bin 0 -> 1948 bytes .../Splc/SplcParser$ExprStmtContext.class | Bin 0 -> 1769 bytes .../Splc/SplcParser$ExpressionContext.class | Bin 0 -> 3554 bytes .../Splc/SplcParser$FuncArgsContext.class | Bin 0 -> 2427 bytes .../Splc/SplcParser$GlobalDefContext.class | Bin 0 -> 3043 bytes .../Splc/SplcParser$IfStmtContext.class | Bin 0 -> 2233 bytes .../Splc/SplcParser$ProgramContext.class | Bin 0 -> 1965 bytes .../Splc/SplcParser$ReturnStmtContext.class | Bin 0 -> 1837 bytes .../Splc/SplcParser$SpecifierContext.class | Bin 0 -> 2729 bytes .../Splc/SplcParser$StatementContext.class | Bin 0 -> 680 bytes .../Splc/SplcParser$VarDecContext.class | Bin 0 -> 2005 bytes .../Splc/SplcParser$VarDecStmtContext.class | Bin 0 -> 2196 bytes .../Splc/SplcParser$WhileStmtContext.class | Bin 0 -> 1997 bytes out/generated/Splc/SplcParser.class | Bin 0 -> 21632 bytes out/generated/Splc/SplcVisitor.class | Bin 0 -> 3013 bytes out/impl/Compiler$SemanticAnalyzer.class | Bin 0 -> 11549 bytes out/impl/Compiler.class | Bin 0 -> 2516 bytes out/impl/symbol/Symbol$Kind.class | Bin 0 -> 1183 bytes out/impl/symbol/Symbol.class | Bin 0 -> 881 bytes out/impl/symbol/SymbolTable.class | Bin 0 -> 3224 bytes out/impl/types/ArrayType.class | Bin 0 -> 1323 bytes out/impl/types/BasicType$Kind.class | Bin 0 -> 1010 bytes out/impl/types/BasicType.class | Bin 0 -> 900 bytes out/impl/types/FunctionType.class | Bin 0 -> 1571 bytes out/impl/types/PointerType.class | Bin 0 -> 1198 bytes out/impl/types/StructType$Member.class | Bin 0 -> 460 bytes out/impl/types/StructType.class | Bin 0 -> 2462 bytes src/main/java/Main.java | 9 +- src/main/java/impl/Compiler.java | 400 +++++++++++++++++- src/main/java/impl/symbol/Symbol.java | 41 ++ src/main/java/impl/symbol/SymbolTable.java | 108 +++++ src/main/java/impl/types/ArrayType.java | 39 ++ src/main/java/impl/types/BasicType.java | 37 ++ src/main/java/impl/types/FunctionType.java | 49 +++ src/main/java/impl/types/PointerType.java | 33 ++ src/main/java/impl/types/StructType.java | 81 ++++ 51 files changed, 774 insertions(+), 24 deletions(-) create mode 100644 out/Main.class create mode 100644 out/framework/AbstractCompiler.class create mode 100644 out/framework/AbstractGrader.class create mode 100644 out/framework/lang/Type.class create mode 100644 out/framework/project3/Grader.class create mode 100644 out/framework/project3/Project3SemanticError$DefinitionOfIncompleteType.class create mode 100644 out/framework/project3/Project3SemanticError$MemberError.class create mode 100644 out/framework/project3/Project3SemanticError$RedeclarationError.class create mode 100644 out/framework/project3/Project3SemanticError$RedefinitionError.class create mode 100644 out/framework/project3/Project3SemanticError$UndeclaredUseError.class create mode 100644 out/framework/project3/Project3SemanticError.class create mode 100644 out/generated/Splc/SplcBaseVisitor.class create mode 100644 out/generated/Splc/SplcLexer.class create mode 100644 out/generated/Splc/SplcListener.class create mode 100644 out/generated/Splc/SplcParser$BracketContext.class create mode 100644 out/generated/Splc/SplcParser$ExprStmtContext.class create mode 100644 out/generated/Splc/SplcParser$ExpressionContext.class create mode 100644 out/generated/Splc/SplcParser$FuncArgsContext.class create mode 100644 out/generated/Splc/SplcParser$GlobalDefContext.class create mode 100644 out/generated/Splc/SplcParser$IfStmtContext.class create mode 100644 out/generated/Splc/SplcParser$ProgramContext.class create mode 100644 out/generated/Splc/SplcParser$ReturnStmtContext.class create mode 100644 out/generated/Splc/SplcParser$SpecifierContext.class create mode 100644 out/generated/Splc/SplcParser$StatementContext.class create mode 100644 out/generated/Splc/SplcParser$VarDecContext.class create mode 100644 out/generated/Splc/SplcParser$VarDecStmtContext.class create mode 100644 out/generated/Splc/SplcParser$WhileStmtContext.class create mode 100644 out/generated/Splc/SplcParser.class create mode 100644 out/generated/Splc/SplcVisitor.class create mode 100644 out/impl/Compiler$SemanticAnalyzer.class create mode 100644 out/impl/Compiler.class create mode 100644 out/impl/symbol/Symbol$Kind.class create mode 100644 out/impl/symbol/Symbol.class create mode 100644 out/impl/symbol/SymbolTable.class create mode 100644 out/impl/types/ArrayType.class create mode 100644 out/impl/types/BasicType$Kind.class create mode 100644 out/impl/types/BasicType.class create mode 100644 out/impl/types/FunctionType.class create mode 100644 out/impl/types/PointerType.class create mode 100644 out/impl/types/StructType$Member.class create mode 100644 out/impl/types/StructType.class create mode 100644 src/main/java/impl/symbol/Symbol.java create mode 100644 src/main/java/impl/symbol/SymbolTable.java create mode 100644 src/main/java/impl/types/ArrayType.java create mode 100644 src/main/java/impl/types/BasicType.java create mode 100644 src/main/java/impl/types/FunctionType.java create mode 100644 src/main/java/impl/types/PointerType.java create mode 100644 src/main/java/impl/types/StructType.java diff --git a/Splc.g4 b/Splc.g4 index ebc957b..abb0833 100644 --- a/Splc.g4 +++ b/Splc.g4 @@ -16,6 +16,7 @@ program: globalDef* EOF; globalDef : specifier Identifier LPAREN funcArgs RPAREN LBRACE statement* RBRACE // function definition + | specifier Identifier LPAREN funcArgs RPAREN SEMI // function declaration | specifier varDec (ASSIGN expression)? SEMI // global variable definition | specifier SEMI // global struct declaration ; diff --git a/out/Main.class b/out/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..cc7f8f99daf04160cf2c274ae1bbabf232a9f559 GIT binary patch literal 712 zcmZva-EPxB5QWbqZntrrG_>h26ev(g(h^H>SwKPv5K=-a1x2d3KpS_d+{SjaS@ZKU zyaT-;5|#P@JQG69x}*sROWyH%=A8X@G(UcQKL_v_4Hr4&1so4Em?e~t
mF{{X01(Fp7w@D
z%fMWqFn~^Dfh~g5lC~kvv*b__7MfwKUZ+t{={K_1=RZ!A fMt7DKdht}?$7DZTE@fp24Wj3eLnGc1bxA>zMxwVdi_QHr4%E|^_M!W
z?3eXd;wxBxML%M)Bf9nU*I&gam2sc+qq_BS&|lM!S?;gvMm r>h(rzrd2_?HH
zsq(WM3r0{dI9ZjS-&pcKl}{$`xCOZ0c+^n*+E&*SvN
z%k<;E^YnxB^uvqvALDck L8}oPwb#VW+8@Lw?L)Cy`-|A3
zeJyU)eh^!=AH{9@RIyE;Bev^4u|qEwJM~RsmwvmrQ{O9g>nFq>y;khiUl;rIcf@}E
zLvcX=TpZND5{L9}#1Z|RxF7#Bp$G8)6*?+ uv6D#2JmS<4y8Vrir9}YV9TZi|OxDm=0Upo;uY(F^Y`+DNIVVteLRxb$!eSkhx
zbjDJl%fQ^u{LcS>=DdHrya71Ij)5g;IwDC#5o6f66}HPCd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