diff --git a/.gitignore b/.gitignore index c1a9cb2..5bf12f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ ### CS323 Template ### #### Ignore generated #### src/main/java/generated +out/ *.tar *.tar.gz diff --git a/out/production/CS323-Compilers-2025F-Projects/Main.class b/out/production/CS323-Compilers-2025F-Projects/Main.class deleted file mode 100644 index 60cb356..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/Main.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/AbstractCompiler.class b/out/production/CS323-Compilers-2025F-Projects/framework/AbstractCompiler.class deleted file mode 100644 index 06b4c3c..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/AbstractCompiler.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/AbstractGrader.class b/out/production/CS323-Compilers-2025F-Projects/framework/AbstractGrader.class deleted file mode 100644 index f4a3239..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/AbstractGrader.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/Utils.class b/out/production/CS323-Compilers-2025F-Projects/framework/Utils.class deleted file mode 100644 index 0a2f6b7..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/Utils.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/lang/Type.class b/out/production/CS323-Compilers-2025F-Projects/framework/lang/Type.class deleted file mode 100644 index af97480..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/lang/Type.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Grader.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Grader.class deleted file mode 100644 index 346d86c..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Grader.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$DefinitionOfIncompleteType.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$DefinitionOfIncompleteType.class deleted file mode 100644 index 840ee01..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$DefinitionOfIncompleteType.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$MemberError.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$MemberError.class deleted file mode 100644 index b7ff75b..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$MemberError.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$RedeclarationError.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$RedeclarationError.class deleted file mode 100644 index 41ae1bd..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$RedeclarationError.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$RedefinitionError.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$RedefinitionError.class deleted file mode 100644 index 2921c83..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$RedefinitionError.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$UndeclaredUseError.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$UndeclaredUseError.class deleted file mode 100644 index cb30da7..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError$UndeclaredUseError.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError.class b/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError.class deleted file mode 100644 index 15dc103..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/framework/project3/Project3SemanticError.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/Splc.interp b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/Splc.interp deleted file mode 100644 index 6bf2184..0000000 --- a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/Splc.interp +++ /dev/null @@ -1,100 +0,0 @@ -token literal names: -null -'int' -'char' -'struct' -'return' -'if' -'else' -'while' -'=' -'+' -'-' -'*' -'/' -'%' -'<' -'<=' -'>' -'>=' -'==' -'!=' -'&&' -'||' -'!' -'++' -'--' -'.' -'->' -'&' -';' -',' -'(' -')' -'{' -'}' -'[' -']' -null -null -null -null -null -null - -token symbolic names: -null -INT -CHAR -STRUCT -RETURN -IF -ELSE -WHILE -ASSIGN -PLUS -MINUS -STAR -DIV -MOD -LT -LE -GT -GE -EQ -NEQ -AND -OR -NOT -INC -DEC -DOT -ARROW -AMP -SEMI -COMMA -LPAREN -RPAREN -LBRACE -RBRACE -LBRACK -RBRACK -Identifier -Number -Char -WS -LINE_COMMENT -BLOCK_COMMENT - -rule names: -program -globalDef -specifier -varDec -funcArgs -statement -expression - - -atn: -[4, 1, 41, 226, 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, 1, 0, 5, 0, 16, 8, 0, 10, 0, 12, 0, 19, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 30, 8, 1, 10, 1, 12, 1, 33, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 41, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 55, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 68, 8, 2, 10, 2, 12, 2, 71, 9, 2, 1, 2, 3, 2, 74, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 84, 8, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 90, 8, 3, 10, 3, 12, 3, 93, 9, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 5, 4, 101, 8, 4, 10, 4, 12, 4, 104, 9, 4, 3, 4, 106, 8, 4, 1, 5, 1, 5, 5, 5, 110, 8, 5, 10, 5, 12, 5, 113, 9, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 120, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 131, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 146, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 161, 8, 6, 10, 6, 12, 6, 164, 9, 6, 3, 6, 166, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 183, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 221, 8, 6, 10, 6, 12, 6, 224, 9, 6, 1, 6, 0, 2, 6, 12, 7, 0, 2, 4, 6, 8, 10, 12, 0, 4, 1, 0, 11, 13, 1, 0, 9, 10, 1, 0, 14, 17, 1, 0, 18, 19, 266, 0, 17, 1, 0, 0, 0, 2, 54, 1, 0, 0, 0, 4, 73, 1, 0, 0, 0, 6, 83, 1, 0, 0, 0, 8, 105, 1, 0, 0, 0, 10, 145, 1, 0, 0, 0, 12, 182, 1, 0, 0, 0, 14, 16, 3, 2, 1, 0, 15, 14, 1, 0, 0, 0, 16, 19, 1, 0, 0, 0, 17, 15, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 17, 1, 0, 0, 0, 20, 21, 5, 0, 0, 1, 21, 1, 1, 0, 0, 0, 22, 23, 3, 4, 2, 0, 23, 24, 5, 36, 0, 0, 24, 25, 5, 30, 0, 0, 25, 26, 3, 8, 4, 0, 26, 27, 5, 31, 0, 0, 27, 31, 5, 32, 0, 0, 28, 30, 3, 10, 5, 0, 29, 28, 1, 0, 0, 0, 30, 33, 1, 0, 0, 0, 31, 29, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 34, 1, 0, 0, 0, 33, 31, 1, 0, 0, 0, 34, 35, 5, 33, 0, 0, 35, 55, 1, 0, 0, 0, 36, 37, 3, 4, 2, 0, 37, 40, 3, 6, 3, 0, 38, 39, 5, 8, 0, 0, 39, 41, 3, 12, 6, 0, 40, 38, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 43, 5, 28, 0, 0, 43, 55, 1, 0, 0, 0, 44, 45, 3, 4, 2, 0, 45, 46, 5, 36, 0, 0, 46, 47, 5, 30, 0, 0, 47, 48, 3, 8, 4, 0, 48, 49, 5, 31, 0, 0, 49, 50, 5, 28, 0, 0, 50, 55, 1, 0, 0, 0, 51, 52, 3, 4, 2, 0, 52, 53, 5, 28, 0, 0, 53, 55, 1, 0, 0, 0, 54, 22, 1, 0, 0, 0, 54, 36, 1, 0, 0, 0, 54, 44, 1, 0, 0, 0, 54, 51, 1, 0, 0, 0, 55, 3, 1, 0, 0, 0, 56, 74, 5, 1, 0, 0, 57, 74, 5, 2, 0, 0, 58, 59, 5, 3, 0, 0, 59, 74, 5, 36, 0, 0, 60, 61, 5, 3, 0, 0, 61, 62, 5, 36, 0, 0, 62, 69, 5, 32, 0, 0, 63, 64, 3, 4, 2, 0, 64, 65, 3, 6, 3, 0, 65, 66, 5, 28, 0, 0, 66, 68, 1, 0, 0, 0, 67, 63, 1, 0, 0, 0, 68, 71, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, 72, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 74, 5, 33, 0, 0, 73, 56, 1, 0, 0, 0, 73, 57, 1, 0, 0, 0, 73, 58, 1, 0, 0, 0, 73, 60, 1, 0, 0, 0, 74, 5, 1, 0, 0, 0, 75, 76, 6, 3, -1, 0, 76, 84, 5, 36, 0, 0, 77, 78, 5, 30, 0, 0, 78, 79, 3, 6, 3, 0, 79, 80, 5, 31, 0, 0, 80, 84, 1, 0, 0, 0, 81, 82, 5, 11, 0, 0, 82, 84, 3, 6, 3, 1, 83, 75, 1, 0, 0, 0, 83, 77, 1, 0, 0, 0, 83, 81, 1, 0, 0, 0, 84, 91, 1, 0, 0, 0, 85, 86, 10, 2, 0, 0, 86, 87, 5, 34, 0, 0, 87, 88, 5, 37, 0, 0, 88, 90, 5, 35, 0, 0, 89, 85, 1, 0, 0, 0, 90, 93, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 7, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 94, 95, 3, 4, 2, 0, 95, 102, 3, 6, 3, 0, 96, 97, 5, 29, 0, 0, 97, 98, 3, 4, 2, 0, 98, 99, 3, 6, 3, 0, 99, 101, 1, 0, 0, 0, 100, 96, 1, 0, 0, 0, 101, 104, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 106, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 105, 94, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 9, 1, 0, 0, 0, 107, 111, 5, 32, 0, 0, 108, 110, 3, 10, 5, 0, 109, 108, 1, 0, 0, 0, 110, 113, 1, 0, 0, 0, 111, 109, 1, 0, 0, 0, 111, 112, 1, 0, 0, 0, 112, 114, 1, 0, 0, 0, 113, 111, 1, 0, 0, 0, 114, 146, 5, 33, 0, 0, 115, 116, 3, 4, 2, 0, 116, 119, 3, 6, 3, 0, 117, 118, 5, 8, 0, 0, 118, 120, 3, 12, 6, 0, 119, 117, 1, 0, 0, 0, 119, 120, 1, 0, 0, 0, 120, 121, 1, 0, 0, 0, 121, 122, 5, 28, 0, 0, 122, 146, 1, 0, 0, 0, 123, 124, 5, 5, 0, 0, 124, 125, 5, 30, 0, 0, 125, 126, 3, 12, 6, 0, 126, 127, 5, 31, 0, 0, 127, 130, 3, 10, 5, 0, 128, 129, 5, 6, 0, 0, 129, 131, 3, 10, 5, 0, 130, 128, 1, 0, 0, 0, 130, 131, 1, 0, 0, 0, 131, 146, 1, 0, 0, 0, 132, 133, 5, 7, 0, 0, 133, 134, 5, 30, 0, 0, 134, 135, 3, 12, 6, 0, 135, 136, 5, 31, 0, 0, 136, 137, 3, 10, 5, 0, 137, 146, 1, 0, 0, 0, 138, 139, 5, 4, 0, 0, 139, 140, 3, 12, 6, 0, 140, 141, 5, 28, 0, 0, 141, 146, 1, 0, 0, 0, 142, 143, 3, 12, 6, 0, 143, 144, 5, 28, 0, 0, 144, 146, 1, 0, 0, 0, 145, 107, 1, 0, 0, 0, 145, 115, 1, 0, 0, 0, 145, 123, 1, 0, 0, 0, 145, 132, 1, 0, 0, 0, 145, 138, 1, 0, 0, 0, 145, 142, 1, 0, 0, 0, 146, 11, 1, 0, 0, 0, 147, 148, 6, 6, -1, 0, 148, 183, 5, 36, 0, 0, 149, 183, 5, 37, 0, 0, 150, 183, 5, 38, 0, 0, 151, 152, 5, 30, 0, 0, 152, 153, 3, 12, 6, 0, 153, 154, 5, 31, 0, 0, 154, 183, 1, 0, 0, 0, 155, 156, 5, 36, 0, 0, 156, 165, 5, 30, 0, 0, 157, 162, 3, 12, 6, 0, 158, 159, 5, 29, 0, 0, 159, 161, 3, 12, 6, 0, 160, 158, 1, 0, 0, 0, 161, 164, 1, 0, 0, 0, 162, 160, 1, 0, 0, 0, 162, 163, 1, 0, 0, 0, 163, 166, 1, 0, 0, 0, 164, 162, 1, 0, 0, 0, 165, 157, 1, 0, 0, 0, 165, 166, 1, 0, 0, 0, 166, 167, 1, 0, 0, 0, 167, 183, 5, 31, 0, 0, 168, 169, 5, 23, 0, 0, 169, 183, 3, 12, 6, 14, 170, 171, 5, 24, 0, 0, 171, 183, 3, 12, 6, 13, 172, 173, 5, 9, 0, 0, 173, 183, 3, 12, 6, 12, 174, 175, 5, 10, 0, 0, 175, 183, 3, 12, 6, 11, 176, 177, 5, 22, 0, 0, 177, 183, 3, 12, 6, 10, 178, 179, 5, 11, 0, 0, 179, 183, 3, 12, 6, 9, 180, 181, 5, 27, 0, 0, 181, 183, 3, 12, 6, 8, 182, 147, 1, 0, 0, 0, 182, 149, 1, 0, 0, 0, 182, 150, 1, 0, 0, 0, 182, 151, 1, 0, 0, 0, 182, 155, 1, 0, 0, 0, 182, 168, 1, 0, 0, 0, 182, 170, 1, 0, 0, 0, 182, 172, 1, 0, 0, 0, 182, 174, 1, 0, 0, 0, 182, 176, 1, 0, 0, 0, 182, 178, 1, 0, 0, 0, 182, 180, 1, 0, 0, 0, 183, 222, 1, 0, 0, 0, 184, 185, 10, 7, 0, 0, 185, 186, 7, 0, 0, 0, 186, 221, 3, 12, 6, 8, 187, 188, 10, 6, 0, 0, 188, 189, 7, 1, 0, 0, 189, 221, 3, 12, 6, 7, 190, 191, 10, 5, 0, 0, 191, 192, 7, 2, 0, 0, 192, 221, 3, 12, 6, 6, 193, 194, 10, 4, 0, 0, 194, 195, 7, 3, 0, 0, 195, 221, 3, 12, 6, 5, 196, 197, 10, 3, 0, 0, 197, 198, 5, 20, 0, 0, 198, 221, 3, 12, 6, 4, 199, 200, 10, 2, 0, 0, 200, 201, 5, 21, 0, 0, 201, 221, 3, 12, 6, 3, 202, 203, 10, 1, 0, 0, 203, 204, 5, 8, 0, 0, 204, 221, 3, 12, 6, 1, 205, 206, 10, 20, 0, 0, 206, 221, 5, 23, 0, 0, 207, 208, 10, 19, 0, 0, 208, 221, 5, 24, 0, 0, 209, 210, 10, 18, 0, 0, 210, 211, 5, 34, 0, 0, 211, 212, 3, 12, 6, 0, 212, 213, 5, 35, 0, 0, 213, 221, 1, 0, 0, 0, 214, 215, 10, 17, 0, 0, 215, 216, 5, 25, 0, 0, 216, 221, 5, 36, 0, 0, 217, 218, 10, 16, 0, 0, 218, 219, 5, 26, 0, 0, 219, 221, 5, 36, 0, 0, 220, 184, 1, 0, 0, 0, 220, 187, 1, 0, 0, 0, 220, 190, 1, 0, 0, 0, 220, 193, 1, 0, 0, 0, 220, 196, 1, 0, 0, 0, 220, 199, 1, 0, 0, 0, 220, 202, 1, 0, 0, 0, 220, 205, 1, 0, 0, 0, 220, 207, 1, 0, 0, 0, 220, 209, 1, 0, 0, 0, 220, 214, 1, 0, 0, 0, 220, 217, 1, 0, 0, 0, 221, 224, 1, 0, 0, 0, 222, 220, 1, 0, 0, 0, 222, 223, 1, 0, 0, 0, 223, 13, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 19, 17, 31, 40, 54, 69, 73, 83, 91, 102, 105, 111, 119, 130, 145, 162, 165, 182, 220, 222] \ No newline at end of file diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/Splc.tokens b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/Splc.tokens deleted file mode 100644 index 66553e7..0000000 --- a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/Splc.tokens +++ /dev/null @@ -1,76 +0,0 @@ -INT=1 -CHAR=2 -STRUCT=3 -RETURN=4 -IF=5 -ELSE=6 -WHILE=7 -ASSIGN=8 -PLUS=9 -MINUS=10 -STAR=11 -DIV=12 -MOD=13 -LT=14 -LE=15 -GT=16 -GE=17 -EQ=18 -NEQ=19 -AND=20 -OR=21 -NOT=22 -INC=23 -DEC=24 -DOT=25 -ARROW=26 -AMP=27 -SEMI=28 -COMMA=29 -LPAREN=30 -RPAREN=31 -LBRACE=32 -RBRACE=33 -LBRACK=34 -RBRACK=35 -Identifier=36 -Number=37 -Char=38 -WS=39 -LINE_COMMENT=40 -BLOCK_COMMENT=41 -'int'=1 -'char'=2 -'struct'=3 -'return'=4 -'if'=5 -'else'=6 -'while'=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 diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcBaseListener.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcBaseListener.class deleted file mode 100644 index b620eba..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcBaseListener.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcBaseVisitor.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcBaseVisitor.class deleted file mode 100644 index f8216dc..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcBaseVisitor.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.class deleted file mode 100644 index b66f3db..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.interp b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.interp deleted file mode 100644 index f22c04a..0000000 --- a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.interp +++ /dev/null @@ -1,140 +0,0 @@ -token literal names: -null -'int' -'char' -'struct' -'return' -'if' -'else' -'while' -'=' -'+' -'-' -'*' -'/' -'%' -'<' -'<=' -'>' -'>=' -'==' -'!=' -'&&' -'||' -'!' -'++' -'--' -'.' -'->' -'&' -';' -',' -'(' -')' -'{' -'}' -'[' -']' -null -null -null -null -null -null - -token symbolic names: -null -INT -CHAR -STRUCT -RETURN -IF -ELSE -WHILE -ASSIGN -PLUS -MINUS -STAR -DIV -MOD -LT -LE -GT -GE -EQ -NEQ -AND -OR -NOT -INC -DEC -DOT -ARROW -AMP -SEMI -COMMA -LPAREN -RPAREN -LBRACE -RBRACE -LBRACK -RBRACK -Identifier -Number -Char -WS -LINE_COMMENT -BLOCK_COMMENT - -rule names: -INT -CHAR -STRUCT -RETURN -IF -ELSE -WHILE -ASSIGN -PLUS -MINUS -STAR -DIV -MOD -LT -LE -GT -GE -EQ -NEQ -AND -OR -NOT -INC -DEC -DOT -ARROW -AMP -SEMI -COMMA -LPAREN -RPAREN -LBRACE -RBRACE -LBRACK -RBRACK -Identifier -Number -Char -WS -LINE_COMMENT -BLOCK_COMMENT - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[4, 0, 41, 242, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 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, 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, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 18, 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, 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, 1, 33, 1, 33, 1, 34, 1, 34, 1, 35, 1, 35, 5, 35, 188, 8, 35, 10, 35, 12, 35, 191, 9, 35, 1, 36, 1, 36, 1, 36, 5, 36, 196, 8, 36, 10, 36, 12, 36, 199, 9, 36, 3, 36, 201, 8, 36, 1, 37, 1, 37, 1, 37, 1, 37, 3, 37, 207, 8, 37, 1, 37, 1, 37, 1, 38, 4, 38, 212, 8, 38, 11, 38, 12, 38, 213, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 39, 5, 39, 222, 8, 39, 10, 39, 12, 39, 225, 9, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 40, 1, 40, 5, 40, 233, 8, 40, 10, 40, 12, 40, 236, 9, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 234, 0, 41, 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, 35, 71, 36, 73, 37, 75, 38, 77, 39, 79, 40, 81, 41, 1, 0, 8, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 49, 57, 1, 0, 48, 57, 4, 0, 10, 10, 13, 13, 39, 39, 92, 92, 5, 0, 39, 39, 48, 48, 92, 92, 110, 110, 116, 116, 3, 0, 9, 10, 13, 13, 32, 32, 2, 0, 10, 10, 13, 13, 248, 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, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, 0, 1, 83, 1, 0, 0, 0, 3, 87, 1, 0, 0, 0, 5, 92, 1, 0, 0, 0, 7, 99, 1, 0, 0, 0, 9, 106, 1, 0, 0, 0, 11, 109, 1, 0, 0, 0, 13, 114, 1, 0, 0, 0, 15, 120, 1, 0, 0, 0, 17, 122, 1, 0, 0, 0, 19, 124, 1, 0, 0, 0, 21, 126, 1, 0, 0, 0, 23, 128, 1, 0, 0, 0, 25, 130, 1, 0, 0, 0, 27, 132, 1, 0, 0, 0, 29, 134, 1, 0, 0, 0, 31, 137, 1, 0, 0, 0, 33, 139, 1, 0, 0, 0, 35, 142, 1, 0, 0, 0, 37, 145, 1, 0, 0, 0, 39, 148, 1, 0, 0, 0, 41, 151, 1, 0, 0, 0, 43, 154, 1, 0, 0, 0, 45, 156, 1, 0, 0, 0, 47, 159, 1, 0, 0, 0, 49, 162, 1, 0, 0, 0, 51, 164, 1, 0, 0, 0, 53, 167, 1, 0, 0, 0, 55, 169, 1, 0, 0, 0, 57, 171, 1, 0, 0, 0, 59, 173, 1, 0, 0, 0, 61, 175, 1, 0, 0, 0, 63, 177, 1, 0, 0, 0, 65, 179, 1, 0, 0, 0, 67, 181, 1, 0, 0, 0, 69, 183, 1, 0, 0, 0, 71, 185, 1, 0, 0, 0, 73, 200, 1, 0, 0, 0, 75, 202, 1, 0, 0, 0, 77, 211, 1, 0, 0, 0, 79, 217, 1, 0, 0, 0, 81, 228, 1, 0, 0, 0, 83, 84, 5, 105, 0, 0, 84, 85, 5, 110, 0, 0, 85, 86, 5, 116, 0, 0, 86, 2, 1, 0, 0, 0, 87, 88, 5, 99, 0, 0, 88, 89, 5, 104, 0, 0, 89, 90, 5, 97, 0, 0, 90, 91, 5, 114, 0, 0, 91, 4, 1, 0, 0, 0, 92, 93, 5, 115, 0, 0, 93, 94, 5, 116, 0, 0, 94, 95, 5, 114, 0, 0, 95, 96, 5, 117, 0, 0, 96, 97, 5, 99, 0, 0, 97, 98, 5, 116, 0, 0, 98, 6, 1, 0, 0, 0, 99, 100, 5, 114, 0, 0, 100, 101, 5, 101, 0, 0, 101, 102, 5, 116, 0, 0, 102, 103, 5, 117, 0, 0, 103, 104, 5, 114, 0, 0, 104, 105, 5, 110, 0, 0, 105, 8, 1, 0, 0, 0, 106, 107, 5, 105, 0, 0, 107, 108, 5, 102, 0, 0, 108, 10, 1, 0, 0, 0, 109, 110, 5, 101, 0, 0, 110, 111, 5, 108, 0, 0, 111, 112, 5, 115, 0, 0, 112, 113, 5, 101, 0, 0, 113, 12, 1, 0, 0, 0, 114, 115, 5, 119, 0, 0, 115, 116, 5, 104, 0, 0, 116, 117, 5, 105, 0, 0, 117, 118, 5, 108, 0, 0, 118, 119, 5, 101, 0, 0, 119, 14, 1, 0, 0, 0, 120, 121, 5, 61, 0, 0, 121, 16, 1, 0, 0, 0, 122, 123, 5, 43, 0, 0, 123, 18, 1, 0, 0, 0, 124, 125, 5, 45, 0, 0, 125, 20, 1, 0, 0, 0, 126, 127, 5, 42, 0, 0, 127, 22, 1, 0, 0, 0, 128, 129, 5, 47, 0, 0, 129, 24, 1, 0, 0, 0, 130, 131, 5, 37, 0, 0, 131, 26, 1, 0, 0, 0, 132, 133, 5, 60, 0, 0, 133, 28, 1, 0, 0, 0, 134, 135, 5, 60, 0, 0, 135, 136, 5, 61, 0, 0, 136, 30, 1, 0, 0, 0, 137, 138, 5, 62, 0, 0, 138, 32, 1, 0, 0, 0, 139, 140, 5, 62, 0, 0, 140, 141, 5, 61, 0, 0, 141, 34, 1, 0, 0, 0, 142, 143, 5, 61, 0, 0, 143, 144, 5, 61, 0, 0, 144, 36, 1, 0, 0, 0, 145, 146, 5, 33, 0, 0, 146, 147, 5, 61, 0, 0, 147, 38, 1, 0, 0, 0, 148, 149, 5, 38, 0, 0, 149, 150, 5, 38, 0, 0, 150, 40, 1, 0, 0, 0, 151, 152, 5, 124, 0, 0, 152, 153, 5, 124, 0, 0, 153, 42, 1, 0, 0, 0, 154, 155, 5, 33, 0, 0, 155, 44, 1, 0, 0, 0, 156, 157, 5, 43, 0, 0, 157, 158, 5, 43, 0, 0, 158, 46, 1, 0, 0, 0, 159, 160, 5, 45, 0, 0, 160, 161, 5, 45, 0, 0, 161, 48, 1, 0, 0, 0, 162, 163, 5, 46, 0, 0, 163, 50, 1, 0, 0, 0, 164, 165, 5, 45, 0, 0, 165, 166, 5, 62, 0, 0, 166, 52, 1, 0, 0, 0, 167, 168, 5, 38, 0, 0, 168, 54, 1, 0, 0, 0, 169, 170, 5, 59, 0, 0, 170, 56, 1, 0, 0, 0, 171, 172, 5, 44, 0, 0, 172, 58, 1, 0, 0, 0, 173, 174, 5, 40, 0, 0, 174, 60, 1, 0, 0, 0, 175, 176, 5, 41, 0, 0, 176, 62, 1, 0, 0, 0, 177, 178, 5, 123, 0, 0, 178, 64, 1, 0, 0, 0, 179, 180, 5, 125, 0, 0, 180, 66, 1, 0, 0, 0, 181, 182, 5, 91, 0, 0, 182, 68, 1, 0, 0, 0, 183, 184, 5, 93, 0, 0, 184, 70, 1, 0, 0, 0, 185, 189, 7, 0, 0, 0, 186, 188, 7, 1, 0, 0, 187, 186, 1, 0, 0, 0, 188, 191, 1, 0, 0, 0, 189, 187, 1, 0, 0, 0, 189, 190, 1, 0, 0, 0, 190, 72, 1, 0, 0, 0, 191, 189, 1, 0, 0, 0, 192, 201, 5, 48, 0, 0, 193, 197, 7, 2, 0, 0, 194, 196, 7, 3, 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, 201, 1, 0, 0, 0, 199, 197, 1, 0, 0, 0, 200, 192, 1, 0, 0, 0, 200, 193, 1, 0, 0, 0, 201, 74, 1, 0, 0, 0, 202, 206, 5, 39, 0, 0, 203, 207, 8, 4, 0, 0, 204, 205, 5, 92, 0, 0, 205, 207, 7, 5, 0, 0, 206, 203, 1, 0, 0, 0, 206, 204, 1, 0, 0, 0, 207, 208, 1, 0, 0, 0, 208, 209, 5, 39, 0, 0, 209, 76, 1, 0, 0, 0, 210, 212, 7, 6, 0, 0, 211, 210, 1, 0, 0, 0, 212, 213, 1, 0, 0, 0, 213, 211, 1, 0, 0, 0, 213, 214, 1, 0, 0, 0, 214, 215, 1, 0, 0, 0, 215, 216, 6, 38, 0, 0, 216, 78, 1, 0, 0, 0, 217, 218, 5, 47, 0, 0, 218, 219, 5, 47, 0, 0, 219, 223, 1, 0, 0, 0, 220, 222, 8, 7, 0, 0, 221, 220, 1, 0, 0, 0, 222, 225, 1, 0, 0, 0, 223, 221, 1, 0, 0, 0, 223, 224, 1, 0, 0, 0, 224, 226, 1, 0, 0, 0, 225, 223, 1, 0, 0, 0, 226, 227, 6, 39, 0, 0, 227, 80, 1, 0, 0, 0, 228, 229, 5, 47, 0, 0, 229, 230, 5, 42, 0, 0, 230, 234, 1, 0, 0, 0, 231, 233, 9, 0, 0, 0, 232, 231, 1, 0, 0, 0, 233, 236, 1, 0, 0, 0, 234, 235, 1, 0, 0, 0, 234, 232, 1, 0, 0, 0, 235, 237, 1, 0, 0, 0, 236, 234, 1, 0, 0, 0, 237, 238, 5, 42, 0, 0, 238, 239, 5, 47, 0, 0, 239, 240, 1, 0, 0, 0, 240, 241, 6, 40, 0, 0, 241, 82, 1, 0, 0, 0, 8, 0, 189, 197, 200, 206, 213, 223, 234, 1, 6, 0, 0] \ No newline at end of file diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.tokens b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.tokens deleted file mode 100644 index 66553e7..0000000 --- a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcLexer.tokens +++ /dev/null @@ -1,76 +0,0 @@ -INT=1 -CHAR=2 -STRUCT=3 -RETURN=4 -IF=5 -ELSE=6 -WHILE=7 -ASSIGN=8 -PLUS=9 -MINUS=10 -STAR=11 -DIV=12 -MOD=13 -LT=14 -LE=15 -GT=16 -GE=17 -EQ=18 -NEQ=19 -AND=20 -OR=21 -NOT=22 -INC=23 -DEC=24 -DOT=25 -ARROW=26 -AMP=27 -SEMI=28 -COMMA=29 -LPAREN=30 -RPAREN=31 -LBRACE=32 -RBRACE=33 -LBRACK=34 -RBRACK=35 -Identifier=36 -Number=37 -Char=38 -WS=39 -LINE_COMMENT=40 -BLOCK_COMMENT=41 -'int'=1 -'char'=2 -'struct'=3 -'return'=4 -'if'=5 -'else'=6 -'while'=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 diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcListener.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcListener.class deleted file mode 100644 index b148f03..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcListener.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$BracketContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$BracketContext.class deleted file mode 100644 index 2b4a981..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$BracketContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ExprStmtContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ExprStmtContext.class deleted file mode 100644 index 0e6d746..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ExprStmtContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ExpressionContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ExpressionContext.class deleted file mode 100644 index ac44044..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ExpressionContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$FuncArgsContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$FuncArgsContext.class deleted file mode 100644 index 4ea47a8..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$FuncArgsContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$GlobalDefContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$GlobalDefContext.class deleted file mode 100644 index f830717..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$GlobalDefContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$IfStmtContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$IfStmtContext.class deleted file mode 100644 index b835967..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$IfStmtContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ProgramContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ProgramContext.class deleted file mode 100644 index 898e569..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ProgramContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ReturnStmtContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ReturnStmtContext.class deleted file mode 100644 index 72a9968..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$ReturnStmtContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$SpecifierContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$SpecifierContext.class deleted file mode 100644 index 9199586..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$SpecifierContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$StatementContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$StatementContext.class deleted file mode 100644 index 12eff62..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$StatementContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$VarDecContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$VarDecContext.class deleted file mode 100644 index d36ae59..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$VarDecContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$VarDecStmtContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$VarDecStmtContext.class deleted file mode 100644 index ffc1685..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$VarDecStmtContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$WhileStmtContext.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$WhileStmtContext.class deleted file mode 100644 index 1223c5c..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser$WhileStmtContext.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser.class deleted file mode 100644 index 8c6b691..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcParser.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcVisitor.class b/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcVisitor.class deleted file mode 100644 index 4242d4a..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/generated/Splc/SplcVisitor.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$ArrayType.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$ArrayType.class deleted file mode 100644 index ec1364f..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$ArrayType.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$BasicType$Kind.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$BasicType$Kind.class deleted file mode 100644 index 6e5204b..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$BasicType$Kind.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$BasicType.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$BasicType.class deleted file mode 100644 index 479945a..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$BasicType.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$FunctionType.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$FunctionType.class deleted file mode 100644 index 0ddfe67..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$FunctionType.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$PointerType.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$PointerType.class deleted file mode 100644 index 137e388..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$PointerType.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$SemanticAnalyzer.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$SemanticAnalyzer.class deleted file mode 100644 index 31a5729..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$SemanticAnalyzer.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$StructType$Member.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$StructType$Member.class deleted file mode 100644 index 5c354ca..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$StructType$Member.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$StructType.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$StructType.class deleted file mode 100644 index 2886f80..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$StructType.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$Symbol$Kind.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$Symbol$Kind.class deleted file mode 100644 index d62ed05..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$Symbol$Kind.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$Symbol.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$Symbol.class deleted file mode 100644 index 1871616..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$Symbol.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$SymbolTable.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$SymbolTable.class deleted file mode 100644 index 23ca8fb..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler$SymbolTable.class and /dev/null differ diff --git a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler.class b/out/production/CS323-Compilers-2025F-Projects/impl/Compiler.class deleted file mode 100644 index 0a66988..0000000 Binary files a/out/production/CS323-Compilers-2025F-Projects/impl/Compiler.class and /dev/null differ diff --git a/src/main/java/impl/Compiler.java b/src/main/java/impl/Compiler.java index 262b3ce..8db5c4e 100644 --- a/src/main/java/impl/Compiler.java +++ b/src/main/java/impl/Compiler.java @@ -4,12 +4,16 @@ import framework.AbstractGrader; import framework.lang.Type; import framework.project3.Project3SemanticError; +import framework.project4.Project4SemanticError; +import framework.project4.Project4Exception; import generated.Splc.SplcBaseVisitor; import generated.Splc.SplcLexer; import generated.Splc.SplcParser; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; import java.io.IOException; @@ -36,16 +40,18 @@ public void start() throws IOException { SemanticAnalyzer analyzer = new SemanticAnalyzer(grader); analyzer.visit(program); - // If we get here, no semantic errors were found - // Phase 2: Print global variables and functions - grader.print("Variables:\n"); - for (Symbol symbol : analyzer.getGlobalVariables()) { - grader.print(symbol.getName() + ": " + symbol.getType().fullPrint() + "\n"); - } - grader.print("\n"); - grader.print("Functions:\n"); - for (Symbol symbol : analyzer.getGlobalFunctions()) { - grader.print(symbol.getName() + ": " + symbol.getType().prettyPrint() + "\n"); + // If we get here, no semantic errors were found (or only Project 4 errors) + // Phase 2: Print global variables and functions only if no errors + if (!analyzer.hasSemanticErrors()) { + grader.print("Variables:\n"); + for (Symbol symbol : analyzer.getGlobalVariables()) { + grader.print(symbol.getName() + ": " + symbol.getType().fullPrint() + "\n"); + } + grader.print("\n"); + grader.print("Functions:\n"); + for (Symbol symbol : analyzer.getGlobalFunctions()) { + grader.print(symbol.getName() + ": " + symbol.getType().prettyPrint() + "\n"); + } } } @@ -324,6 +330,7 @@ private static class SymbolTable { private final Deque> otherScopes = new ArrayDeque<>(); // variables, functions private final Deque> tagScopes = new ArrayDeque<>(); // struct tags + private static final int FILE_SCOPE_ID = 0; private int scopeIdCounter = 0; private int currentScopeId = 0; @@ -365,20 +372,27 @@ public void updateOther(String name, Type type, Symbol.Kind kind) { currentScope.put(name, new Symbol(name, type, kind, currentScopeId)); } - // Add symbol to "tag" namespace (struct tags) + // Add symbol to "tag" namespace (struct tags) - always at file scope public boolean addTag(String name, Type type) { - Map currentScope = tagScopes.peek(); - if (currentScope.containsKey(name)) { - return false; // Already exists in current scope + // Structure tags always have file scope per C standard + Map fileScope = getFileTagScope(); + if (fileScope.containsKey(name)) { + return false; // Already exists in file scope } - currentScope.put(name, new Symbol(name, type, Symbol.Kind.STRUCT_TAG, currentScopeId)); + fileScope.put(name, new Symbol(name, type, Symbol.Kind.STRUCT_TAG, FILE_SCOPE_ID)); return true; } - // Update existing tag in current scope (for completing incomplete structs) + // Update existing tag at file scope (for completing incomplete structs) public void updateTag(String name, Type type) { - Map currentScope = tagScopes.peek(); - currentScope.put(name, new Symbol(name, type, Symbol.Kind.STRUCT_TAG, currentScopeId)); + // Structure tags always have file scope per C standard + Map fileScope = getFileTagScope(); + fileScope.put(name, new Symbol(name, type, Symbol.Kind.STRUCT_TAG, FILE_SCOPE_ID)); + } + + // Get file scope for tags (bottom of the stack) - O(1) access + private Map getFileTagScope() { + return ((ArrayDeque>) tagScopes).peekLast(); } // Lookup in "other" namespace @@ -423,7 +437,9 @@ public boolean existsInCurrentScopeOther(String name) { } public boolean existsInCurrentScopeTag(String name) { - return tagScopes.peek().containsKey(name); + // Structure tags always have file scope + Map fileScope = getFileTagScope(); + return fileScope.containsKey(name); } // Get all symbols in file scope (for printing at the end) @@ -441,6 +457,17 @@ public List getFileScopeOthers() { // ===== Semantic Analyzer ===== + // Expression info: type + value category + private static class ExprInfo { + public final Type type; + public final boolean isLvalue; + + public ExprInfo(Type type, boolean isLvalue) { + this.type = type; + this.isLvalue = isLvalue; + } + } + private static class SemanticAnalyzer extends SplcBaseVisitor { private final AbstractGrader grader; private final SymbolTable symbolTable; @@ -448,6 +475,8 @@ private static class SemanticAnalyzer extends SplcBaseVisitor { private final List globalFunctions = new ArrayList<>(); private final Map incompleteGlobals = new LinkedHashMap<>(); + private Type currentFunctionReturnType = null; // Track current function's return type + private boolean hasSemanticErrors = false; // Track if any semantic errors occurred public SemanticAnalyzer(AbstractGrader grader) { @@ -463,6 +492,10 @@ public List getGlobalFunctions() { return globalFunctions; } + public boolean hasSemanticErrors() { + return hasSemanticErrors; + } + private List getTagNamesFromType(Type type) { List result = new ArrayList<>(); if (type instanceof StructType) { @@ -561,6 +594,7 @@ public Type visitGlobalDef(SplcParser.GlobalDefContext ctx) { // Enter function scope for parameters and body symbolTable.enterScope(); + currentFunctionReturnType = specType; // Track return type for return statement checking // Add parameters to the function scope if (ctx.funcArgs().specifier() != null && !ctx.funcArgs().specifier().isEmpty()) { @@ -600,33 +634,47 @@ public Type visitGlobalDef(SplcParser.GlobalDefContext ctx) { } globalVariables.add(new Symbol(varName, varType, Symbol.Kind.VARIABLE, 0)); - // Check for incomplete type if (!isCompleteType(varType)) { // For arrays, the element type must be complete immediately // For direct struct types, we can defer the check per v4 spec if (requiresImmediateCompletenessCheck(varType)) { - if (!isCompleteType(varType)) { - grader.reportSemanticError(Project3SemanticError.definitionIncomplete(getIdentifierNode(ctx.varDec()))); - } - } else if (!isCompleteType(varType)) { + grader.reportSemanticError(Project3SemanticError.definitionIncomplete(getIdentifierNode(ctx.varDec()))); + } else { // Defer check for direct struct types incompleteGlobals.put(new Symbol(varName, varType, Symbol.Kind.VARIABLE, 0), getIdentifierNode(ctx.varDec())); } } - // Check redefinition -// if (symbolTable.existsInCurrentScopeOther(varName)) { -// grader.reportSemanticError(Project3SemanticError.redefinition(getIdentifierNode(ctx.varDec()))); -// } - // 查 file scope,变量/函数/声明同名都不行 -// for (Symbol s : symbolTable.getFileScopeOthers()) { -// if (s.getName().equals(varName)) { -// grader.reportSemanticError(Project3SemanticError.redefinition(getIdentifierNode(ctx.varDec()))); -// break; -// } -// } - + // Check initialization expression if present using assignment rules [2.2.14] + if (ctx.expression() != null) { + try { + ExprInfo exprInfo = checkExpression(ctx.expression()); + + // Check if lhs or rhs is array type - arrays cannot be assigned + if (varType instanceof ArrayType || exprInfo.type instanceof ArrayType) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + + // Check that both sides are integer or pointer types + if (!isIntegerType(varType) && !isPointerType(varType)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + if (!isIntegerType(exprInfo.type) && !isPointerType(exprInfo.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + + // Special case: allow 0 as null pointer + boolean rhsIsZero = isConstantZero(ctx.expression()); + + if (!rhsIsZero && !typesEqual(varType, exprInfo.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + } catch (Project4Exception ex) { + hasSemanticErrors = true; + grader.reportSemanticError(ex); + } + } } else if (ctx.Identifier() != null && ctx.funcArgs() != null) { // Function declaration: specifier Identifier LPAREN funcArgs RPAREN SEMI @@ -764,16 +812,53 @@ public Type visitVarDecStmt(SplcParser.VarDecStmtContext ctx) { symbolTable.addOther(varName, varType, Symbol.Kind.VARIABLE); - // Visit initialization expression if present + // Visit initialization expression if present and check type compatibility + // Use assignment rules [2.2.14] with unmatchedTypeForBinaryOP for type errors if (ctx.expression() != null) { - visitExpression(ctx.expression()); + try { + ExprInfo exprInfo = checkExpression(ctx.expression()); + + // Check if lhs or rhs is array type - arrays cannot be assigned + if (varType instanceof ArrayType || exprInfo.type instanceof ArrayType) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + + // Check that both sides are integer or pointer types + if (!isIntegerType(varType) && !isPointerType(varType)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + if (!isIntegerType(exprInfo.type) && !isPointerType(exprInfo.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + + // Special case: allow 0 as null pointer + boolean rhsIsZero = isConstantZero(ctx.expression()); + + if (!rhsIsZero && !typesEqual(varType, exprInfo.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx.expression(), ctx.ASSIGN().getSymbol(), varType, exprInfo.type).throwException(); + } + } catch (Project4Exception ex) { + hasSemanticErrors = true; + grader.reportSemanticError(ex); + } } return null; } @Override public Type visitIfStmt(SplcParser.IfStmtContext ctx) { - visitExpression(ctx.expression()); + // Check condition type + try { + ExprInfo condInfo = checkExpression(ctx.expression()); + // Condition must be integer or pointer + if (!isIntegerType(condInfo.type) && !isPointerType(condInfo.type)) { + Project4SemanticError.unexpectedType(ctx.expression(), condInfo.type).throwException(); + } + } catch (Project4Exception ex) { + hasSemanticErrors = true; + grader.reportSemanticError(ex); + } + visit(ctx.statement(0)); if (ctx.statement().size() > 1) { visit(ctx.statement(1)); @@ -783,46 +868,479 @@ public Type visitIfStmt(SplcParser.IfStmtContext ctx) { @Override public Type visitWhileStmt(SplcParser.WhileStmtContext ctx) { - visitExpression(ctx.expression()); + // Check condition type + try { + ExprInfo condInfo = checkExpression(ctx.expression()); + // Condition must be integer or pointer + if (!isIntegerType(condInfo.type) && !isPointerType(condInfo.type)) { + Project4SemanticError.unexpectedType(ctx.expression(), condInfo.type).throwException(); + } + } catch (Project4Exception ex) { + hasSemanticErrors = true; + grader.reportSemanticError(ex); + } + visit(ctx.statement()); return null; } @Override public Type visitReturnStmt(SplcParser.ReturnStmtContext ctx) { - visitExpression(ctx.expression()); + // Check return type + try { + ExprInfo exprInfo = checkExpression(ctx.expression()); + if (currentFunctionReturnType != null && !typesEqual(currentFunctionReturnType, exprInfo.type)) { + Project4SemanticError.unexpectedType(ctx.expression(), exprInfo.type).throwException(); + } + } catch (Project4Exception ex) { + hasSemanticErrors = true; + grader.reportSemanticError(ex); + } return null; } @Override public Type visitExprStmt(SplcParser.ExprStmtContext ctx) { - visitExpression(ctx.expression()); + // Just check the expression + try { + checkExpression(ctx.expression()); + } catch (Project4Exception ex) { + hasSemanticErrors = true; + grader.reportSemanticError(ex); + } return null; } - @Override - public Type visitExpression(SplcParser.ExpressionContext ctx) { - // First, check if this expression has an identifier that needs to be looked up - if (ctx.Identifier() != null) { + // ===== Expression Type Checking ===== + + private ExprInfo checkExpression(SplcParser.ExpressionContext ctx) { + // Identifier (but not member access or function call) + if (ctx.Identifier() != null && ctx.LPAREN() == null && ctx.DOT() == null && ctx.ARROW() == null) { String name = ctx.Identifier().getText(); Symbol symbol = symbolTable.lookupOther(name); if (symbol == null) { grader.reportSemanticError(Project3SemanticError.undeclaredUse(ctx.Identifier())); + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); // Error recovery } + if (symbol.getKind() == Symbol.Kind.FUNCTION || symbol.getKind() == Symbol.Kind.FUNCTION_DECL) { + Project4SemanticError.identifierNotVariable(ctx, name).throwException(); + } + return new ExprInfo(symbol.getType(), true); // Variables are lvalues } - // Visit all sub-expressions - for (int i = 0; i < ctx.getChildCount(); i++) { - if (ctx.getChild(i) instanceof SplcParser.ExpressionContext) { - visitExpression((SplcParser.ExpressionContext) ctx.getChild(i)); + // Number + if (ctx.Number() != null) { + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Parenthesized expression + if (ctx.LPAREN() != null && ctx.expression().size() == 1 && ctx.Identifier() == null) { + ExprInfo inner = checkExpression(ctx.expression(0)); + return new ExprInfo(inner.type, inner.isLvalue); + } + + // Function call: Identifier LPAREN (expression (COMMA expression)*)? RPAREN + if (ctx.Identifier() != null && ctx.LPAREN() != null) { + String funcName = ctx.Identifier().getText(); + Symbol symbol = symbolTable.lookupOther(funcName); + if (symbol == null) { + grader.reportSemanticError(Project3SemanticError.undeclaredUse(ctx.Identifier())); + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + if (symbol.getKind() != Symbol.Kind.FUNCTION && symbol.getKind() != Symbol.Kind.FUNCTION_DECL) { + Project4SemanticError.identifierNotFunction(ctx, funcName).throwException(); + } + + FunctionType funcType = (FunctionType) symbol.getType(); + List paramTypes = funcType.getParameterTypes(); + + // Get actual arguments + List args = new ArrayList<>(); + for (int i = 0; i < ctx.expression().size(); i++) { + args.add(ctx.expression(i)); + } + + // Check parameter count + if (args.size() != paramTypes.size()) { + Project4SemanticError.badParamCount(ctx, paramTypes.size(), args.size()).throwException(); + } + + // Check parameter types + for (int i = 0; i < args.size(); i++) { + ExprInfo argInfo = checkExpression(args.get(i)); + if (!typesEqual(paramTypes.get(i), argInfo.type)) { + Project4SemanticError.badParamType(ctx, i + 1).throwException(); + } + } + + return new ExprInfo(funcType.getReturnType(), false); + } + + // Array access: expression LBRACK expression RBRACK + if (ctx.LBRACK() != null) { + ExprInfo arrayInfo = checkExpression(ctx.expression(0)); + ExprInfo indexInfo = checkExpression(ctx.expression(1)); + + // Index must be integer + if (!isIntegerType(indexInfo.type)) { + Project4SemanticError.unexpectedType(ctx, indexInfo.type).throwException(); + } + + Type elementType; + if (arrayInfo.type instanceof ArrayType) { + // If it's an array, it must be an lvalue + if (!arrayInfo.isLvalue) { + Project4SemanticError.unexpectedType(ctx, arrayInfo.type).throwException(); + } + elementType = ((ArrayType) arrayInfo.type).getElementType(); + } else if (arrayInfo.type instanceof PointerType) { + elementType = ((PointerType) arrayInfo.type).getReferencedType(); + } else { + Project4SemanticError.unexpectedType(ctx, arrayInfo.type).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + return new ExprInfo(elementType, true); // Array access is lvalue + } + + // Struct member access: expression DOT Identifier + if (ctx.DOT() != null) { + ExprInfo structInfo = checkExpression(ctx.expression(0)); + String memberName = ctx.Identifier().getText(); + + if (!(structInfo.type instanceof StructType)) { + Project4SemanticError.unexpectedType(ctx, structInfo.type).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + if (!structInfo.isLvalue) { + Project4SemanticError.lvalueRequired(ctx).throwException(); + } + + // Look up the struct type by tag to get the current (possibly completed) definition + StructType embeddedStructType = (StructType) structInfo.type; + Symbol currentTagSymbol = symbolTable.lookupTag(embeddedStructType.getTag()); + StructType structType; + if (currentTagSymbol != null && currentTagSymbol.getType() instanceof StructType) { + structType = (StructType) currentTagSymbol.getType(); + } else { + structType = embeddedStructType; + } + + if (!structType.isComplete()) { + Project4SemanticError.unexpectedType(ctx, structType).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + // Find member + Type memberType = null; + for (StructType.Member member : structType.getMembers()) { + if (member.name.equals(memberName)) { + memberType = member.type; + break; + } + } + + if (memberType == null) { + Project4SemanticError.badMember(ctx, structType, memberName).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); } + + return new ExprInfo(memberType, true); // Member access is lvalue } + // Struct pointer access: expression ARROW Identifier + if (ctx.ARROW() != null) { + ExprInfo ptrInfo = checkExpression(ctx.expression(0)); + String memberName = ctx.Identifier().getText(); + + if (!(ptrInfo.type instanceof PointerType)) { + Project4SemanticError.unexpectedType(ctx, ptrInfo.type).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + Type referencedType = ((PointerType) ptrInfo.type).getReferencedType(); + if (!(referencedType instanceof StructType)) { + Project4SemanticError.unexpectedType(ctx, ptrInfo.type).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + // Look up the struct type by tag to get the current (possibly completed) definition + StructType embeddedStructType = (StructType) referencedType; + Symbol currentTagSymbol = symbolTable.lookupTag(embeddedStructType.getTag()); + StructType structType; + if (currentTagSymbol != null && currentTagSymbol.getType() instanceof StructType) { + structType = (StructType) currentTagSymbol.getType(); + } else { + structType = embeddedStructType; + } + + if (!structType.isComplete()) { + Project4SemanticError.unexpectedType(ctx, ptrInfo.type).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + // Find member + Type memberType = null; + for (StructType.Member member : structType.getMembers()) { + if (member.name.equals(memberName)) { + memberType = member.type; + break; + } + } + + if (memberType == null) { + Project4SemanticError.badMember(ctx, structType, memberName).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + return new ExprInfo(memberType, true); // Member access is lvalue + } + + // Postfix increment/decrement: expression INC/DEC + if (ctx.INC() != null || ctx.DEC() != null) { + if (ctx.expression().size() == 1) { + ExprInfo operandInfo = checkExpression(ctx.expression(0)); + + if (!operandInfo.isLvalue) { + Project4SemanticError.lvalueRequired(ctx).throwException(); + } + + if (!isIntegerType(operandInfo.type) && !isPointerType(operandInfo.type)) { + Project4SemanticError.unexpectedType(ctx, operandInfo.type).throwException(); + } + + return new ExprInfo(operandInfo.type, false); // Result is rvalue + } + } + + // Prefix unary operators + if (ctx.expression().size() == 1) { + // Prefix increment/decrement + if ((ctx.INC() != null || ctx.DEC() != null) && ctx.expression().size() == 1) { + ExprInfo operandInfo = checkExpression(ctx.expression(0)); + + if (!operandInfo.isLvalue) { + Project4SemanticError.lvalueRequired(ctx).throwException(); + } + + if (!isIntegerType(operandInfo.type) && !isPointerType(operandInfo.type)) { + Project4SemanticError.unexpectedType(ctx, operandInfo.type).throwException(); + } + + return new ExprInfo(operandInfo.type, false); // Result is rvalue + } + + // Unary plus/minus + if (ctx.PLUS() != null || ctx.MINUS() != null) { + ExprInfo operandInfo = checkExpression(ctx.expression(0)); + + if (!isIntegerType(operandInfo.type)) { + Project4SemanticError.unexpectedType(ctx, operandInfo.type).throwException(); + } + + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Logical NOT + if (ctx.NOT() != null) { + ExprInfo operandInfo = checkExpression(ctx.expression(0)); + + if (!isIntegerType(operandInfo.type) && !isPointerType(operandInfo.type)) { + Project4SemanticError.unexpectedType(ctx, operandInfo.type).throwException(); + } + + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Dereference: STAR expression + if (ctx.STAR() != null) { + ExprInfo operandInfo = checkExpression(ctx.expression(0)); + + if (!(operandInfo.type instanceof PointerType)) { + Project4SemanticError.unexpectedType(ctx, operandInfo.type).throwException(); + return new ExprInfo(new BasicType(BasicType.Kind.INT), true); + } + + Type referencedType = ((PointerType) operandInfo.type).getReferencedType(); + return new ExprInfo(referencedType, true); // Dereference is lvalue + } + + // Address-of: AMP expression + if (ctx.AMP() != null) { + ExprInfo operandInfo = checkExpression(ctx.expression(0)); + + if (!operandInfo.isLvalue) { + Project4SemanticError.lvalueRequired(ctx).throwException(); + } + + Type ptrType = new PointerType(operandInfo.type); + return new ExprInfo(ptrType, false); // Address-of is rvalue + } + } + + // Binary operators + if (ctx.expression().size() == 2) { + ExprInfo lhs = checkExpression(ctx.expression(0)); + ExprInfo rhs = checkExpression(ctx.expression(1)); + + // Arithmetic: *, /, % + if (ctx.STAR() != null || ctx.DIV() != null || ctx.MOD() != null) { + if (!isIntegerType(lhs.type)) { + Project4SemanticError.unexpectedType(ctx, lhs.type).throwException(); + } + if (!isIntegerType(rhs.type)) { + Project4SemanticError.unexpectedType(ctx, rhs.type).throwException(); + } + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Addition/Subtraction + if (ctx.PLUS() != null || ctx.MINUS() != null) { + Token op = ctx.PLUS() != null ? ctx.PLUS().getSymbol() : ctx.MINUS().getSymbol(); + + // Both integer + if (isIntegerType(lhs.type) && isIntegerType(rhs.type)) { + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Pointer + integer or integer + pointer (for addition only) + if (ctx.PLUS() != null) { + if (isPointerType(lhs.type) && isIntegerType(rhs.type)) { + return new ExprInfo(lhs.type, false); + } + if (isIntegerType(lhs.type) && isPointerType(rhs.type)) { + return new ExprInfo(rhs.type, false); + } + } + + // Pointer - integer + if (ctx.MINUS() != null) { + if (isPointerType(lhs.type) && isIntegerType(rhs.type)) { + return new ExprInfo(lhs.type, false); + } + // Pointer - pointer + if (isPointerType(lhs.type) && isPointerType(rhs.type)) { + if (!typesEqual(lhs.type, rhs.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, op, lhs.type, rhs.type).throwException(); + } + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + } + + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, op, lhs.type, rhs.type).throwException(); + } + + // Comparison: <, <=, >, >= + if (ctx.LT() != null || ctx.LE() != null || ctx.GT() != null || ctx.GE() != null) { + if (!isIntegerType(lhs.type)) { + Project4SemanticError.unexpectedType(ctx, lhs.type).throwException(); + } + if (!isIntegerType(rhs.type)) { + Project4SemanticError.unexpectedType(ctx, rhs.type).throwException(); + } + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Equality: ==, != + if (ctx.EQ() != null || ctx.NEQ() != null) { + Token op = ctx.EQ() != null ? ctx.EQ().getSymbol() : ctx.NEQ().getSymbol(); + + // Check if both are integers or pointers + if (!isIntegerType(lhs.type) && !isPointerType(lhs.type)) { + Project4SemanticError.unexpectedType(ctx, lhs.type).throwException(); + } + if (!isIntegerType(rhs.type) && !isPointerType(rhs.type)) { + Project4SemanticError.unexpectedType(ctx, rhs.type).throwException(); + } + + // Special case: allow 0 as null pointer + boolean lhsIsZero = isConstantZero(ctx.expression(0)); + boolean rhsIsZero = isConstantZero(ctx.expression(1)); + + if (!lhsIsZero && !rhsIsZero && !typesEqual(lhs.type, rhs.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, op, lhs.type, rhs.type).throwException(); + } + + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Logical: &&, || + if (ctx.AND() != null || ctx.OR() != null) { + if (!isIntegerType(lhs.type) && !isPointerType(lhs.type)) { + Project4SemanticError.unexpectedType(ctx, lhs.type).throwException(); + } + if (!isIntegerType(rhs.type) && !isPointerType(rhs.type)) { + Project4SemanticError.unexpectedType(ctx, rhs.type).throwException(); + } + return new ExprInfo(new BasicType(BasicType.Kind.INT), false); + } + + // Assignment: = + if (ctx.ASSIGN() != null) { + if (!lhs.isLvalue) { + Project4SemanticError.lvalueRequired(ctx).throwException(); + } + + // Check if lhs or rhs is array type - arrays cannot be assigned + if (lhs.type instanceof ArrayType || rhs.type instanceof ArrayType) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, ctx.ASSIGN().getSymbol(), lhs.type, rhs.type).throwException(); + } + + if (!isIntegerType(lhs.type) && !isPointerType(lhs.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, ctx.ASSIGN().getSymbol(), lhs.type, rhs.type).throwException(); + } + if (!isIntegerType(rhs.type) && !isPointerType(rhs.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, ctx.ASSIGN().getSymbol(), lhs.type, rhs.type).throwException(); + } + + // Special case: allow 0 as null pointer + boolean rhsIsZero = isConstantZero(ctx.expression(1)); + + if (!rhsIsZero && !typesEqual(lhs.type, rhs.type)) { + Project4SemanticError.unmatchedTypeForBinaryOP(ctx, ctx.ASSIGN().getSymbol(), lhs.type, rhs.type).throwException(); + } + + return new ExprInfo(rhs.type, false); // Assignment returns rvalue + } + } + + // Should not reach here - all expression cases should be handled above + throw new RuntimeException("Unexpected expression structure in checkExpression"); + } + + @Override + public Type visitExpression(SplcParser.ExpressionContext ctx) { + // This should not be used in Project 4, but keep for compatibility return null; } // Helper methods + private boolean isConstantZero(SplcParser.ExpressionContext ctx) { + // Check if expression is directly 0 (optionally wrapped in parentheses) + if (ctx.Number() != null && ctx.Number().getText().equals("0")) { + return true; + } + // Check if it's parenthesized zero + if (ctx.LPAREN() != null && ctx.expression().size() == 1 && ctx.Identifier() == null) { + return isConstantZero(ctx.expression(0)); + } + return false; + } + + private boolean isIntegerType(Type type) { + return type instanceof BasicType && ((BasicType) type).getKind() == BasicType.Kind.INT; + } + + private boolean isPointerType(Type type) { + return type instanceof PointerType; + } + + private boolean typesEqual(Type t1, Type t2) { + return t1.equals(t2); + } + private String extractIdentifierFromVarDec(SplcParser.VarDecContext ctx) { if (ctx.Identifier() != null) { return ctx.Identifier().getText();