summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Compiler/CCompilerVisitor.cs34
-rw-r--r--Compiler/CGrammar.g48
-rw-r--r--Compiler/gen/CGrammar.interp3
-rw-r--r--Compiler/gen/CGrammarBaseVisitor.cs21
-rw-r--r--Compiler/gen/CGrammarParser.cs581
-rw-r--r--Compiler/gen/CGrammarVisitor.cs13
-rw-r--r--ROMs/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--ROMs/hello_c.asm14
-rw-r--r--ROMs/hello_c.c4
9 files changed, 328 insertions, 350 deletions
diff --git a/Compiler/CCompilerVisitor.cs b/Compiler/CCompilerVisitor.cs
index aa08147..fb7df0f 100644
--- a/Compiler/CCompilerVisitor.cs
+++ b/Compiler/CCompilerVisitor.cs
@@ -546,23 +546,33 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
{
string cond = this.Visit(context.expression())
?? throw new CompilerException("If condition was not an expression");
-
- // Else branch is first since it saves us from having to perform a NOT operation.
- // If cond, jump to then, else fall through to else, then jump to end
-
- string thenBranch = this.GenerateBranchLabel("then");
string endBranch = this.GenerateBranchLabel("end");
this.Instruction($"bz {cond}", "check if condition");
- this.Instruction($"jmp {thenBranch}");
-
- this.GeneratedComment("if failed");
+
if (context.@else != null)
- this.Visit(context.@else);
- this.Instruction($"jmp {endBranch}");
+ {
+ // Else branch is first since it saves us from having to perform a NOT operation.
+ // If cond, jump to then, else fall through to else, then jump to end
+
+ string thenBranch = this.GenerateBranchLabel("then");
+
+ this.Instruction($"jmp {thenBranch}");
+
+ this.GeneratedComment("if failed");
+ if (context.@else != null)
+ this.Visit(context.@else);
+ this.Instruction($"jmp {endBranch}");
- this.Label(thenBranch, "if succeeded");
- this.Visit(context.then);
+ this.Label(thenBranch, "if succeeded");
+ this.Visit(context.then);
+ }
+ else
+ {
+ this.Instruction($"not");
+ this.Instruction($"jmp {endBranch}", "if succeeds, continue, else jump to end");
+ this.Visit(context.then);
+ }
this.Label(endBranch);
diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4
index aec4694..484cc90 100644
--- a/Compiler/CGrammar.g4
+++ b/Compiler/CGrammar.g4
@@ -14,11 +14,6 @@ function
: 'int' name=ID '(' ')' block
;
-body
- : statement
- | block
- ;
-
block
: '{' block_item* '}'
;
@@ -30,8 +25,9 @@ block_item
statement
: 'return' expression ';' #returnStatement
- | 'if' '(' expression ')' then=body ('else' else=body) #ifStatement
+ | 'if' '(' expression ')' then=statement ('else' else=statement)? #ifStatement
| expression #expressionStatement
+ | block #blockStatement
;
diff --git a/Compiler/gen/CGrammar.interp b/Compiler/gen/CGrammar.interp
index 7d5c6e5..a1df3d4 100644
--- a/Compiler/gen/CGrammar.interp
+++ b/Compiler/gen/CGrammar.interp
@@ -105,7 +105,6 @@ COMMENT
rule names:
program
function
-body
block
block_item
statement
@@ -116,4 +115,4 @@ target
atn:
-[4, 1, 49, 210, 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, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 3, 2, 32, 8, 2, 1, 3, 1, 3, 5, 3, 36, 8, 3, 10, 3, 12, 3, 39, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 3, 4, 45, 8, 4, 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, 60, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 66, 8, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1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 0, 0, 24, 25, 5, 46, 0, 0, 25, 26, 5, 2, 0, 0, 26, 27, 5, 3, 0, 0, 27, 28, 3, 6, 3, 0, 28, 3, 1, 0, 0, 0, 29, 32, 3, 10, 5, 0, 30, 32, 3, 6, 3, 0, 31, 29, 1, 0, 0, 0, 31, 30, 1, 0, 0, 0, 32, 5, 1, 0, 0, 0, 33, 37, 5, 4, 0, 0, 34, 36, 3, 8, 4, 0, 35, 34, 1, 0, 0, 0, 36, 39, 1, 0, 0, 0, 37, 35, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 37, 1, 0, 0, 0, 40, 41, 5, 5, 0, 0, 41, 7, 1, 0, 0, 0, 42, 45, 3, 10, 5, 0, 43, 45, 3, 12, 6, 0, 44, 42, 1, 0, 0, 0, 44, 43, 1, 0, 0, 0, 45, 9, 1, 0, 0, 0, 46, 47, 5, 6, 0, 0, 47, 48, 3, 14, 7, 0, 48, 49, 5, 7, 0, 0, 49, 60, 1, 0, 0, 0, 50, 51, 5, 8, 0, 0, 51, 52, 5, 2, 0, 0, 52, 53, 3, 14, 7, 0, 53, 54, 5, 3, 0, 0, 54, 55, 3, 4, 2, 0, 55, 56, 5, 9, 0, 0, 56, 57, 3, 4, 2, 0, 57, 60, 1, 0, 0, 0, 58, 60, 3, 14, 7, 0, 59, 46, 1, 0, 0, 0, 59, 50, 1, 0, 0, 0, 59, 58, 1, 0, 0, 0, 60, 11, 1, 0, 0, 0, 61, 62, 5, 1, 0, 0, 62, 65, 5, 46, 0, 0, 63, 64, 5, 10, 0, 0, 64, 66, 3, 14, 7, 0, 65, 63, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 68, 5, 7, 0, 0, 68, 13, 1, 0, 0, 0, 69, 70, 6, 7, -1, 0, 70, 71, 5, 2, 0, 0, 71, 72, 3, 14, 7, 0, 72, 73, 5, 3, 0, 0, 73, 136, 1, 0, 0, 0, 74, 136, 3, 16, 8, 0, 75, 76, 3, 18, 9, 0, 76, 77, 5, 10, 0, 0, 77, 78, 3, 14, 7, 0, 78, 79, 5, 7, 0, 0, 79, 136, 1, 0, 0, 0, 80, 136, 5, 46, 0, 0, 81, 82, 5, 11, 0, 0, 82, 136, 3, 14, 7, 36, 83, 84, 5, 12, 0, 0, 84, 136, 3, 14, 7, 35, 85, 86, 5, 13, 0, 0, 86, 136, 3, 18, 9, 0, 87, 88, 5, 14, 0, 0, 88, 136, 3, 18, 9, 0, 89, 90, 3, 18, 9, 0, 90, 91, 5, 13, 0, 0, 91, 136, 1, 0, 0, 0, 92, 93, 3, 18, 9, 0, 93, 94, 5, 14, 0, 0, 94, 136, 1, 0, 0, 0, 95, 96, 3, 18, 9, 0, 96, 97, 5, 33, 0, 0, 97, 98, 3, 14, 7, 12, 98, 136, 1, 0, 0, 0, 99, 100, 3, 18, 9, 0, 100, 101, 5, 34, 0, 0, 101, 102, 3, 14, 7, 11, 102, 136, 1, 0, 0, 0, 103, 104, 3, 18, 9, 0, 104, 105, 5, 35, 0, 0, 105, 106, 3, 14, 7, 10, 106, 136, 1, 0, 0, 0, 107, 108, 3, 18, 9, 0, 108, 109, 5, 36, 0, 0, 109, 110, 3, 14, 7, 9, 110, 136, 1, 0, 0, 0, 111, 112, 3, 18, 9, 0, 112, 113, 5, 37, 0, 0, 113, 114, 3, 14, 7, 8, 114, 136, 1, 0, 0, 0, 115, 116, 3, 18, 9, 0, 116, 117, 5, 38, 0, 0, 117, 118, 3, 14, 7, 7, 118, 136, 1, 0, 0, 0, 119, 120, 3, 18, 9, 0, 120, 121, 5, 39, 0, 0, 121, 122, 3, 14, 7, 6, 122, 136, 1, 0, 0, 0, 123, 124, 3, 18, 9, 0, 124, 125, 5, 40, 0, 0, 125, 126, 3, 14, 7, 5, 126, 136, 1, 0, 0, 0, 127, 128, 3, 18, 9, 0, 128, 129, 5, 41, 0, 0, 129, 130, 3, 14, 7, 4, 130, 136, 1, 0, 0, 0, 131, 132, 3, 18, 9, 0, 132, 133, 5, 42, 0, 0, 133, 134, 3, 14, 7, 3, 134, 136, 1, 0, 0, 0, 135, 69, 1, 0, 0, 0, 135, 74, 1, 0, 0, 0, 135, 75, 1, 0, 0, 0, 135, 80, 1, 0, 0, 0, 135, 81, 1, 0, 0, 0, 135, 83, 1, 0, 0, 0, 135, 85, 1, 0, 0, 0, 135, 87, 1, 0, 0, 0, 135, 89, 1, 0, 0, 0, 135, 92, 1, 0, 0, 0, 135, 95, 1, 0, 0, 0, 135, 99, 1, 0, 0, 0, 135, 103, 1, 0, 0, 0, 135, 107, 1, 0, 0, 0, 135, 111, 1, 0, 0, 0, 135, 115, 1, 0, 0, 0, 135, 119, 1, 0, 0, 0, 135, 123, 1, 0, 0, 0, 135, 127, 1, 0, 0, 0, 135, 131, 1, 0, 0, 0, 136, 202, 1, 0, 0, 0, 137, 138, 10, 30, 0, 0, 138, 139, 5, 15, 0, 0, 139, 201, 3, 14, 7, 31, 140, 141, 10, 29, 0, 0, 141, 142, 5, 16, 0, 0, 142, 201, 3, 14, 7, 30, 143, 144, 10, 28, 0, 0, 144, 145, 5, 17, 0, 0, 145, 201, 3, 14, 7, 29, 146, 147, 10, 27, 0, 0, 147, 148, 5, 18, 0, 0, 148, 201, 3, 14, 7, 28, 149, 150, 10, 26, 0, 0, 150, 151, 5, 19, 0, 0, 151, 201, 3, 14, 7, 27, 152, 153, 10, 25, 0, 0, 153, 154, 5, 20, 0, 0, 154, 201, 3, 14, 7, 26, 155, 156, 10, 24, 0, 0, 156, 157, 5, 21, 0, 0, 157, 201, 3, 14, 7, 25, 158, 159, 10, 23, 0, 0, 159, 160, 5, 22, 0, 0, 160, 201, 3, 14, 7, 24, 161, 162, 10, 22, 0, 0, 162, 163, 5, 23, 0, 0, 163, 201, 3, 14, 7, 23, 164, 165, 10, 21, 0, 0, 165, 166, 5, 24, 0, 0, 166, 201, 3, 14, 7, 22, 167, 168, 10, 20, 0, 0, 168, 169, 5, 25, 0, 0, 169, 201, 3, 14, 7, 21, 170, 171, 10, 19, 0, 0, 171, 172, 5, 26, 0, 0, 172, 201, 3, 14, 7, 20, 173, 174, 10, 18, 0, 0, 174, 175, 5, 27, 0, 0, 175, 201, 3, 14, 7, 19, 176, 177, 10, 17, 0, 0, 177, 178, 5, 28, 0, 0, 178, 201, 3, 14, 7, 18, 179, 180, 10, 16, 0, 0, 180, 181, 5, 29, 0, 0, 181, 201, 3, 14, 7, 17, 182, 183, 10, 15, 0, 0, 183, 184, 5, 30, 0, 0, 184, 201, 3, 14, 7, 16, 185, 186, 10, 14, 0, 0, 186, 187, 5, 31, 0, 0, 187, 201, 3, 14, 7, 15, 188, 189, 10, 13, 0, 0, 189, 190, 5, 32, 0, 0, 190, 201, 3, 14, 7, 14, 191, 192, 10, 2, 0, 0, 192, 193, 5, 43, 0, 0, 193, 201, 3, 14, 7, 3, 194, 195, 10, 1, 0, 0, 195, 196, 5, 44, 0, 0, 196, 197, 3, 14, 7, 0, 197, 198, 5, 45, 0, 0, 198, 199, 3, 14, 7, 2, 199, 201, 1, 0, 0, 0, 200, 137, 1, 0, 0, 0, 200, 140, 1, 0, 0, 0, 200, 143, 1, 0, 0, 0, 200, 146, 1, 0, 0, 0, 200, 149, 1, 0, 0, 0, 200, 152, 1, 0, 0, 0, 200, 155, 1, 0, 0, 0, 200, 158, 1, 0, 0, 0, 200, 161, 1, 0, 0, 0, 200, 164, 1, 0, 0, 0, 200, 167, 1, 0, 0, 0, 200, 170, 1, 0, 0, 0, 200, 173, 1, 0, 0, 0, 200, 176, 1, 0, 0, 0, 200, 179, 1, 0, 0, 0, 200, 182, 1, 0, 0, 0, 200, 185, 1, 0, 0, 0, 200, 188, 1, 0, 0, 0, 200, 191, 1, 0, 0, 0, 200, 194, 1, 0, 0, 0, 201, 204, 1, 0, 0, 0, 202, 200, 1, 0, 0, 0, 202, 203, 1, 0, 0, 0, 203, 15, 1, 0, 0, 0, 204, 202, 1, 0, 0, 0, 205, 206, 5, 47, 0, 0, 206, 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5, 7, 0, 0, 43, 56, 1, 0, 0, 0, 44, 45, 5, 8, 0, 0, 45, 46, 5, 2, 0, 0, 46, 47, 3, 12, 6, 0, 47, 48, 5, 3, 0, 0, 48, 51, 3, 8, 4, 0, 49, 50, 5, 9, 0, 0, 50, 52, 3, 8, 4, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 56, 1, 0, 0, 0, 53, 56, 3, 12, 6, 0, 54, 56, 3, 4, 2, 0, 55, 40, 1, 0, 0, 0, 55, 44, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 54, 1, 0, 0, 0, 56, 9, 1, 0, 0, 0, 57, 58, 5, 1, 0, 0, 58, 61, 5, 46, 0, 0, 59, 60, 5, 10, 0, 0, 60, 62, 3, 12, 6, 0, 61, 59, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 64, 5, 7, 0, 0, 64, 11, 1, 0, 0, 0, 65, 66, 6, 6, -1, 0, 66, 67, 5, 2, 0, 0, 67, 68, 3, 12, 6, 0, 68, 69, 5, 3, 0, 0, 69, 132, 1, 0, 0, 0, 70, 132, 3, 14, 7, 0, 71, 72, 3, 16, 8, 0, 72, 73, 5, 10, 0, 0, 73, 74, 3, 12, 6, 0, 74, 75, 5, 7, 0, 0, 75, 132, 1, 0, 0, 0, 76, 132, 5, 46, 0, 0, 77, 78, 5, 11, 0, 0, 78, 132, 3, 12, 6, 36, 79, 80, 5, 12, 0, 0, 80, 132, 3, 12, 6, 35, 81, 82, 5, 13, 0, 0, 82, 132, 3, 16, 8, 0, 83, 84, 5, 14, 0, 0, 84, 132, 3, 16, 8, 0, 85, 86, 3, 16, 8, 0, 86, 87, 5, 13, 0, 0, 87, 132, 1, 0, 0, 0, 88, 89, 3, 16, 8, 0, 89, 90, 5, 14, 0, 0, 90, 132, 1, 0, 0, 0, 91, 92, 3, 16, 8, 0, 92, 93, 5, 33, 0, 0, 93, 94, 3, 12, 6, 12, 94, 132, 1, 0, 0, 0, 95, 96, 3, 16, 8, 0, 96, 97, 5, 34, 0, 0, 97, 98, 3, 12, 6, 11, 98, 132, 1, 0, 0, 0, 99, 100, 3, 16, 8, 0, 100, 101, 5, 35, 0, 0, 101, 102, 3, 12, 6, 10, 102, 132, 1, 0, 0, 0, 103, 104, 3, 16, 8, 0, 104, 105, 5, 36, 0, 0, 105, 106, 3, 12, 6, 9, 106, 132, 1, 0, 0, 0, 107, 108, 3, 16, 8, 0, 108, 109, 5, 37, 0, 0, 109, 110, 3, 12, 6, 8, 110, 132, 1, 0, 0, 0, 111, 112, 3, 16, 8, 0, 112, 113, 5, 38, 0, 0, 113, 114, 3, 12, 6, 7, 114, 132, 1, 0, 0, 0, 115, 116, 3, 16, 8, 0, 116, 117, 5, 39, 0, 0, 117, 118, 3, 12, 6, 6, 118, 132, 1, 0, 0, 0, 119, 120, 3, 16, 8, 0, 120, 121, 5, 40, 0, 0, 121, 122, 3, 12, 6, 5, 122, 132, 1, 0, 0, 0, 123, 124, 3, 16, 8, 0, 124, 125, 5, 41, 0, 0, 125, 126, 3, 12, 6, 4, 126, 132, 1, 0, 0, 0, 127, 128, 3, 16, 8, 0, 128, 129, 5, 42, 0, 0, 129, 130, 3, 12, 6, 3, 130, 132, 1, 0, 0, 0, 131, 65, 1, 0, 0, 0, 131, 70, 1, 0, 0, 0, 131, 71, 1, 0, 0, 0, 131, 76, 1, 0, 0, 0, 131, 77, 1, 0, 0, 0, 131, 79, 1, 0, 0, 0, 131, 81, 1, 0, 0, 0, 131, 83, 1, 0, 0, 0, 131, 85, 1, 0, 0, 0, 131, 88, 1, 0, 0, 0, 131, 91, 1, 0, 0, 0, 131, 95, 1, 0, 0, 0, 131, 99, 1, 0, 0, 0, 131, 103, 1, 0, 0, 0, 131, 107, 1, 0, 0, 0, 131, 111, 1, 0, 0, 0, 131, 115, 1, 0, 0, 0, 131, 119, 1, 0, 0, 0, 131, 123, 1, 0, 0, 0, 131, 127, 1, 0, 0, 0, 132, 198, 1, 0, 0, 0, 133, 134, 10, 30, 0, 0, 134, 135, 5, 15, 0, 0, 135, 197, 3, 12, 6, 31, 136, 137, 10, 29, 0, 0, 137, 138, 5, 16, 0, 0, 138, 197, 3, 12, 6, 30, 139, 140, 10, 28, 0, 0, 140, 141, 5, 17, 0, 0, 141, 197, 3, 12, 6, 29, 142, 143, 10, 27, 0, 0, 143, 144, 5, 18, 0, 0, 144, 197, 3, 12, 6, 28, 145, 146, 10, 26, 0, 0, 146, 147, 5, 19, 0, 0, 147, 197, 3, 12, 6, 27, 148, 149, 10, 25, 0, 0, 149, 150, 5, 20, 0, 0, 150, 197, 3, 12, 6, 26, 151, 152, 10, 24, 0, 0, 152, 153, 5, 21, 0, 0, 153, 197, 3, 12, 6, 25, 154, 155, 10, 23, 0, 0, 155, 156, 5, 22, 0, 0, 156, 197, 3, 12, 6, 24, 157, 158, 10, 22, 0, 0, 158, 159, 5, 23, 0, 0, 159, 197, 3, 12, 6, 23, 160, 161, 10, 21, 0, 0, 161, 162, 5, 24, 0, 0, 162, 197, 3, 12, 6, 22, 163, 164, 10, 20, 0, 0, 164, 165, 5, 25, 0, 0, 165, 197, 3, 12, 6, 21, 166, 167, 10, 19, 0, 0, 167, 168, 5, 26, 0, 0, 168, 197, 3, 12, 6, 20, 169, 170, 10, 18, 0, 0, 170, 171, 5, 27, 0, 0, 171, 197, 3, 12, 6, 19, 172, 173, 10, 17, 0, 0, 173, 174, 5, 28, 0, 0, 174, 197, 3, 12, 6, 18, 175, 176, 10, 16, 0, 0, 176, 177, 5, 29, 0, 0, 177, 197, 3, 12, 6, 17, 178, 179, 10, 15, 0, 0, 179, 180, 5, 30, 0, 0, 180, 197, 3, 12, 6, 16, 181, 182, 10, 14, 0, 0, 182, 183, 5, 31, 0, 0, 183, 197, 3, 12, 6, 15, 184, 185, 10, 13, 0, 0, 185, 186, 5, 32, 0, 0, 186, 197, 3, 12, 6, 14, 187, 188, 10, 2, 0, 0, 188, 189, 5, 43, 0, 0, 189, 197, 3, 12, 6, 3, 190, 191, 10, 1, 0, 0, 191, 192, 5, 44, 0, 0, 192, 193, 3, 12, 6, 0, 193, 194, 5, 45, 0, 0, 194, 195, 3, 12, 6, 2, 195, 197, 1, 0, 0, 0, 196, 133, 1, 0, 0, 0, 196, 136, 1, 0, 0, 0, 196, 139, 1, 0, 0, 0, 196, 142, 1, 0, 0, 0, 196, 145, 1, 0, 0, 0, 196, 148, 1, 0, 0, 0, 196, 151, 1, 0, 0, 0, 196, 154, 1, 0, 0, 0, 196, 157, 1, 0, 0, 0, 196, 160, 1, 0, 0, 0, 196, 163, 1, 0, 0, 0, 196, 166, 1, 0, 0, 0, 196, 169, 1, 0, 0, 0, 196, 172, 1, 0, 0, 0, 196, 175, 1, 0, 0, 0, 196, 178, 1, 0, 0, 0, 196, 181, 1, 0, 0, 0, 196, 184, 1, 0, 0, 0, 196, 187, 1, 0, 0, 0, 196, 190, 1, 0, 0, 0, 197, 200, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 198, 199, 1, 0, 0, 0, 199, 13, 1, 0, 0, 0, 200, 198, 1, 0, 0, 0, 201, 202, 5, 47, 0, 0, 202, 15, 1, 0, 0, 0, 203, 204, 5, 46, 0, 0, 204, 17, 1, 0, 0, 0, 8, 31, 38, 51, 55, 61, 131, 196, 198] \ No newline at end of file
diff --git a/Compiler/gen/CGrammarBaseVisitor.cs b/Compiler/gen/CGrammarBaseVisitor.cs
index 704cdd1..9964929 100644
--- a/Compiler/gen/CGrammarBaseVisitor.cs
+++ b/Compiler/gen/CGrammarBaseVisitor.cs
@@ -55,16 +55,6 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// <return>The visitor result.</return>
public virtual Result VisitFunction([NotNull] CGrammarParser.FunctionContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by <see cref="CGrammarParser.body"/>.
- /// <para>
- /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
- /// on <paramref name="context"/>.
- /// </para>
- /// </summary>
- /// <param name="context">The parse tree.</param>
- /// <return>The visitor result.</return>
- public virtual Result VisitBody([NotNull] CGrammarParser.BodyContext context) { return VisitChildren(context); }
- /// <summary>
/// Visit a parse tree produced by <see cref="CGrammarParser.block"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -118,6 +108,17 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// <return>The visitor result.</return>
public virtual Result VisitExpressionStatement([NotNull] CGrammarParser.ExpressionStatementContext context) { return VisitChildren(context); }
/// <summary>
+ /// Visit a parse tree produced by the <c>blockStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// <para>
+ /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
+ /// on <paramref name="context"/>.
+ /// </para>
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ public virtual Result VisitBlockStatement([NotNull] CGrammarParser.BlockStatementContext context) { return VisitChildren(context); }
+ /// <summary>
/// Visit a parse tree produced by the <c>variableDeclaration</c>
/// labeled alternative in <see cref="CGrammarParser.declaration"/>.
/// <para>
diff --git a/Compiler/gen/CGrammarParser.cs b/Compiler/gen/CGrammarParser.cs
index f0db2f0..d858fbe 100644
--- a/Compiler/gen/CGrammarParser.cs
+++ b/Compiler/gen/CGrammarParser.cs
@@ -44,11 +44,11 @@ public partial class CGrammarParser : Parser {
T__38=39, T__39=40, T__40=41, T__41=42, T__42=43, T__43=44, T__44=45,
ID=46, INT=47, WS=48, COMMENT=49;
public const int
- RULE_program = 0, RULE_function = 1, RULE_body = 2, RULE_block = 3, RULE_block_item = 4,
- RULE_statement = 5, RULE_declaration = 6, RULE_expression = 7, RULE_constant = 8,
- RULE_target = 9;
+ RULE_program = 0, RULE_function = 1, RULE_block = 2, RULE_block_item = 3,
+ RULE_statement = 4, RULE_declaration = 5, RULE_expression = 6, RULE_constant = 7,
+ RULE_target = 8;
public static readonly string[] ruleNames = {
- "program", "function", "body", "block", "block_item", "statement", "declaration",
+ "program", "function", "block", "block_item", "statement", "declaration",
"expression", "constant", "target"
};
@@ -123,9 +123,9 @@ public partial class CGrammarParser : Parser {
try {
EnterOuterAlt(_localctx, 1);
{
- State = 20;
+ State = 18;
function();
- State = 21;
+ State = 19;
Match(Eof);
}
}
@@ -166,15 +166,15 @@ public partial class CGrammarParser : Parser {
try {
EnterOuterAlt(_localctx, 1);
{
- State = 23;
+ State = 21;
Match(T__0);
- State = 24;
+ State = 22;
_localctx.name = Match(ID);
- State = 25;
+ State = 23;
Match(T__1);
- State = 26;
+ State = 24;
Match(T__2);
- State = 27;
+ State = 25;
block();
}
}
@@ -189,71 +189,6 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class BodyContext : ParserRuleContext {
- [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() {
- return GetRuleContext<StatementContext>(0);
- }
- [System.Diagnostics.DebuggerNonUserCode] public BlockContext block() {
- return GetRuleContext<BlockContext>(0);
- }
- public BodyContext(ParserRuleContext parent, int invokingState)
- : base(parent, invokingState)
- {
- }
- public override int RuleIndex { get { return RULE_body; } }
- [System.Diagnostics.DebuggerNonUserCode]
- public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
- ICGrammarVisitor<TResult> typedVisitor = visitor as ICGrammarVisitor<TResult>;
- if (typedVisitor != null) return typedVisitor.VisitBody(this);
- else return visitor.VisitChildren(this);
- }
- }
-
- [RuleVersion(0)]
- public BodyContext body() {
- BodyContext _localctx = new BodyContext(Context, State);
- EnterRule(_localctx, 4, RULE_body);
- try {
- State = 31;
- ErrorHandler.Sync(this);
- switch (TokenStream.LA(1)) {
- case T__1:
- case T__5:
- case T__7:
- case T__10:
- case T__11:
- case T__12:
- case T__13:
- case ID:
- case INT:
- EnterOuterAlt(_localctx, 1);
- {
- State = 29;
- statement();
- }
- break;
- case T__3:
- EnterOuterAlt(_localctx, 2);
- {
- State = 30;
- block();
- }
- break;
- default:
- throw new NoViableAltException(this);
- }
- }
- catch (RecognitionException re) {
- _localctx.exception = re;
- ErrorHandler.ReportError(this, re);
- ErrorHandler.Recover(this, re);
- }
- finally {
- ExitRule();
- }
- return _localctx;
- }
-
public partial class BlockContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public Block_itemContext[] block_item() {
return GetRuleContexts<Block_itemContext>();
@@ -277,28 +212,28 @@ public partial class CGrammarParser : Parser {
[RuleVersion(0)]
public BlockContext block() {
BlockContext _localctx = new BlockContext(Context, State);
- EnterRule(_localctx, 6, RULE_block);
+ EnterRule(_localctx, 4, RULE_block);
int _la;
try {
EnterOuterAlt(_localctx, 1);
{
- State = 33;
+ State = 27;
Match(T__3);
- State = 37;
+ State = 31;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
- while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 211106232564038L) != 0)) {
+ while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 211106232564054L) != 0)) {
{
{
- State = 34;
+ State = 28;
block_item();
}
}
- State = 39;
+ State = 33;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
}
- State = 40;
+ State = 34;
Match(T__4);
}
}
@@ -336,12 +271,13 @@ public partial class CGrammarParser : Parser {
[RuleVersion(0)]
public Block_itemContext block_item() {
Block_itemContext _localctx = new Block_itemContext(Context, State);
- EnterRule(_localctx, 8, RULE_block_item);
+ EnterRule(_localctx, 6, RULE_block_item);
try {
- State = 44;
+ State = 38;
ErrorHandler.Sync(this);
switch (TokenStream.LA(1)) {
case T__1:
+ case T__3:
case T__5:
case T__7:
case T__10:
@@ -352,14 +288,14 @@ public partial class CGrammarParser : Parser {
case INT:
EnterOuterAlt(_localctx, 1);
{
- State = 42;
+ State = 36;
statement();
}
break;
case T__0:
EnterOuterAlt(_localctx, 2);
{
- State = 43;
+ State = 37;
declaration();
}
break;
@@ -390,6 +326,18 @@ public partial class CGrammarParser : Parser {
base.CopyFrom(context);
}
}
+ public partial class BlockStatementContext : StatementContext {
+ [System.Diagnostics.DebuggerNonUserCode] public BlockContext block() {
+ return GetRuleContext<BlockContext>(0);
+ }
+ public BlockStatementContext(StatementContext context) { CopyFrom(context); }
+ [System.Diagnostics.DebuggerNonUserCode]
+ public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
+ ICGrammarVisitor<TResult> typedVisitor = visitor as ICGrammarVisitor<TResult>;
+ if (typedVisitor != null) return typedVisitor.VisitBlockStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
public partial class ExpressionStatementContext : StatementContext {
[System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
return GetRuleContext<ExpressionContext>(0);
@@ -415,16 +363,16 @@ public partial class CGrammarParser : Parser {
}
}
public partial class IfStatementContext : StatementContext {
- public BodyContext then;
- public BodyContext @else;
+ public StatementContext then;
+ public StatementContext @else;
[System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
return GetRuleContext<ExpressionContext>(0);
}
- [System.Diagnostics.DebuggerNonUserCode] public BodyContext[] body() {
- return GetRuleContexts<BodyContext>();
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext[] statement() {
+ return GetRuleContexts<StatementContext>();
}
- [System.Diagnostics.DebuggerNonUserCode] public BodyContext body(int i) {
- return GetRuleContext<BodyContext>(i);
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement(int i) {
+ return GetRuleContext<StatementContext>(i);
}
public IfStatementContext(StatementContext context) { CopyFrom(context); }
[System.Diagnostics.DebuggerNonUserCode]
@@ -438,20 +386,20 @@ public partial class CGrammarParser : Parser {
[RuleVersion(0)]
public StatementContext statement() {
StatementContext _localctx = new StatementContext(Context, State);
- EnterRule(_localctx, 10, RULE_statement);
+ EnterRule(_localctx, 8, RULE_statement);
try {
- State = 59;
+ State = 55;
ErrorHandler.Sync(this);
switch (TokenStream.LA(1)) {
case T__5:
_localctx = new ReturnStatementContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 46;
+ State = 40;
Match(T__5);
- State = 47;
+ State = 41;
expression(0);
- State = 48;
+ State = 42;
Match(T__6);
}
break;
@@ -459,21 +407,27 @@ public partial class CGrammarParser : Parser {
_localctx = new IfStatementContext(_localctx);
EnterOuterAlt(_localctx, 2);
{
- State = 50;
+ State = 44;
Match(T__7);
- State = 51;
+ State = 45;
Match(T__1);
- State = 52;
+ State = 46;
expression(0);
- State = 53;
+ State = 47;
Match(T__2);
- State = 54;
- ((IfStatementContext)_localctx).then = body();
- {
- State = 55;
- Match(T__8);
- State = 56;
- ((IfStatementContext)_localctx).@else = body();
+ State = 48;
+ ((IfStatementContext)_localctx).then = statement();
+ State = 51;
+ ErrorHandler.Sync(this);
+ switch ( Interpreter.AdaptivePredict(TokenStream,2,Context) ) {
+ case 1:
+ {
+ State = 49;
+ Match(T__8);
+ State = 50;
+ ((IfStatementContext)_localctx).@else = statement();
+ }
+ break;
}
}
break;
@@ -487,10 +441,18 @@ public partial class CGrammarParser : Parser {
_localctx = new ExpressionStatementContext(_localctx);
EnterOuterAlt(_localctx, 3);
{
- State = 58;
+ State = 53;
expression(0);
}
break;
+ case T__3:
+ _localctx = new BlockStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 4);
+ {
+ State = 54;
+ block();
+ }
+ break;
default:
throw new NoViableAltException(this);
}
@@ -537,29 +499,29 @@ public partial class CGrammarParser : Parser {
[RuleVersion(0)]
public DeclarationContext declaration() {
DeclarationContext _localctx = new DeclarationContext(Context, State);
- EnterRule(_localctx, 12, RULE_declaration);
+ EnterRule(_localctx, 10, RULE_declaration);
int _la;
try {
_localctx = new VariableDeclarationContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 61;
+ State = 57;
Match(T__0);
- State = 62;
+ State = 58;
((VariableDeclarationContext)_localctx).name = Match(ID);
- State = 65;
+ State = 61;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
if (_la==T__9) {
{
- State = 63;
+ State = 59;
Match(T__9);
- State = 64;
+ State = 60;
((VariableDeclarationContext)_localctx).value = expression(0);
}
}
- State = 67;
+ State = 63;
Match(T__6);
}
}
@@ -1209,13 +1171,13 @@ public partial class CGrammarParser : Parser {
int _parentState = State;
ExpressionContext _localctx = new ExpressionContext(Context, _parentState);
ExpressionContext _prevctx = _localctx;
- int _startState = 14;
- EnterRecursionRule(_localctx, 14, RULE_expression, _p);
+ int _startState = 12;
+ EnterRecursionRule(_localctx, 12, RULE_expression, _p);
try {
int _alt;
EnterOuterAlt(_localctx, 1);
{
- State = 135;
+ State = 131;
ErrorHandler.Sync(this);
switch ( Interpreter.AdaptivePredict(TokenStream,5,Context) ) {
case 1:
@@ -1224,11 +1186,11 @@ public partial class CGrammarParser : Parser {
Context = _localctx;
_prevctx = _localctx;
- State = 70;
+ State = 66;
Match(T__1);
- State = 71;
+ State = 67;
expression(0);
- State = 72;
+ State = 68;
Match(T__2);
}
break;
@@ -1237,7 +1199,7 @@ public partial class CGrammarParser : Parser {
_localctx = new ConstantExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 74;
+ State = 70;
constant();
}
break;
@@ -1246,13 +1208,13 @@ public partial class CGrammarParser : Parser {
_localctx = new AssignmentExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 75;
+ State = 71;
target();
- State = 76;
+ State = 72;
Match(T__9);
- State = 77;
+ State = 73;
expression(0);
- State = 78;
+ State = 74;
Match(T__6);
}
break;
@@ -1261,7 +1223,7 @@ public partial class CGrammarParser : Parser {
_localctx = new VariableExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 80;
+ State = 76;
Match(ID);
}
break;
@@ -1270,9 +1232,9 @@ public partial class CGrammarParser : Parser {
_localctx = new NotExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 81;
+ State = 77;
Match(T__10);
- State = 82;
+ State = 78;
expression(36);
}
break;
@@ -1281,9 +1243,9 @@ public partial class CGrammarParser : Parser {
_localctx = new InvertExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 83;
+ State = 79;
Match(T__11);
- State = 84;
+ State = 80;
expression(35);
}
break;
@@ -1292,9 +1254,9 @@ public partial class CGrammarParser : Parser {
_localctx = new IncrementPrefixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 85;
+ State = 81;
Match(T__12);
- State = 86;
+ State = 82;
target();
}
break;
@@ -1303,9 +1265,9 @@ public partial class CGrammarParser : Parser {
_localctx = new DecrementPrefixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 87;
+ State = 83;
Match(T__13);
- State = 88;
+ State = 84;
target();
}
break;
@@ -1314,9 +1276,9 @@ public partial class CGrammarParser : Parser {
_localctx = new IncrementPostfixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 89;
+ State = 85;
target();
- State = 90;
+ State = 86;
Match(T__12);
}
break;
@@ -1325,9 +1287,9 @@ public partial class CGrammarParser : Parser {
_localctx = new DecrementPostfixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 92;
+ State = 88;
target();
- State = 93;
+ State = 89;
Match(T__13);
}
break;
@@ -1336,11 +1298,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundMultiplyExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 95;
+ State = 91;
target();
- State = 96;
+ State = 92;
Match(T__32);
- State = 97;
+ State = 93;
expression(12);
}
break;
@@ -1349,11 +1311,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundDivideExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 99;
+ State = 95;
target();
- State = 100;
+ State = 96;
Match(T__33);
- State = 101;
+ State = 97;
expression(11);
}
break;
@@ -1362,11 +1324,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundModulusExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 103;
+ State = 99;
target();
- State = 104;
+ State = 100;
Match(T__34);
- State = 105;
+ State = 101;
expression(10);
}
break;
@@ -1375,11 +1337,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundAddExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 107;
+ State = 103;
target();
- State = 108;
+ State = 104;
Match(T__35);
- State = 109;
+ State = 105;
expression(9);
}
break;
@@ -1388,11 +1350,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundSubtractExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 111;
+ State = 107;
target();
- State = 112;
+ State = 108;
Match(T__36);
- State = 113;
+ State = 109;
expression(8);
}
break;
@@ -1401,11 +1363,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundBitwiseAndExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 115;
+ State = 111;
target();
- State = 116;
+ State = 112;
Match(T__37);
- State = 117;
+ State = 113;
expression(7);
}
break;
@@ -1414,11 +1376,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundBitwiseOrExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 119;
+ State = 115;
target();
- State = 120;
+ State = 116;
Match(T__38);
- State = 121;
+ State = 117;
expression(6);
}
break;
@@ -1427,11 +1389,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundBitwiseXorExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 123;
+ State = 119;
target();
- State = 124;
+ State = 120;
Match(T__39);
- State = 125;
+ State = 121;
expression(5);
}
break;
@@ -1440,11 +1402,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundBitwiseLeftShiftExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 127;
+ State = 123;
target();
- State = 128;
+ State = 124;
Match(T__40);
- State = 129;
+ State = 125;
expression(4);
}
break;
@@ -1453,17 +1415,17 @@ public partial class CGrammarParser : Parser {
_localctx = new CompoundBitwiseRightShiftExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 131;
+ State = 127;
target();
- State = 132;
+ State = 128;
Match(T__41);
- State = 133;
+ State = 129;
expression(3);
}
break;
}
Context.Stop = TokenStream.LT(-1);
- State = 202;
+ State = 198;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,7,Context);
while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
@@ -1472,7 +1434,7 @@ public partial class CGrammarParser : Parser {
TriggerExitRuleEvent();
_prevctx = _localctx;
{
- State = 200;
+ State = 196;
ErrorHandler.Sync(this);
switch ( Interpreter.AdaptivePredict(TokenStream,6,Context) ) {
case 1:
@@ -1480,11 +1442,11 @@ public partial class CGrammarParser : Parser {
_localctx = new MultiplyExpressionContext(new ExpressionContext(_parentctx, _parentState));
((MultiplyExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 137;
+ State = 133;
if (!(Precpred(Context, 30))) throw new FailedPredicateException(this, "Precpred(Context, 30)");
- State = 138;
+ State = 134;
Match(T__14);
- State = 139;
+ State = 135;
((MultiplyExpressionContext)_localctx).right = expression(31);
}
break;
@@ -1493,11 +1455,11 @@ public partial class CGrammarParser : Parser {
_localctx = new DivideExpressionContext(new ExpressionContext(_parentctx, _parentState));
((DivideExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 140;
+ State = 136;
if (!(Precpred(Context, 29))) throw new FailedPredicateException(this, "Precpred(Context, 29)");
- State = 141;
+ State = 137;
Match(T__15);
- State = 142;
+ State = 138;
((DivideExpressionContext)_localctx).right = expression(30);
}
break;
@@ -1506,11 +1468,11 @@ public partial class CGrammarParser : Parser {
_localctx = new ModulusExpressionContext(new ExpressionContext(_parentctx, _parentState));
((ModulusExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 143;
+ State = 139;
if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)");
- State = 144;
+ State = 140;
Match(T__16);
- State = 145;
+ State = 141;
((ModulusExpressionContext)_localctx).right = expression(29);
}
break;
@@ -1519,11 +1481,11 @@ public partial class CGrammarParser : Parser {
_localctx = new AddExpressionContext(new ExpressionContext(_parentctx, _parentState));
((AddExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 146;
+ State = 142;
if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)");
- State = 147;
+ State = 143;
Match(T__17);
- State = 148;
+ State = 144;
((AddExpressionContext)_localctx).right = expression(28);
}
break;
@@ -1532,11 +1494,11 @@ public partial class CGrammarParser : Parser {
_localctx = new SubtractExpressionContext(new ExpressionContext(_parentctx, _parentState));
((SubtractExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 149;
+ State = 145;
if (!(Precpred(Context, 26))) throw new FailedPredicateException(this, "Precpred(Context, 26)");
- State = 150;
+ State = 146;
Match(T__18);
- State = 151;
+ State = 147;
((SubtractExpressionContext)_localctx).right = expression(27);
}
break;
@@ -1545,11 +1507,11 @@ public partial class CGrammarParser : Parser {
_localctx = new LessThanExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LessThanExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 152;
+ State = 148;
if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)");
- State = 153;
+ State = 149;
Match(T__19);
- State = 154;
+ State = 150;
((LessThanExpressionContext)_localctx).right = expression(26);
}
break;
@@ -1558,11 +1520,11 @@ public partial class CGrammarParser : Parser {
_localctx = new GreaterThanExpressionContext(new ExpressionContext(_parentctx, _parentState));
((GreaterThanExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 155;
+ State = 151;
if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)");
- State = 156;
+ State = 152;
Match(T__20);
- State = 157;
+ State = 153;
((GreaterThanExpressionContext)_localctx).right = expression(25);
}
break;
@@ -1571,11 +1533,11 @@ public partial class CGrammarParser : Parser {
_localctx = new LessThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LessThanOrEqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 158;
+ State = 154;
if (!(Precpred(Context, 23))) throw new FailedPredicateException(this, "Precpred(Context, 23)");
- State = 159;
+ State = 155;
Match(T__21);
- State = 160;
+ State = 156;
((LessThanOrEqualExpressionContext)_localctx).right = expression(24);
}
break;
@@ -1584,11 +1546,11 @@ public partial class CGrammarParser : Parser {
_localctx = new GreaterThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((GreaterThanOrEqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 161;
+ State = 157;
if (!(Precpred(Context, 22))) throw new FailedPredicateException(this, "Precpred(Context, 22)");
- State = 162;
+ State = 158;
Match(T__22);
- State = 163;
+ State = 159;
((GreaterThanOrEqualExpressionContext)_localctx).right = expression(23);
}
break;
@@ -1597,11 +1559,11 @@ public partial class CGrammarParser : Parser {
_localctx = new EqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((EqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 164;
+ State = 160;
if (!(Precpred(Context, 21))) throw new FailedPredicateException(this, "Precpred(Context, 21)");
- State = 165;
+ State = 161;
Match(T__23);
- State = 166;
+ State = 162;
((EqualExpressionContext)_localctx).right = expression(22);
}
break;
@@ -1610,11 +1572,11 @@ public partial class CGrammarParser : Parser {
_localctx = new NotEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((NotEqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 167;
+ State = 163;
if (!(Precpred(Context, 20))) throw new FailedPredicateException(this, "Precpred(Context, 20)");
- State = 168;
+ State = 164;
Match(T__24);
- State = 169;
+ State = 165;
((NotEqualExpressionContext)_localctx).right = expression(21);
}
break;
@@ -1623,11 +1585,11 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseAndExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseAndExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 170;
+ State = 166;
if (!(Precpred(Context, 19))) throw new FailedPredicateException(this, "Precpred(Context, 19)");
- State = 171;
+ State = 167;
Match(T__25);
- State = 172;
+ State = 168;
((BitwiseAndExpressionContext)_localctx).right = expression(20);
}
break;
@@ -1636,11 +1598,11 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseOrExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseOrExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 173;
+ State = 169;
if (!(Precpred(Context, 18))) throw new FailedPredicateException(this, "Precpred(Context, 18)");
- State = 174;
+ State = 170;
Match(T__26);
- State = 175;
+ State = 171;
((BitwiseOrExpressionContext)_localctx).right = expression(19);
}
break;
@@ -1649,11 +1611,11 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseXorExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseXorExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 176;
+ State = 172;
if (!(Precpred(Context, 17))) throw new FailedPredicateException(this, "Precpred(Context, 17)");
- State = 177;
+ State = 173;
Match(T__27);
- State = 178;
+ State = 174;
((BitwiseXorExpressionContext)_localctx).right = expression(18);
}
break;
@@ -1662,11 +1624,11 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseLeftShiftExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseLeftShiftExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 179;
+ State = 175;
if (!(Precpred(Context, 16))) throw new FailedPredicateException(this, "Precpred(Context, 16)");
- State = 180;
+ State = 176;
Match(T__28);
- State = 181;
+ State = 177;
((BitwiseLeftShiftExpressionContext)_localctx).right = expression(17);
}
break;
@@ -1675,11 +1637,11 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseRightShiftExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseRightShiftExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 182;
+ State = 178;
if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)");
- State = 183;
+ State = 179;
Match(T__29);
- State = 184;
+ State = 180;
((BitwiseRightShiftExpressionContext)_localctx).right = expression(16);
}
break;
@@ -1688,11 +1650,11 @@ public partial class CGrammarParser : Parser {
_localctx = new LogicalAndExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LogicalAndExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 185;
+ State = 181;
if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)");
- State = 186;
+ State = 182;
Match(T__30);
- State = 187;
+ State = 183;
((LogicalAndExpressionContext)_localctx).right = expression(15);
}
break;
@@ -1701,11 +1663,11 @@ public partial class CGrammarParser : Parser {
_localctx = new LogicalOrExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LogicalOrExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 188;
+ State = 184;
if (!(Precpred(Context, 13))) throw new FailedPredicateException(this, "Precpred(Context, 13)");
- State = 189;
+ State = 185;
Match(T__31);
- State = 190;
+ State = 186;
((LogicalOrExpressionContext)_localctx).right = expression(14);
}
break;
@@ -1714,11 +1676,11 @@ public partial class CGrammarParser : Parser {
_localctx = new CommaExpressionContext(new ExpressionContext(_parentctx, _parentState));
((CommaExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 191;
+ State = 187;
if (!(Precpred(Context, 2))) throw new FailedPredicateException(this, "Precpred(Context, 2)");
- State = 192;
+ State = 188;
Match(T__42);
- State = 193;
+ State = 189;
((CommaExpressionContext)_localctx).right = expression(3);
}
break;
@@ -1727,22 +1689,22 @@ public partial class CGrammarParser : Parser {
_localctx = new TernaryExpressionContext(new ExpressionContext(_parentctx, _parentState));
((TernaryExpressionContext)_localctx).cond = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 194;
+ State = 190;
if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)");
- State = 195;
+ State = 191;
Match(T__43);
- State = 196;
+ State = 192;
((TernaryExpressionContext)_localctx).then = expression(0);
- State = 197;
+ State = 193;
Match(T__44);
- State = 198;
+ State = 194;
((TernaryExpressionContext)_localctx).@else = expression(2);
}
break;
}
}
}
- State = 204;
+ State = 200;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,7,Context);
}
@@ -1785,12 +1747,12 @@ public partial class CGrammarParser : Parser {
[RuleVersion(0)]
public ConstantContext constant() {
ConstantContext _localctx = new ConstantContext(Context, State);
- EnterRule(_localctx, 16, RULE_constant);
+ EnterRule(_localctx, 14, RULE_constant);
try {
_localctx = new IntConstantContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 205;
+ State = 201;
Match(INT);
}
}
@@ -1831,12 +1793,12 @@ public partial class CGrammarParser : Parser {
[RuleVersion(0)]
public TargetContext target() {
TargetContext _localctx = new TargetContext(Context, State);
- EnterRule(_localctx, 18, RULE_target);
+ EnterRule(_localctx, 16, RULE_target);
try {
_localctx = new VariableTargetContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 207;
+ State = 203;
Match(ID);
}
}
@@ -1853,7 +1815,7 @@ public partial class CGrammarParser : Parser {
public override bool Sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
- case 7: return expression_sempred((ExpressionContext)_localctx, predIndex);
+ case 6: return expression_sempred((ExpressionContext)_localctx, predIndex);
}
return true;
}
@@ -1884,75 +1846,74 @@ public partial class CGrammarParser : Parser {
}
private static int[] _serializedATN = {
- 4,1,49,210,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,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,3,2,32,
- 8,2,1,3,1,3,5,3,36,8,3,10,3,12,3,39,9,3,1,3,1,3,1,4,1,4,3,4,45,8,4,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,60,8,5,1,6,1,6,1,6,
- 1,6,3,6,66,8,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
- 1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,
- 7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
- 1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,
- 7,1,7,3,7,136,8,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
- 1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,
- 7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
- 1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,5,7,201,8,
- 7,10,7,12,7,204,9,7,1,8,1,8,1,9,1,9,1,9,0,1,14,10,0,2,4,6,8,10,12,14,16,
- 18,0,0,244,0,20,1,0,0,0,2,23,1,0,0,0,4,31,1,0,0,0,6,33,1,0,0,0,8,44,1,
- 0,0,0,10,59,1,0,0,0,12,61,1,0,0,0,14,135,1,0,0,0,16,205,1,0,0,0,18,207,
- 1,0,0,0,20,21,3,2,1,0,21,22,5,0,0,1,22,1,1,0,0,0,23,24,5,1,0,0,24,25,5,
- 46,0,0,25,26,5,2,0,0,26,27,5,3,0,0,27,28,3,6,3,0,28,3,1,0,0,0,29,32,3,
- 10,5,0,30,32,3,6,3,0,31,29,1,0,0,0,31,30,1,0,0,0,32,5,1,0,0,0,33,37,5,
- 4,0,0,34,36,3,8,4,0,35,34,1,0,0,0,36,39,1,0,0,0,37,35,1,0,0,0,37,38,1,
- 0,0,0,38,40,1,0,0,0,39,37,1,0,0,0,40,41,5,5,0,0,41,7,1,0,0,0,42,45,3,10,
- 5,0,43,45,3,12,6,0,44,42,1,0,0,0,44,43,1,0,0,0,45,9,1,0,0,0,46,47,5,6,
- 0,0,47,48,3,14,7,0,48,49,5,7,0,0,49,60,1,0,0,0,50,51,5,8,0,0,51,52,5,2,
- 0,0,52,53,3,14,7,0,53,54,5,3,0,0,54,55,3,4,2,0,55,56,5,9,0,0,56,57,3,4,
- 2,0,57,60,1,0,0,0,58,60,3,14,7,0,59,46,1,0,0,0,59,50,1,0,0,0,59,58,1,0,
- 0,0,60,11,1,0,0,0,61,62,5,1,0,0,62,65,5,46,0,0,63,64,5,10,0,0,64,66,3,
- 14,7,0,65,63,1,0,0,0,65,66,1,0,0,0,66,67,1,0,0,0,67,68,5,7,0,0,68,13,1,
- 0,0,0,69,70,6,7,-1,0,70,71,5,2,0,0,71,72,3,14,7,0,72,73,5,3,0,0,73,136,
- 1,0,0,0,74,136,3,16,8,0,75,76,3,18,9,0,76,77,5,10,0,0,77,78,3,14,7,0,78,
- 79,5,7,0,0,79,136,1,0,0,0,80,136,5,46,0,0,81,82,5,11,0,0,82,136,3,14,7,
- 36,83,84,5,12,0,0,84,136,3,14,7,35,85,86,5,13,0,0,86,136,3,18,9,0,87,88,
- 5,14,0,0,88,136,3,18,9,0,89,90,3,18,9,0,90,91,5,13,0,0,91,136,1,0,0,0,
- 92,93,3,18,9,0,93,94,5,14,0,0,94,136,1,0,0,0,95,96,3,18,9,0,96,97,5,33,
- 0,0,97,98,3,14,7,12,98,136,1,0,0,0,99,100,3,18,9,0,100,101,5,34,0,0,101,
- 102,3,14,7,11,102,136,1,0,0,0,103,104,3,18,9,0,104,105,5,35,0,0,105,106,
- 3,14,7,10,106,136,1,0,0,0,107,108,3,18,9,0,108,109,5,36,0,0,109,110,3,
- 14,7,9,110,136,1,0,0,0,111,112,3,18,9,0,112,113,5,37,0,0,113,114,3,14,
- 7,8,114,136,1,0,0,0,115,116,3,18,9,0,116,117,5,38,0,0,117,118,3,14,7,7,
- 118,136,1,0,0,0,119,120,3,18,9,0,120,121,5,39,0,0,121,122,3,14,7,6,122,
- 136,1,0,0,0,123,124,3,18,9,0,124,125,5,40,0,0,125,126,3,14,7,5,126,136,
- 1,0,0,0,127,128,3,18,9,0,128,129,5,41,0,0,129,130,3,14,7,4,130,136,1,0,
- 0,0,131,132,3,18,9,0,132,133,5,42,0,0,133,134,3,14,7,3,134,136,1,0,0,0,
- 135,69,1,0,0,0,135,74,1,0,0,0,135,75,1,0,0,0,135,80,1,0,0,0,135,81,1,0,
- 0,0,135,83,1,0,0,0,135,85,1,0,0,0,135,87,1,0,0,0,135,89,1,0,0,0,135,92,
- 1,0,0,0,135,95,1,0,0,0,135,99,1,0,0,0,135,103,1,0,0,0,135,107,1,0,0,0,
- 135,111,1,0,0,0,135,115,1,0,0,0,135,119,1,0,0,0,135,123,1,0,0,0,135,127,
- 1,0,0,0,135,131,1,0,0,0,136,202,1,0,0,0,137,138,10,30,0,0,138,139,5,15,
- 0,0,139,201,3,14,7,31,140,141,10,29,0,0,141,142,5,16,0,0,142,201,3,14,
- 7,30,143,144,10,28,0,0,144,145,5,17,0,0,145,201,3,14,7,29,146,147,10,27,
- 0,0,147,148,5,18,0,0,148,201,3,14,7,28,149,150,10,26,0,0,150,151,5,19,
- 0,0,151,201,3,14,7,27,152,153,10,25,0,0,153,154,5,20,0,0,154,201,3,14,
- 7,26,155,156,10,24,0,0,156,157,5,21,0,0,157,201,3,14,7,25,158,159,10,23,
- 0,0,159,160,5,22,0,0,160,201,3,14,7,24,161,162,10,22,0,0,162,163,5,23,
- 0,0,163,201,3,14,7,23,164,165,10,21,0,0,165,166,5,24,0,0,166,201,3,14,
- 7,22,167,168,10,20,0,0,168,169,5,25,0,0,169,201,3,14,7,21,170,171,10,19,
- 0,0,171,172,5,26,0,0,172,201,3,14,7,20,173,174,10,18,0,0,174,175,5,27,
- 0,0,175,201,3,14,7,19,176,177,10,17,0,0,177,178,5,28,0,0,178,201,3,14,
- 7,18,179,180,10,16,0,0,180,181,5,29,0,0,181,201,3,14,7,17,182,183,10,15,
- 0,0,183,184,5,30,0,0,184,201,3,14,7,16,185,186,10,14,0,0,186,187,5,31,
- 0,0,187,201,3,14,7,15,188,189,10,13,0,0,189,190,5,32,0,0,190,201,3,14,
- 7,14,191,192,10,2,0,0,192,193,5,43,0,0,193,201,3,14,7,3,194,195,10,1,0,
- 0,195,196,5,44,0,0,196,197,3,14,7,0,197,198,5,45,0,0,198,199,3,14,7,2,
- 199,201,1,0,0,0,200,137,1,0,0,0,200,140,1,0,0,0,200,143,1,0,0,0,200,146,
- 1,0,0,0,200,149,1,0,0,0,200,152,1,0,0,0,200,155,1,0,0,0,200,158,1,0,0,
- 0,200,161,1,0,0,0,200,164,1,0,0,0,200,167,1,0,0,0,200,170,1,0,0,0,200,
- 173,1,0,0,0,200,176,1,0,0,0,200,179,1,0,0,0,200,182,1,0,0,0,200,185,1,
- 0,0,0,200,188,1,0,0,0,200,191,1,0,0,0,200,194,1,0,0,0,201,204,1,0,0,0,
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,1,12,9,0,2,4,6,8,10,12,14,16,0,0,242,0,18,1,
+ 0,0,0,2,21,1,0,0,0,4,27,1,0,0,0,6,38,1,0,0,0,8,55,1,0,0,0,10,57,1,0,0,
+ 0,12,131,1,0,0,0,14,201,1,0,0,0,16,203,1,0,0,0,18,19,3,2,1,0,19,20,5,0,
+ 0,1,20,1,1,0,0,0,21,22,5,1,0,0,22,23,5,46,0,0,23,24,5,2,0,0,24,25,5,3,
+ 0,0,25,26,3,4,2,0,26,3,1,0,0,0,27,31,5,4,0,0,28,30,3,6,3,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,5,0,0,35,5,1,0,0,0,36,39,3,8,4,0,37,39,3,10,5,0,38,36,1,0,0,
+ 0,38,37,1,0,0,0,39,7,1,0,0,0,40,41,5,6,0,0,41,42,3,12,6,0,42,43,5,7,0,
+ 0,43,56,1,0,0,0,44,45,5,8,0,0,45,46,5,2,0,0,46,47,3,12,6,0,47,48,5,3,0,
+ 0,48,51,3,8,4,0,49,50,5,9,0,0,50,52,3,8,4,0,51,49,1,0,0,0,51,52,1,0,0,
+ 0,52,56,1,0,0,0,53,56,3,12,6,0,54,56,3,4,2,0,55,40,1,0,0,0,55,44,1,0,0,
+ 0,55,53,1,0,0,0,55,54,1,0,0,0,56,9,1,0,0,0,57,58,5,1,0,0,58,61,5,46,0,
+ 0,59,60,5,10,0,0,60,62,3,12,6,0,61,59,1,0,0,0,61,62,1,0,0,0,62,63,1,0,
+ 0,0,63,64,5,7,0,0,64,11,1,0,0,0,65,66,6,6,-1,0,66,67,5,2,0,0,67,68,3,12,
+ 6,0,68,69,5,3,0,0,69,132,1,0,0,0,70,132,3,14,7,0,71,72,3,16,8,0,72,73,
+ 5,10,0,0,73,74,3,12,6,0,74,75,5,7,0,0,75,132,1,0,0,0,76,132,5,46,0,0,77,
+ 78,5,11,0,0,78,132,3,12,6,36,79,80,5,12,0,0,80,132,3,12,6,35,81,82,5,13,
+ 0,0,82,132,3,16,8,0,83,84,5,14,0,0,84,132,3,16,8,0,85,86,3,16,8,0,86,87,
+ 5,13,0,0,87,132,1,0,0,0,88,89,3,16,8,0,89,90,5,14,0,0,90,132,1,0,0,0,91,
+ 92,3,16,8,0,92,93,5,33,0,0,93,94,3,12,6,12,94,132,1,0,0,0,95,96,3,16,8,
+ 0,96,97,5,34,0,0,97,98,3,12,6,11,98,132,1,0,0,0,99,100,3,16,8,0,100,101,
+ 5,35,0,0,101,102,3,12,6,10,102,132,1,0,0,0,103,104,3,16,8,0,104,105,5,
+ 36,0,0,105,106,3,12,6,9,106,132,1,0,0,0,107,108,3,16,8,0,108,109,5,37,
+ 0,0,109,110,3,12,6,8,110,132,1,0,0,0,111,112,3,16,8,0,112,113,5,38,0,0,
+ 113,114,3,12,6,7,114,132,1,0,0,0,115,116,3,16,8,0,116,117,5,39,0,0,117,
+ 118,3,12,6,6,118,132,1,0,0,0,119,120,3,16,8,0,120,121,5,40,0,0,121,122,
+ 3,12,6,5,122,132,1,0,0,0,123,124,3,16,8,0,124,125,5,41,0,0,125,126,3,12,
+ 6,4,126,132,1,0,0,0,127,128,3,16,8,0,128,129,5,42,0,0,129,130,3,12,6,3,
+ 130,132,1,0,0,0,131,65,1,0,0,0,131,70,1,0,0,0,131,71,1,0,0,0,131,76,1,
+ 0,0,0,131,77,1,0,0,0,131,79,1,0,0,0,131,81,1,0,0,0,131,83,1,0,0,0,131,
+ 85,1,0,0,0,131,88,1,0,0,0,131,91,1,0,0,0,131,95,1,0,0,0,131,99,1,0,0,0,
+ 131,103,1,0,0,0,131,107,1,0,0,0,131,111,1,0,0,0,131,115,1,0,0,0,131,119,
+ 1,0,0,0,131,123,1,0,0,0,131,127,1,0,0,0,132,198,1,0,0,0,133,134,10,30,
+ 0,0,134,135,5,15,0,0,135,197,3,12,6,31,136,137,10,29,0,0,137,138,5,16,
+ 0,0,138,197,3,12,6,30,139,140,10,28,0,0,140,141,5,17,0,0,141,197,3,12,
+ 6,29,142,143,10,27,0,0,143,144,5,18,0,0,144,197,3,12,6,28,145,146,10,26,
+ 0,0,146,147,5,19,0,0,147,197,3,12,6,27,148,149,10,25,0,0,149,150,5,20,
+ 0,0,150,197,3,12,6,26,151,152,10,24,0,0,152,153,5,21,0,0,153,197,3,12,
+ 6,25,154,155,10,23,0,0,155,156,5,22,0,0,156,197,3,12,6,24,157,158,10,22,
+ 0,0,158,159,5,23,0,0,159,197,3,12,6,23,160,161,10,21,0,0,161,162,5,24,
+ 0,0,162,197,3,12,6,22,163,164,10,20,0,0,164,165,5,25,0,0,165,197,3,12,
+ 6,21,166,167,10,19,0,0,167,168,5,26,0,0,168,197,3,12,6,20,169,170,10,18,
+ 0,0,170,171,5,27,0,0,171,197,3,12,6,19,172,173,10,17,0,0,173,174,5,28,
+ 0,0,174,197,3,12,6,18,175,176,10,16,0,0,176,177,5,29,0,0,177,197,3,12,
+ 6,17,178,179,10,15,0,0,179,180,5,30,0,0,180,197,3,12,6,16,181,182,10,14,
+ 0,0,182,183,5,31,0,0,183,197,3,12,6,15,184,185,10,13,0,0,185,186,5,32,
+ 0,0,186,197,3,12,6,14,187,188,10,2,0,0,188,189,5,43,0,0,189,197,3,12,6,
+ 3,190,191,10,1,0,0,191,192,5,44,0,0,192,193,3,12,6,0,193,194,5,45,0,0,
+ 194,195,3,12,6,2,195,197,1,0,0,0,196,133,1,0,0,0,196,136,1,0,0,0,196,139,
+ 1,0,0,0,196,142,1,0,0,0,196,145,1,0,0,0,196,148,1,0,0,0,196,151,1,0,0,
+ 0,196,154,1,0,0,0,196,157,1,0,0,0,196,160,1,0,0,0,196,163,1,0,0,0,196,
+ 166,1,0,0,0,196,169,1,0,0,0,196,172,1,0,0,0,196,175,1,0,0,0,196,178,1,
+ 0,0,0,196,181,1,0,0,0,196,184,1,0,0,0,196,187,1,0,0,0,196,190,1,0,0,0,
+ 197,200,1,0,0,0,198,196,1,0,0,0,198,199,1,0,0,0,199,13,1,0,0,0,200,198,
+ 1,0,0,0,201,202,5,47,0,0,202,15,1,0,0,0,203,204,5,46,0,0,204,17,1,0,0,
+ 0,8,31,38,51,55,61,131,196,198
};
public static readonly ATN _ATN =
diff --git a/Compiler/gen/CGrammarVisitor.cs b/Compiler/gen/CGrammarVisitor.cs
index 50cb551..e0689f0 100644
--- a/Compiler/gen/CGrammarVisitor.cs
+++ b/Compiler/gen/CGrammarVisitor.cs
@@ -44,12 +44,6 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitFunction([NotNull] CGrammarParser.FunctionContext context);
/// <summary>
- /// Visit a parse tree produced by <see cref="CGrammarParser.body"/>.
- /// </summary>
- /// <param name="context">The parse tree.</param>
- /// <return>The visitor result.</return>
- Result VisitBody([NotNull] CGrammarParser.BodyContext context);
- /// <summary>
/// Visit a parse tree produced by <see cref="CGrammarParser.block"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
@@ -83,6 +77,13 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitExpressionStatement([NotNull] CGrammarParser.ExpressionStatementContext context);
/// <summary>
+ /// Visit a parse tree produced by the <c>blockStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitBlockStatement([NotNull] CGrammarParser.BlockStatementContext context);
+ /// <summary>
/// Visit a parse tree produced by the <c>variableDeclaration</c>
/// labeled alternative in <see cref="CGrammarParser.declaration"/>.
/// </summary>
diff --git a/ROMs/.DS_Store b/ROMs/.DS_Store
index 775e323..4906c1a 100644
--- a/ROMs/.DS_Store
+++ b/ROMs/.DS_Store
Binary files differ
diff --git a/ROMs/hello_c.asm b/ROMs/hello_c.asm
index 6eba849..e06d4e0 100644
--- a/ROMs/hello_c.asm
+++ b/ROMs/hello_c.asm
@@ -1,9 +1,17 @@
_main:
; comment
mov 5, [$51FF] ; int a = 5
- add [$51FF], 5 ; compute addition
- mov AX, [$51FF] ; store back into left param
- mov [$51FF], V0 ; return value
+ push [$51FF] ; left operand
+ mov 5, V1 ; right operand
+ pop V0 ; get left operand back
+ cmp V0, V1 ; compute equality check
+ bz LX ; check if condition
+ not
+ jmp _end_1 ; if succeeds, continue, else jump to end
+ mov 99, V0 ; return value
+ ret
+_end_1:
+ mov 0, V0 ; return value
ret
mov 0, V0 ; fallback return 0
ret
diff --git a/ROMs/hello_c.c b/ROMs/hello_c.c
index d0abdd5..3310b6b 100644
--- a/ROMs/hello_c.c
+++ b/ROMs/hello_c.c
@@ -2,5 +2,7 @@ int main()
{
//comment
int a = 5;
- return a += 5;
+ if (a == 5)
+ return 99;
+ return 0;
} \ No newline at end of file