summaryrefslogtreecommitdiff
path: root/Compiler
diff options
context:
space:
mode:
Diffstat (limited to 'Compiler')
-rw-r--r--Compiler/CCompilerVisitor.cs356
-rw-r--r--Compiler/CGrammar.g425
-rw-r--r--Compiler/Context.cs23
-rw-r--r--Compiler/FunctionReference.cs129
-rw-r--r--Compiler/Program.cs31
-rw-r--r--Compiler/VariableReference.cs13
-rw-r--r--Compiler/gen/CGrammar.interp16
-rw-r--r--Compiler/gen/CGrammar.tokens104
-rw-r--r--Compiler/gen/CGrammarBaseVisitor.cs113
-rw-r--r--Compiler/gen/CGrammarLexer.cs185
-rw-r--r--Compiler/gen/CGrammarLexer.interp21
-rw-r--r--Compiler/gen/CGrammarLexer.tokens104
-rw-r--r--Compiler/gen/CGrammarParser.cs1313
-rw-r--r--Compiler/gen/CGrammarVisitor.cs75
14 files changed, 1801 insertions, 707 deletions
diff --git a/Compiler/CCompilerVisitor.cs b/Compiler/CCompilerVisitor.cs
index fb7df0f..abe831d 100644
--- a/Compiler/CCompilerVisitor.cs
+++ b/Compiler/CCompilerVisitor.cs
@@ -1,30 +1,33 @@
namespace Q1.Compiler;
+using System.Runtime.CompilerServices;
using Antlr4.Runtime.Tree;
using Emulator;
public class CCompilerVisitor : CGrammarBaseVisitor<string?>
{
- private int _branchCount = 1;
- private List<string> _instructions = new();
- private Stack<Dictionary<string, int>> _variableStack = new();
- private int _memPointer = Q1Layout.FreeMemoryStart;
+ private int _branchCount = 1;
+ private List<string> _instructions = new();
+ private Stack<Dictionary<string, VariableReference>> _variableStack = new();
+ private List<FunctionReference> _methods = new();
+ private static int _memLowest = Q1Layout.FreeMemoryStart;
+ private static int _memPointer = CCompilerVisitor._memLowest;
private const int ColumnWidth = 30;
public readonly CommentCompilationMode CommentMode;
-
+
public CCompilerVisitor(CommentCompilationMode commentMode)
{
this.CommentMode = commentMode;
}
- private int FindVariable(string varName)
+ private VariableReference FindVariable(string varName)
{
- foreach (Dictionary<string, int> variables in this._variableStack)
+ foreach (Dictionary<string, VariableReference> variables in this._variableStack)
{
- if (variables.TryGetValue(varName, out int address))
- return address;
+ if (variables.TryGetValue(varName, out VariableReference? reference))
+ return reference;
}
throw new CompilerException($"Variable {varName} could not be found in current scope.");
@@ -32,8 +35,8 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
private int Alloc(int size)
{
- int loc = this._memPointer;
- this._memPointer += size;
+ int loc = CCompilerVisitor._memPointer;
+ CCompilerVisitor._memPointer += size;
return loc;
}
@@ -52,7 +55,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
{
this._instructions.Add("");
}
- private void Label(string name, string? generatedComment = null)
+ private void Branch(string name, string? generatedComment = null)
{
this._instructions.Add($"{name}:");
if (generatedComment != null)
@@ -63,7 +66,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
if (this.CommentMode.HasFlag(CommentCompilationMode.UserDefined))
this._instructions.Add($" ; {comment}");
}
-
+
private void GeneratedComment(string comment)
{
if (this.CommentMode.HasFlag(CommentCompilationMode.Generated))
@@ -87,25 +90,139 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
public IEnumerable<string> Compile(CGrammarParser.ProgramContext program)
{
+ Instruction("jmp _main");
this.Visit(program);
return this._instructions;
}
- public override string? VisitFunction(CGrammarParser.FunctionContext context)
+ private FunctionReference CreateOrGetFunctionReference(string name, string type)
+ {
+ FunctionReference? function = this._methods.FirstOrDefault(x => x.Name == name);
+ if (function != null)
+ return function;
+
+ function = new FunctionReference(name, type);
+ this._methods.Add(function);
+
+ return function;
+ }
+
+ private FunctionReference GetFunctionReference(string name)
+ {
+ FunctionReference? function = this._methods.FirstOrDefault(x => x.Name == name);
+ if (function != null)
+ return function;
+
+ throw new CompilerException($"Function '{name}' has not been defined or prototyped.");
+ }
+
+ public override string? VisitFunctionPrototype(CGrammarParser.FunctionPrototypeContext context)
{
string functionName = context.name.Text;
- this._variableStack.Push(new());
+ string type = "int";
+
+ List<string> parameterTypes = context._types.Select(x => x.Text).ToList();
+ List<string> parameterNames = context._params.Select(x => x.Text).ToList();
- this.Label($"_{functionName}");
+ FunctionReference function = this.CreateOrGetFunctionReference(functionName, type);
+ FunctionOverload overload = function.CreateOverloadWithoutBody(parameterNames, parameterTypes);
+
+ function.Overloads.Add(overload);
+
+ return null;
+ }
+ public override string? VisitFunctionDefinition(CGrammarParser.FunctionDefinitionContext context)
+ {
+ string functionName = context.name.Text;
+ string type = "int";
+
+ List<string> paramTypes = context._types.Select(x => x.Text).ToList();
+ List<string> paramNames = context._params.Select(x => x.Text).ToList();
+
+ FunctionReference function = this.CreateOrGetFunctionReference(functionName, type);
+ FunctionOverload overload = function.CreateOverloadWithBody(paramNames, paramTypes);
+
+ this.Branch(function.GetBranchName(overload), function.GetBranchFriendlyName(overload));
+
+ if (paramNames.Count > 0)
+ this.Instruction("pop V0", "preserve function return address");
+
+ Dictionary<string, VariableReference> scope = this.EnterScope();
+ foreach ((string paramName, string paramType) in paramNames.Zip(paramTypes))
+ {
+ int paramSize = 2;
+ int addr = this.Alloc(paramSize);
+ scope[paramName] = new(addr, paramSize);
+ this.Instruction($"pop [${addr:X4}]", $"param {paramType} {paramName}");
+ }
+
+ if (paramNames.Count > 0)
+ this.Instruction("push V0", "restore function return address");
+
this.VisitChildren(context);
+ this.ExitScope();
+
this.Instruction("mov 0, V0", "fallback return 0");
this.Instruction("ret");
this.Blank();
- this._variableStack.Pop();
+ return null;
+ }
+
+ public override string? VisitCallExpression(CGrammarParser.CallExpressionContext context)
+ {
+ string functionName = context.ID().GetText();
+
+ FunctionReference function = this.GetFunctionReference(functionName);
+ FunctionOverload overload = function.GetOverload(context._params.Count);
+
+ // We reverse arugments so when we perform pop, its in the right order
+ CGrammarParser.ExpressionContext[] argumentsReversed = context._params.Reverse().ToArray();
+
+ for (int i = 0; i < argumentsReversed.Length; i++)
+ {
+ CGrammarParser.ExpressionContext argument = argumentsReversed[i];
+ string result = this.Visit(argument)
+ ?? throw new CompilerException("Function call argument was not an expression");
+
+ this.Instruction($"push {result}", $"arg {overload.ParameterTypes[i]} {overload.ParameterNames[i]}");
+ }
+
+ this.Instruction($"call {function.GetBranchName(overload)}", function.GetBranchFriendlyName(overload));
+
+ return "V0";
+ }
+
+ public override string? VisitBlock(CGrammarParser.BlockContext context)
+ {
+ this.EnterScope();
+
+ this.VisitChildren(context);
+
+ this.ExitScope();
return null;
}
+ private Dictionary<string, VariableReference> EnterScope()
+ {
+ Dictionary<string, VariableReference> scope = new();
+ this._variableStack.Push(scope);
+
+ return scope;
+ }
+ private void ExitScope()
+ {
+ foreach ((string key, VariableReference value) in this._variableStack.Peek())
+ {
+ CCompilerVisitor._memPointer -= value.Size;
+ if (CCompilerVisitor._memPointer < CCompilerVisitor._memLowest)
+ throw new CompilerException("Memory pointer is lower than mem lowest!");
+ }
+
+ // Delete scope
+ this._variableStack.Pop();
+ }
+
public override string? VisitParenthesizedExpression(CGrammarParser.ParenthesizedExpressionContext context)
{
return this.Visit(context.expression());
@@ -169,8 +286,8 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
if (right == null)
throw new CompilerException($"Right operand for {operationFriendlyName} was not an expression.");
- this.Instruction($"mov {right}, V1", "right operand");
- this.Instruction($"pop V0", "get left operand back");
+ this.Instruction($"mov {right}, V1", "right operand");
+ this.Instruction($"pop V0", "get left operand back");
this.Instruction($"{operation} V0, V1", $"compute {operationFriendlyName}");
}
private string BaseBinaryCompoundOperation(CGrammarParser.TargetContext leftTarget, CGrammarParser.ExpressionContext rightExpr, string operation, string operationFriendlyName, string operationOutput)
@@ -184,7 +301,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
throw new CompilerException($"Right operand for {operationFriendlyName} was not an expression.");
// No need for stack maniupulation because left is a target and is assumed to stay constant
- this.Instruction($"{operation} {left}, {right}", $"compute {operationFriendlyName}");
+ this.Instruction($"{operation} {left}, {right}", $"compute {operationFriendlyName}");
this.Instruction($"mov {operationOutput}, {left}", "store back into left param");
return left;
}
@@ -253,7 +370,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"jmp {clauseBranch}"); // only if bz is not 0
this.Instruction("mov 1, V0", "first operand succeeded, store 1 and skip second operand");
this.Instruction($"jmp {endBranch}");
- this.Label(clauseBranch);
+ this.Branch(clauseBranch);
string? right = this.Visit(context.right);
if (right == null)
@@ -262,7 +379,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"cmp {right}, 0", "compare result from second operand to 0");
this.Instruction("not");
this.Instruction("mov LX, V0", "store second operand result");
- this.Label(endBranch);
+ this.Branch(endBranch);
return "V0";
}
@@ -281,7 +398,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"jmp {clauseBranch}"); // only if bz is not 0
this.Instruction("mov 0, V0", "first operand failed, store 0 and skip second");
this.Instruction($"jmp {endBranch}");
- this.Label(clauseBranch);
+ this.Branch(clauseBranch);
string? right = this.Visit(context.right);
if (right == null)
@@ -290,7 +407,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"cmp {right}, 0", "compare result from second operand to 0");
this.Instruction("not");
this.Instruction("mov LX, V0", "store second operand result");
- this.Label(endBranch);
+ this.Branch(endBranch);
return "V0";
}
@@ -303,7 +420,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction("bz");
this.Instruction($"jmp {endBranch}");
this.Instruction($"gt V0, V1");
- this.Label(endBranch);
+ this.Branch(endBranch);
return "LX";
}
@@ -315,7 +432,7 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction("bz");
this.Instruction($"jmp {endBranch}");
this.Instruction($"lt V0, V1");
- this.Label(endBranch);
+ this.Branch(endBranch);
return "LX";
}
@@ -347,18 +464,19 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
public override string? VisitVariableDeclaration(CGrammarParser.VariableDeclarationContext context)
{
- int addr = this.Alloc(2);
+ int size = 2;
+ int addr = this.Alloc(size);
string name = context.name.Text;
- Dictionary<string, int> scope = this._variableStack.Peek();
+ Dictionary<string, VariableReference> scope = this._variableStack.Peek();
if (scope.ContainsKey(name))
throw new CompilerException($"Variable {name} already exists in current scope.");
- scope[name] = addr;
+ scope[name] = new VariableReference(addr, size);
if (context.value != null)
{
- string? initialValue = this.Visit(context.value)
- ?? throw new CompilerException("Initial variable definition value was not an expression");
+ string initialValue = this.Visit(context.value)
+ ?? throw new CompilerException("Initial variable definition value was not an expression");
this.Instruction($"mov {initialValue}, [${addr:X4}]", $"int {name} = {initialValue}");
}
else
@@ -369,24 +487,24 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
public override string? VisitVariableExpression(CGrammarParser.VariableExpressionContext context)
{
string varName = context.ID().GetText();
- int addr = this.FindVariable(varName);
+ VariableReference reference = this.FindVariable(varName);
- return $"[${addr:X4}]";
+ return $"[${reference.Address:X4}]";
}
public override string? VisitVariableTarget(CGrammarParser.VariableTargetContext context)
{
string varName = context.ID().GetText();
- int addr = this.FindVariable(varName);
+ VariableReference reference = this.FindVariable(varName);
- return $"[${addr:X4}]";
+ return $"[${reference.Address:X4}]";
}
public override string? VisitAssignmentExpression(CGrammarParser.AssignmentExpressionContext context)
{
string? target = this.Visit(context.target());
string? value = this.Visit(context.expression());
- this.Instruction($"mov {value}, {target}");
+ this.Instruction($"mov {value}, {target}", $"{target} = {value}");
return target;
}
@@ -505,12 +623,12 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"pop V0");
return "V0";
}
-
- public override string? VisitCommaExpression(CGrammarParser.CommaExpressionContext context)
- {
- this.Visit(context.left);
- return this.Visit(context.right);
- }
+ //
+ // public override string? VisitCommaExpression(CGrammarParser.CommaExpressionContext context)
+ // {
+ // this.Visit(context.left);
+ // return this.Visit(context.right);
+ // }
public override string? VisitTernaryExpression(CGrammarParser.TernaryExpressionContext context)
{
@@ -526,18 +644,18 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"bz {cond}", "check ternary condition");
this.Instruction($"jmp {thenBranch}");
-
+
result = this.Visit(context.@else)
?? throw new CompilerException("Else branch was not an expression");
this.Instruction($"mov {result}, V0", "store ternary fail result");
this.Instruction($"jmp {endBranch}");
- this.Label(thenBranch);
+ this.Branch(thenBranch);
result = this.Visit(context.then)
?? throw new CompilerException("Else branch was not an expression");
this.Instruction($"mov {result}, V0", "store ternary success result");
- this.Label(endBranch);
+ this.Branch(endBranch);
return "V0";
}
@@ -547,24 +665,24 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
string cond = this.Visit(context.expression())
?? throw new CompilerException("If condition was not an expression");
string endBranch = this.GenerateBranchLabel("end");
-
+
this.Instruction($"bz {cond}", "check if condition");
-
+
if (context.@else != null)
{
// 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.Branch(thenBranch, "if succeeded");
this.Visit(context.then);
}
else
@@ -573,9 +691,127 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
this.Instruction($"jmp {endBranch}", "if succeeds, continue, else jump to end");
this.Visit(context.then);
}
-
- this.Label(endBranch);
-
+
+ this.Branch(endBranch);
+
+ return null;
+ }
+
+ public override string? VisitForExprStatement(CGrammarParser.ForExprStatementContext context)
+ {
+ string bodyBranch = this.GenerateBranchLabel("body");
+ string endBranch = this.GenerateBranchLabel("end");
+
+ context.LoopBodyBranch = bodyBranch;
+ context.LoopEndBranch = endBranch;
+
+ this.EnterScope();
+ this.Visit(context.initializer);
+
+ this.Branch(bodyBranch);
+ string cond = this.Visit(context.cond)
+ ?? throw new CompilerException("For condition was not an expression");
+
+ this.Instruction($"not {cond}");
+ this.Instruction($"bz");
+ this.Instruction($"jmp {endBranch}", "if for condition fails, jump to end");
+
+ this.Visit(context.body);
+ this.Visit(context.post);
+
+ this.Branch(endBranch);
+ this.ExitScope();
+
+ return null;
+ }
+ public override string? VisitForDeclStatement(CGrammarParser.ForDeclStatementContext context)
+ {
+ string bodyBranch = this.GenerateBranchLabel("body");
+ string endBranch = this.GenerateBranchLabel("end");
+
+ context.LoopBodyBranch = bodyBranch;
+ context.LoopEndBranch = endBranch;
+
+ this.EnterScope();
+ this.Visit(context.initializer);
+
+ this.Branch(bodyBranch);
+ string cond = this.Visit(context.cond)
+ ?? throw new CompilerException("For condition was not an expression");
+
+ this.Instruction($"not {cond}");
+ this.Instruction($"bz");
+ this.Instruction($"jmp {endBranch}", "if for condition fails, jump to end");
+
+ this.Visit(context.body);
+ this.Visit(context.post);
+
+ this.Branch(endBranch);
+ this.ExitScope();
+
+ return null;
+ }
+ public override string? VisitWhileStatement(CGrammarParser.WhileStatementContext context)
+ {
+ string bodyBranch = this.GenerateBranchLabel("body");
+ string endBranch = this.GenerateBranchLabel("end");
+
+ context.LoopBodyBranch = bodyBranch;
+ context.LoopEndBranch = endBranch;
+
+ this.Branch(bodyBranch);
+ string cond = this.Visit(context.cond)
+ ?? throw new CompilerException("While condition was not an expression");
+
+ this.Instruction($"not {cond}");
+ this.Instruction($"bz");
+ this.Instruction($"jmp {endBranch}", "if while condition fails, jump to end");
+
+ this.Visit(context.body);
+
+ this.Branch(endBranch);
+
+ return null;
+ }
+
+ public override string? VisitDoWhileStatement(CGrammarParser.DoWhileStatementContext context)
+ {
+ string bodyBranch = this.GenerateBranchLabel("body");
+ string endBranch = this.GenerateBranchLabel("end");
+
+ context.LoopBodyBranch = bodyBranch;
+ context.LoopEndBranch = endBranch;
+
+ this.Branch(bodyBranch);
+ this.Visit(context.body);
+
+ string cond = this.Visit(context.cond)
+ ?? throw new CompilerException("While condition was not an expression");
+
+ this.Instruction($"bz {cond}");
+ this.Instruction($"jmp {bodyBranch}", "if while condition succeeds, jump back to start");
+
+ this.Branch(endBranch);
+
+ return null;
+ }
+
+ public override string? VisitBreakStatement(CGrammarParser.BreakStatementContext context)
+ {
+ if (context.LoopEndBranch == null)
+ throw new CompilerException("Cannot break, not inside loop with end");
+
+ this.Instruction($"jmp {context.LoopEndBranch}", "break");
+
+ return null;
+ }
+ public override string? VisitContinueStatement(CGrammarParser.ContinueStatementContext context)
+ {
+ if (context.LoopBodyBranch == null)
+ throw new CompilerException("Cannot skip body (continue), not inside loop with body");
+
+ this.Instruction($"jmp {context.LoopBodyBranch}", "continue");
+
return null;
}
@@ -584,17 +820,23 @@ public class CCompilerVisitor : CGrammarBaseVisitor<string?>
if (node.Symbol.Type == CGrammarParser.COMMENT)
{
// strip // and \n and whitespace
- string comment = node.Symbol.Text
- .TrimStart("//").TrimEnd('\n').Trim();
-
+ string comment = node
+ .Symbol.Text
+ .TrimStart("//")
+ .TrimEnd('\n')
+ .Trim();
+
this.UserComment(comment);
}
-
+
return base.VisitErrorNode(node);
}
public override string? Visit(IParseTree tree)
{
+ if (tree is Context childCtx && tree.Parent is Context ctx)
+ ctx.SyncProps(childCtx);
+
return base.Visit(tree);
}
diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4
index 484cc90..b0f145f 100644
--- a/Compiler/CGrammar.g4
+++ b/Compiler/CGrammar.g4
@@ -1,5 +1,9 @@
grammar CGrammar;
+options {
+ contextSuperClass = Q1.Compiler.Context;
+}
+
ID: [a-zA-Z_][a-zA-Z0-9_]*;
INT: [0-9]+;
WS: [ \t\r\n]+ -> skip;
@@ -7,11 +11,12 @@ COMMENT: '//' .*? ([\n] | EOF) -> channel(HIDDEN);
program
- : function EOF
+ : function+ EOF
;
function
- : 'int' name=ID '(' ')' block
+ : 'int' name=ID '(' ( types+='int' params+=ID (',' types+='int' params+=ID )* )? ')' ';' #functionPrototype
+ | 'int' name=ID '(' ( types+='int' params+=ID (',' types+='int' params+=ID )* )? ')' block #functionDefinition
;
block
@@ -26,8 +31,15 @@ block_item
statement
: 'return' expression ';' #returnStatement
| 'if' '(' expression ')' then=statement ('else' else=statement)? #ifStatement
- | expression #expressionStatement
+ | 'for' '(' (initializer=expression)? ';' cond=expression? ';' post=expression? ')' body=statement #forExprStatement
+ | 'for' '(' initializer=declaration cond=expression? ';' post=expression? ')' body=statement #forDeclStatement
+ | 'while' '(' cond=expression ')' body=statement #whileStatement
+ | 'do' body=statement 'while' '(' cond=expression ')' ';' #doWhileStatement
+ | 'break' ';' #breakStatement
+ | 'continue' ';' #continueStatement
+ | expression ';' #expressionStatement
| block #blockStatement
+ | ';' #nullStatement
;
@@ -37,10 +49,13 @@ declaration
expression
: '(' expression ')' #parenthesizedExpression
+// | left=expression ',' right=expression #commaExpression
| constant #constantExpression
- | target '=' expression ';' #assignmentExpression
+ | target '=' expression #assignmentExpression
| ID #variableExpression
+ | ID '(' ( params+=expression (',' params+=expression )* )? ')' #callExpression
+
| '!' expression #notExpression
| '~' expression #invertExpression
@@ -87,8 +102,6 @@ expression
| target '<<=' expression #compoundBitwiseLeftShiftExpression
| target '>>=' expression #compoundBitwiseRightShiftExpression
- | left=expression ',' right=expression #commaExpression
-
| cond=expression '?' then=expression ':' else=expression #ternaryExpression
;
diff --git a/Compiler/Context.cs b/Compiler/Context.cs
new file mode 100644
index 0000000..52e577f
--- /dev/null
+++ b/Compiler/Context.cs
@@ -0,0 +1,23 @@
+namespace Q1.Compiler;
+
+using Antlr4.Runtime;
+
+public class Context : ParserRuleContext
+{
+ public string? LoopEndBranch;
+ public string? LoopBodyBranch;
+
+ public Context() { }
+
+ public Context(ParserRuleContext parent, int invokingStateNumber)
+ : base((Context) parent, invokingStateNumber)
+ {
+ }
+
+
+ public void SyncProps(Context childCtx)
+ {
+ childCtx.LoopBodyBranch = this.LoopBodyBranch;
+ childCtx.LoopEndBranch = this.LoopEndBranch;
+ }
+} \ No newline at end of file
diff --git a/Compiler/FunctionReference.cs b/Compiler/FunctionReference.cs
new file mode 100644
index 0000000..cf120ad
--- /dev/null
+++ b/Compiler/FunctionReference.cs
@@ -0,0 +1,129 @@
+namespace Q1.Compiler;
+
+using System.Reflection.Metadata;
+using System.Text;
+
+public class FunctionReference
+{
+ // TODO: Implement return type
+ public string Name;
+ public string Type;
+ public List<FunctionOverload> Overloads = new();
+
+ public FunctionReference(string name, string type)
+ {
+ this.Type = type;
+ this.Name = name;
+ }
+
+ public string GetBranchName(FunctionOverload overload)
+ {
+ List<(string paramName, string paramType)> parameters = overload
+ .ParameterNames
+ .Zip(overload.ParameterTypes)
+ .ToList();
+
+ StringBuilder branchName = new();
+ branchName.Append($"_{this.Name}");
+
+ if (parameters.Count > 0)
+ {
+ branchName.Append($"_{string.Join("__", parameters
+ .Select(x => $"{x.paramType}_{x.paramName}"))}");
+ }
+
+ return branchName.ToString();
+ }
+
+ public string GetBranchFriendlyName(FunctionOverload overload)
+ {
+ List<(string paramName, string paramType)> parameters = overload
+ .ParameterNames
+ .Zip(overload.ParameterTypes)
+ .ToList();
+
+ StringBuilder branchName = new();
+ branchName.Append($"{this.Type} {this.Name}");
+ branchName.Append("(");
+
+ branchName.Append(string.Join(", ", parameters
+ .Select(x => $"{x.paramType} {x.paramName}")));
+
+ branchName.Append(")");
+
+ return branchName.ToString();
+ }
+
+ public FunctionOverload CreateOverloadWithBody(List<string> parameterNames, List<string> parameterTypes)
+ {
+ FunctionOverload? existingOverload = this.Overloads
+ .FirstOrDefault(x => x.ParamsMatch(parameterNames, parameterTypes));
+
+ if (existingOverload != null)
+ {
+ if (existingOverload.BodyImplemented)
+ throw new CompilerException($"Cannot define another overload for {this.Name},"
+ + $" as one with an identical signature and body already exists.");
+
+ existingOverload.BodyImplemented = true;
+ return existingOverload;
+ }
+ else
+ {
+ FunctionOverload newOverload = new(parameterNames, parameterTypes, true);
+ this.Overloads.Add(newOverload);
+ return newOverload;
+ }
+ }
+
+ public FunctionOverload CreateOverloadWithoutBody(List<string> parameterNames, List<string> parameterTypes)
+ {
+ FunctionOverload? existingOverload = this.Overloads
+ .FirstOrDefault(x => x.ParamsMatch(parameterNames, parameterTypes));
+
+ if (existingOverload != null)
+ {
+ if (!existingOverload.BodyImplemented)
+ throw new CompilerException($"Cannot prototype another overload for {this.Name},"
+ + $" as one with an identical signature already exists.");
+ return existingOverload;
+ }
+ else
+ {
+ FunctionOverload newOverload = new(parameterNames, parameterTypes, false);
+ this.Overloads.Add(newOverload);
+ return newOverload;
+ }
+ }
+ public FunctionOverload GetOverload(int paramsCount)
+ {
+ FunctionOverload? overload = this.Overloads
+ .FirstOrDefault(x => x.ParameterTypes.Count == paramsCount);
+
+ if (overload != null)
+ return overload;
+
+ throw new CompilerException($"Overload for {this.Name} with {paramsCount} arguments could not be found.");
+ }
+}
+
+public class FunctionOverload
+{
+ // TODO: Implement return type
+ public List<string> ParameterTypes;
+ public List<string> ParameterNames;
+ public bool BodyImplemented;
+
+ public FunctionOverload(List<string> parameterNames, List<string> parameterTypes, bool bodyImplemented)
+ {
+ this.ParameterTypes = parameterTypes;
+ this.ParameterNames = parameterNames;
+ this.BodyImplemented = bodyImplemented;
+ }
+
+ public bool ParamsMatch(List<string> parameterNames, List<string> parameterTypes)
+ {
+ return this.ParameterNames.SequenceEqual(parameterNames)
+ && this.ParameterTypes.SequenceEqual(parameterTypes);
+ }
+} \ No newline at end of file
diff --git a/Compiler/Program.cs b/Compiler/Program.cs
index fdd8722..9259205 100644
--- a/Compiler/Program.cs
+++ b/Compiler/Program.cs
@@ -22,17 +22,24 @@ class Program
Environment.CurrentDirectory = Path.GetDirectoryName(options.InputFile) ?? Environment.CurrentDirectory;
options.InputFile = Path.GetFileName(options.InputFile);
- AntlrFileStream inputStream = new(options.InputFile);
- CGrammarLexer lexer = new(inputStream);
- lexer.RemoveErrorListeners();
-
- ITokenStream tokenStream = new BufferedTokenStream(lexer);
- CGrammarParser parser = new(tokenStream);
- parser.RemoveErrorListeners();
-
- CCompilerVisitor compiler = new(options.CommentCompilationMode);
- IEnumerable<string> result = compiler.Compile(parser.program());
-
- File.WriteAllLines(options.OutputFile, result);
+ try
+ {
+ AntlrFileStream inputStream = new(options.InputFile);
+ CGrammarLexer lexer = new(inputStream);
+ lexer.RemoveErrorListeners();
+
+ ITokenStream tokenStream = new BufferedTokenStream(lexer);
+ CGrammarParser parser = new(tokenStream);
+ parser.RemoveErrorListeners();
+
+ CCompilerVisitor compiler = new(options.CommentCompilationMode);
+ IEnumerable<string> result = compiler.Compile(parser.program());
+
+ File.WriteAllLines(options.OutputFile, result);
+ }
+ catch (CompilerException ex)
+ {
+ Console.WriteLine($"{ex.Message}");
+ }
}
} \ No newline at end of file
diff --git a/Compiler/VariableReference.cs b/Compiler/VariableReference.cs
new file mode 100644
index 0000000..9524e98
--- /dev/null
+++ b/Compiler/VariableReference.cs
@@ -0,0 +1,13 @@
+namespace Q1.Compiler;
+
+public class VariableReference
+{
+ public int Address;
+ public int Size;
+
+ public VariableReference(int address, int size)
+ {
+ this.Address = address;
+ this.Size = size;
+ }
+} \ No newline at end of file
diff --git a/Compiler/gen/CGrammar.interp b/Compiler/gen/CGrammar.interp
index a1df3d4..6c55ec3 100644
--- a/Compiler/gen/CGrammar.interp
+++ b/Compiler/gen/CGrammar.interp
@@ -2,13 +2,19 @@ token literal names:
null
'int'
'('
+','
')'
+';'
'{'
'}'
'return'
-';'
'if'
'else'
+'for'
+'while'
+'do'
+'break'
+'continue'
'='
'!'
'~'
@@ -42,7 +48,6 @@ null
'^='
'<<='
'>>='
-','
'?'
':'
null
@@ -97,6 +102,11 @@ null
null
null
null
+null
+null
+null
+null
+null
ID
INT
WS
@@ -115,4 +125,4 @@ target
atn:
-[4, 1, 49, 206, 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, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 5, 2, 30, 8, 2, 10, 2, 12, 2, 33, 9, 2, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 39, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 52, 8, 4, 1, 4, 1, 4, 3, 4, 56, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 62, 8, 5, 1, 5, 1, 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, 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, 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, 3, 6, 132, 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, 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, 197, 8, 6, 10, 6, 12, 6, 200, 9, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 0, 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] \ No newline at end of file
+[4, 1, 54, 298, 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, 1, 0, 4, 0, 20, 8, 0, 11, 0, 12, 0, 21, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 34, 8, 1, 10, 1, 12, 1, 37, 9, 1, 3, 1, 39, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 51, 8, 1, 10, 1, 12, 1, 54, 9, 1, 3, 1, 56, 8, 1, 1, 1, 1, 1, 3, 1, 60, 8, 1, 1, 2, 1, 2, 5, 2, 64, 8, 2, 10, 2, 12, 2, 67, 9, 2, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 73, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 86, 8, 4, 1, 4, 1, 4, 1, 4, 3, 4, 91, 8, 4, 1, 4, 1, 4, 3, 4, 95, 8, 4, 1, 4, 1, 4, 3, 4, 99, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 107, 8, 4, 1, 4, 1, 4, 3, 4, 111, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 139, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 145, 8, 5, 1, 5, 1, 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, 1, 6, 1, 6, 1, 6, 5, 6, 165, 8, 6, 10, 6, 12, 6, 168, 9, 6, 3, 6, 170, 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, 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, 3, 6, 227, 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, 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, 289, 8, 6, 10, 6, 12, 6, 292, 9, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 0, 1, 12, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 0, 0, 354, 0, 19, 1, 0, 0, 0, 2, 59, 1, 0, 0, 0, 4, 61, 1, 0, 0, 0, 6, 72, 1, 0, 0, 0, 8, 138, 1, 0, 0, 0, 10, 140, 1, 0, 0, 0, 12, 226, 1, 0, 0, 0, 14, 293, 1, 0, 0, 0, 16, 295, 1, 0, 0, 0, 18, 20, 3, 2, 1, 0, 19, 18, 1, 0, 0, 0, 20, 21, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 24, 5, 0, 0, 1, 24, 1, 1, 0, 0, 0, 25, 26, 5, 1, 0, 0, 26, 27, 5, 51, 0, 0, 27, 38, 5, 2, 0, 0, 28, 29, 5, 1, 0, 0, 29, 35, 5, 51, 0, 0, 30, 31, 5, 3, 0, 0, 31, 32, 5, 1, 0, 0, 32, 34, 5, 51, 0, 0, 33, 30, 1, 0, 0, 0, 34, 37, 1, 0, 0, 0, 35, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 39, 1, 0, 0, 0, 37, 35, 1, 0, 0, 0, 38, 28, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 41, 5, 4, 0, 0, 41, 60, 5, 5, 0, 0, 42, 43, 5, 1, 0, 0, 43, 44, 5, 51, 0, 0, 44, 55, 5, 2, 0, 0, 45, 46, 5, 1, 0, 0, 46, 52, 5, 51, 0, 0, 47, 48, 5, 3, 0, 0, 48, 49, 5, 1, 0, 0, 49, 51, 5, 51, 0, 0, 50, 47, 1, 0, 0, 0, 51, 54, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 56, 1, 0, 0, 0, 54, 52, 1, 0, 0, 0, 55, 45, 1, 0, 0, 0, 55, 56, 1, 0, 0, 0, 56, 57, 1, 0, 0, 0, 57, 58, 5, 4, 0, 0, 58, 60, 3, 4, 2, 0, 59, 25, 1, 0, 0, 0, 59, 42, 1, 0, 0, 0, 60, 3, 1, 0, 0, 0, 61, 65, 5, 6, 0, 0, 62, 64, 3, 6, 3, 0, 63, 62, 1, 0, 0, 0, 64, 67, 1, 0, 0, 0, 65, 63, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 68, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 68, 69, 5, 7, 0, 0, 69, 5, 1, 0, 0, 0, 70, 73, 3, 8, 4, 0, 71, 73, 3, 10, 5, 0, 72, 70, 1, 0, 0, 0, 72, 71, 1, 0, 0, 0, 73, 7, 1, 0, 0, 0, 74, 75, 5, 8, 0, 0, 75, 76, 3, 12, 6, 0, 76, 77, 5, 5, 0, 0, 77, 139, 1, 0, 0, 0, 78, 79, 5, 9, 0, 0, 79, 80, 5, 2, 0, 0, 80, 81, 3, 12, 6, 0, 81, 82, 5, 4, 0, 0, 82, 85, 3, 8, 4, 0, 83, 84, 5, 10, 0, 0, 84, 86, 3, 8, 4, 0, 85, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 139, 1, 0, 0, 0, 87, 88, 5, 11, 0, 0, 88, 90, 5, 2, 0, 0, 89, 91, 3, 12, 6, 0, 90, 89, 1, 0, 0, 0, 90, 91, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 94, 5, 5, 0, 0, 93, 95, 3, 12, 6, 0, 94, 93, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 98, 5, 5, 0, 0, 97, 99, 3, 12, 6, 0, 98, 97, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 101, 5, 4, 0, 0, 101, 139, 3, 8, 4, 0, 102, 103, 5, 11, 0, 0, 103, 104, 5, 2, 0, 0, 104, 106, 3, 10, 5, 0, 105, 107, 3, 12, 6, 0, 106, 105, 1, 0, 0, 0, 106, 107, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 110, 5, 5, 0, 0, 109, 111, 3, 12, 6, 0, 110, 109, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 112, 1, 0, 0, 0, 112, 113, 5, 4, 0, 0, 113, 114, 3, 8, 4, 0, 114, 139, 1, 0, 0, 0, 115, 116, 5, 12, 0, 0, 116, 117, 5, 2, 0, 0, 117, 118, 3, 12, 6, 0, 118, 119, 5, 4, 0, 0, 119, 120, 3, 8, 4, 0, 120, 139, 1, 0, 0, 0, 121, 122, 5, 13, 0, 0, 122, 123, 3, 8, 4, 0, 123, 124, 5, 12, 0, 0, 124, 125, 5, 2, 0, 0, 125, 126, 3, 12, 6, 0, 126, 127, 5, 4, 0, 0, 127, 128, 5, 5, 0, 0, 128, 139, 1, 0, 0, 0, 129, 130, 5, 14, 0, 0, 130, 139, 5, 5, 0, 0, 131, 132, 5, 15, 0, 0, 132, 139, 5, 5, 0, 0, 133, 134, 3, 12, 6, 0, 134, 135, 5, 5, 0, 0, 135, 139, 1, 0, 0, 0, 136, 139, 3, 4, 2, 0, 137, 139, 5, 5, 0, 0, 138, 74, 1, 0, 0, 0, 138, 78, 1, 0, 0, 0, 138, 87, 1, 0, 0, 0, 138, 102, 1, 0, 0, 0, 138, 115, 1, 0, 0, 0, 138, 121, 1, 0, 0, 0, 138, 129, 1, 0, 0, 0, 138, 131, 1, 0, 0, 0, 138, 133, 1, 0, 0, 0, 138, 136, 1, 0, 0, 0, 138, 137, 1, 0, 0, 0, 139, 9, 1, 0, 0, 0, 140, 141, 5, 1, 0, 0, 141, 144, 5, 51, 0, 0, 142, 143, 5, 16, 0, 0, 143, 145, 3, 12, 6, 0, 144, 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 146, 1, 0, 0, 0, 146, 147, 5, 5, 0, 0, 147, 11, 1, 0, 0, 0, 148, 149, 6, 6, -1, 0, 149, 150, 5, 2, 0, 0, 150, 151, 3, 12, 6, 0, 151, 152, 5, 4, 0, 0, 152, 227, 1, 0, 0, 0, 153, 227, 3, 14, 7, 0, 154, 155, 3, 16, 8, 0, 155, 156, 5, 16, 0, 0, 156, 157, 3, 12, 6, 38, 157, 227, 1, 0, 0, 0, 158, 227, 5, 51, 0, 0, 159, 160, 5, 51, 0, 0, 160, 169, 5, 2, 0, 0, 161, 166, 3, 12, 6, 0, 162, 163, 5, 3, 0, 0, 163, 165, 3, 12, 6, 0, 164, 162, 1, 0, 0, 0, 165, 168, 1, 0, 0, 0, 166, 164, 1, 0, 0, 0, 166, 167, 1, 0, 0, 0, 167, 170, 1, 0, 0, 0, 168, 166, 1, 0, 0, 0, 169, 161, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, 171, 227, 5, 4, 0, 0, 172, 173, 5, 17, 0, 0, 173, 227, 3, 12, 6, 35, 174, 175, 5, 18, 0, 0, 175, 227, 3, 12, 6, 34, 176, 177, 5, 19, 0, 0, 177, 227, 3, 16, 8, 0, 178, 179, 5, 20, 0, 0, 179, 227, 3, 16, 8, 0, 180, 181, 3, 16, 8, 0, 181, 182, 5, 19, 0, 0, 182, 227, 1, 0, 0, 0, 183, 184, 3, 16, 8, 0, 184, 185, 5, 20, 0, 0, 185, 227, 1, 0, 0, 0, 186, 187, 3, 16, 8, 0, 187, 188, 5, 39, 0, 0, 188, 189, 3, 12, 6, 11, 189, 227, 1, 0, 0, 0, 190, 191, 3, 16, 8, 0, 191, 192, 5, 40, 0, 0, 192, 193, 3, 12, 6, 10, 193, 227, 1, 0, 0, 0, 194, 195, 3, 16, 8, 0, 195, 196, 5, 41, 0, 0, 196, 197, 3, 12, 6, 9, 197, 227, 1, 0, 0, 0, 198, 199, 3, 16, 8, 0, 199, 200, 5, 42, 0, 0, 200, 201, 3, 12, 6, 8, 201, 227, 1, 0, 0, 0, 202, 203, 3, 16, 8, 0, 203, 204, 5, 43, 0, 0, 204, 205, 3, 12, 6, 7, 205, 227, 1, 0, 0, 0, 206, 207, 3, 16, 8, 0, 207, 208, 5, 44, 0, 0, 208, 209, 3, 12, 6, 6, 209, 227, 1, 0, 0, 0, 210, 211, 3, 16, 8, 0, 211, 212, 5, 45, 0, 0, 212, 213, 3, 12, 6, 5, 213, 227, 1, 0, 0, 0, 214, 215, 3, 16, 8, 0, 215, 216, 5, 46, 0, 0, 216, 217, 3, 12, 6, 4, 217, 227, 1, 0, 0, 0, 218, 219, 3, 16, 8, 0, 219, 220, 5, 47, 0, 0, 220, 221, 3, 12, 6, 3, 221, 227, 1, 0, 0, 0, 222, 223, 3, 16, 8, 0, 223, 224, 5, 48, 0, 0, 224, 225, 3, 12, 6, 2, 225, 227, 1, 0, 0, 0, 226, 148, 1, 0, 0, 0, 226, 153, 1, 0, 0, 0, 226, 154, 1, 0, 0, 0, 226, 158, 1, 0, 0, 0, 226, 159, 1, 0, 0, 0, 226, 172, 1, 0, 0, 0, 226, 174, 1, 0, 0, 0, 226, 176, 1, 0, 0, 0, 226, 178, 1, 0, 0, 0, 226, 180, 1, 0, 0, 0, 226, 183, 1, 0, 0, 0, 226, 186, 1, 0, 0, 0, 226, 190, 1, 0, 0, 0, 226, 194, 1, 0, 0, 0, 226, 198, 1, 0, 0, 0, 226, 202, 1, 0, 0, 0, 226, 206, 1, 0, 0, 0, 226, 210, 1, 0, 0, 0, 226, 214, 1, 0, 0, 0, 226, 218, 1, 0, 0, 0, 226, 222, 1, 0, 0, 0, 227, 290, 1, 0, 0, 0, 228, 229, 10, 29, 0, 0, 229, 230, 5, 21, 0, 0, 230, 289, 3, 12, 6, 30, 231, 232, 10, 28, 0, 0, 232, 233, 5, 22, 0, 0, 233, 289, 3, 12, 6, 29, 234, 235, 10, 27, 0, 0, 235, 236, 5, 23, 0, 0, 236, 289, 3, 12, 6, 28, 237, 238, 10, 26, 0, 0, 238, 239, 5, 24, 0, 0, 239, 289, 3, 12, 6, 27, 240, 241, 10, 25, 0, 0, 241, 242, 5, 25, 0, 0, 242, 289, 3, 12, 6, 26, 243, 244, 10, 24, 0, 0, 244, 245, 5, 26, 0, 0, 245, 289, 3, 12, 6, 25, 246, 247, 10, 23, 0, 0, 247, 248, 5, 27, 0, 0, 248, 289, 3, 12, 6, 24, 249, 250, 10, 22, 0, 0, 250, 251, 5, 28, 0, 0, 251, 289, 3, 12, 6, 23, 252, 253, 10, 21, 0, 0, 253, 254, 5, 29, 0, 0, 254, 289, 3, 12, 6, 22, 255, 256, 10, 20, 0, 0, 256, 257, 5, 30, 0, 0, 257, 289, 3, 12, 6, 21, 258, 259, 10, 19, 0, 0, 259, 260, 5, 31, 0, 0, 260, 289, 3, 12, 6, 20, 261, 262, 10, 18, 0, 0, 262, 263, 5, 32, 0, 0, 263, 289, 3, 12, 6, 19, 264, 265, 10, 17, 0, 0, 265, 266, 5, 33, 0, 0, 266, 289, 3, 12, 6, 18, 267, 268, 10, 16, 0, 0, 268, 269, 5, 34, 0, 0, 269, 289, 3, 12, 6, 17, 270, 271, 10, 15, 0, 0, 271, 272, 5, 35, 0, 0, 272, 289, 3, 12, 6, 16, 273, 274, 10, 14, 0, 0, 274, 275, 5, 36, 0, 0, 275, 289, 3, 12, 6, 15, 276, 277, 10, 13, 0, 0, 277, 278, 5, 37, 0, 0, 278, 289, 3, 12, 6, 14, 279, 280, 10, 12, 0, 0, 280, 281, 5, 38, 0, 0, 281, 289, 3, 12, 6, 13, 282, 283, 10, 1, 0, 0, 283, 284, 5, 49, 0, 0, 284, 285, 3, 12, 6, 0, 285, 286, 5, 50, 0, 0, 286, 287, 3, 12, 6, 2, 287, 289, 1, 0, 0, 0, 288, 228, 1, 0, 0, 0, 288, 231, 1, 0, 0, 0, 288, 234, 1, 0, 0, 0, 288, 237, 1, 0, 0, 0, 288, 240, 1, 0, 0, 0, 288, 243, 1, 0, 0, 0, 288, 246, 1, 0, 0, 0, 288, 249, 1, 0, 0, 0, 288, 252, 1, 0, 0, 0, 288, 255, 1, 0, 0, 0, 288, 258, 1, 0, 0, 0, 288, 261, 1, 0, 0, 0, 288, 264, 1, 0, 0, 0, 288, 267, 1, 0, 0, 0, 288, 270, 1, 0, 0, 0, 288, 273, 1, 0, 0, 0, 288, 276, 1, 0, 0, 0, 288, 279, 1, 0, 0, 0, 288, 282, 1, 0, 0, 0, 289, 292, 1, 0, 0, 0, 290, 288, 1, 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 13, 1, 0, 0, 0, 292, 290, 1, 0, 0, 0, 293, 294, 5, 52, 0, 0, 294, 15, 1, 0, 0, 0, 295, 296, 5, 51, 0, 0, 296, 17, 1, 0, 0, 0, 21, 21, 35, 38, 52, 55, 59, 65, 72, 85, 90, 94, 98, 106, 110, 138, 144, 166, 169, 226, 288, 290] \ No newline at end of file
diff --git a/Compiler/gen/CGrammar.tokens b/Compiler/gen/CGrammar.tokens
index 7556128..0da6b57 100644
--- a/Compiler/gen/CGrammar.tokens
+++ b/Compiler/gen/CGrammar.tokens
@@ -43,52 +43,62 @@ T__41=42
T__42=43
T__43=44
T__44=45
-ID=46
-INT=47
-WS=48
-COMMENT=49
+T__45=46
+T__46=47
+T__47=48
+T__48=49
+T__49=50
+ID=51
+INT=52
+WS=53
+COMMENT=54
'int'=1
'('=2
-')'=3
-'{'=4
-'}'=5
-'return'=6
-';'=7
-'if'=8
-'else'=9
-'='=10
-'!'=11
-'~'=12
-'++'=13
-'--'=14
-'*'=15
-'/'=16
-'%'=17
-'+'=18
-'-'=19
-'<'=20
-'>'=21
-'<='=22
-'>='=23
-'=='=24
-'!='=25
-'&'=26
-'|'=27
-'^'=28
-'<<'=29
-'>>'=30
-'&&'=31
-'||'=32
-'*='=33
-'/='=34
-'%='=35
-'+='=36
-'-='=37
-'&='=38
-'|='=39
-'^='=40
-'<<='=41
-'>>='=42
-','=43
-'?'=44
-':'=45
+','=3
+')'=4
+';'=5
+'{'=6
+'}'=7
+'return'=8
+'if'=9
+'else'=10
+'for'=11
+'while'=12
+'do'=13
+'break'=14
+'continue'=15
+'='=16
+'!'=17
+'~'=18
+'++'=19
+'--'=20
+'*'=21
+'/'=22
+'%'=23
+'+'=24
+'-'=25
+'<'=26
+'>'=27
+'<='=28
+'>='=29
+'=='=30
+'!='=31
+'&'=32
+'|'=33
+'^'=34
+'<<'=35
+'>>'=36
+'&&'=37
+'||'=38
+'*='=39
+'/='=40
+'%='=41
+'+='=42
+'-='=43
+'&='=44
+'|='=45
+'^='=46
+'<<='=47
+'>>='=48
+'?'=49
+':'=50
diff --git a/Compiler/gen/CGrammarBaseVisitor.cs b/Compiler/gen/CGrammarBaseVisitor.cs
index 9964929..0893e73 100644
--- a/Compiler/gen/CGrammarBaseVisitor.cs
+++ b/Compiler/gen/CGrammarBaseVisitor.cs
@@ -45,7 +45,8 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// <return>The visitor result.</return>
public virtual Result VisitProgram([NotNull] CGrammarParser.ProgramContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by <see cref="CGrammarParser.function"/>.
+ /// Visit a parse tree produced by the <c>functionPrototype</c>
+ /// labeled alternative in <see cref="CGrammarParser.function"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
@@ -53,7 +54,18 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- public virtual Result VisitFunction([NotNull] CGrammarParser.FunctionContext context) { return VisitChildren(context); }
+ public virtual Result VisitFunctionPrototype([NotNull] CGrammarParser.FunctionPrototypeContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>functionDefinition</c>
+ /// labeled alternative in <see cref="CGrammarParser.function"/>.
+ /// <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 VisitFunctionDefinition([NotNull] CGrammarParser.FunctionDefinitionContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="CGrammarParser.block"/>.
/// <para>
@@ -97,6 +109,72 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// <return>The visitor result.</return>
public virtual Result VisitIfStatement([NotNull] CGrammarParser.IfStatementContext context) { return VisitChildren(context); }
/// <summary>
+ /// Visit a parse tree produced by the <c>forExprStatement</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 VisitForExprStatement([NotNull] CGrammarParser.ForExprStatementContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>forDeclStatement</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 VisitForDeclStatement([NotNull] CGrammarParser.ForDeclStatementContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>whileStatement</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 VisitWhileStatement([NotNull] CGrammarParser.WhileStatementContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>doWhileStatement</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 VisitDoWhileStatement([NotNull] CGrammarParser.DoWhileStatementContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>breakStatement</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 VisitBreakStatement([NotNull] CGrammarParser.BreakStatementContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>continueStatement</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 VisitContinueStatement([NotNull] CGrammarParser.ContinueStatementContext context) { return VisitChildren(context); }
+ /// <summary>
/// Visit a parse tree produced by the <c>expressionStatement</c>
/// labeled alternative in <see cref="CGrammarParser.statement"/>.
/// <para>
@@ -119,6 +197,17 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// <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>nullStatement</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 VisitNullStatement([NotNull] CGrammarParser.NullStatementContext context) { return VisitChildren(context); }
+ /// <summary>
/// Visit a parse tree produced by the <c>variableDeclaration</c>
/// labeled alternative in <see cref="CGrammarParser.declaration"/>.
/// <para>
@@ -449,7 +538,7 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// <return>The visitor result.</return>
public virtual Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by the <c>commaExpression</c>
+ /// Visit a parse tree produced by the <c>incrementPrefixExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -458,9 +547,9 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- public virtual Result VisitCommaExpression([NotNull] CGrammarParser.CommaExpressionContext context) { return VisitChildren(context); }
+ public virtual Result VisitIncrementPrefixExpression([NotNull] CGrammarParser.IncrementPrefixExpressionContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by the <c>incrementPrefixExpression</c>
+ /// Visit a parse tree produced by the <c>greaterThanOrEqualExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -469,9 +558,9 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- public virtual Result VisitIncrementPrefixExpression([NotNull] CGrammarParser.IncrementPrefixExpressionContext context) { return VisitChildren(context); }
+ public virtual Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by the <c>greaterThanOrEqualExpression</c>
+ /// Visit a parse tree produced by the <c>divideExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -480,9 +569,9 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- public virtual Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context) { return VisitChildren(context); }
+ public virtual Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by the <c>divideExpression</c>
+ /// Visit a parse tree produced by the <c>bitwiseOrExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -491,9 +580,9 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- public virtual Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context) { return VisitChildren(context); }
+ public virtual Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context) { return VisitChildren(context); }
/// <summary>
- /// Visit a parse tree produced by the <c>bitwiseOrExpression</c>
+ /// Visit a parse tree produced by the <c>callExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -502,7 +591,7 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- public virtual Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context) { return VisitChildren(context); }
+ public virtual Result VisitCallExpression([NotNull] CGrammarParser.CallExpressionContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>addExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
diff --git a/Compiler/gen/CGrammarLexer.cs b/Compiler/gen/CGrammarLexer.cs
index 8d6ed18..81b8945 100644
--- a/Compiler/gen/CGrammarLexer.cs
+++ b/Compiler/gen/CGrammarLexer.cs
@@ -39,7 +39,8 @@ public partial class CGrammarLexer : Lexer {
T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31,
T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38,
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;
+ T__45=46, T__46=47, T__47=48, T__48=49, T__49=50, ID=51, INT=52, WS=53,
+ COMMENT=54;
public static string[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
@@ -54,7 +55,8 @@ public partial class CGrammarLexer : Lexer {
"T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24",
"T__25", "T__26", "T__27", "T__28", "T__29", "T__30", "T__31", "T__32",
"T__33", "T__34", "T__35", "T__36", "T__37", "T__38", "T__39", "T__40",
- "T__41", "T__42", "T__43", "T__44", "ID", "INT", "WS", "COMMENT"
+ "T__41", "T__42", "T__43", "T__44", "T__45", "T__46", "T__47", "T__48",
+ "T__49", "ID", "INT", "WS", "COMMENT"
};
@@ -68,18 +70,19 @@ public partial class CGrammarLexer : Lexer {
}
private static readonly string[] _LiteralNames = {
- null, "'int'", "'('", "')'", "'{'", "'}'", "'return'", "';'", "'if'",
- "'else'", "'='", "'!'", "'~'", "'++'", "'--'", "'*'", "'/'", "'%'", "'+'",
- "'-'", "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'&'", "'|'", "'^'",
- "'<<'", "'>>'", "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='",
- "'&='", "'|='", "'^='", "'<<='", "'>>='", "','", "'?'", "':'"
+ null, "'int'", "'('", "','", "')'", "';'", "'{'", "'}'", "'return'", "'if'",
+ "'else'", "'for'", "'while'", "'do'", "'break'", "'continue'", "'='",
+ "'!'", "'~'", "'++'", "'--'", "'*'", "'/'", "'%'", "'+'", "'-'", "'<'",
+ "'>'", "'<='", "'>='", "'=='", "'!='", "'&'", "'|'", "'^'", "'<<'", "'>>'",
+ "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", "'|='",
+ "'^='", "'<<='", "'>>='", "'?'", "':'"
};
private static readonly string[] _SymbolicNames = {
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, null, null, null, "ID", "INT",
- "WS", "COMMENT"
+ null, null, null, null, null, null, null, null, null, null, null, null,
+ null, null, null, "ID", "INT", "WS", "COMMENT"
};
public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);
@@ -109,87 +112,99 @@ public partial class CGrammarLexer : Lexer {
}
}
private static int[] _serializedATN = {
- 4,0,49,255,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,
+ 4,0,54,293,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,
7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,
7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28,
7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,2,33,7,33,2,34,7,34,2,35,
7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,39,7,39,2,40,7,40,2,41,7,41,2,42,
- 7,42,2,43,7,43,2,44,7,44,2,45,7,45,2,46,7,46,2,47,7,47,2,48,7,48,1,0,1,
- 0,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,
- 1,6,1,6,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,
- 12,1,12,1,12,1,13,1,13,1,13,1,14,1,14,1,15,1,15,1,16,1,16,1,17,1,17,1,
- 18,1,18,1,19,1,19,1,20,1,20,1,21,1,21,1,21,1,22,1,22,1,22,1,23,1,23,1,
- 23,1,24,1,24,1,24,1,25,1,25,1,26,1,26,1,27,1,27,1,28,1,28,1,28,1,29,1,
- 29,1,29,1,30,1,30,1,30,1,31,1,31,1,31,1,32,1,32,1,32,1,33,1,33,1,33,1,
- 34,1,34,1,34,1,35,1,35,1,35,1,36,1,36,1,36,1,37,1,37,1,37,1,38,1,38,1,
- 38,1,39,1,39,1,39,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,41,1,42,1,42,1,
- 43,1,43,1,44,1,44,1,45,1,45,5,45,225,8,45,10,45,12,45,228,9,45,1,46,4,
- 46,231,8,46,11,46,12,46,232,1,47,4,47,236,8,47,11,47,12,47,237,1,47,1,
- 47,1,48,1,48,1,48,1,48,5,48,246,8,48,10,48,12,48,249,9,48,1,48,3,48,252,
- 8,48,1,48,1,48,1,247,0,49,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,83,42,85,43,87,44,89,45,91,46,
- 93,47,95,48,97,49,1,0,5,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,
- 122,1,0,48,57,3,0,9,10,13,13,32,32,1,1,10,10,258,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,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0,0,0,89,1,0,0,0,0,91,1,0,0,
- 0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0,0,1,99,1,0,0,0,3,103,1,0,0,0,5,
- 105,1,0,0,0,7,107,1,0,0,0,9,109,1,0,0,0,11,111,1,0,0,0,13,118,1,0,0,0,
- 15,120,1,0,0,0,17,123,1,0,0,0,19,128,1,0,0,0,21,130,1,0,0,0,23,132,1,0,
- 0,0,25,134,1,0,0,0,27,137,1,0,0,0,29,140,1,0,0,0,31,142,1,0,0,0,33,144,
- 1,0,0,0,35,146,1,0,0,0,37,148,1,0,0,0,39,150,1,0,0,0,41,152,1,0,0,0,43,
- 154,1,0,0,0,45,157,1,0,0,0,47,160,1,0,0,0,49,163,1,0,0,0,51,166,1,0,0,
- 0,53,168,1,0,0,0,55,170,1,0,0,0,57,172,1,0,0,0,59,175,1,0,0,0,61,178,1,
- 0,0,0,63,181,1,0,0,0,65,184,1,0,0,0,67,187,1,0,0,0,69,190,1,0,0,0,71,193,
- 1,0,0,0,73,196,1,0,0,0,75,199,1,0,0,0,77,202,1,0,0,0,79,205,1,0,0,0,81,
- 208,1,0,0,0,83,212,1,0,0,0,85,216,1,0,0,0,87,218,1,0,0,0,89,220,1,0,0,
- 0,91,222,1,0,0,0,93,230,1,0,0,0,95,235,1,0,0,0,97,241,1,0,0,0,99,100,5,
- 105,0,0,100,101,5,110,0,0,101,102,5,116,0,0,102,2,1,0,0,0,103,104,5,40,
- 0,0,104,4,1,0,0,0,105,106,5,41,0,0,106,6,1,0,0,0,107,108,5,123,0,0,108,
- 8,1,0,0,0,109,110,5,125,0,0,110,10,1,0,0,0,111,112,5,114,0,0,112,113,5,
- 101,0,0,113,114,5,116,0,0,114,115,5,117,0,0,115,116,5,114,0,0,116,117,
- 5,110,0,0,117,12,1,0,0,0,118,119,5,59,0,0,119,14,1,0,0,0,120,121,5,105,
- 0,0,121,122,5,102,0,0,122,16,1,0,0,0,123,124,5,101,0,0,124,125,5,108,0,
- 0,125,126,5,115,0,0,126,127,5,101,0,0,127,18,1,0,0,0,128,129,5,61,0,0,
- 129,20,1,0,0,0,130,131,5,33,0,0,131,22,1,0,0,0,132,133,5,126,0,0,133,24,
- 1,0,0,0,134,135,5,43,0,0,135,136,5,43,0,0,136,26,1,0,0,0,137,138,5,45,
- 0,0,138,139,5,45,0,0,139,28,1,0,0,0,140,141,5,42,0,0,141,30,1,0,0,0,142,
- 143,5,47,0,0,143,32,1,0,0,0,144,145,5,37,0,0,145,34,1,0,0,0,146,147,5,
- 43,0,0,147,36,1,0,0,0,148,149,5,45,0,0,149,38,1,0,0,0,150,151,5,60,0,0,
- 151,40,1,0,0,0,152,153,5,62,0,0,153,42,1,0,0,0,154,155,5,60,0,0,155,156,
- 5,61,0,0,156,44,1,0,0,0,157,158,5,62,0,0,158,159,5,61,0,0,159,46,1,0,0,
- 0,160,161,5,61,0,0,161,162,5,61,0,0,162,48,1,0,0,0,163,164,5,33,0,0,164,
- 165,5,61,0,0,165,50,1,0,0,0,166,167,5,38,0,0,167,52,1,0,0,0,168,169,5,
- 124,0,0,169,54,1,0,0,0,170,171,5,94,0,0,171,56,1,0,0,0,172,173,5,60,0,
- 0,173,174,5,60,0,0,174,58,1,0,0,0,175,176,5,62,0,0,176,177,5,62,0,0,177,
- 60,1,0,0,0,178,179,5,38,0,0,179,180,5,38,0,0,180,62,1,0,0,0,181,182,5,
- 124,0,0,182,183,5,124,0,0,183,64,1,0,0,0,184,185,5,42,0,0,185,186,5,61,
- 0,0,186,66,1,0,0,0,187,188,5,47,0,0,188,189,5,61,0,0,189,68,1,0,0,0,190,
- 191,5,37,0,0,191,192,5,61,0,0,192,70,1,0,0,0,193,194,5,43,0,0,194,195,
- 5,61,0,0,195,72,1,0,0,0,196,197,5,45,0,0,197,198,5,61,0,0,198,74,1,0,0,
- 0,199,200,5,38,0,0,200,201,5,61,0,0,201,76,1,0,0,0,202,203,5,124,0,0,203,
- 204,5,61,0,0,204,78,1,0,0,0,205,206,5,94,0,0,206,207,5,61,0,0,207,80,1,
- 0,0,0,208,209,5,60,0,0,209,210,5,60,0,0,210,211,5,61,0,0,211,82,1,0,0,
- 0,212,213,5,62,0,0,213,214,5,62,0,0,214,215,5,61,0,0,215,84,1,0,0,0,216,
- 217,5,44,0,0,217,86,1,0,0,0,218,219,5,63,0,0,219,88,1,0,0,0,220,221,5,
- 58,0,0,221,90,1,0,0,0,222,226,7,0,0,0,223,225,7,1,0,0,224,223,1,0,0,0,
- 225,228,1,0,0,0,226,224,1,0,0,0,226,227,1,0,0,0,227,92,1,0,0,0,228,226,
- 1,0,0,0,229,231,7,2,0,0,230,229,1,0,0,0,231,232,1,0,0,0,232,230,1,0,0,
- 0,232,233,1,0,0,0,233,94,1,0,0,0,234,236,7,3,0,0,235,234,1,0,0,0,236,237,
- 1,0,0,0,237,235,1,0,0,0,237,238,1,0,0,0,238,239,1,0,0,0,239,240,6,47,0,
- 0,240,96,1,0,0,0,241,242,5,47,0,0,242,243,5,47,0,0,243,247,1,0,0,0,244,
- 246,9,0,0,0,245,244,1,0,0,0,246,249,1,0,0,0,247,248,1,0,0,0,247,245,1,
- 0,0,0,248,251,1,0,0,0,249,247,1,0,0,0,250,252,7,4,0,0,251,250,1,0,0,0,
- 252,253,1,0,0,0,253,254,6,48,1,0,254,98,1,0,0,0,6,0,226,232,237,247,251,
- 2,6,0,0,0,1,0
+ 7,42,2,43,7,43,2,44,7,44,2,45,7,45,2,46,7,46,2,47,7,47,2,48,7,48,2,49,
+ 7,49,2,50,7,50,2,51,7,51,2,52,7,52,2,53,7,53,1,0,1,0,1,0,1,0,1,1,1,1,1,
+ 2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,8,
+ 1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,
+ 11,1,11,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,
+ 14,1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,16,1,16,1,17,1,17,1,18,1,18,1,
+ 18,1,19,1,19,1,19,1,20,1,20,1,21,1,21,1,22,1,22,1,23,1,23,1,24,1,24,1,
+ 25,1,25,1,26,1,26,1,27,1,27,1,27,1,28,1,28,1,28,1,29,1,29,1,29,1,30,1,
+ 30,1,30,1,31,1,31,1,32,1,32,1,33,1,33,1,34,1,34,1,34,1,35,1,35,1,35,1,
+ 36,1,36,1,36,1,37,1,37,1,37,1,38,1,38,1,38,1,39,1,39,1,39,1,40,1,40,1,
+ 40,1,41,1,41,1,41,1,42,1,42,1,42,1,43,1,43,1,43,1,44,1,44,1,44,1,45,1,
+ 45,1,45,1,46,1,46,1,46,1,46,1,47,1,47,1,47,1,47,1,48,1,48,1,49,1,49,1,
+ 50,1,50,5,50,263,8,50,10,50,12,50,266,9,50,1,51,4,51,269,8,51,11,51,12,
+ 51,270,1,52,4,52,274,8,52,11,52,12,52,275,1,52,1,52,1,53,1,53,1,53,1,53,
+ 5,53,284,8,53,10,53,12,53,287,9,53,1,53,3,53,290,8,53,1,53,1,53,1,285,
+ 0,54,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,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49,99,
+ 50,101,51,103,52,105,53,107,54,1,0,5,3,0,65,90,95,95,97,122,4,0,48,57,
+ 65,90,95,95,97,122,1,0,48,57,3,0,9,10,13,13,32,32,1,1,10,10,296,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,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0,0,0,89,1,0,0,
+ 0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0,0,0,99,1,0,0,0,0,101,
+ 1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,107,1,0,0,0,1,109,1,0,0,0,3,113,
+ 1,0,0,0,5,115,1,0,0,0,7,117,1,0,0,0,9,119,1,0,0,0,11,121,1,0,0,0,13,123,
+ 1,0,0,0,15,125,1,0,0,0,17,132,1,0,0,0,19,135,1,0,0,0,21,140,1,0,0,0,23,
+ 144,1,0,0,0,25,150,1,0,0,0,27,153,1,0,0,0,29,159,1,0,0,0,31,168,1,0,0,
+ 0,33,170,1,0,0,0,35,172,1,0,0,0,37,174,1,0,0,0,39,177,1,0,0,0,41,180,1,
+ 0,0,0,43,182,1,0,0,0,45,184,1,0,0,0,47,186,1,0,0,0,49,188,1,0,0,0,51,190,
+ 1,0,0,0,53,192,1,0,0,0,55,194,1,0,0,0,57,197,1,0,0,0,59,200,1,0,0,0,61,
+ 203,1,0,0,0,63,206,1,0,0,0,65,208,1,0,0,0,67,210,1,0,0,0,69,212,1,0,0,
+ 0,71,215,1,0,0,0,73,218,1,0,0,0,75,221,1,0,0,0,77,224,1,0,0,0,79,227,1,
+ 0,0,0,81,230,1,0,0,0,83,233,1,0,0,0,85,236,1,0,0,0,87,239,1,0,0,0,89,242,
+ 1,0,0,0,91,245,1,0,0,0,93,248,1,0,0,0,95,252,1,0,0,0,97,256,1,0,0,0,99,
+ 258,1,0,0,0,101,260,1,0,0,0,103,268,1,0,0,0,105,273,1,0,0,0,107,279,1,
+ 0,0,0,109,110,5,105,0,0,110,111,5,110,0,0,111,112,5,116,0,0,112,2,1,0,
+ 0,0,113,114,5,40,0,0,114,4,1,0,0,0,115,116,5,44,0,0,116,6,1,0,0,0,117,
+ 118,5,41,0,0,118,8,1,0,0,0,119,120,5,59,0,0,120,10,1,0,0,0,121,122,5,123,
+ 0,0,122,12,1,0,0,0,123,124,5,125,0,0,124,14,1,0,0,0,125,126,5,114,0,0,
+ 126,127,5,101,0,0,127,128,5,116,0,0,128,129,5,117,0,0,129,130,5,114,0,
+ 0,130,131,5,110,0,0,131,16,1,0,0,0,132,133,5,105,0,0,133,134,5,102,0,0,
+ 134,18,1,0,0,0,135,136,5,101,0,0,136,137,5,108,0,0,137,138,5,115,0,0,138,
+ 139,5,101,0,0,139,20,1,0,0,0,140,141,5,102,0,0,141,142,5,111,0,0,142,143,
+ 5,114,0,0,143,22,1,0,0,0,144,145,5,119,0,0,145,146,5,104,0,0,146,147,5,
+ 105,0,0,147,148,5,108,0,0,148,149,5,101,0,0,149,24,1,0,0,0,150,151,5,100,
+ 0,0,151,152,5,111,0,0,152,26,1,0,0,0,153,154,5,98,0,0,154,155,5,114,0,
+ 0,155,156,5,101,0,0,156,157,5,97,0,0,157,158,5,107,0,0,158,28,1,0,0,0,
+ 159,160,5,99,0,0,160,161,5,111,0,0,161,162,5,110,0,0,162,163,5,116,0,0,
+ 163,164,5,105,0,0,164,165,5,110,0,0,165,166,5,117,0,0,166,167,5,101,0,
+ 0,167,30,1,0,0,0,168,169,5,61,0,0,169,32,1,0,0,0,170,171,5,33,0,0,171,
+ 34,1,0,0,0,172,173,5,126,0,0,173,36,1,0,0,0,174,175,5,43,0,0,175,176,5,
+ 43,0,0,176,38,1,0,0,0,177,178,5,45,0,0,178,179,5,45,0,0,179,40,1,0,0,0,
+ 180,181,5,42,0,0,181,42,1,0,0,0,182,183,5,47,0,0,183,44,1,0,0,0,184,185,
+ 5,37,0,0,185,46,1,0,0,0,186,187,5,43,0,0,187,48,1,0,0,0,188,189,5,45,0,
+ 0,189,50,1,0,0,0,190,191,5,60,0,0,191,52,1,0,0,0,192,193,5,62,0,0,193,
+ 54,1,0,0,0,194,195,5,60,0,0,195,196,5,61,0,0,196,56,1,0,0,0,197,198,5,
+ 62,0,0,198,199,5,61,0,0,199,58,1,0,0,0,200,201,5,61,0,0,201,202,5,61,0,
+ 0,202,60,1,0,0,0,203,204,5,33,0,0,204,205,5,61,0,0,205,62,1,0,0,0,206,
+ 207,5,38,0,0,207,64,1,0,0,0,208,209,5,124,0,0,209,66,1,0,0,0,210,211,5,
+ 94,0,0,211,68,1,0,0,0,212,213,5,60,0,0,213,214,5,60,0,0,214,70,1,0,0,0,
+ 215,216,5,62,0,0,216,217,5,62,0,0,217,72,1,0,0,0,218,219,5,38,0,0,219,
+ 220,5,38,0,0,220,74,1,0,0,0,221,222,5,124,0,0,222,223,5,124,0,0,223,76,
+ 1,0,0,0,224,225,5,42,0,0,225,226,5,61,0,0,226,78,1,0,0,0,227,228,5,47,
+ 0,0,228,229,5,61,0,0,229,80,1,0,0,0,230,231,5,37,0,0,231,232,5,61,0,0,
+ 232,82,1,0,0,0,233,234,5,43,0,0,234,235,5,61,0,0,235,84,1,0,0,0,236,237,
+ 5,45,0,0,237,238,5,61,0,0,238,86,1,0,0,0,239,240,5,38,0,0,240,241,5,61,
+ 0,0,241,88,1,0,0,0,242,243,5,124,0,0,243,244,5,61,0,0,244,90,1,0,0,0,245,
+ 246,5,94,0,0,246,247,5,61,0,0,247,92,1,0,0,0,248,249,5,60,0,0,249,250,
+ 5,60,0,0,250,251,5,61,0,0,251,94,1,0,0,0,252,253,5,62,0,0,253,254,5,62,
+ 0,0,254,255,5,61,0,0,255,96,1,0,0,0,256,257,5,63,0,0,257,98,1,0,0,0,258,
+ 259,5,58,0,0,259,100,1,0,0,0,260,264,7,0,0,0,261,263,7,1,0,0,262,261,1,
+ 0,0,0,263,266,1,0,0,0,264,262,1,0,0,0,264,265,1,0,0,0,265,102,1,0,0,0,
+ 266,264,1,0,0,0,267,269,7,2,0,0,268,267,1,0,0,0,269,270,1,0,0,0,270,268,
+ 1,0,0,0,270,271,1,0,0,0,271,104,1,0,0,0,272,274,7,3,0,0,273,272,1,0,0,
+ 0,274,275,1,0,0,0,275,273,1,0,0,0,275,276,1,0,0,0,276,277,1,0,0,0,277,
+ 278,6,52,0,0,278,106,1,0,0,0,279,280,5,47,0,0,280,281,5,47,0,0,281,285,
+ 1,0,0,0,282,284,9,0,0,0,283,282,1,0,0,0,284,287,1,0,0,0,285,286,1,0,0,
+ 0,285,283,1,0,0,0,286,289,1,0,0,0,287,285,1,0,0,0,288,290,7,4,0,0,289,
+ 288,1,0,0,0,290,291,1,0,0,0,291,292,6,53,1,0,292,108,1,0,0,0,6,0,264,270,
+ 275,285,289,2,6,0,0,0,1,0
};
public static readonly ATN _ATN =
diff --git a/Compiler/gen/CGrammarLexer.interp b/Compiler/gen/CGrammarLexer.interp
index faa747d..474d0f9 100644
--- a/Compiler/gen/CGrammarLexer.interp
+++ b/Compiler/gen/CGrammarLexer.interp
@@ -2,13 +2,19 @@ token literal names:
null
'int'
'('
+','
')'
+';'
'{'
'}'
'return'
-';'
'if'
'else'
+'for'
+'while'
+'do'
+'break'
+'continue'
'='
'!'
'~'
@@ -42,7 +48,6 @@ null
'^='
'<<='
'>>='
-','
'?'
':'
null
@@ -97,6 +102,11 @@ null
null
null
null
+null
+null
+null
+null
+null
ID
INT
WS
@@ -148,6 +158,11 @@ T__41
T__42
T__43
T__44
+T__45
+T__46
+T__47
+T__48
+T__49
ID
INT
WS
@@ -161,4 +176,4 @@ mode names:
DEFAULT_MODE
atn:
-[4, 0, 49, 255, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 1, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 1, 36, 1, 36, 1, 36, 1, 37, 1, 37, 1, 37, 1, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 40, 1, 40, 1, 41, 1, 41, 1, 41, 1, 41, 1, 42, 1, 42, 1, 43, 1, 43, 1, 44, 1, 44, 1, 45, 1, 45, 5, 45, 225, 8, 45, 10, 45, 12, 45, 228, 9, 45, 1, 46, 4, 46, 231, 8, 46, 11, 46, 12, 46, 232, 1, 47, 4, 47, 236, 8, 47, 11, 47, 12, 47, 237, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 5, 48, 246, 8, 48, 10, 48, 12, 48, 249, 9, 48, 1, 48, 3, 48, 252, 8, 48, 1, 48, 1, 48, 1, 247, 0, 49, 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, 83, 42, 85, 43, 87, 44, 89, 45, 91, 46, 93, 47, 95, 48, 97, 49, 1, 0, 5, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 48, 57, 3, 0, 9, 10, 13, 13, 32, 32, 1, 1, 10, 10, 258, 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, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 95, 1, 0, 0, 0, 0, 97, 1, 0, 0, 0, 1, 99, 1, 0, 0, 0, 3, 103, 1, 0, 0, 0, 5, 105, 1, 0, 0, 0, 7, 107, 1, 0, 0, 0, 9, 109, 1, 0, 0, 0, 11, 111, 1, 0, 0, 0, 13, 118, 1, 0, 0, 0, 15, 120, 1, 0, 0, 0, 17, 123, 1, 0, 0, 0, 19, 128, 1, 0, 0, 0, 21, 130, 1, 0, 0, 0, 23, 132, 1, 0, 0, 0, 25, 134, 1, 0, 0, 0, 27, 137, 1, 0, 0, 0, 29, 140, 1, 0, 0, 0, 31, 142, 1, 0, 0, 0, 33, 144, 1, 0, 0, 0, 35, 146, 1, 0, 0, 0, 37, 148, 1, 0, 0, 0, 39, 150, 1, 0, 0, 0, 41, 152, 1, 0, 0, 0, 43, 154, 1, 0, 0, 0, 45, 157, 1, 0, 0, 0, 47, 160, 1, 0, 0, 0, 49, 163, 1, 0, 0, 0, 51, 166, 1, 0, 0, 0, 53, 168, 1, 0, 0, 0, 55, 170, 1, 0, 0, 0, 57, 172, 1, 0, 0, 0, 59, 175, 1, 0, 0, 0, 61, 178, 1, 0, 0, 0, 63, 181, 1, 0, 0, 0, 65, 184, 1, 0, 0, 0, 67, 187, 1, 0, 0, 0, 69, 190, 1, 0, 0, 0, 71, 193, 1, 0, 0, 0, 73, 196, 1, 0, 0, 0, 75, 199, 1, 0, 0, 0, 77, 202, 1, 0, 0, 0, 79, 205, 1, 0, 0, 0, 81, 208, 1, 0, 0, 0, 83, 212, 1, 0, 0, 0, 85, 216, 1, 0, 0, 0, 87, 218, 1, 0, 0, 0, 89, 220, 1, 0, 0, 0, 91, 222, 1, 0, 0, 0, 93, 230, 1, 0, 0, 0, 95, 235, 1, 0, 0, 0, 97, 241, 1, 0, 0, 0, 99, 100, 5, 105, 0, 0, 100, 101, 5, 110, 0, 0, 101, 102, 5, 116, 0, 0, 102, 2, 1, 0, 0, 0, 103, 104, 5, 40, 0, 0, 104, 4, 1, 0, 0, 0, 105, 106, 5, 41, 0, 0, 106, 6, 1, 0, 0, 0, 107, 108, 5, 123, 0, 0, 108, 8, 1, 0, 0, 0, 109, 110, 5, 125, 0, 0, 110, 10, 1, 0, 0, 0, 111, 112, 5, 114, 0, 0, 112, 113, 5, 101, 0, 0, 113, 114, 5, 116, 0, 0, 114, 115, 5, 117, 0, 0, 115, 116, 5, 114, 0, 0, 116, 117, 5, 110, 0, 0, 117, 12, 1, 0, 0, 0, 118, 119, 5, 59, 0, 0, 119, 14, 1, 0, 0, 0, 120, 121, 5, 105, 0, 0, 121, 122, 5, 102, 0, 0, 122, 16, 1, 0, 0, 0, 123, 124, 5, 101, 0, 0, 124, 125, 5, 108, 0, 0, 125, 126, 5, 115, 0, 0, 126, 127, 5, 101, 0, 0, 127, 18, 1, 0, 0, 0, 128, 129, 5, 61, 0, 0, 129, 20, 1, 0, 0, 0, 130, 131, 5, 33, 0, 0, 131, 22, 1, 0, 0, 0, 132, 133, 5, 126, 0, 0, 133, 24, 1, 0, 0, 0, 134, 135, 5, 43, 0, 0, 135, 136, 5, 43, 0, 0, 136, 26, 1, 0, 0, 0, 137, 138, 5, 45, 0, 0, 138, 139, 5, 45, 0, 0, 139, 28, 1, 0, 0, 0, 140, 141, 5, 42, 0, 0, 141, 30, 1, 0, 0, 0, 142, 143, 5, 47, 0, 0, 143, 32, 1, 0, 0, 0, 144, 145, 5, 37, 0, 0, 145, 34, 1, 0, 0, 0, 146, 147, 5, 43, 0, 0, 147, 36, 1, 0, 0, 0, 148, 149, 5, 45, 0, 0, 149, 38, 1, 0, 0, 0, 150, 151, 5, 60, 0, 0, 151, 40, 1, 0, 0, 0, 152, 153, 5, 62, 0, 0, 153, 42, 1, 0, 0, 0, 154, 155, 5, 60, 0, 0, 155, 156, 5, 61, 0, 0, 156, 44, 1, 0, 0, 0, 157, 158, 5, 62, 0, 0, 158, 159, 5, 61, 0, 0, 159, 46, 1, 0, 0, 0, 160, 161, 5, 61, 0, 0, 161, 162, 5, 61, 0, 0, 162, 48, 1, 0, 0, 0, 163, 164, 5, 33, 0, 0, 164, 165, 5, 61, 0, 0, 165, 50, 1, 0, 0, 0, 166, 167, 5, 38, 0, 0, 167, 52, 1, 0, 0, 0, 168, 169, 5, 124, 0, 0, 169, 54, 1, 0, 0, 0, 170, 171, 5, 94, 0, 0, 171, 56, 1, 0, 0, 0, 172, 173, 5, 60, 0, 0, 173, 174, 5, 60, 0, 0, 174, 58, 1, 0, 0, 0, 175, 176, 5, 62, 0, 0, 176, 177, 5, 62, 0, 0, 177, 60, 1, 0, 0, 0, 178, 179, 5, 38, 0, 0, 179, 180, 5, 38, 0, 0, 180, 62, 1, 0, 0, 0, 181, 182, 5, 124, 0, 0, 182, 183, 5, 124, 0, 0, 183, 64, 1, 0, 0, 0, 184, 185, 5, 42, 0, 0, 185, 186, 5, 61, 0, 0, 186, 66, 1, 0, 0, 0, 187, 188, 5, 47, 0, 0, 188, 189, 5, 61, 0, 0, 189, 68, 1, 0, 0, 0, 190, 191, 5, 37, 0, 0, 191, 192, 5, 61, 0, 0, 192, 70, 1, 0, 0, 0, 193, 194, 5, 43, 0, 0, 194, 195, 5, 61, 0, 0, 195, 72, 1, 0, 0, 0, 196, 197, 5, 45, 0, 0, 197, 198, 5, 61, 0, 0, 198, 74, 1, 0, 0, 0, 199, 200, 5, 38, 0, 0, 200, 201, 5, 61, 0, 0, 201, 76, 1, 0, 0, 0, 202, 203, 5, 124, 0, 0, 203, 204, 5, 61, 0, 0, 204, 78, 1, 0, 0, 0, 205, 206, 5, 94, 0, 0, 206, 207, 5, 61, 0, 0, 207, 80, 1, 0, 0, 0, 208, 209, 5, 60, 0, 0, 209, 210, 5, 60, 0, 0, 210, 211, 5, 61, 0, 0, 211, 82, 1, 0, 0, 0, 212, 213, 5, 62, 0, 0, 213, 214, 5, 62, 0, 0, 214, 215, 5, 61, 0, 0, 215, 84, 1, 0, 0, 0, 216, 217, 5, 44, 0, 0, 217, 86, 1, 0, 0, 0, 218, 219, 5, 63, 0, 0, 219, 88, 1, 0, 0, 0, 220, 221, 5, 58, 0, 0, 221, 90, 1, 0, 0, 0, 222, 226, 7, 0, 0, 0, 223, 225, 7, 1, 0, 0, 224, 223, 1, 0, 0, 0, 225, 228, 1, 0, 0, 0, 226, 224, 1, 0, 0, 0, 226, 227, 1, 0, 0, 0, 227, 92, 1, 0, 0, 0, 228, 226, 1, 0, 0, 0, 229, 231, 7, 2, 0, 0, 230, 229, 1, 0, 0, 0, 231, 232, 1, 0, 0, 0, 232, 230, 1, 0, 0, 0, 232, 233, 1, 0, 0, 0, 233, 94, 1, 0, 0, 0, 234, 236, 7, 3, 0, 0, 235, 234, 1, 0, 0, 0, 236, 237, 1, 0, 0, 0, 237, 235, 1, 0, 0, 0, 237, 238, 1, 0, 0, 0, 238, 239, 1, 0, 0, 0, 239, 240, 6, 47, 0, 0, 240, 96, 1, 0, 0, 0, 241, 242, 5, 47, 0, 0, 242, 243, 5, 47, 0, 0, 243, 247, 1, 0, 0, 0, 244, 246, 9, 0, 0, 0, 245, 244, 1, 0, 0, 0, 246, 249, 1, 0, 0, 0, 247, 248, 1, 0, 0, 0, 247, 245, 1, 0, 0, 0, 248, 251, 1, 0, 0, 0, 249, 247, 1, 0, 0, 0, 250, 252, 7, 4, 0, 0, 251, 250, 1, 0, 0, 0, 252, 253, 1, 0, 0, 0, 253, 254, 6, 48, 1, 0, 254, 98, 1, 0, 0, 0, 6, 0, 226, 232, 237, 247, 251, 2, 6, 0, 0, 0, 1, 0] \ No newline at end of file
+[4, 0, 54, 293, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 1, 36, 1, 36, 1, 36, 1, 37, 1, 37, 1, 37, 1, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 40, 1, 41, 1, 41, 1, 41, 1, 42, 1, 42, 1, 42, 1, 43, 1, 43, 1, 43, 1, 44, 1, 44, 1, 44, 1, 45, 1, 45, 1, 45, 1, 46, 1, 46, 1, 46, 1, 46, 1, 47, 1, 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 49, 1, 49, 1, 50, 1, 50, 5, 50, 263, 8, 50, 10, 50, 12, 50, 266, 9, 50, 1, 51, 4, 51, 269, 8, 51, 11, 51, 12, 51, 270, 1, 52, 4, 52, 274, 8, 52, 11, 52, 12, 52, 275, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 53, 5, 53, 284, 8, 53, 10, 53, 12, 53, 287, 9, 53, 1, 53, 3, 53, 290, 8, 53, 1, 53, 1, 53, 1, 285, 0, 54, 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, 83, 42, 85, 43, 87, 44, 89, 45, 91, 46, 93, 47, 95, 48, 97, 49, 99, 50, 101, 51, 103, 52, 105, 53, 107, 54, 1, 0, 5, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 48, 57, 3, 0, 9, 10, 13, 13, 32, 32, 1, 1, 10, 10, 296, 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, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 95, 1, 0, 0, 0, 0, 97, 1, 0, 0, 0, 0, 99, 1, 0, 0, 0, 0, 101, 1, 0, 0, 0, 0, 103, 1, 0, 0, 0, 0, 105, 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 1, 109, 1, 0, 0, 0, 3, 113, 1, 0, 0, 0, 5, 115, 1, 0, 0, 0, 7, 117, 1, 0, 0, 0, 9, 119, 1, 0, 0, 0, 11, 121, 1, 0, 0, 0, 13, 123, 1, 0, 0, 0, 15, 125, 1, 0, 0, 0, 17, 132, 1, 0, 0, 0, 19, 135, 1, 0, 0, 0, 21, 140, 1, 0, 0, 0, 23, 144, 1, 0, 0, 0, 25, 150, 1, 0, 0, 0, 27, 153, 1, 0, 0, 0, 29, 159, 1, 0, 0, 0, 31, 168, 1, 0, 0, 0, 33, 170, 1, 0, 0, 0, 35, 172, 1, 0, 0, 0, 37, 174, 1, 0, 0, 0, 39, 177, 1, 0, 0, 0, 41, 180, 1, 0, 0, 0, 43, 182, 1, 0, 0, 0, 45, 184, 1, 0, 0, 0, 47, 186, 1, 0, 0, 0, 49, 188, 1, 0, 0, 0, 51, 190, 1, 0, 0, 0, 53, 192, 1, 0, 0, 0, 55, 194, 1, 0, 0, 0, 57, 197, 1, 0, 0, 0, 59, 200, 1, 0, 0, 0, 61, 203, 1, 0, 0, 0, 63, 206, 1, 0, 0, 0, 65, 208, 1, 0, 0, 0, 67, 210, 1, 0, 0, 0, 69, 212, 1, 0, 0, 0, 71, 215, 1, 0, 0, 0, 73, 218, 1, 0, 0, 0, 75, 221, 1, 0, 0, 0, 77, 224, 1, 0, 0, 0, 79, 227, 1, 0, 0, 0, 81, 230, 1, 0, 0, 0, 83, 233, 1, 0, 0, 0, 85, 236, 1, 0, 0, 0, 87, 239, 1, 0, 0, 0, 89, 242, 1, 0, 0, 0, 91, 245, 1, 0, 0, 0, 93, 248, 1, 0, 0, 0, 95, 252, 1, 0, 0, 0, 97, 256, 1, 0, 0, 0, 99, 258, 1, 0, 0, 0, 101, 260, 1, 0, 0, 0, 103, 268, 1, 0, 0, 0, 105, 273, 1, 0, 0, 0, 107, 279, 1, 0, 0, 0, 109, 110, 5, 105, 0, 0, 110, 111, 5, 110, 0, 0, 111, 112, 5, 116, 0, 0, 112, 2, 1, 0, 0, 0, 113, 114, 5, 40, 0, 0, 114, 4, 1, 0, 0, 0, 115, 116, 5, 44, 0, 0, 116, 6, 1, 0, 0, 0, 117, 118, 5, 41, 0, 0, 118, 8, 1, 0, 0, 0, 119, 120, 5, 59, 0, 0, 120, 10, 1, 0, 0, 0, 121, 122, 5, 123, 0, 0, 122, 12, 1, 0, 0, 0, 123, 124, 5, 125, 0, 0, 124, 14, 1, 0, 0, 0, 125, 126, 5, 114, 0, 0, 126, 127, 5, 101, 0, 0, 127, 128, 5, 116, 0, 0, 128, 129, 5, 117, 0, 0, 129, 130, 5, 114, 0, 0, 130, 131, 5, 110, 0, 0, 131, 16, 1, 0, 0, 0, 132, 133, 5, 105, 0, 0, 133, 134, 5, 102, 0, 0, 134, 18, 1, 0, 0, 0, 135, 136, 5, 101, 0, 0, 136, 137, 5, 108, 0, 0, 137, 138, 5, 115, 0, 0, 138, 139, 5, 101, 0, 0, 139, 20, 1, 0, 0, 0, 140, 141, 5, 102, 0, 0, 141, 142, 5, 111, 0, 0, 142, 143, 5, 114, 0, 0, 143, 22, 1, 0, 0, 0, 144, 145, 5, 119, 0, 0, 145, 146, 5, 104, 0, 0, 146, 147, 5, 105, 0, 0, 147, 148, 5, 108, 0, 0, 148, 149, 5, 101, 0, 0, 149, 24, 1, 0, 0, 0, 150, 151, 5, 100, 0, 0, 151, 152, 5, 111, 0, 0, 152, 26, 1, 0, 0, 0, 153, 154, 5, 98, 0, 0, 154, 155, 5, 114, 0, 0, 155, 156, 5, 101, 0, 0, 156, 157, 5, 97, 0, 0, 157, 158, 5, 107, 0, 0, 158, 28, 1, 0, 0, 0, 159, 160, 5, 99, 0, 0, 160, 161, 5, 111, 0, 0, 161, 162, 5, 110, 0, 0, 162, 163, 5, 116, 0, 0, 163, 164, 5, 105, 0, 0, 164, 165, 5, 110, 0, 0, 165, 166, 5, 117, 0, 0, 166, 167, 5, 101, 0, 0, 167, 30, 1, 0, 0, 0, 168, 169, 5, 61, 0, 0, 169, 32, 1, 0, 0, 0, 170, 171, 5, 33, 0, 0, 171, 34, 1, 0, 0, 0, 172, 173, 5, 126, 0, 0, 173, 36, 1, 0, 0, 0, 174, 175, 5, 43, 0, 0, 175, 176, 5, 43, 0, 0, 176, 38, 1, 0, 0, 0, 177, 178, 5, 45, 0, 0, 178, 179, 5, 45, 0, 0, 179, 40, 1, 0, 0, 0, 180, 181, 5, 42, 0, 0, 181, 42, 1, 0, 0, 0, 182, 183, 5, 47, 0, 0, 183, 44, 1, 0, 0, 0, 184, 185, 5, 37, 0, 0, 185, 46, 1, 0, 0, 0, 186, 187, 5, 43, 0, 0, 187, 48, 1, 0, 0, 0, 188, 189, 5, 45, 0, 0, 189, 50, 1, 0, 0, 0, 190, 191, 5, 60, 0, 0, 191, 52, 1, 0, 0, 0, 192, 193, 5, 62, 0, 0, 193, 54, 1, 0, 0, 0, 194, 195, 5, 60, 0, 0, 195, 196, 5, 61, 0, 0, 196, 56, 1, 0, 0, 0, 197, 198, 5, 62, 0, 0, 198, 199, 5, 61, 0, 0, 199, 58, 1, 0, 0, 0, 200, 201, 5, 61, 0, 0, 201, 202, 5, 61, 0, 0, 202, 60, 1, 0, 0, 0, 203, 204, 5, 33, 0, 0, 204, 205, 5, 61, 0, 0, 205, 62, 1, 0, 0, 0, 206, 207, 5, 38, 0, 0, 207, 64, 1, 0, 0, 0, 208, 209, 5, 124, 0, 0, 209, 66, 1, 0, 0, 0, 210, 211, 5, 94, 0, 0, 211, 68, 1, 0, 0, 0, 212, 213, 5, 60, 0, 0, 213, 214, 5, 60, 0, 0, 214, 70, 1, 0, 0, 0, 215, 216, 5, 62, 0, 0, 216, 217, 5, 62, 0, 0, 217, 72, 1, 0, 0, 0, 218, 219, 5, 38, 0, 0, 219, 220, 5, 38, 0, 0, 220, 74, 1, 0, 0, 0, 221, 222, 5, 124, 0, 0, 222, 223, 5, 124, 0, 0, 223, 76, 1, 0, 0, 0, 224, 225, 5, 42, 0, 0, 225, 226, 5, 61, 0, 0, 226, 78, 1, 0, 0, 0, 227, 228, 5, 47, 0, 0, 228, 229, 5, 61, 0, 0, 229, 80, 1, 0, 0, 0, 230, 231, 5, 37, 0, 0, 231, 232, 5, 61, 0, 0, 232, 82, 1, 0, 0, 0, 233, 234, 5, 43, 0, 0, 234, 235, 5, 61, 0, 0, 235, 84, 1, 0, 0, 0, 236, 237, 5, 45, 0, 0, 237, 238, 5, 61, 0, 0, 238, 86, 1, 0, 0, 0, 239, 240, 5, 38, 0, 0, 240, 241, 5, 61, 0, 0, 241, 88, 1, 0, 0, 0, 242, 243, 5, 124, 0, 0, 243, 244, 5, 61, 0, 0, 244, 90, 1, 0, 0, 0, 245, 246, 5, 94, 0, 0, 246, 247, 5, 61, 0, 0, 247, 92, 1, 0, 0, 0, 248, 249, 5, 60, 0, 0, 249, 250, 5, 60, 0, 0, 250, 251, 5, 61, 0, 0, 251, 94, 1, 0, 0, 0, 252, 253, 5, 62, 0, 0, 253, 254, 5, 62, 0, 0, 254, 255, 5, 61, 0, 0, 255, 96, 1, 0, 0, 0, 256, 257, 5, 63, 0, 0, 257, 98, 1, 0, 0, 0, 258, 259, 5, 58, 0, 0, 259, 100, 1, 0, 0, 0, 260, 264, 7, 0, 0, 0, 261, 263, 7, 1, 0, 0, 262, 261, 1, 0, 0, 0, 263, 266, 1, 0, 0, 0, 264, 262, 1, 0, 0, 0, 264, 265, 1, 0, 0, 0, 265, 102, 1, 0, 0, 0, 266, 264, 1, 0, 0, 0, 267, 269, 7, 2, 0, 0, 268, 267, 1, 0, 0, 0, 269, 270, 1, 0, 0, 0, 270, 268, 1, 0, 0, 0, 270, 271, 1, 0, 0, 0, 271, 104, 1, 0, 0, 0, 272, 274, 7, 3, 0, 0, 273, 272, 1, 0, 0, 0, 274, 275, 1, 0, 0, 0, 275, 273, 1, 0, 0, 0, 275, 276, 1, 0, 0, 0, 276, 277, 1, 0, 0, 0, 277, 278, 6, 52, 0, 0, 278, 106, 1, 0, 0, 0, 279, 280, 5, 47, 0, 0, 280, 281, 5, 47, 0, 0, 281, 285, 1, 0, 0, 0, 282, 284, 9, 0, 0, 0, 283, 282, 1, 0, 0, 0, 284, 287, 1, 0, 0, 0, 285, 286, 1, 0, 0, 0, 285, 283, 1, 0, 0, 0, 286, 289, 1, 0, 0, 0, 287, 285, 1, 0, 0, 0, 288, 290, 7, 4, 0, 0, 289, 288, 1, 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 292, 6, 53, 1, 0, 292, 108, 1, 0, 0, 0, 6, 0, 264, 270, 275, 285, 289, 2, 6, 0, 0, 0, 1, 0] \ No newline at end of file
diff --git a/Compiler/gen/CGrammarLexer.tokens b/Compiler/gen/CGrammarLexer.tokens
index 7556128..0da6b57 100644
--- a/Compiler/gen/CGrammarLexer.tokens
+++ b/Compiler/gen/CGrammarLexer.tokens
@@ -43,52 +43,62 @@ T__41=42
T__42=43
T__43=44
T__44=45
-ID=46
-INT=47
-WS=48
-COMMENT=49
+T__45=46
+T__46=47
+T__47=48
+T__48=49
+T__49=50
+ID=51
+INT=52
+WS=53
+COMMENT=54
'int'=1
'('=2
-')'=3
-'{'=4
-'}'=5
-'return'=6
-';'=7
-'if'=8
-'else'=9
-'='=10
-'!'=11
-'~'=12
-'++'=13
-'--'=14
-'*'=15
-'/'=16
-'%'=17
-'+'=18
-'-'=19
-'<'=20
-'>'=21
-'<='=22
-'>='=23
-'=='=24
-'!='=25
-'&'=26
-'|'=27
-'^'=28
-'<<'=29
-'>>'=30
-'&&'=31
-'||'=32
-'*='=33
-'/='=34
-'%='=35
-'+='=36
-'-='=37
-'&='=38
-'|='=39
-'^='=40
-'<<='=41
-'>>='=42
-','=43
-'?'=44
-':'=45
+','=3
+')'=4
+';'=5
+'{'=6
+'}'=7
+'return'=8
+'if'=9
+'else'=10
+'for'=11
+'while'=12
+'do'=13
+'break'=14
+'continue'=15
+'='=16
+'!'=17
+'~'=18
+'++'=19
+'--'=20
+'*'=21
+'/'=22
+'%'=23
+'+'=24
+'-'=25
+'<'=26
+'>'=27
+'<='=28
+'>='=29
+'=='=30
+'!='=31
+'&'=32
+'|'=33
+'^'=34
+'<<'=35
+'>>'=36
+'&&'=37
+'||'=38
+'*='=39
+'/='=40
+'%='=41
+'+='=42
+'-='=43
+'&='=44
+'|='=45
+'^='=46
+'<<='=47
+'>>='=48
+'?'=49
+':'=50
diff --git a/Compiler/gen/CGrammarParser.cs b/Compiler/gen/CGrammarParser.cs
index d858fbe..184d28e 100644
--- a/Compiler/gen/CGrammarParser.cs
+++ b/Compiler/gen/CGrammarParser.cs
@@ -42,7 +42,8 @@ public partial class CGrammarParser : Parser {
T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31,
T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38,
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;
+ T__45=46, T__46=47, T__47=48, T__48=49, T__49=50, ID=51, INT=52, WS=53,
+ COMMENT=54;
public const int
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,
@@ -53,18 +54,19 @@ public partial class CGrammarParser : Parser {
};
private static readonly string[] _LiteralNames = {
- null, "'int'", "'('", "')'", "'{'", "'}'", "'return'", "';'", "'if'",
- "'else'", "'='", "'!'", "'~'", "'++'", "'--'", "'*'", "'/'", "'%'", "'+'",
- "'-'", "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'&'", "'|'", "'^'",
- "'<<'", "'>>'", "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='",
- "'&='", "'|='", "'^='", "'<<='", "'>>='", "','", "'?'", "':'"
+ null, "'int'", "'('", "','", "')'", "';'", "'{'", "'}'", "'return'", "'if'",
+ "'else'", "'for'", "'while'", "'do'", "'break'", "'continue'", "'='",
+ "'!'", "'~'", "'++'", "'--'", "'*'", "'/'", "'%'", "'+'", "'-'", "'<'",
+ "'>'", "'<='", "'>='", "'=='", "'!='", "'&'", "'|'", "'^'", "'<<'", "'>>'",
+ "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", "'|='",
+ "'^='", "'<<='", "'>>='", "'?'", "':'"
};
private static readonly string[] _SymbolicNames = {
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, null, null, null, "ID", "INT",
- "WS", "COMMENT"
+ null, null, null, null, null, null, null, null, null, null, null, null,
+ null, null, null, "ID", "INT", "WS", "COMMENT"
};
public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);
@@ -98,11 +100,14 @@ public partial class CGrammarParser : Parser {
Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
}
- public partial class ProgramContext : ParserRuleContext {
- [System.Diagnostics.DebuggerNonUserCode] public FunctionContext function() {
- return GetRuleContext<FunctionContext>(0);
- }
+ public partial class ProgramContext : Q1.Compiler.Context {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode Eof() { return GetToken(CGrammarParser.Eof, 0); }
+ [System.Diagnostics.DebuggerNonUserCode] public FunctionContext[] function() {
+ return GetRuleContexts<FunctionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public FunctionContext function(int i) {
+ return GetRuleContext<FunctionContext>(i);
+ }
public ProgramContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
@@ -120,12 +125,25 @@ public partial class CGrammarParser : Parser {
public ProgramContext program() {
ProgramContext _localctx = new ProgramContext(Context, State);
EnterRule(_localctx, 0, RULE_program);
+ int _la;
try {
EnterOuterAlt(_localctx, 1);
{
- State = 18;
- function();
State = 19;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ do {
+ {
+ {
+ State = 18;
+ function();
+ }
+ }
+ State = 21;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ } while ( _la==T__0 );
+ State = 23;
Match(Eof);
}
}
@@ -140,21 +158,54 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class FunctionContext : ParserRuleContext {
- public IToken name;
- [System.Diagnostics.DebuggerNonUserCode] public BlockContext block() {
- return GetRuleContext<BlockContext>(0);
- }
- [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); }
+ public partial class FunctionContext : Q1.Compiler.Context {
public FunctionContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_function; } }
+
+ public FunctionContext() { }
+ public virtual void CopyFrom(FunctionContext context) {
+ base.CopyFrom(context);
+ }
+ }
+ public partial class FunctionPrototypeContext : FunctionContext {
+ public IToken name;
+ public IToken s1;
+ public IList<IToken> _types = new List<IToken>();
+ public IToken _ID;
+ public IList<IToken> _params = new List<IToken>();
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] ID() { return GetTokens(CGrammarParser.ID); }
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID(int i) {
+ return GetToken(CGrammarParser.ID, i);
+ }
+ public FunctionPrototypeContext(FunctionContext 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.VisitFunction(this);
+ if (typedVisitor != null) return typedVisitor.VisitFunctionPrototype(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class FunctionDefinitionContext : FunctionContext {
+ public IToken name;
+ public IToken s1;
+ public IList<IToken> _types = new List<IToken>();
+ public IToken _ID;
+ public IList<IToken> _params = new List<IToken>();
+ [System.Diagnostics.DebuggerNonUserCode] public BlockContext block() {
+ return GetRuleContext<BlockContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] ID() { return GetTokens(CGrammarParser.ID); }
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID(int i) {
+ return GetToken(CGrammarParser.ID, i);
+ }
+ public FunctionDefinitionContext(FunctionContext 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.VisitFunctionDefinition(this);
else return visitor.VisitChildren(this);
}
}
@@ -163,19 +214,111 @@ public partial class CGrammarParser : Parser {
public FunctionContext function() {
FunctionContext _localctx = new FunctionContext(Context, State);
EnterRule(_localctx, 2, RULE_function);
+ int _la;
try {
- EnterOuterAlt(_localctx, 1);
- {
- State = 21;
- Match(T__0);
- State = 22;
- _localctx.name = Match(ID);
- State = 23;
- Match(T__1);
- State = 24;
- Match(T__2);
- State = 25;
- block();
+ State = 59;
+ ErrorHandler.Sync(this);
+ switch ( Interpreter.AdaptivePredict(TokenStream,5,Context) ) {
+ case 1:
+ _localctx = new FunctionPrototypeContext(_localctx);
+ EnterOuterAlt(_localctx, 1);
+ {
+ State = 25;
+ Match(T__0);
+ State = 26;
+ ((FunctionPrototypeContext)_localctx).name = Match(ID);
+ State = 27;
+ Match(T__1);
+ State = 38;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if (_la==T__0) {
+ {
+ State = 28;
+ ((FunctionPrototypeContext)_localctx).s1 = Match(T__0);
+ ((FunctionPrototypeContext)_localctx)._types.Add(((FunctionPrototypeContext)_localctx).s1);
+ State = 29;
+ ((FunctionPrototypeContext)_localctx)._ID = Match(ID);
+ ((FunctionPrototypeContext)_localctx)._params.Add(((FunctionPrototypeContext)_localctx)._ID);
+ State = 35;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ while (_la==T__2) {
+ {
+ {
+ State = 30;
+ Match(T__2);
+ State = 31;
+ ((FunctionPrototypeContext)_localctx).s1 = Match(T__0);
+ ((FunctionPrototypeContext)_localctx)._types.Add(((FunctionPrototypeContext)_localctx).s1);
+ State = 32;
+ ((FunctionPrototypeContext)_localctx)._ID = Match(ID);
+ ((FunctionPrototypeContext)_localctx)._params.Add(((FunctionPrototypeContext)_localctx)._ID);
+ }
+ }
+ State = 37;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ }
+ }
+ }
+
+ State = 40;
+ Match(T__3);
+ State = 41;
+ Match(T__4);
+ }
+ break;
+ case 2:
+ _localctx = new FunctionDefinitionContext(_localctx);
+ EnterOuterAlt(_localctx, 2);
+ {
+ State = 42;
+ Match(T__0);
+ State = 43;
+ ((FunctionDefinitionContext)_localctx).name = Match(ID);
+ State = 44;
+ Match(T__1);
+ State = 55;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if (_la==T__0) {
+ {
+ State = 45;
+ ((FunctionDefinitionContext)_localctx).s1 = Match(T__0);
+ ((FunctionDefinitionContext)_localctx)._types.Add(((FunctionDefinitionContext)_localctx).s1);
+ State = 46;
+ ((FunctionDefinitionContext)_localctx)._ID = Match(ID);
+ ((FunctionDefinitionContext)_localctx)._params.Add(((FunctionDefinitionContext)_localctx)._ID);
+ State = 52;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ while (_la==T__2) {
+ {
+ {
+ State = 47;
+ Match(T__2);
+ State = 48;
+ ((FunctionDefinitionContext)_localctx).s1 = Match(T__0);
+ ((FunctionDefinitionContext)_localctx)._types.Add(((FunctionDefinitionContext)_localctx).s1);
+ State = 49;
+ ((FunctionDefinitionContext)_localctx)._ID = Match(ID);
+ ((FunctionDefinitionContext)_localctx)._params.Add(((FunctionDefinitionContext)_localctx)._ID);
+ }
+ }
+ State = 54;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ }
+ }
+ }
+
+ State = 57;
+ Match(T__3);
+ State = 58;
+ block();
+ }
+ break;
}
}
catch (RecognitionException re) {
@@ -189,7 +332,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class BlockContext : ParserRuleContext {
+ public partial class BlockContext : Q1.Compiler.Context {
[System.Diagnostics.DebuggerNonUserCode] public Block_itemContext[] block_item() {
return GetRuleContexts<Block_itemContext>();
}
@@ -217,24 +360,24 @@ public partial class CGrammarParser : Parser {
try {
EnterOuterAlt(_localctx, 1);
{
- State = 27;
- Match(T__3);
- State = 31;
+ State = 61;
+ Match(T__5);
+ State = 65;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
- while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 211106232564054L) != 0)) {
+ while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443086182L) != 0)) {
{
{
- State = 28;
+ State = 62;
block_item();
}
}
- State = 33;
+ State = 67;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
}
- State = 34;
- Match(T__4);
+ State = 68;
+ Match(T__6);
}
}
catch (RecognitionException re) {
@@ -248,7 +391,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class Block_itemContext : ParserRuleContext {
+ public partial class Block_itemContext : Q1.Compiler.Context {
[System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() {
return GetRuleContext<StatementContext>(0);
}
@@ -273,29 +416,35 @@ public partial class CGrammarParser : Parser {
Block_itemContext _localctx = new Block_itemContext(Context, State);
EnterRule(_localctx, 6, RULE_block_item);
try {
- State = 38;
+ State = 72;
ErrorHandler.Sync(this);
switch (TokenStream.LA(1)) {
case T__1:
- case T__3:
+ case T__4:
case T__5:
case T__7:
+ case T__8:
case T__10:
case T__11:
case T__12:
case T__13:
+ case T__14:
+ case T__16:
+ case T__17:
+ case T__18:
+ case T__19:
case ID:
case INT:
EnterOuterAlt(_localctx, 1);
{
- State = 36;
+ State = 70;
statement();
}
break;
case T__0:
EnterOuterAlt(_localctx, 2);
{
- State = 37;
+ State = 71;
declaration();
}
break;
@@ -314,7 +463,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class StatementContext : ParserRuleContext {
+ public partial class StatementContext : Q1.Compiler.Context {
public StatementContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
@@ -326,6 +475,48 @@ public partial class CGrammarParser : Parser {
base.CopyFrom(context);
}
}
+ public partial class WhileStatementContext : StatementContext {
+ public ExpressionContext cond;
+ public StatementContext body;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
+ return GetRuleContext<ExpressionContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() {
+ return GetRuleContext<StatementContext>(0);
+ }
+ public WhileStatementContext(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.VisitWhileStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class ForDeclStatementContext : StatementContext {
+ public DeclarationContext initializer;
+ public ExpressionContext cond;
+ public ExpressionContext post;
+ public StatementContext body;
+ [System.Diagnostics.DebuggerNonUserCode] public DeclarationContext declaration() {
+ return GetRuleContext<DeclarationContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() {
+ return GetRuleContext<StatementContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public ForDeclStatementContext(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.VisitForDeclStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
public partial class BlockStatementContext : StatementContext {
[System.Diagnostics.DebuggerNonUserCode] public BlockContext block() {
return GetRuleContext<BlockContext>(0);
@@ -338,6 +529,72 @@ public partial class CGrammarParser : Parser {
else return visitor.VisitChildren(this);
}
}
+ public partial class NullStatementContext : StatementContext {
+ public NullStatementContext(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.VisitNullStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class ForExprStatementContext : StatementContext {
+ public ExpressionContext initializer;
+ public ExpressionContext cond;
+ public ExpressionContext post;
+ public StatementContext body;
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() {
+ return GetRuleContext<StatementContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public ForExprStatementContext(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.VisitForExprStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class BreakStatementContext : StatementContext {
+ public BreakStatementContext(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.VisitBreakStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class DoWhileStatementContext : StatementContext {
+ public StatementContext body;
+ public ExpressionContext cond;
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement() {
+ return GetRuleContext<StatementContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
+ return GetRuleContext<ExpressionContext>(0);
+ }
+ public DoWhileStatementContext(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.VisitDoWhileStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class ContinueStatementContext : StatementContext {
+ public ContinueStatementContext(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.VisitContinueStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
public partial class ExpressionStatementContext : StatementContext {
[System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
return GetRuleContext<ExpressionContext>(0);
@@ -387,74 +644,219 @@ public partial class CGrammarParser : Parser {
public StatementContext statement() {
StatementContext _localctx = new StatementContext(Context, State);
EnterRule(_localctx, 8, RULE_statement);
+ int _la;
try {
- State = 55;
+ State = 138;
ErrorHandler.Sync(this);
- switch (TokenStream.LA(1)) {
- case T__5:
+ switch ( Interpreter.AdaptivePredict(TokenStream,14,Context) ) {
+ case 1:
_localctx = new ReturnStatementContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 40;
- Match(T__5);
- State = 41;
+ State = 74;
+ Match(T__7);
+ State = 75;
expression(0);
- State = 42;
- Match(T__6);
+ State = 76;
+ Match(T__4);
}
break;
- case T__7:
+ case 2:
_localctx = new IfStatementContext(_localctx);
EnterOuterAlt(_localctx, 2);
{
- State = 44;
- Match(T__7);
- State = 45;
+ State = 78;
+ Match(T__8);
+ State = 79;
Match(T__1);
- State = 46;
+ State = 80;
expression(0);
- State = 47;
- Match(T__2);
- State = 48;
+ State = 81;
+ Match(T__3);
+ State = 82;
((IfStatementContext)_localctx).then = statement();
- State = 51;
+ State = 85;
ErrorHandler.Sync(this);
- switch ( Interpreter.AdaptivePredict(TokenStream,2,Context) ) {
+ switch ( Interpreter.AdaptivePredict(TokenStream,8,Context) ) {
case 1:
{
- State = 49;
- Match(T__8);
- State = 50;
+ State = 83;
+ Match(T__9);
+ State = 84;
((IfStatementContext)_localctx).@else = statement();
}
break;
}
}
break;
- case T__1:
- case T__10:
- case T__11:
- case T__12:
- case T__13:
- case ID:
- case INT:
- _localctx = new ExpressionStatementContext(_localctx);
+ case 3:
+ _localctx = new ForExprStatementContext(_localctx);
EnterOuterAlt(_localctx, 3);
{
- State = 53;
+ State = 87;
+ Match(T__10);
+ State = 88;
+ Match(T__1);
+ State = 90;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443021828L) != 0)) {
+ {
+ State = 89;
+ ((ForExprStatementContext)_localctx).initializer = expression(0);
+ }
+ }
+
+ State = 92;
+ Match(T__4);
+ State = 94;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443021828L) != 0)) {
+ {
+ State = 93;
+ ((ForExprStatementContext)_localctx).cond = expression(0);
+ }
+ }
+
+ State = 96;
+ Match(T__4);
+ State = 98;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443021828L) != 0)) {
+ {
+ State = 97;
+ ((ForExprStatementContext)_localctx).post = expression(0);
+ }
+ }
+
+ State = 100;
+ Match(T__3);
+ State = 101;
+ ((ForExprStatementContext)_localctx).body = statement();
+ }
+ break;
+ case 4:
+ _localctx = new ForDeclStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 4);
+ {
+ State = 102;
+ Match(T__10);
+ State = 103;
+ Match(T__1);
+ State = 104;
+ ((ForDeclStatementContext)_localctx).initializer = declaration();
+ State = 106;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443021828L) != 0)) {
+ {
+ State = 105;
+ ((ForDeclStatementContext)_localctx).cond = expression(0);
+ }
+ }
+
+ State = 108;
+ Match(T__4);
+ State = 110;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443021828L) != 0)) {
+ {
+ State = 109;
+ ((ForDeclStatementContext)_localctx).post = expression(0);
+ }
+ }
+
+ State = 112;
+ Match(T__3);
+ State = 113;
+ ((ForDeclStatementContext)_localctx).body = statement();
+ }
+ break;
+ case 5:
+ _localctx = new WhileStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 5);
+ {
+ State = 115;
+ Match(T__11);
+ State = 116;
+ Match(T__1);
+ State = 117;
+ ((WhileStatementContext)_localctx).cond = expression(0);
+ State = 118;
+ Match(T__3);
+ State = 119;
+ ((WhileStatementContext)_localctx).body = statement();
+ }
+ break;
+ case 6:
+ _localctx = new DoWhileStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 6);
+ {
+ State = 121;
+ Match(T__12);
+ State = 122;
+ ((DoWhileStatementContext)_localctx).body = statement();
+ State = 123;
+ Match(T__11);
+ State = 124;
+ Match(T__1);
+ State = 125;
+ ((DoWhileStatementContext)_localctx).cond = expression(0);
+ State = 126;
+ Match(T__3);
+ State = 127;
+ Match(T__4);
+ }
+ break;
+ case 7:
+ _localctx = new BreakStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 7);
+ {
+ State = 129;
+ Match(T__13);
+ State = 130;
+ Match(T__4);
+ }
+ break;
+ case 8:
+ _localctx = new ContinueStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 8);
+ {
+ State = 131;
+ Match(T__14);
+ State = 132;
+ Match(T__4);
+ }
+ break;
+ case 9:
+ _localctx = new ExpressionStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 9);
+ {
+ State = 133;
expression(0);
+ State = 134;
+ Match(T__4);
}
break;
- case T__3:
+ case 10:
_localctx = new BlockStatementContext(_localctx);
- EnterOuterAlt(_localctx, 4);
+ EnterOuterAlt(_localctx, 10);
{
- State = 54;
+ State = 136;
block();
}
break;
- default:
- throw new NoViableAltException(this);
+ case 11:
+ _localctx = new NullStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 11);
+ {
+ State = 137;
+ Match(T__4);
+ }
+ break;
}
}
catch (RecognitionException re) {
@@ -468,7 +870,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class DeclarationContext : ParserRuleContext {
+ public partial class DeclarationContext : Q1.Compiler.Context {
public DeclarationContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
@@ -505,24 +907,24 @@ public partial class CGrammarParser : Parser {
_localctx = new VariableDeclarationContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 57;
+ State = 140;
Match(T__0);
- State = 58;
+ State = 141;
((VariableDeclarationContext)_localctx).name = Match(ID);
- State = 61;
+ State = 144;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
- if (_la==T__9) {
+ if (_la==T__15) {
{
- State = 59;
- Match(T__9);
- State = 60;
+ State = 142;
+ Match(T__15);
+ State = 143;
((VariableDeclarationContext)_localctx).value = expression(0);
}
}
- State = 63;
- Match(T__6);
+ State = 146;
+ Match(T__4);
}
}
catch (RecognitionException re) {
@@ -536,7 +938,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class ExpressionContext : ParserRuleContext {
+ public partial class ExpressionContext : Q1.Compiler.Context {
public ExpressionContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
@@ -986,23 +1388,6 @@ public partial class CGrammarParser : Parser {
else return visitor.VisitChildren(this);
}
}
- public partial class CommaExpressionContext : ExpressionContext {
- public ExpressionContext left;
- public ExpressionContext right;
- [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
- return GetRuleContexts<ExpressionContext>();
- }
- [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
- return GetRuleContext<ExpressionContext>(i);
- }
- public CommaExpressionContext(ExpressionContext 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.VisitCommaExpression(this);
- else return visitor.VisitChildren(this);
- }
- }
public partial class IncrementPrefixExpressionContext : ExpressionContext {
[System.Diagnostics.DebuggerNonUserCode] public TargetContext target() {
return GetRuleContext<TargetContext>(0);
@@ -1066,6 +1451,24 @@ public partial class CGrammarParser : Parser {
else return visitor.VisitChildren(this);
}
}
+ public partial class CallExpressionContext : ExpressionContext {
+ public ExpressionContext _expression;
+ public IList<ExpressionContext> _params = new List<ExpressionContext>();
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public CallExpressionContext(ExpressionContext 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.VisitCallExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
public partial class AddExpressionContext : ExpressionContext {
public ExpressionContext left;
public ExpressionContext right;
@@ -1173,25 +1576,26 @@ public partial class CGrammarParser : Parser {
ExpressionContext _prevctx = _localctx;
int _startState = 12;
EnterRecursionRule(_localctx, 12, RULE_expression, _p);
+ int _la;
try {
int _alt;
EnterOuterAlt(_localctx, 1);
{
- State = 131;
+ State = 226;
ErrorHandler.Sync(this);
- switch ( Interpreter.AdaptivePredict(TokenStream,5,Context) ) {
+ switch ( Interpreter.AdaptivePredict(TokenStream,18,Context) ) {
case 1:
{
_localctx = new ParenthesizedExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 66;
+ State = 149;
Match(T__1);
- State = 67;
+ State = 150;
expression(0);
- State = 68;
- Match(T__2);
+ State = 151;
+ Match(T__3);
}
break;
case 2:
@@ -1199,7 +1603,7 @@ public partial class CGrammarParser : Parser {
_localctx = new ConstantExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 70;
+ State = 153;
constant();
}
break;
@@ -1208,14 +1612,12 @@ public partial class CGrammarParser : Parser {
_localctx = new AssignmentExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 71;
+ State = 154;
target();
- State = 72;
- Match(T__9);
- State = 73;
- expression(0);
- State = 74;
- Match(T__6);
+ State = 155;
+ Match(T__15);
+ State = 156;
+ expression(38);
}
break;
case 4:
@@ -1223,231 +1625,272 @@ public partial class CGrammarParser : Parser {
_localctx = new VariableExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 76;
+ State = 158;
Match(ID);
}
break;
case 5:
{
- _localctx = new NotExpressionContext(_localctx);
+ _localctx = new CallExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 77;
- Match(T__10);
- State = 78;
- expression(36);
+ State = 159;
+ Match(ID);
+ State = 160;
+ Match(T__1);
+ State = 169;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 6755399443021828L) != 0)) {
+ {
+ State = 161;
+ ((CallExpressionContext)_localctx)._expression = expression(0);
+ ((CallExpressionContext)_localctx)._params.Add(((CallExpressionContext)_localctx)._expression);
+ State = 166;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ while (_la==T__2) {
+ {
+ {
+ State = 162;
+ Match(T__2);
+ State = 163;
+ ((CallExpressionContext)_localctx)._expression = expression(0);
+ ((CallExpressionContext)_localctx)._params.Add(((CallExpressionContext)_localctx)._expression);
+ }
+ }
+ State = 168;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ }
+ }
+ }
+
+ State = 171;
+ Match(T__3);
}
break;
case 6:
{
- _localctx = new InvertExpressionContext(_localctx);
+ _localctx = new NotExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 79;
- Match(T__11);
- State = 80;
+ State = 172;
+ Match(T__16);
+ State = 173;
expression(35);
}
break;
case 7:
{
- _localctx = new IncrementPrefixExpressionContext(_localctx);
+ _localctx = new InvertExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 81;
- Match(T__12);
- State = 82;
- target();
+ State = 174;
+ Match(T__17);
+ State = 175;
+ expression(34);
}
break;
case 8:
{
- _localctx = new DecrementPrefixExpressionContext(_localctx);
+ _localctx = new IncrementPrefixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 83;
- Match(T__13);
- State = 84;
+ State = 176;
+ Match(T__18);
+ State = 177;
target();
}
break;
case 9:
{
- _localctx = new IncrementPostfixExpressionContext(_localctx);
+ _localctx = new DecrementPrefixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 85;
+ State = 178;
+ Match(T__19);
+ State = 179;
target();
- State = 86;
- Match(T__12);
}
break;
case 10:
{
- _localctx = new DecrementPostfixExpressionContext(_localctx);
+ _localctx = new IncrementPostfixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 88;
+ State = 180;
target();
- State = 89;
- Match(T__13);
+ State = 181;
+ Match(T__18);
}
break;
case 11:
{
- _localctx = new CompoundMultiplyExpressionContext(_localctx);
+ _localctx = new DecrementPostfixExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 91;
+ State = 183;
target();
- State = 92;
- Match(T__32);
- State = 93;
- expression(12);
+ State = 184;
+ Match(T__19);
}
break;
case 12:
{
- _localctx = new CompoundDivideExpressionContext(_localctx);
+ _localctx = new CompoundMultiplyExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 95;
+ State = 186;
target();
- State = 96;
- Match(T__33);
- State = 97;
+ State = 187;
+ Match(T__38);
+ State = 188;
expression(11);
}
break;
case 13:
{
- _localctx = new CompoundModulusExpressionContext(_localctx);
+ _localctx = new CompoundDivideExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 99;
+ State = 190;
target();
- State = 100;
- Match(T__34);
- State = 101;
+ State = 191;
+ Match(T__39);
+ State = 192;
expression(10);
}
break;
case 14:
{
- _localctx = new CompoundAddExpressionContext(_localctx);
+ _localctx = new CompoundModulusExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 103;
+ State = 194;
target();
- State = 104;
- Match(T__35);
- State = 105;
+ State = 195;
+ Match(T__40);
+ State = 196;
expression(9);
}
break;
case 15:
{
- _localctx = new CompoundSubtractExpressionContext(_localctx);
+ _localctx = new CompoundAddExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 107;
+ State = 198;
target();
- State = 108;
- Match(T__36);
- State = 109;
+ State = 199;
+ Match(T__41);
+ State = 200;
expression(8);
}
break;
case 16:
{
- _localctx = new CompoundBitwiseAndExpressionContext(_localctx);
+ _localctx = new CompoundSubtractExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 111;
+ State = 202;
target();
- State = 112;
- Match(T__37);
- State = 113;
+ State = 203;
+ Match(T__42);
+ State = 204;
expression(7);
}
break;
case 17:
{
- _localctx = new CompoundBitwiseOrExpressionContext(_localctx);
+ _localctx = new CompoundBitwiseAndExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 115;
+ State = 206;
target();
- State = 116;
- Match(T__38);
- State = 117;
+ State = 207;
+ Match(T__43);
+ State = 208;
expression(6);
}
break;
case 18:
{
- _localctx = new CompoundBitwiseXorExpressionContext(_localctx);
+ _localctx = new CompoundBitwiseOrExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 119;
+ State = 210;
target();
- State = 120;
- Match(T__39);
- State = 121;
+ State = 211;
+ Match(T__44);
+ State = 212;
expression(5);
}
break;
case 19:
{
- _localctx = new CompoundBitwiseLeftShiftExpressionContext(_localctx);
+ _localctx = new CompoundBitwiseXorExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 123;
+ State = 214;
target();
- State = 124;
- Match(T__40);
- State = 125;
+ State = 215;
+ Match(T__45);
+ State = 216;
expression(4);
}
break;
case 20:
{
- _localctx = new CompoundBitwiseRightShiftExpressionContext(_localctx);
+ _localctx = new CompoundBitwiseLeftShiftExpressionContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
- State = 127;
+ State = 218;
target();
- State = 128;
- Match(T__41);
- State = 129;
+ State = 219;
+ Match(T__46);
+ State = 220;
expression(3);
}
break;
+ case 21:
+ {
+ _localctx = new CompoundBitwiseRightShiftExpressionContext(_localctx);
+ Context = _localctx;
+ _prevctx = _localctx;
+ State = 222;
+ target();
+ State = 223;
+ Match(T__47);
+ State = 224;
+ expression(2);
+ }
+ break;
}
Context.Stop = TokenStream.LT(-1);
- State = 198;
+ State = 290;
ErrorHandler.Sync(this);
- _alt = Interpreter.AdaptivePredict(TokenStream,7,Context);
+ _alt = Interpreter.AdaptivePredict(TokenStream,20,Context);
while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( ParseListeners!=null )
TriggerExitRuleEvent();
_prevctx = _localctx;
{
- State = 196;
+ State = 288;
ErrorHandler.Sync(this);
- switch ( Interpreter.AdaptivePredict(TokenStream,6,Context) ) {
+ switch ( Interpreter.AdaptivePredict(TokenStream,19,Context) ) {
case 1:
{
_localctx = new MultiplyExpressionContext(new ExpressionContext(_parentctx, _parentState));
((MultiplyExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 133;
- if (!(Precpred(Context, 30))) throw new FailedPredicateException(this, "Precpred(Context, 30)");
- State = 134;
- Match(T__14);
- State = 135;
- ((MultiplyExpressionContext)_localctx).right = expression(31);
+ State = 228;
+ if (!(Precpred(Context, 29))) throw new FailedPredicateException(this, "Precpred(Context, 29)");
+ State = 229;
+ Match(T__20);
+ State = 230;
+ ((MultiplyExpressionContext)_localctx).right = expression(30);
}
break;
case 2:
@@ -1455,12 +1898,12 @@ public partial class CGrammarParser : Parser {
_localctx = new DivideExpressionContext(new ExpressionContext(_parentctx, _parentState));
((DivideExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 136;
- if (!(Precpred(Context, 29))) throw new FailedPredicateException(this, "Precpred(Context, 29)");
- State = 137;
- Match(T__15);
- State = 138;
- ((DivideExpressionContext)_localctx).right = expression(30);
+ State = 231;
+ if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)");
+ State = 232;
+ Match(T__21);
+ State = 233;
+ ((DivideExpressionContext)_localctx).right = expression(29);
}
break;
case 3:
@@ -1468,12 +1911,12 @@ public partial class CGrammarParser : Parser {
_localctx = new ModulusExpressionContext(new ExpressionContext(_parentctx, _parentState));
((ModulusExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 139;
- if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)");
- State = 140;
- Match(T__16);
- State = 141;
- ((ModulusExpressionContext)_localctx).right = expression(29);
+ State = 234;
+ if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)");
+ State = 235;
+ Match(T__22);
+ State = 236;
+ ((ModulusExpressionContext)_localctx).right = expression(28);
}
break;
case 4:
@@ -1481,12 +1924,12 @@ public partial class CGrammarParser : Parser {
_localctx = new AddExpressionContext(new ExpressionContext(_parentctx, _parentState));
((AddExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 142;
- if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)");
- State = 143;
- Match(T__17);
- State = 144;
- ((AddExpressionContext)_localctx).right = expression(28);
+ State = 237;
+ if (!(Precpred(Context, 26))) throw new FailedPredicateException(this, "Precpred(Context, 26)");
+ State = 238;
+ Match(T__23);
+ State = 239;
+ ((AddExpressionContext)_localctx).right = expression(27);
}
break;
case 5:
@@ -1494,12 +1937,12 @@ public partial class CGrammarParser : Parser {
_localctx = new SubtractExpressionContext(new ExpressionContext(_parentctx, _parentState));
((SubtractExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 145;
- if (!(Precpred(Context, 26))) throw new FailedPredicateException(this, "Precpred(Context, 26)");
- State = 146;
- Match(T__18);
- State = 147;
- ((SubtractExpressionContext)_localctx).right = expression(27);
+ State = 240;
+ if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)");
+ State = 241;
+ Match(T__24);
+ State = 242;
+ ((SubtractExpressionContext)_localctx).right = expression(26);
}
break;
case 6:
@@ -1507,12 +1950,12 @@ public partial class CGrammarParser : Parser {
_localctx = new LessThanExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LessThanExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 148;
- if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)");
- State = 149;
- Match(T__19);
- State = 150;
- ((LessThanExpressionContext)_localctx).right = expression(26);
+ State = 243;
+ if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)");
+ State = 244;
+ Match(T__25);
+ State = 245;
+ ((LessThanExpressionContext)_localctx).right = expression(25);
}
break;
case 7:
@@ -1520,12 +1963,12 @@ public partial class CGrammarParser : Parser {
_localctx = new GreaterThanExpressionContext(new ExpressionContext(_parentctx, _parentState));
((GreaterThanExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 151;
- if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)");
- State = 152;
- Match(T__20);
- State = 153;
- ((GreaterThanExpressionContext)_localctx).right = expression(25);
+ State = 246;
+ if (!(Precpred(Context, 23))) throw new FailedPredicateException(this, "Precpred(Context, 23)");
+ State = 247;
+ Match(T__26);
+ State = 248;
+ ((GreaterThanExpressionContext)_localctx).right = expression(24);
}
break;
case 8:
@@ -1533,12 +1976,12 @@ public partial class CGrammarParser : Parser {
_localctx = new LessThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LessThanOrEqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 154;
- if (!(Precpred(Context, 23))) throw new FailedPredicateException(this, "Precpred(Context, 23)");
- State = 155;
- Match(T__21);
- State = 156;
- ((LessThanOrEqualExpressionContext)_localctx).right = expression(24);
+ State = 249;
+ if (!(Precpred(Context, 22))) throw new FailedPredicateException(this, "Precpred(Context, 22)");
+ State = 250;
+ Match(T__27);
+ State = 251;
+ ((LessThanOrEqualExpressionContext)_localctx).right = expression(23);
}
break;
case 9:
@@ -1546,12 +1989,12 @@ public partial class CGrammarParser : Parser {
_localctx = new GreaterThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((GreaterThanOrEqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 157;
- if (!(Precpred(Context, 22))) throw new FailedPredicateException(this, "Precpred(Context, 22)");
- State = 158;
- Match(T__22);
- State = 159;
- ((GreaterThanOrEqualExpressionContext)_localctx).right = expression(23);
+ State = 252;
+ if (!(Precpred(Context, 21))) throw new FailedPredicateException(this, "Precpred(Context, 21)");
+ State = 253;
+ Match(T__28);
+ State = 254;
+ ((GreaterThanOrEqualExpressionContext)_localctx).right = expression(22);
}
break;
case 10:
@@ -1559,12 +2002,12 @@ public partial class CGrammarParser : Parser {
_localctx = new EqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((EqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 160;
- if (!(Precpred(Context, 21))) throw new FailedPredicateException(this, "Precpred(Context, 21)");
- State = 161;
- Match(T__23);
- State = 162;
- ((EqualExpressionContext)_localctx).right = expression(22);
+ State = 255;
+ if (!(Precpred(Context, 20))) throw new FailedPredicateException(this, "Precpred(Context, 20)");
+ State = 256;
+ Match(T__29);
+ State = 257;
+ ((EqualExpressionContext)_localctx).right = expression(21);
}
break;
case 11:
@@ -1572,12 +2015,12 @@ public partial class CGrammarParser : Parser {
_localctx = new NotEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
((NotEqualExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 163;
- if (!(Precpred(Context, 20))) throw new FailedPredicateException(this, "Precpred(Context, 20)");
- State = 164;
- Match(T__24);
- State = 165;
- ((NotEqualExpressionContext)_localctx).right = expression(21);
+ State = 258;
+ if (!(Precpred(Context, 19))) throw new FailedPredicateException(this, "Precpred(Context, 19)");
+ State = 259;
+ Match(T__30);
+ State = 260;
+ ((NotEqualExpressionContext)_localctx).right = expression(20);
}
break;
case 12:
@@ -1585,12 +2028,12 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseAndExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseAndExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 166;
- if (!(Precpred(Context, 19))) throw new FailedPredicateException(this, "Precpred(Context, 19)");
- State = 167;
- Match(T__25);
- State = 168;
- ((BitwiseAndExpressionContext)_localctx).right = expression(20);
+ State = 261;
+ if (!(Precpred(Context, 18))) throw new FailedPredicateException(this, "Precpred(Context, 18)");
+ State = 262;
+ Match(T__31);
+ State = 263;
+ ((BitwiseAndExpressionContext)_localctx).right = expression(19);
}
break;
case 13:
@@ -1598,12 +2041,12 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseOrExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseOrExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 169;
- if (!(Precpred(Context, 18))) throw new FailedPredicateException(this, "Precpred(Context, 18)");
- State = 170;
- Match(T__26);
- State = 171;
- ((BitwiseOrExpressionContext)_localctx).right = expression(19);
+ State = 264;
+ if (!(Precpred(Context, 17))) throw new FailedPredicateException(this, "Precpred(Context, 17)");
+ State = 265;
+ Match(T__32);
+ State = 266;
+ ((BitwiseOrExpressionContext)_localctx).right = expression(18);
}
break;
case 14:
@@ -1611,12 +2054,12 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseXorExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseXorExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 172;
- if (!(Precpred(Context, 17))) throw new FailedPredicateException(this, "Precpred(Context, 17)");
- State = 173;
- Match(T__27);
- State = 174;
- ((BitwiseXorExpressionContext)_localctx).right = expression(18);
+ State = 267;
+ if (!(Precpred(Context, 16))) throw new FailedPredicateException(this, "Precpred(Context, 16)");
+ State = 268;
+ Match(T__33);
+ State = 269;
+ ((BitwiseXorExpressionContext)_localctx).right = expression(17);
}
break;
case 15:
@@ -1624,12 +2067,12 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseLeftShiftExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseLeftShiftExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 175;
- if (!(Precpred(Context, 16))) throw new FailedPredicateException(this, "Precpred(Context, 16)");
- State = 176;
- Match(T__28);
- State = 177;
- ((BitwiseLeftShiftExpressionContext)_localctx).right = expression(17);
+ State = 270;
+ if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)");
+ State = 271;
+ Match(T__34);
+ State = 272;
+ ((BitwiseLeftShiftExpressionContext)_localctx).right = expression(16);
}
break;
case 16:
@@ -1637,12 +2080,12 @@ public partial class CGrammarParser : Parser {
_localctx = new BitwiseRightShiftExpressionContext(new ExpressionContext(_parentctx, _parentState));
((BitwiseRightShiftExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 178;
- if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)");
- State = 179;
- Match(T__29);
- State = 180;
- ((BitwiseRightShiftExpressionContext)_localctx).right = expression(16);
+ State = 273;
+ if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)");
+ State = 274;
+ Match(T__35);
+ State = 275;
+ ((BitwiseRightShiftExpressionContext)_localctx).right = expression(15);
}
break;
case 17:
@@ -1650,12 +2093,12 @@ public partial class CGrammarParser : Parser {
_localctx = new LogicalAndExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LogicalAndExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 181;
- if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)");
- State = 182;
- Match(T__30);
- State = 183;
- ((LogicalAndExpressionContext)_localctx).right = expression(15);
+ State = 276;
+ if (!(Precpred(Context, 13))) throw new FailedPredicateException(this, "Precpred(Context, 13)");
+ State = 277;
+ Match(T__36);
+ State = 278;
+ ((LogicalAndExpressionContext)_localctx).right = expression(14);
}
break;
case 18:
@@ -1663,50 +2106,37 @@ public partial class CGrammarParser : Parser {
_localctx = new LogicalOrExpressionContext(new ExpressionContext(_parentctx, _parentState));
((LogicalOrExpressionContext)_localctx).left = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 184;
- if (!(Precpred(Context, 13))) throw new FailedPredicateException(this, "Precpred(Context, 13)");
- State = 185;
- Match(T__31);
- State = 186;
- ((LogicalOrExpressionContext)_localctx).right = expression(14);
+ State = 279;
+ if (!(Precpred(Context, 12))) throw new FailedPredicateException(this, "Precpred(Context, 12)");
+ State = 280;
+ Match(T__37);
+ State = 281;
+ ((LogicalOrExpressionContext)_localctx).right = expression(13);
}
break;
case 19:
{
- _localctx = new CommaExpressionContext(new ExpressionContext(_parentctx, _parentState));
- ((CommaExpressionContext)_localctx).left = _prevctx;
- PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 187;
- if (!(Precpred(Context, 2))) throw new FailedPredicateException(this, "Precpred(Context, 2)");
- State = 188;
- Match(T__42);
- State = 189;
- ((CommaExpressionContext)_localctx).right = expression(3);
- }
- break;
- case 20:
- {
_localctx = new TernaryExpressionContext(new ExpressionContext(_parentctx, _parentState));
((TernaryExpressionContext)_localctx).cond = _prevctx;
PushNewRecursionContext(_localctx, _startState, RULE_expression);
- State = 190;
+ State = 282;
if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)");
- State = 191;
- Match(T__43);
- State = 192;
+ State = 283;
+ Match(T__48);
+ State = 284;
((TernaryExpressionContext)_localctx).then = expression(0);
- State = 193;
- Match(T__44);
- State = 194;
+ State = 285;
+ Match(T__49);
+ State = 286;
((TernaryExpressionContext)_localctx).@else = expression(2);
}
break;
}
}
}
- State = 200;
+ State = 292;
ErrorHandler.Sync(this);
- _alt = Interpreter.AdaptivePredict(TokenStream,7,Context);
+ _alt = Interpreter.AdaptivePredict(TokenStream,20,Context);
}
}
}
@@ -1721,7 +2151,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class ConstantContext : ParserRuleContext {
+ public partial class ConstantContext : Q1.Compiler.Context {
public ConstantContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
@@ -1752,7 +2182,7 @@ public partial class CGrammarParser : Parser {
_localctx = new IntConstantContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 201;
+ State = 293;
Match(INT);
}
}
@@ -1767,7 +2197,7 @@ public partial class CGrammarParser : Parser {
return _localctx;
}
- public partial class TargetContext : ParserRuleContext {
+ public partial class TargetContext : Q1.Compiler.Context {
public TargetContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
@@ -1798,7 +2228,7 @@ public partial class CGrammarParser : Parser {
_localctx = new VariableTargetContext(_localctx);
EnterOuterAlt(_localctx, 1);
{
- State = 203;
+ State = 295;
Match(ID);
}
}
@@ -1821,99 +2251,130 @@ public partial class CGrammarParser : Parser {
}
private bool expression_sempred(ExpressionContext _localctx, int predIndex) {
switch (predIndex) {
- case 0: return Precpred(Context, 30);
- case 1: return Precpred(Context, 29);
- case 2: return Precpred(Context, 28);
- case 3: return Precpred(Context, 27);
- case 4: return Precpred(Context, 26);
- case 5: return Precpred(Context, 25);
- case 6: return Precpred(Context, 24);
- case 7: return Precpred(Context, 23);
- case 8: return Precpred(Context, 22);
- case 9: return Precpred(Context, 21);
- case 10: return Precpred(Context, 20);
- case 11: return Precpred(Context, 19);
- case 12: return Precpred(Context, 18);
- case 13: return Precpred(Context, 17);
- case 14: return Precpred(Context, 16);
- case 15: return Precpred(Context, 15);
- case 16: return Precpred(Context, 14);
- case 17: return Precpred(Context, 13);
- case 18: return Precpred(Context, 2);
- case 19: return Precpred(Context, 1);
+ case 0: return Precpred(Context, 29);
+ case 1: return Precpred(Context, 28);
+ case 2: return Precpred(Context, 27);
+ case 3: return Precpred(Context, 26);
+ case 4: return Precpred(Context, 25);
+ case 5: return Precpred(Context, 24);
+ case 6: return Precpred(Context, 23);
+ case 7: return Precpred(Context, 22);
+ case 8: return Precpred(Context, 21);
+ case 9: return Precpred(Context, 20);
+ case 10: return Precpred(Context, 19);
+ case 11: return Precpred(Context, 18);
+ case 12: return Precpred(Context, 17);
+ case 13: return Precpred(Context, 16);
+ case 14: return Precpred(Context, 15);
+ case 15: return Precpred(Context, 14);
+ case 16: return Precpred(Context, 13);
+ case 17: return Precpred(Context, 12);
+ case 18: return Precpred(Context, 1);
}
return true;
}
private static int[] _serializedATN = {
- 4,1,49,206,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,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,5,2,30,8,2,10,
- 2,12,2,33,9,2,1,2,1,2,1,3,1,3,3,3,39,8,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,
- 4,1,4,1,4,1,4,3,4,52,8,4,1,4,1,4,3,4,56,8,4,1,5,1,5,1,5,1,5,3,5,62,8,5,
- 1,5,1,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,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,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,3,6,132,
+ 4,1,54,298,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,1,0,4,0,20,8,0,11,0,12,0,21,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,5,1,34,8,1,10,1,12,1,37,9,1,3,1,39,8,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,5,1,51,8,1,10,1,12,1,54,9,1,3,1,56,8,1,1,1,1,1,3,1,60,
+ 8,1,1,2,1,2,5,2,64,8,2,10,2,12,2,67,9,2,1,2,1,2,1,3,1,3,3,3,73,8,3,1,4,
+ 1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,86,8,4,1,4,1,4,1,4,3,4,91,
+ 8,4,1,4,1,4,3,4,95,8,4,1,4,1,4,3,4,99,8,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,
+ 107,8,4,1,4,1,4,3,4,111,8,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,
+ 4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,139,
+ 8,4,1,5,1,5,1,5,1,5,3,5,145,8,5,1,5,1,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,1,6,1,6,1,6,5,6,165,8,6,10,6,12,6,168,9,6,3,6,170,
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,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,197,8,6,10,6,12,6,200,
- 9,6,1,7,1,7,1,8,1,8,1,8,0,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
+ 6,1,6,1,6,1,6,3,6,227,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,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,289,8,6,10,
+ 6,12,6,292,9,6,1,7,1,7,1,8,1,8,1,8,0,1,12,9,0,2,4,6,8,10,12,14,16,0,0,
+ 354,0,19,1,0,0,0,2,59,1,0,0,0,4,61,1,0,0,0,6,72,1,0,0,0,8,138,1,0,0,0,
+ 10,140,1,0,0,0,12,226,1,0,0,0,14,293,1,0,0,0,16,295,1,0,0,0,18,20,3,2,
+ 1,0,19,18,1,0,0,0,20,21,1,0,0,0,21,19,1,0,0,0,21,22,1,0,0,0,22,23,1,0,
+ 0,0,23,24,5,0,0,1,24,1,1,0,0,0,25,26,5,1,0,0,26,27,5,51,0,0,27,38,5,2,
+ 0,0,28,29,5,1,0,0,29,35,5,51,0,0,30,31,5,3,0,0,31,32,5,1,0,0,32,34,5,51,
+ 0,0,33,30,1,0,0,0,34,37,1,0,0,0,35,33,1,0,0,0,35,36,1,0,0,0,36,39,1,0,
+ 0,0,37,35,1,0,0,0,38,28,1,0,0,0,38,39,1,0,0,0,39,40,1,0,0,0,40,41,5,4,
+ 0,0,41,60,5,5,0,0,42,43,5,1,0,0,43,44,5,51,0,0,44,55,5,2,0,0,45,46,5,1,
+ 0,0,46,52,5,51,0,0,47,48,5,3,0,0,48,49,5,1,0,0,49,51,5,51,0,0,50,47,1,
+ 0,0,0,51,54,1,0,0,0,52,50,1,0,0,0,52,53,1,0,0,0,53,56,1,0,0,0,54,52,1,
+ 0,0,0,55,45,1,0,0,0,55,56,1,0,0,0,56,57,1,0,0,0,57,58,5,4,0,0,58,60,3,
+ 4,2,0,59,25,1,0,0,0,59,42,1,0,0,0,60,3,1,0,0,0,61,65,5,6,0,0,62,64,3,6,
+ 3,0,63,62,1,0,0,0,64,67,1,0,0,0,65,63,1,0,0,0,65,66,1,0,0,0,66,68,1,0,
+ 0,0,67,65,1,0,0,0,68,69,5,7,0,0,69,5,1,0,0,0,70,73,3,8,4,0,71,73,3,10,
+ 5,0,72,70,1,0,0,0,72,71,1,0,0,0,73,7,1,0,0,0,74,75,5,8,0,0,75,76,3,12,
+ 6,0,76,77,5,5,0,0,77,139,1,0,0,0,78,79,5,9,0,0,79,80,5,2,0,0,80,81,3,12,
+ 6,0,81,82,5,4,0,0,82,85,3,8,4,0,83,84,5,10,0,0,84,86,3,8,4,0,85,83,1,0,
+ 0,0,85,86,1,0,0,0,86,139,1,0,0,0,87,88,5,11,0,0,88,90,5,2,0,0,89,91,3,
+ 12,6,0,90,89,1,0,0,0,90,91,1,0,0,0,91,92,1,0,0,0,92,94,5,5,0,0,93,95,3,
+ 12,6,0,94,93,1,0,0,0,94,95,1,0,0,0,95,96,1,0,0,0,96,98,5,5,0,0,97,99,3,
+ 12,6,0,98,97,1,0,0,0,98,99,1,0,0,0,99,100,1,0,0,0,100,101,5,4,0,0,101,
+ 139,3,8,4,0,102,103,5,11,0,0,103,104,5,2,0,0,104,106,3,10,5,0,105,107,
+ 3,12,6,0,106,105,1,0,0,0,106,107,1,0,0,0,107,108,1,0,0,0,108,110,5,5,0,
+ 0,109,111,3,12,6,0,110,109,1,0,0,0,110,111,1,0,0,0,111,112,1,0,0,0,112,
+ 113,5,4,0,0,113,114,3,8,4,0,114,139,1,0,0,0,115,116,5,12,0,0,116,117,5,
+ 2,0,0,117,118,3,12,6,0,118,119,5,4,0,0,119,120,3,8,4,0,120,139,1,0,0,0,
+ 121,122,5,13,0,0,122,123,3,8,4,0,123,124,5,12,0,0,124,125,5,2,0,0,125,
+ 126,3,12,6,0,126,127,5,4,0,0,127,128,5,5,0,0,128,139,1,0,0,0,129,130,5,
+ 14,0,0,130,139,5,5,0,0,131,132,5,15,0,0,132,139,5,5,0,0,133,134,3,12,6,
+ 0,134,135,5,5,0,0,135,139,1,0,0,0,136,139,3,4,2,0,137,139,5,5,0,0,138,
+ 74,1,0,0,0,138,78,1,0,0,0,138,87,1,0,0,0,138,102,1,0,0,0,138,115,1,0,0,
+ 0,138,121,1,0,0,0,138,129,1,0,0,0,138,131,1,0,0,0,138,133,1,0,0,0,138,
+ 136,1,0,0,0,138,137,1,0,0,0,139,9,1,0,0,0,140,141,5,1,0,0,141,144,5,51,
+ 0,0,142,143,5,16,0,0,143,145,3,12,6,0,144,142,1,0,0,0,144,145,1,0,0,0,
+ 145,146,1,0,0,0,146,147,5,5,0,0,147,11,1,0,0,0,148,149,6,6,-1,0,149,150,
+ 5,2,0,0,150,151,3,12,6,0,151,152,5,4,0,0,152,227,1,0,0,0,153,227,3,14,
+ 7,0,154,155,3,16,8,0,155,156,5,16,0,0,156,157,3,12,6,38,157,227,1,0,0,
+ 0,158,227,5,51,0,0,159,160,5,51,0,0,160,169,5,2,0,0,161,166,3,12,6,0,162,
+ 163,5,3,0,0,163,165,3,12,6,0,164,162,1,0,0,0,165,168,1,0,0,0,166,164,1,
+ 0,0,0,166,167,1,0,0,0,167,170,1,0,0,0,168,166,1,0,0,0,169,161,1,0,0,0,
+ 169,170,1,0,0,0,170,171,1,0,0,0,171,227,5,4,0,0,172,173,5,17,0,0,173,227,
+ 3,12,6,35,174,175,5,18,0,0,175,227,3,12,6,34,176,177,5,19,0,0,177,227,
+ 3,16,8,0,178,179,5,20,0,0,179,227,3,16,8,0,180,181,3,16,8,0,181,182,5,
+ 19,0,0,182,227,1,0,0,0,183,184,3,16,8,0,184,185,5,20,0,0,185,227,1,0,0,
+ 0,186,187,3,16,8,0,187,188,5,39,0,0,188,189,3,12,6,11,189,227,1,0,0,0,
+ 190,191,3,16,8,0,191,192,5,40,0,0,192,193,3,12,6,10,193,227,1,0,0,0,194,
+ 195,3,16,8,0,195,196,5,41,0,0,196,197,3,12,6,9,197,227,1,0,0,0,198,199,
+ 3,16,8,0,199,200,5,42,0,0,200,201,3,12,6,8,201,227,1,0,0,0,202,203,3,16,
+ 8,0,203,204,5,43,0,0,204,205,3,12,6,7,205,227,1,0,0,0,206,207,3,16,8,0,
+ 207,208,5,44,0,0,208,209,3,12,6,6,209,227,1,0,0,0,210,211,3,16,8,0,211,
+ 212,5,45,0,0,212,213,3,12,6,5,213,227,1,0,0,0,214,215,3,16,8,0,215,216,
+ 5,46,0,0,216,217,3,12,6,4,217,227,1,0,0,0,218,219,3,16,8,0,219,220,5,47,
+ 0,0,220,221,3,12,6,3,221,227,1,0,0,0,222,223,3,16,8,0,223,224,5,48,0,0,
+ 224,225,3,12,6,2,225,227,1,0,0,0,226,148,1,0,0,0,226,153,1,0,0,0,226,154,
+ 1,0,0,0,226,158,1,0,0,0,226,159,1,0,0,0,226,172,1,0,0,0,226,174,1,0,0,
+ 0,226,176,1,0,0,0,226,178,1,0,0,0,226,180,1,0,0,0,226,183,1,0,0,0,226,
+ 186,1,0,0,0,226,190,1,0,0,0,226,194,1,0,0,0,226,198,1,0,0,0,226,202,1,
+ 0,0,0,226,206,1,0,0,0,226,210,1,0,0,0,226,214,1,0,0,0,226,218,1,0,0,0,
+ 226,222,1,0,0,0,227,290,1,0,0,0,228,229,10,29,0,0,229,230,5,21,0,0,230,
+ 289,3,12,6,30,231,232,10,28,0,0,232,233,5,22,0,0,233,289,3,12,6,29,234,
+ 235,10,27,0,0,235,236,5,23,0,0,236,289,3,12,6,28,237,238,10,26,0,0,238,
+ 239,5,24,0,0,239,289,3,12,6,27,240,241,10,25,0,0,241,242,5,25,0,0,242,
+ 289,3,12,6,26,243,244,10,24,0,0,244,245,5,26,0,0,245,289,3,12,6,25,246,
+ 247,10,23,0,0,247,248,5,27,0,0,248,289,3,12,6,24,249,250,10,22,0,0,250,
+ 251,5,28,0,0,251,289,3,12,6,23,252,253,10,21,0,0,253,254,5,29,0,0,254,
+ 289,3,12,6,22,255,256,10,20,0,0,256,257,5,30,0,0,257,289,3,12,6,21,258,
+ 259,10,19,0,0,259,260,5,31,0,0,260,289,3,12,6,20,261,262,10,18,0,0,262,
+ 263,5,32,0,0,263,289,3,12,6,19,264,265,10,17,0,0,265,266,5,33,0,0,266,
+ 289,3,12,6,18,267,268,10,16,0,0,268,269,5,34,0,0,269,289,3,12,6,17,270,
+ 271,10,15,0,0,271,272,5,35,0,0,272,289,3,12,6,16,273,274,10,14,0,0,274,
+ 275,5,36,0,0,275,289,3,12,6,15,276,277,10,13,0,0,277,278,5,37,0,0,278,
+ 289,3,12,6,14,279,280,10,12,0,0,280,281,5,38,0,0,281,289,3,12,6,13,282,
+ 283,10,1,0,0,283,284,5,49,0,0,284,285,3,12,6,0,285,286,5,50,0,0,286,287,
+ 3,12,6,2,287,289,1,0,0,0,288,228,1,0,0,0,288,231,1,0,0,0,288,234,1,0,0,
+ 0,288,237,1,0,0,0,288,240,1,0,0,0,288,243,1,0,0,0,288,246,1,0,0,0,288,
+ 249,1,0,0,0,288,252,1,0,0,0,288,255,1,0,0,0,288,258,1,0,0,0,288,261,1,
+ 0,0,0,288,264,1,0,0,0,288,267,1,0,0,0,288,270,1,0,0,0,288,273,1,0,0,0,
+ 288,276,1,0,0,0,288,279,1,0,0,0,288,282,1,0,0,0,289,292,1,0,0,0,290,288,
+ 1,0,0,0,290,291,1,0,0,0,291,13,1,0,0,0,292,290,1,0,0,0,293,294,5,52,0,
+ 0,294,15,1,0,0,0,295,296,5,51,0,0,296,17,1,0,0,0,21,21,35,38,52,55,59,
+ 65,72,85,90,94,98,106,110,138,144,166,169,226,288,290
};
public static readonly ATN _ATN =
diff --git a/Compiler/gen/CGrammarVisitor.cs b/Compiler/gen/CGrammarVisitor.cs
index e0689f0..a3271f8 100644
--- a/Compiler/gen/CGrammarVisitor.cs
+++ b/Compiler/gen/CGrammarVisitor.cs
@@ -38,11 +38,19 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitProgram([NotNull] CGrammarParser.ProgramContext context);
/// <summary>
- /// Visit a parse tree produced by <see cref="CGrammarParser.function"/>.
+ /// Visit a parse tree produced by the <c>functionPrototype</c>
+ /// labeled alternative in <see cref="CGrammarParser.function"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
- Result VisitFunction([NotNull] CGrammarParser.FunctionContext context);
+ Result VisitFunctionPrototype([NotNull] CGrammarParser.FunctionPrototypeContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>functionDefinition</c>
+ /// labeled alternative in <see cref="CGrammarParser.function"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitFunctionDefinition([NotNull] CGrammarParser.FunctionDefinitionContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="CGrammarParser.block"/>.
/// </summary>
@@ -70,6 +78,48 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitIfStatement([NotNull] CGrammarParser.IfStatementContext context);
/// <summary>
+ /// Visit a parse tree produced by the <c>forExprStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitForExprStatement([NotNull] CGrammarParser.ForExprStatementContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>forDeclStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitForDeclStatement([NotNull] CGrammarParser.ForDeclStatementContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>whileStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitWhileStatement([NotNull] CGrammarParser.WhileStatementContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>doWhileStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitDoWhileStatement([NotNull] CGrammarParser.DoWhileStatementContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>breakStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitBreakStatement([NotNull] CGrammarParser.BreakStatementContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>continueStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitContinueStatement([NotNull] CGrammarParser.ContinueStatementContext context);
+ /// <summary>
/// Visit a parse tree produced by the <c>expressionStatement</c>
/// labeled alternative in <see cref="CGrammarParser.statement"/>.
/// </summary>
@@ -84,6 +134,13 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitBlockStatement([NotNull] CGrammarParser.BlockStatementContext context);
/// <summary>
+ /// Visit a parse tree produced by the <c>nullStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitNullStatement([NotNull] CGrammarParser.NullStatementContext context);
+ /// <summary>
/// Visit a parse tree produced by the <c>variableDeclaration</c>
/// labeled alternative in <see cref="CGrammarParser.declaration"/>.
/// </summary>
@@ -294,13 +351,6 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context);
/// <summary>
- /// Visit a parse tree produced by the <c>commaExpression</c>
- /// labeled alternative in <see cref="CGrammarParser.expression"/>.
- /// </summary>
- /// <param name="context">The parse tree.</param>
- /// <return>The visitor result.</return>
- Result VisitCommaExpression([NotNull] CGrammarParser.CommaExpressionContext context);
- /// <summary>
/// Visit a parse tree produced by the <c>incrementPrefixExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// </summary>
@@ -329,6 +379,13 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context);
/// <summary>
+ /// Visit a parse tree produced by the <c>callExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitCallExpression([NotNull] CGrammarParser.CallExpressionContext context);
+ /// <summary>
/// Visit a parse tree produced by the <c>addExpression</c>
/// labeled alternative in <see cref="CGrammarParser.expression"/>.
/// </summary>