diff options
Diffstat (limited to 'Compiler')
| -rw-r--r-- | Compiler/CCompilerVisitor.cs | 906 | ||||
| -rw-r--r-- | Compiler/CGrammar.g4 | 17 | ||||
| -rw-r--r-- | Compiler/CType.cs | 31 | ||||
| -rw-r--r-- | Compiler/FunctionReference.cs | 20 | ||||
| -rw-r--r-- | Compiler/Program.cs | 20 | ||||
| -rw-r--r-- | Compiler/Target.cs | 15 | ||||
| -rw-r--r-- | Compiler/VariableReference.cs | 8 | ||||
| -rw-r--r-- | Compiler/gen/CGrammar.interp | 14 | ||||
| -rw-r--r-- | Compiler/gen/CGrammar.tokens | 91 | ||||
| -rw-r--r-- | Compiler/gen/CGrammarBaseVisitor.cs | 44 | ||||
| -rw-r--r-- | Compiler/gen/CGrammarLexer.cs | 219 | ||||
| -rw-r--r-- | Compiler/gen/CGrammarLexer.interp | 18 | ||||
| -rw-r--r-- | Compiler/gen/CGrammarLexer.tokens | 91 | ||||
| -rw-r--r-- | Compiler/gen/CGrammarParser.cs | 919 | ||||
| -rw-r--r-- | Compiler/gen/CGrammarVisitor.cs | 28 | ||||
| -rw-r--r-- | Compiler/visitors/Constants.cs | 50 | ||||
| -rw-r--r-- | Compiler/visitors/Definitions.cs | 123 | ||||
| -rw-r--r-- | Compiler/visitors/Expressions.cs | 134 | ||||
| -rw-r--r-- | Compiler/visitors/FlowControl.cs | 177 | ||||
| -rw-r--r-- | Compiler/visitors/Main.cs | 183 | ||||
| -rw-r--r-- | Compiler/visitors/Operations.cs | 305 | ||||
| -rw-r--r-- | Compiler/visitors/Targets.cs | 40 |
22 files changed, 1968 insertions, 1485 deletions
diff --git a/Compiler/CCompilerVisitor.cs b/Compiler/CCompilerVisitor.cs deleted file mode 100644 index 9ffc639..0000000 --- a/Compiler/CCompilerVisitor.cs +++ /dev/null @@ -1,906 +0,0 @@ -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, VariableReference>> _variableStack = new(); - private List<FunctionReference> _methods = new(); - private static int _memLowest = Q1Layout.FreeMemoryStart; - private static int _memPointer = CCompilerVisitor._memLowest; - - private List<(CGrammarParser.FunctionDefinitionContext context, - FunctionReference function, FunctionOverload overload, - List<string> paramNames, List<string> paramTypes)> _functionBodies = new(); - - private const int ColumnWidth = 30; - - public readonly CommentCompilationMode CommentMode; - - public CCompilerVisitor(CommentCompilationMode commentMode) - { - this.CommentMode = commentMode; - } - - private VariableReference FindVariable(string varName) - { - foreach (Dictionary<string, VariableReference> variables in this._variableStack) - { - if (variables.TryGetValue(varName, out VariableReference? reference)) - return reference; - } - - throw new CompilerException($"Variable {varName} could not be found in current scope."); - } - - private int Alloc(int size) - { - int loc = CCompilerVisitor._memPointer; - CCompilerVisitor._memPointer += size; - - return loc; - } - - private string GenerateBranchLabel(string type) - { - return $"_{type}_{_branchCount++}"; - } - private void Instruction(string instruction, string? generatedComment = null) - { - this._instructions.Add($" {instruction}"); - if (generatedComment != null) - this.CommentLastInstruction(generatedComment); - } - private void Blank() - { - this._instructions.Add(""); - } - private void Branch(string name, string? generatedComment = null) - { - this._instructions.Add($"{name}:"); - if (generatedComment != null) - this.CommentLastInstruction(generatedComment); - } - private void UserComment(string comment) - { - if (this.CommentMode.HasFlag(CommentCompilationMode.UserDefined)) - this._instructions.Add($" ; {comment}"); - } - - private void GeneratedComment(string comment) - { - if (this.CommentMode.HasFlag(CommentCompilationMode.Generated)) - this._instructions.Add($"{"".PadRight(CCompilerVisitor.ColumnWidth)}; {comment}"); - } - - private void CommentLastInstruction(string comment) - { - if (!this.CommentMode.HasFlag(CommentCompilationMode.Generated)) - return; - - if (this._instructions.Count == 0) - throw new Exception("Cannot add comment to last instruction, there are none"); - - string lastInstruction = this._instructions[^1]; - lastInstruction = $"{lastInstruction.PadRight(CCompilerVisitor.ColumnWidth)}; {comment}"; - - this._instructions[^1] = lastInstruction; - } - - - public IEnumerable<string> Compile(CGrammarParser.ProgramContext program) - { - Instruction("jmp _main"); - this.Visit(program); - - foreach ((CGrammarParser.FunctionDefinitionContext context, - FunctionReference function, FunctionOverload overload, - List<string> paramNames, List<string> paramTypes) in this._functionBodies) - this.VisitFunctionBody(context, function, overload, paramNames, paramTypes); - - return this._instructions; - } - - 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; - string type = "int"; - - List<string> parameterTypes = context._types.Select(x => x.Text).ToList(); - List<string> parameterNames = context._params.Select(x => x.Text).ToList(); - - 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._functionBodies.Add((context, function, overload, paramNames, paramTypes)); - - return null; - } - private void VisitFunctionBody(CGrammarParser.FunctionDefinitionContext context, FunctionReference function, FunctionOverload overload, List<string> paramNames, List<string> 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(); - } - - 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()); - } - public override string? VisitReturnStatement(CGrammarParser.ReturnStatementContext context) - { - if (context.expression() != null) - { - string? expression = this.Visit(context.expression()); - if (expression != null) - { - this.Instruction($"mov {expression}, V0", "return value"); - this.Instruction($"ret"); - } - else - throw new CompilerException("Return value was not an expression."); - } - else - this.Instruction("ret"); - - return null; - } - public override string? VisitIntConstant(CGrammarParser.IntConstantContext context) - { - string valueString = context.INT().GetText(); - if (int.TryParse(valueString, out int value)) - return $"{value}"; - else - throw new CompilerException($"Invalid integer value: {valueString}"); - } - - public override string? VisitHexConstant(CGrammarParser.HexConstantContext context) - { - string valueString = context.HEX().GetText(); - valueString = valueString[2..]; // Remove 0x - return $"${valueString}"; - } - - public override string? VisitNotExpression(CGrammarParser.NotExpressionContext context) - { - string? value = this.Visit(context.expression()); - if (value == null) - throw new CompilerException("Value for negating was not an expression."); - - this.Instruction($"not {value}"); - return "LX"; - } - - public override string? VisitInvertExpression(CGrammarParser.InvertExpressionContext context) - { - string? value = this.Visit(context.expression()); - if (value == null) - throw new CompilerException("Value for inversion was not an expression."); - - this.Instruction($"inv {value}"); - return "DX"; - } - - private void BaseBinaryOperation(CGrammarParser.ExpressionContext leftExpr, CGrammarParser.ExpressionContext rightExpr, string operation, string operationFriendlyName) - { - string? left = this.Visit(leftExpr); - if (left == null) - throw new CompilerException($"Left operand for {operationFriendlyName} was not an expression."); - - this.Instruction($"push {left}", "left operand"); - - string? right = this.Visit(rightExpr); - 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($"{operation} V0, V1", $"compute {operationFriendlyName}"); - } - private string BaseBinaryCompoundOperation(CGrammarParser.TargetContext leftTarget, CGrammarParser.ExpressionContext rightExpr, string operation, string operationFriendlyName, string operationOutput) - { - string? left = this.Visit(leftTarget); - if (left == null) - throw new CompilerException($"Left operand for {operationFriendlyName} was not an expression."); - - string? right = this.Visit(rightExpr); - if (right == null) - 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($"mov {operationOutput}, {left}", "store back into left param"); - return left; - } - public override string? VisitAddExpression(CGrammarParser.AddExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "add", "addition"); - return "AX"; - } - public override string? VisitSubtractExpression(CGrammarParser.SubtractExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "sub", "subtraction"); - return "AX"; - } - public override string? VisitMultiplyExpression(CGrammarParser.MultiplyExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "mul", "multiplication"); - return "AX"; - } - public override string? VisitDivideExpression(CGrammarParser.DivideExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "div", "division"); - return "AX"; - } - public override string? VisitModulusExpression(CGrammarParser.ModulusExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "mod", "modulus"); - return "AX"; - } - - public override string? VisitEqualExpression(CGrammarParser.EqualExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); - return "LX"; - } - - public override string? VisitNotEqualExpression(CGrammarParser.NotEqualExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "cmp", "inequality check"); - this.Instruction($"not"); // lx is implicit - return "LX"; - } - - public override string? VisitGreaterThanExpression(CGrammarParser.GreaterThanExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "gt", "greater than check"); - return "LX"; - } - - public override string? VisitLessThanExpression(CGrammarParser.LessThanExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "lt", "less than check"); - return "LX"; - } - - public override string? VisitLogicalOrExpression(CGrammarParser.LogicalOrExpressionContext context) - { - string? left = this.Visit(context.left); - if (left == null) - throw new CompilerException("Left operand for logical OR was not an expression."); - - string clauseBranch = this.GenerateBranchLabel("clause"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction($"cmp {left}, 0", "logical or"); - this.Instruction("bz"); // implicit LX - 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.Branch(clauseBranch); - - string? right = this.Visit(context.right); - if (right == null) - throw new CompilerException("Right operand for logical OR was not an expression."); - - 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.Branch(endBranch); - - return "V0"; - } - public override string? VisitLogicalAndExpression(CGrammarParser.LogicalAndExpressionContext context) - { - string? left = this.Visit(context.left); - if (left == null) - throw new CompilerException("Left operand for logical OR was not an expression."); - - string clauseBranch = this.GenerateBranchLabel("clause"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction($"cmp {left}, 0", "logical and"); - this.Instruction("not"); - this.Instruction("bz"); // implicit LX - 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.Branch(clauseBranch); - - string? right = this.Visit(context.right); - if (right == null) - throw new CompilerException("Right operand for logical OR was not an expression."); - - 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.Branch(endBranch); - - return "V0"; - } - - public override string? VisitGreaterThanOrEqualExpression(CGrammarParser.GreaterThanOrEqualExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction("bz"); - this.Instruction($"jmp {endBranch}"); - this.Instruction($"gt V0, V1"); - this.Branch(endBranch); - - return "LX"; - } - public override string? VisitLessThanOrEqualExpression(CGrammarParser.LessThanOrEqualExpressionContext context) - { - BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); - string endBranch = this.GenerateBranchLabel("end"); - - this.Instruction("bz"); - this.Instruction($"jmp {endBranch}"); - this.Instruction($"lt V0, V1"); - this.Branch(endBranch); - - return "LX"; - } - public override string? VisitBitwiseXorExpression(CGrammarParser.BitwiseXorExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "xor", "exclusive or"); - return "DX"; - } - public override string? VisitBitwiseOrExpression(CGrammarParser.BitwiseOrExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "or", "or"); - return "DX"; - } - public override string? VisitBitwiseAndExpression(CGrammarParser.BitwiseAndExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "and", "and"); - return "DX"; - } - public override string? VisitBitwiseLeftShiftExpression(CGrammarParser.BitwiseLeftShiftExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "shl", "left shift"); - return "DX"; - } - public override string? VisitBitwiseRightShiftExpression(CGrammarParser.BitwiseRightShiftExpressionContext context) - { - this.BaseBinaryOperation(context.left, context.right, "shr", "right shift"); - return "DX"; - } - - public override string? VisitVariableDeclaration(CGrammarParser.VariableDeclarationContext context) - { - int size = 2; - int addr = this.Alloc(size); - string name = context.name.Text; - - Dictionary<string, VariableReference> scope = this._variableStack.Peek(); - if (scope.ContainsKey(name)) - throw new CompilerException($"Variable {name} already exists in current scope."); - - 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"); - this.Instruction($"mov {initialValue}, [${addr:X4}]", $"int {name} = {initialValue}"); - } - else - this.Instruction($"mov 0, [${addr:X4}]", $"int {name}"); - - return null; - } - public override string? VisitVariableExpression(CGrammarParser.VariableExpressionContext context) - { - string varName = context.ID().GetText(); - VariableReference reference = this.FindVariable(varName); - - return $"[${reference.Address:X4}]"; - } - - public override string? VisitVariableTarget(CGrammarParser.VariableTargetContext context) - { - string varName = context.ID().GetText(); - VariableReference reference = this.FindVariable(varName); - - 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}", $"{target} = {value}"); - return target; - } - - public override string? VisitCompoundAddExpression(CGrammarParser.CompoundAddExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "add", - "addition", - "AX"); - } - public override string? VisitCompoundSubtractExpression(CGrammarParser.CompoundSubtractExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "sub", - "subtraction", - "AX"); - } - public override string? VisitCompoundMultiplyExpression(CGrammarParser.CompoundMultiplyExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "mult", - "multiplication", - "AX"); - } - public override string? VisitCompoundDivideExpression(CGrammarParser.CompoundDivideExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "div", - "division", - "AX"); - } - public override string? VisitCompoundModulusExpression(CGrammarParser.CompoundModulusExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "mod", - "modulus", - "AX"); - } - - public override string? VisitCompoundBitwiseOrExpression(CGrammarParser.CompoundBitwiseOrExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "or", - "or", - "DX"); - } - public override string? VisitCompoundBitwiseXorExpression(CGrammarParser.CompoundBitwiseXorExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "xor", - "exclusive or", - "DX"); - } - public override string? VisitCompoundBitwiseAndExpression(CGrammarParser.CompoundBitwiseAndExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "and", - "and", - "DX"); - } - - public override string? VisitCompoundBitwiseLeftShiftExpression(CGrammarParser.CompoundBitwiseLeftShiftExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "shl", - "left shift", - "DX"); - } - public override string? VisitCompoundBitwiseRightShiftExpression(CGrammarParser.CompoundBitwiseRightShiftExpressionContext context) - { - return BaseBinaryCompoundOperation(context.target(), - context.expression(), - "shr", - "right shift", - "DX"); - } - - public override string? VisitIncrementPrefixExpression(CGrammarParser.IncrementPrefixExpressionContext context) - { - string target = this.Visit(context.target()) - ?? throw new CompilerException("Increment target was not an expression"); - this.Instruction($"inc {target}", "++i"); - return target; - } - public override string? VisitDecrementPrefixExpression(CGrammarParser.DecrementPrefixExpressionContext context) - { - string target = this.Visit(context.target()) - ?? throw new CompilerException("Decrement target was not an expression"); - this.Instruction($"dec {target}", "--i"); - return target; - } - public override string? VisitIncrementPostfixExpression(CGrammarParser.IncrementPostfixExpressionContext context) - { - string target = this.Visit(context.target()) - ?? throw new CompilerException("Increment target was not an expression"); - this.Instruction($"push {target}", "i++"); - this.Instruction($"inc {target}"); - this.Instruction("pop V0"); - return "V0"; - } - public override string? VisitDecrementPostfixExpression(CGrammarParser.DecrementPostfixExpressionContext context) - { - string target = this.Visit(context.target()) - ?? throw new CompilerException("Decrement target was not an expression"); - this.Instruction($"push {target}", "i--"); - this.Instruction($"dec {target}"); - 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? VisitTernaryExpression(CGrammarParser.TernaryExpressionContext context) - { - string cond = this.Visit(context.cond) - ?? throw new CompilerException("Ternary condition was not an expression"); - - string thenBranch = this.GenerateBranchLabel("then"); - string endBranch = this.GenerateBranchLabel("end"); - string result; - - // 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 - - 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.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.Branch(endBranch); - - return "V0"; - } - - public override string? VisitIfStatement(CGrammarParser.IfStatementContext context) - { - 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.Branch(thenBranch, "if succeeded"); - this.Visit(context.then); - } - else - { - this.Instruction($"not"); - this.Instruction($"jmp {endBranch}", "if succeeds, continue, else jump to end"); - this.Visit(context.then); - } - - this.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; - } - - public override string? VisitAddressOfExpression(CGrammarParser.AddressOfExpressionContext context) - { - string target = this.Visit(context.target()) - ?? throw new CompilerException("Address of target was not a targetable expression"); - - if (target.StartsWith("@")) - return target[1..]; - - if (target.StartsWith("[") && target.EndsWith("]")) - return target[1..^1]; - - throw new CompilerException($"Could not get address of target '{target}'"); - } - public override string? VisitDereferenceExpression(CGrammarParser.DereferenceExpressionContext context) - { - string value = this.Visit(context.expression()) - ?? throw new CompilerException("Dereference pointer was not an expression"); - - this.Instruction($"mov {value}, V0", "move pointer into register for dereference"); - return "[V0]"; - } - - public override string? VisitErrorNode(IErrorNode node) - { - if (node.Symbol.Type == CGrammarParser.COMMENT) - { - // strip // and \n and whitespace - 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); - } - - /// <summary> - /// Basically identical to base version, except calls Visit on each child, making Visit not redundant. - /// </summary> - public override string? VisitChildren(IRuleNode node) - { - string? result = this.DefaultResult; - int childCount = node.ChildCount; - for (int i = 0; i < childCount && this.ShouldVisitNextChild(node, result); ++i) - { - string? nextResult = this.Visit(node.GetChild(i)); - result = this.AggregateResult(result, nextResult); - } - return result; - } -} - -public class CType -{ - public string - public int Size; -}
\ No newline at end of file diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4 index b0a03f7..f89896a 100644 --- a/Compiler/CGrammar.g4 +++ b/Compiler/CGrammar.g4 @@ -4,13 +4,16 @@ options { contextSuperClass = Q1.Compiler.Context; } -HEX: '0x' [0-9a-fA-F]; +HEX: '0x' [0-9a-fA-F]+; ID: [a-zA-Z_][a-zA-Z0-9_]*; INT: [0-9]+; WS: [ \t\r\n]+ -> skip; COMMENT: '//' .*? ([\n] | EOF) -> channel(HIDDEN); +DIRECTIVE: '#' .*? ([\n] | EOF) -> channel(HIDDEN); +LETTER: '\'' . '\''; +STRING: '"' .*? '"'; program : function+ EOF @@ -52,6 +55,7 @@ declaration expression : '(' expression ')' #parenthesizedExpression // | left=expression ',' right=expression #commaExpression + | 'new' type '[' INT? ']' '{' ( params+=expression (',' params+=expression )* )? '}' #arrayExpression | constant #constantExpression | target '=' expression #assignmentExpression | '*' expression #dereferenceExpression @@ -59,7 +63,7 @@ expression | ID #variableExpression | ID '(' ( params+=expression (',' params+=expression )* )? ')' #callExpression - | obj=expression '[' indexer=expression ']' #indexExpression + | obj=target '[' indexer=expression ']' #indexExpression | '!' expression #notExpression | '~' expression #invertExpression @@ -113,14 +117,17 @@ expression constant : INT # intConstant | HEX # hexConstant + | LETTER # charConstant + | STRING # stringConstant ; type - : 'int' #intType - | 'char' #charType - | type '*' #pointerType + : 'int' + | 'char' + | type '*' ; target : ID # variableTarget + | obj=target '[' indexer=expression ']' #indexerTarget ;
\ No newline at end of file diff --git a/Compiler/CType.cs b/Compiler/CType.cs new file mode 100644 index 0000000..61b5108 --- /dev/null +++ b/Compiler/CType.cs @@ -0,0 +1,31 @@ +namespace Q1.Compiler.visitors; + +public class CType +{ + public string Name; + public int Size; + + public CType(string name, int size) + { + this.Name = name; + this.Size = size; + + if (size > 2) + throw new CompilerException("Types that take up more than 2 bytes are not supported"); + } + + public override string ToString() => this.Name; + + public static readonly CType Int = new("int", 2); + public static readonly CType Char = new("char", 1); +} + +public class CTypePtr : CType +{ + public CType Sub; + + public CTypePtr(CType sub) : base($"{sub.Name}*",2) + { + this.Sub = sub; + } +}
\ No newline at end of file diff --git a/Compiler/FunctionReference.cs b/Compiler/FunctionReference.cs index cf120ad..b63247a 100644 --- a/Compiler/FunctionReference.cs +++ b/Compiler/FunctionReference.cs @@ -2,15 +2,16 @@ namespace Q1.Compiler; using System.Reflection.Metadata; using System.Text; +using visitors; public class FunctionReference { // TODO: Implement return type public string Name; - public string Type; + public CType Type; public List<FunctionOverload> Overloads = new(); - public FunctionReference(string name, string type) + public FunctionReference(string name, CType type) { this.Type = type; this.Name = name; @@ -18,7 +19,7 @@ public class FunctionReference public string GetBranchName(FunctionOverload overload) { - List<(string paramName, string paramType)> parameters = overload + List<(string paramName, CType paramType)> parameters = overload .ParameterNames .Zip(overload.ParameterTypes) .ToList(); @@ -37,7 +38,7 @@ public class FunctionReference public string GetBranchFriendlyName(FunctionOverload overload) { - List<(string paramName, string paramType)> parameters = overload + List<(string paramName, CType paramType)> parameters = overload .ParameterNames .Zip(overload.ParameterTypes) .ToList(); @@ -54,7 +55,7 @@ public class FunctionReference return branchName.ToString(); } - public FunctionOverload CreateOverloadWithBody(List<string> parameterNames, List<string> parameterTypes) + public FunctionOverload CreateOverloadWithBody(List<string> parameterNames, List<CType> parameterTypes) { FunctionOverload? existingOverload = this.Overloads .FirstOrDefault(x => x.ParamsMatch(parameterNames, parameterTypes)); @@ -76,7 +77,7 @@ public class FunctionReference } } - public FunctionOverload CreateOverloadWithoutBody(List<string> parameterNames, List<string> parameterTypes) + public FunctionOverload CreateOverloadWithoutBody(List<string> parameterNames, List<CType> parameterTypes) { FunctionOverload? existingOverload = this.Overloads .FirstOrDefault(x => x.ParamsMatch(parameterNames, parameterTypes)); @@ -109,19 +110,18 @@ public class FunctionReference public class FunctionOverload { - // TODO: Implement return type - public List<string> ParameterTypes; + public List<CType> ParameterTypes; public List<string> ParameterNames; public bool BodyImplemented; - public FunctionOverload(List<string> parameterNames, List<string> parameterTypes, bool bodyImplemented) + public FunctionOverload(List<string> parameterNames, List<CType> parameterTypes, bool bodyImplemented) { this.ParameterTypes = parameterTypes; this.ParameterNames = parameterNames; this.BodyImplemented = bodyImplemented; } - public bool ParamsMatch(List<string> parameterNames, List<string> parameterTypes) + public bool ParamsMatch(List<string> parameterNames, List<CType> parameterTypes) { return this.ParameterNames.SequenceEqual(parameterNames) && this.ParameterTypes.SequenceEqual(parameterTypes); diff --git a/Compiler/Program.cs b/Compiler/Program.cs index 9259205..3a277a1 100644 --- a/Compiler/Program.cs +++ b/Compiler/Program.cs @@ -1,10 +1,12 @@ namespace Q1.Compiler; +using System.Text; using Antlr4.Runtime; using CommandLine; +using visitors; using Parser = CommandLine.Parser; -class Program +public class Program { static void Main(string[] args) { @@ -12,15 +14,15 @@ class Program { with.CaseInsensitiveEnumValues = true; }); - - commandLineParser.ParseArguments<CompilerOptions>(args) + + commandLineParser + .ParseArguments<CompilerOptions>(args) .WithParsed(Program.Main); } - static void Main(CompilerOptions options) + public static void Main(CompilerOptions options) { - Environment.CurrentDirectory = Path.GetDirectoryName(options.InputFile) ?? Environment.CurrentDirectory; - options.InputFile = Path.GetFileName(options.InputFile); + options.InputFile = options.InputFile; try { @@ -32,10 +34,14 @@ class Program CGrammarParser parser = new(tokenStream); parser.RemoveErrorListeners(); - CCompilerVisitor compiler = new(options.CommentCompilationMode); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + Encoding encoding = Encoding.GetEncoding(437); + CCompilerVisitor compiler = new(options.CommentCompilationMode, encoding); IEnumerable<string> result = compiler.Compile(parser.program()); File.WriteAllLines(options.OutputFile, result); + + Console.WriteLine("Compilation successful."); } catch (CompilerException ex) { diff --git a/Compiler/Target.cs b/Compiler/Target.cs new file mode 100644 index 0000000..84d055d --- /dev/null +++ b/Compiler/Target.cs @@ -0,0 +1,15 @@ +namespace Q1.Compiler.visitors; + +public class Target +{ + public string Value; + public string Address; + public CType Type; + + public Target(CType type, string value, string address) + { + this.Value = value; + this.Address = address; + this.Type = type; + } +}
\ No newline at end of file diff --git a/Compiler/VariableReference.cs b/Compiler/VariableReference.cs index 9524e98..4682d40 100644 --- a/Compiler/VariableReference.cs +++ b/Compiler/VariableReference.cs @@ -1,13 +1,15 @@ namespace Q1.Compiler; +using visitors; + public class VariableReference { public int Address; - public int Size; + public CType Type; - public VariableReference(int address, int size) + public VariableReference(int address, CType type) { this.Address = address; - this.Size = size; + this.Type = type; } }
\ No newline at end of file diff --git a/Compiler/gen/CGrammar.interp b/Compiler/gen/CGrammar.interp index 5cabe48..c4ec388 100644 --- a/Compiler/gen/CGrammar.interp +++ b/Compiler/gen/CGrammar.interp @@ -15,10 +15,11 @@ null 'break' 'continue' '=' -'*' -'&' +'new' '[' ']' +'*' +'&' '!' '~' '++' @@ -58,6 +59,9 @@ null null null null +null +null +null token symbolic names: null @@ -114,11 +118,15 @@ null null null null +null HEX ID INT WS COMMENT +DIRECTIVE +LETTER +STRING rule names: program @@ -134,4 +142,4 @@ target atn: -[4, 1, 58, 327, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 4, 0, 22, 8, 0, 11, 0, 12, 0, 23, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 37, 8, 1, 10, 1, 12, 1, 40, 9, 1, 3, 1, 42, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 56, 8, 1, 10, 1, 12, 1, 59, 9, 1, 3, 1, 61, 8, 1, 1, 1, 1, 1, 1, 1, 3, 1, 66, 8, 1, 1, 2, 1, 2, 5, 2, 70, 8, 2, 10, 2, 12, 2, 73, 9, 2, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 79, 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, 92, 8, 4, 1, 4, 1, 4, 1, 4, 3, 4, 97, 8, 4, 1, 4, 1, 4, 3, 4, 101, 8, 4, 1, 4, 1, 4, 3, 4, 105, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 113, 8, 4, 1, 4, 1, 4, 3, 4, 117, 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, 145, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 151, 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, 5, 6, 175, 8, 6, 10, 6, 12, 6, 178, 9, 6, 3, 6, 180, 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, 237, 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, 1, 6, 1, 6, 5, 6, 304, 8, 6, 10, 6, 12, 6, 307, 9, 6, 1, 7, 1, 7, 3, 7, 311, 8, 7, 1, 8, 1, 8, 1, 8, 3, 8, 316, 8, 8, 1, 8, 1, 8, 5, 8, 320, 8, 8, 10, 8, 12, 8, 323, 9, 8, 1, 9, 1, 9, 1, 9, 0, 2, 12, 16, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 0, 388, 0, 21, 1, 0, 0, 0, 2, 65, 1, 0, 0, 0, 4, 67, 1, 0, 0, 0, 6, 78, 1, 0, 0, 0, 8, 144, 1, 0, 0, 0, 10, 146, 1, 0, 0, 0, 12, 236, 1, 0, 0, 0, 14, 310, 1, 0, 0, 0, 16, 315, 1, 0, 0, 0, 18, 324, 1, 0, 0, 0, 20, 22, 3, 2, 1, 0, 21, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 5, 0, 0, 1, 26, 1, 1, 0, 0, 0, 27, 28, 3, 16, 8, 0, 28, 29, 5, 55, 0, 0, 29, 41, 5, 1, 0, 0, 30, 31, 3, 16, 8, 0, 31, 38, 5, 55, 0, 0, 32, 33, 5, 2, 0, 0, 33, 34, 3, 16, 8, 0, 34, 35, 5, 55, 0, 0, 35, 37, 1, 0, 0, 0, 36, 32, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 42, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 30, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 44, 5, 3, 0, 0, 44, 45, 5, 4, 0, 0, 45, 66, 1, 0, 0, 0, 46, 47, 3, 16, 8, 0, 47, 48, 5, 55, 0, 0, 48, 60, 5, 1, 0, 0, 49, 50, 3, 16, 8, 0, 50, 57, 5, 55, 0, 0, 51, 52, 5, 2, 0, 0, 52, 53, 3, 16, 8, 0, 53, 54, 5, 55, 0, 0, 54, 56, 1, 0, 0, 0, 55, 51, 1, 0, 0, 0, 56, 59, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 60, 49, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 63, 5, 3, 0, 0, 63, 64, 3, 4, 2, 0, 64, 66, 1, 0, 0, 0, 65, 27, 1, 0, 0, 0, 65, 46, 1, 0, 0, 0, 66, 3, 1, 0, 0, 0, 67, 71, 5, 5, 0, 0, 68, 70, 3, 6, 3, 0, 69, 68, 1, 0, 0, 0, 70, 73, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 74, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 74, 75, 5, 6, 0, 0, 75, 5, 1, 0, 0, 0, 76, 79, 3, 8, 4, 0, 77, 79, 3, 10, 5, 0, 78, 76, 1, 0, 0, 0, 78, 77, 1, 0, 0, 0, 79, 7, 1, 0, 0, 0, 80, 81, 5, 7, 0, 0, 81, 82, 3, 12, 6, 0, 82, 83, 5, 4, 0, 0, 83, 145, 1, 0, 0, 0, 84, 85, 5, 8, 0, 0, 85, 86, 5, 1, 0, 0, 86, 87, 3, 12, 6, 0, 87, 88, 5, 3, 0, 0, 88, 91, 3, 8, 4, 0, 89, 90, 5, 9, 0, 0, 90, 92, 3, 8, 4, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 145, 1, 0, 0, 0, 93, 94, 5, 10, 0, 0, 94, 96, 5, 1, 0, 0, 95, 97, 3, 12, 6, 0, 96, 95, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 100, 5, 4, 0, 0, 99, 101, 3, 12, 6, 0, 100, 99, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 104, 5, 4, 0, 0, 103, 105, 3, 12, 6, 0, 104, 103, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 107, 5, 3, 0, 0, 107, 145, 3, 8, 4, 0, 108, 109, 5, 10, 0, 0, 109, 110, 5, 1, 0, 0, 110, 112, 3, 10, 5, 0, 111, 113, 3, 12, 6, 0, 112, 111, 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 116, 5, 4, 0, 0, 115, 117, 3, 12, 6, 0, 116, 115, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 118, 1, 0, 0, 0, 118, 119, 5, 3, 0, 0, 119, 120, 3, 8, 4, 0, 120, 145, 1, 0, 0, 0, 121, 122, 5, 11, 0, 0, 122, 123, 5, 1, 0, 0, 123, 124, 3, 12, 6, 0, 124, 125, 5, 3, 0, 0, 125, 126, 3, 8, 4, 0, 126, 145, 1, 0, 0, 0, 127, 128, 5, 12, 0, 0, 128, 129, 3, 8, 4, 0, 129, 130, 5, 11, 0, 0, 130, 131, 5, 1, 0, 0, 131, 132, 3, 12, 6, 0, 132, 133, 5, 3, 0, 0, 133, 134, 5, 4, 0, 0, 134, 145, 1, 0, 0, 0, 135, 136, 5, 13, 0, 0, 136, 145, 5, 4, 0, 0, 137, 138, 5, 14, 0, 0, 138, 145, 5, 4, 0, 0, 139, 140, 3, 12, 6, 0, 140, 141, 5, 4, 0, 0, 141, 145, 1, 0, 0, 0, 142, 145, 3, 4, 2, 0, 143, 145, 5, 4, 0, 0, 144, 80, 1, 0, 0, 0, 144, 84, 1, 0, 0, 0, 144, 93, 1, 0, 0, 0, 144, 108, 1, 0, 0, 0, 144, 121, 1, 0, 0, 0, 144, 127, 1, 0, 0, 0, 144, 135, 1, 0, 0, 0, 144, 137, 1, 0, 0, 0, 144, 139, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 143, 1, 0, 0, 0, 145, 9, 1, 0, 0, 0, 146, 147, 3, 16, 8, 0, 147, 150, 5, 55, 0, 0, 148, 149, 5, 15, 0, 0, 149, 151, 3, 12, 6, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 153, 5, 4, 0, 0, 153, 11, 1, 0, 0, 0, 154, 155, 6, 6, -1, 0, 155, 156, 5, 1, 0, 0, 156, 157, 3, 12, 6, 0, 157, 158, 5, 3, 0, 0, 158, 237, 1, 0, 0, 0, 159, 237, 3, 14, 7, 0, 160, 161, 3, 18, 9, 0, 161, 162, 5, 15, 0, 0, 162, 163, 3, 12, 6, 41, 163, 237, 1, 0, 0, 0, 164, 165, 5, 16, 0, 0, 165, 237, 3, 12, 6, 40, 166, 167, 5, 17, 0, 0, 167, 237, 3, 18, 9, 0, 168, 237, 5, 55, 0, 0, 169, 170, 5, 55, 0, 0, 170, 179, 5, 1, 0, 0, 171, 176, 3, 12, 6, 0, 172, 173, 5, 2, 0, 0, 173, 175, 3, 12, 6, 0, 174, 172, 1, 0, 0, 0, 175, 178, 1, 0, 0, 0, 176, 174, 1, 0, 0, 0, 176, 177, 1, 0, 0, 0, 177, 180, 1, 0, 0, 0, 178, 176, 1, 0, 0, 0, 179, 171, 1, 0, 0, 0, 179, 180, 1, 0, 0, 0, 180, 181, 1, 0, 0, 0, 181, 237, 5, 3, 0, 0, 182, 183, 5, 20, 0, 0, 183, 237, 3, 12, 6, 35, 184, 185, 5, 21, 0, 0, 185, 237, 3, 12, 6, 34, 186, 187, 5, 22, 0, 0, 187, 237, 3, 18, 9, 0, 188, 189, 5, 23, 0, 0, 189, 237, 3, 18, 9, 0, 190, 191, 3, 18, 9, 0, 191, 192, 5, 22, 0, 0, 192, 237, 1, 0, 0, 0, 193, 194, 3, 18, 9, 0, 194, 195, 5, 23, 0, 0, 195, 237, 1, 0, 0, 0, 196, 197, 3, 18, 9, 0, 197, 198, 5, 40, 0, 0, 198, 199, 3, 12, 6, 11, 199, 237, 1, 0, 0, 0, 200, 201, 3, 18, 9, 0, 201, 202, 5, 41, 0, 0, 202, 203, 3, 12, 6, 10, 203, 237, 1, 0, 0, 0, 204, 205, 3, 18, 9, 0, 205, 206, 5, 42, 0, 0, 206, 207, 3, 12, 6, 9, 207, 237, 1, 0, 0, 0, 208, 209, 3, 18, 9, 0, 209, 210, 5, 43, 0, 0, 210, 211, 3, 12, 6, 8, 211, 237, 1, 0, 0, 0, 212, 213, 3, 18, 9, 0, 213, 214, 5, 44, 0, 0, 214, 215, 3, 12, 6, 7, 215, 237, 1, 0, 0, 0, 216, 217, 3, 18, 9, 0, 217, 218, 5, 45, 0, 0, 218, 219, 3, 12, 6, 6, 219, 237, 1, 0, 0, 0, 220, 221, 3, 18, 9, 0, 221, 222, 5, 46, 0, 0, 222, 223, 3, 12, 6, 5, 223, 237, 1, 0, 0, 0, 224, 225, 3, 18, 9, 0, 225, 226, 5, 47, 0, 0, 226, 227, 3, 12, 6, 4, 227, 237, 1, 0, 0, 0, 228, 229, 3, 18, 9, 0, 229, 230, 5, 48, 0, 0, 230, 231, 3, 12, 6, 3, 231, 237, 1, 0, 0, 0, 232, 233, 3, 18, 9, 0, 233, 234, 5, 49, 0, 0, 234, 235, 3, 12, 6, 2, 235, 237, 1, 0, 0, 0, 236, 154, 1, 0, 0, 0, 236, 159, 1, 0, 0, 0, 236, 160, 1, 0, 0, 0, 236, 164, 1, 0, 0, 0, 236, 166, 1, 0, 0, 0, 236, 168, 1, 0, 0, 0, 236, 169, 1, 0, 0, 0, 236, 182, 1, 0, 0, 0, 236, 184, 1, 0, 0, 0, 236, 186, 1, 0, 0, 0, 236, 188, 1, 0, 0, 0, 236, 190, 1, 0, 0, 0, 236, 193, 1, 0, 0, 0, 236, 196, 1, 0, 0, 0, 236, 200, 1, 0, 0, 0, 236, 204, 1, 0, 0, 0, 236, 208, 1, 0, 0, 0, 236, 212, 1, 0, 0, 0, 236, 216, 1, 0, 0, 0, 236, 220, 1, 0, 0, 0, 236, 224, 1, 0, 0, 0, 236, 228, 1, 0, 0, 0, 236, 232, 1, 0, 0, 0, 237, 305, 1, 0, 0, 0, 238, 239, 10, 29, 0, 0, 239, 240, 5, 16, 0, 0, 240, 304, 3, 12, 6, 30, 241, 242, 10, 28, 0, 0, 242, 243, 5, 24, 0, 0, 243, 304, 3, 12, 6, 29, 244, 245, 10, 27, 0, 0, 245, 246, 5, 25, 0, 0, 246, 304, 3, 12, 6, 28, 247, 248, 10, 26, 0, 0, 248, 249, 5, 26, 0, 0, 249, 304, 3, 12, 6, 27, 250, 251, 10, 25, 0, 0, 251, 252, 5, 27, 0, 0, 252, 304, 3, 12, 6, 26, 253, 254, 10, 24, 0, 0, 254, 255, 5, 28, 0, 0, 255, 304, 3, 12, 6, 25, 256, 257, 10, 23, 0, 0, 257, 258, 5, 29, 0, 0, 258, 304, 3, 12, 6, 24, 259, 260, 10, 22, 0, 0, 260, 261, 5, 30, 0, 0, 261, 304, 3, 12, 6, 23, 262, 263, 10, 21, 0, 0, 263, 264, 5, 31, 0, 0, 264, 304, 3, 12, 6, 22, 265, 266, 10, 20, 0, 0, 266, 267, 5, 32, 0, 0, 267, 304, 3, 12, 6, 21, 268, 269, 10, 19, 0, 0, 269, 270, 5, 33, 0, 0, 270, 304, 3, 12, 6, 20, 271, 272, 10, 18, 0, 0, 272, 273, 5, 17, 0, 0, 273, 304, 3, 12, 6, 19, 274, 275, 10, 17, 0, 0, 275, 276, 5, 34, 0, 0, 276, 304, 3, 12, 6, 18, 277, 278, 10, 16, 0, 0, 278, 279, 5, 35, 0, 0, 279, 304, 3, 12, 6, 17, 280, 281, 10, 15, 0, 0, 281, 282, 5, 36, 0, 0, 282, 304, 3, 12, 6, 16, 283, 284, 10, 14, 0, 0, 284, 285, 5, 37, 0, 0, 285, 304, 3, 12, 6, 15, 286, 287, 10, 13, 0, 0, 287, 288, 5, 38, 0, 0, 288, 304, 3, 12, 6, 14, 289, 290, 10, 12, 0, 0, 290, 291, 5, 39, 0, 0, 291, 304, 3, 12, 6, 13, 292, 293, 10, 1, 0, 0, 293, 294, 5, 50, 0, 0, 294, 295, 3, 12, 6, 0, 295, 296, 5, 51, 0, 0, 296, 297, 3, 12, 6, 2, 297, 304, 1, 0, 0, 0, 298, 299, 10, 36, 0, 0, 299, 300, 5, 18, 0, 0, 300, 301, 3, 12, 6, 0, 301, 302, 5, 19, 0, 0, 302, 304, 1, 0, 0, 0, 303, 238, 1, 0, 0, 0, 303, 241, 1, 0, 0, 0, 303, 244, 1, 0, 0, 0, 303, 247, 1, 0, 0, 0, 303, 250, 1, 0, 0, 0, 303, 253, 1, 0, 0, 0, 303, 256, 1, 0, 0, 0, 303, 259, 1, 0, 0, 0, 303, 262, 1, 0, 0, 0, 303, 265, 1, 0, 0, 0, 303, 268, 1, 0, 0, 0, 303, 271, 1, 0, 0, 0, 303, 274, 1, 0, 0, 0, 303, 277, 1, 0, 0, 0, 303, 280, 1, 0, 0, 0, 303, 283, 1, 0, 0, 0, 303, 286, 1, 0, 0, 0, 303, 289, 1, 0, 0, 0, 303, 292, 1, 0, 0, 0, 303, 298, 1, 0, 0, 0, 304, 307, 1, 0, 0, 0, 305, 303, 1, 0, 0, 0, 305, 306, 1, 0, 0, 0, 306, 13, 1, 0, 0, 0, 307, 305, 1, 0, 0, 0, 308, 311, 5, 56, 0, 0, 309, 311, 5, 54, 0, 0, 310, 308, 1, 0, 0, 0, 310, 309, 1, 0, 0, 0, 311, 15, 1, 0, 0, 0, 312, 313, 6, 8, -1, 0, 313, 316, 5, 52, 0, 0, 314, 316, 5, 53, 0, 0, 315, 312, 1, 0, 0, 0, 315, 314, 1, 0, 0, 0, 316, 321, 1, 0, 0, 0, 317, 318, 10, 1, 0, 0, 318, 320, 5, 16, 0, 0, 319, 317, 1, 0, 0, 0, 320, 323, 1, 0, 0, 0, 321, 319, 1, 0, 0, 0, 321, 322, 1, 0, 0, 0, 322, 17, 1, 0, 0, 0, 323, 321, 1, 0, 0, 0, 324, 325, 5, 55, 0, 0, 325, 19, 1, 0, 0, 0, 24, 23, 38, 41, 57, 60, 65, 71, 78, 91, 96, 100, 104, 112, 116, 144, 150, 176, 179, 236, 303, 305, 310, 315, 321]
\ No newline at end of file +[4, 1, 62, 360, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 4, 0, 22, 8, 0, 11, 0, 12, 0, 23, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 37, 8, 1, 10, 1, 12, 1, 40, 9, 1, 3, 1, 42, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 56, 8, 1, 10, 1, 12, 1, 59, 9, 1, 3, 1, 61, 8, 1, 1, 1, 1, 1, 1, 1, 3, 1, 66, 8, 1, 1, 2, 1, 2, 5, 2, 70, 8, 2, 10, 2, 12, 2, 73, 9, 2, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 79, 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, 92, 8, 4, 1, 4, 1, 4, 1, 4, 3, 4, 97, 8, 4, 1, 4, 1, 4, 3, 4, 101, 8, 4, 1, 4, 1, 4, 3, 4, 105, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 113, 8, 4, 1, 4, 1, 4, 3, 4, 117, 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, 145, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 151, 8, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 164, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 171, 8, 6, 10, 6, 12, 6, 174, 9, 6, 3, 6, 176, 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, 5, 6, 195, 8, 6, 10, 6, 12, 6, 198, 9, 6, 3, 6, 200, 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, 3, 6, 262, 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, 324, 8, 6, 10, 6, 12, 6, 327, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 333, 8, 7, 1, 8, 1, 8, 1, 8, 3, 8, 338, 8, 8, 1, 8, 1, 8, 5, 8, 342, 8, 8, 10, 8, 12, 8, 345, 9, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 5, 9, 355, 8, 9, 10, 9, 12, 9, 358, 9, 9, 1, 9, 0, 3, 12, 16, 18, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 0, 428, 0, 21, 1, 0, 0, 0, 2, 65, 1, 0, 0, 0, 4, 67, 1, 0, 0, 0, 6, 78, 1, 0, 0, 0, 8, 144, 1, 0, 0, 0, 10, 146, 1, 0, 0, 0, 12, 261, 1, 0, 0, 0, 14, 332, 1, 0, 0, 0, 16, 337, 1, 0, 0, 0, 18, 346, 1, 0, 0, 0, 20, 22, 3, 2, 1, 0, 21, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 5, 0, 0, 1, 26, 1, 1, 0, 0, 0, 27, 28, 3, 16, 8, 0, 28, 29, 5, 56, 0, 0, 29, 41, 5, 1, 0, 0, 30, 31, 3, 16, 8, 0, 31, 38, 5, 56, 0, 0, 32, 33, 5, 2, 0, 0, 33, 34, 3, 16, 8, 0, 34, 35, 5, 56, 0, 0, 35, 37, 1, 0, 0, 0, 36, 32, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 42, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 30, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 44, 5, 3, 0, 0, 44, 45, 5, 4, 0, 0, 45, 66, 1, 0, 0, 0, 46, 47, 3, 16, 8, 0, 47, 48, 5, 56, 0, 0, 48, 60, 5, 1, 0, 0, 49, 50, 3, 16, 8, 0, 50, 57, 5, 56, 0, 0, 51, 52, 5, 2, 0, 0, 52, 53, 3, 16, 8, 0, 53, 54, 5, 56, 0, 0, 54, 56, 1, 0, 0, 0, 55, 51, 1, 0, 0, 0, 56, 59, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 60, 49, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 63, 5, 3, 0, 0, 63, 64, 3, 4, 2, 0, 64, 66, 1, 0, 0, 0, 65, 27, 1, 0, 0, 0, 65, 46, 1, 0, 0, 0, 66, 3, 1, 0, 0, 0, 67, 71, 5, 5, 0, 0, 68, 70, 3, 6, 3, 0, 69, 68, 1, 0, 0, 0, 70, 73, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 74, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 74, 75, 5, 6, 0, 0, 75, 5, 1, 0, 0, 0, 76, 79, 3, 8, 4, 0, 77, 79, 3, 10, 5, 0, 78, 76, 1, 0, 0, 0, 78, 77, 1, 0, 0, 0, 79, 7, 1, 0, 0, 0, 80, 81, 5, 7, 0, 0, 81, 82, 3, 12, 6, 0, 82, 83, 5, 4, 0, 0, 83, 145, 1, 0, 0, 0, 84, 85, 5, 8, 0, 0, 85, 86, 5, 1, 0, 0, 86, 87, 3, 12, 6, 0, 87, 88, 5, 3, 0, 0, 88, 91, 3, 8, 4, 0, 89, 90, 5, 9, 0, 0, 90, 92, 3, 8, 4, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 145, 1, 0, 0, 0, 93, 94, 5, 10, 0, 0, 94, 96, 5, 1, 0, 0, 95, 97, 3, 12, 6, 0, 96, 95, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 100, 5, 4, 0, 0, 99, 101, 3, 12, 6, 0, 100, 99, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 104, 5, 4, 0, 0, 103, 105, 3, 12, 6, 0, 104, 103, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 107, 5, 3, 0, 0, 107, 145, 3, 8, 4, 0, 108, 109, 5, 10, 0, 0, 109, 110, 5, 1, 0, 0, 110, 112, 3, 10, 5, 0, 111, 113, 3, 12, 6, 0, 112, 111, 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 116, 5, 4, 0, 0, 115, 117, 3, 12, 6, 0, 116, 115, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 118, 1, 0, 0, 0, 118, 119, 5, 3, 0, 0, 119, 120, 3, 8, 4, 0, 120, 145, 1, 0, 0, 0, 121, 122, 5, 11, 0, 0, 122, 123, 5, 1, 0, 0, 123, 124, 3, 12, 6, 0, 124, 125, 5, 3, 0, 0, 125, 126, 3, 8, 4, 0, 126, 145, 1, 0, 0, 0, 127, 128, 5, 12, 0, 0, 128, 129, 3, 8, 4, 0, 129, 130, 5, 11, 0, 0, 130, 131, 5, 1, 0, 0, 131, 132, 3, 12, 6, 0, 132, 133, 5, 3, 0, 0, 133, 134, 5, 4, 0, 0, 134, 145, 1, 0, 0, 0, 135, 136, 5, 13, 0, 0, 136, 145, 5, 4, 0, 0, 137, 138, 5, 14, 0, 0, 138, 145, 5, 4, 0, 0, 139, 140, 3, 12, 6, 0, 140, 141, 5, 4, 0, 0, 141, 145, 1, 0, 0, 0, 142, 145, 3, 4, 2, 0, 143, 145, 5, 4, 0, 0, 144, 80, 1, 0, 0, 0, 144, 84, 1, 0, 0, 0, 144, 93, 1, 0, 0, 0, 144, 108, 1, 0, 0, 0, 144, 121, 1, 0, 0, 0, 144, 127, 1, 0, 0, 0, 144, 135, 1, 0, 0, 0, 144, 137, 1, 0, 0, 0, 144, 139, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 143, 1, 0, 0, 0, 145, 9, 1, 0, 0, 0, 146, 147, 3, 16, 8, 0, 147, 150, 5, 56, 0, 0, 148, 149, 5, 15, 0, 0, 149, 151, 3, 12, 6, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 153, 5, 4, 0, 0, 153, 11, 1, 0, 0, 0, 154, 155, 6, 6, -1, 0, 155, 156, 5, 1, 0, 0, 156, 157, 3, 12, 6, 0, 157, 158, 5, 3, 0, 0, 158, 262, 1, 0, 0, 0, 159, 160, 5, 16, 0, 0, 160, 161, 3, 16, 8, 0, 161, 163, 5, 17, 0, 0, 162, 164, 5, 57, 0, 0, 163, 162, 1, 0, 0, 0, 163, 164, 1, 0, 0, 0, 164, 165, 1, 0, 0, 0, 165, 166, 5, 18, 0, 0, 166, 175, 5, 5, 0, 0, 167, 172, 3, 12, 6, 0, 168, 169, 5, 2, 0, 0, 169, 171, 3, 12, 6, 0, 170, 168, 1, 0, 0, 0, 171, 174, 1, 0, 0, 0, 172, 170, 1, 0, 0, 0, 172, 173, 1, 0, 0, 0, 173, 176, 1, 0, 0, 0, 174, 172, 1, 0, 0, 0, 175, 167, 1, 0, 0, 0, 175, 176, 1, 0, 0, 0, 176, 177, 1, 0, 0, 0, 177, 178, 5, 6, 0, 0, 178, 262, 1, 0, 0, 0, 179, 262, 3, 14, 7, 0, 180, 181, 3, 18, 9, 0, 181, 182, 5, 15, 0, 0, 182, 183, 3, 12, 6, 41, 183, 262, 1, 0, 0, 0, 184, 185, 5, 19, 0, 0, 185, 262, 3, 12, 6, 40, 186, 187, 5, 20, 0, 0, 187, 262, 3, 18, 9, 0, 188, 262, 5, 56, 0, 0, 189, 190, 5, 56, 0, 0, 190, 199, 5, 1, 0, 0, 191, 196, 3, 12, 6, 0, 192, 193, 5, 2, 0, 0, 193, 195, 3, 12, 6, 0, 194, 192, 1, 0, 0, 0, 195, 198, 1, 0, 0, 0, 196, 194, 1, 0, 0, 0, 196, 197, 1, 0, 0, 0, 197, 200, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 199, 191, 1, 0, 0, 0, 199, 200, 1, 0, 0, 0, 200, 201, 1, 0, 0, 0, 201, 262, 5, 3, 0, 0, 202, 203, 3, 18, 9, 0, 203, 204, 5, 17, 0, 0, 204, 205, 3, 12, 6, 0, 205, 206, 5, 18, 0, 0, 206, 262, 1, 0, 0, 0, 207, 208, 5, 21, 0, 0, 208, 262, 3, 12, 6, 35, 209, 210, 5, 22, 0, 0, 210, 262, 3, 12, 6, 34, 211, 212, 5, 23, 0, 0, 212, 262, 3, 18, 9, 0, 213, 214, 5, 24, 0, 0, 214, 262, 3, 18, 9, 0, 215, 216, 3, 18, 9, 0, 216, 217, 5, 23, 0, 0, 217, 262, 1, 0, 0, 0, 218, 219, 3, 18, 9, 0, 219, 220, 5, 24, 0, 0, 220, 262, 1, 0, 0, 0, 221, 222, 3, 18, 9, 0, 222, 223, 5, 41, 0, 0, 223, 224, 3, 12, 6, 11, 224, 262, 1, 0, 0, 0, 225, 226, 3, 18, 9, 0, 226, 227, 5, 42, 0, 0, 227, 228, 3, 12, 6, 10, 228, 262, 1, 0, 0, 0, 229, 230, 3, 18, 9, 0, 230, 231, 5, 43, 0, 0, 231, 232, 3, 12, 6, 9, 232, 262, 1, 0, 0, 0, 233, 234, 3, 18, 9, 0, 234, 235, 5, 44, 0, 0, 235, 236, 3, 12, 6, 8, 236, 262, 1, 0, 0, 0, 237, 238, 3, 18, 9, 0, 238, 239, 5, 45, 0, 0, 239, 240, 3, 12, 6, 7, 240, 262, 1, 0, 0, 0, 241, 242, 3, 18, 9, 0, 242, 243, 5, 46, 0, 0, 243, 244, 3, 12, 6, 6, 244, 262, 1, 0, 0, 0, 245, 246, 3, 18, 9, 0, 246, 247, 5, 47, 0, 0, 247, 248, 3, 12, 6, 5, 248, 262, 1, 0, 0, 0, 249, 250, 3, 18, 9, 0, 250, 251, 5, 48, 0, 0, 251, 252, 3, 12, 6, 4, 252, 262, 1, 0, 0, 0, 253, 254, 3, 18, 9, 0, 254, 255, 5, 49, 0, 0, 255, 256, 3, 12, 6, 3, 256, 262, 1, 0, 0, 0, 257, 258, 3, 18, 9, 0, 258, 259, 5, 50, 0, 0, 259, 260, 3, 12, 6, 2, 260, 262, 1, 0, 0, 0, 261, 154, 1, 0, 0, 0, 261, 159, 1, 0, 0, 0, 261, 179, 1, 0, 0, 0, 261, 180, 1, 0, 0, 0, 261, 184, 1, 0, 0, 0, 261, 186, 1, 0, 0, 0, 261, 188, 1, 0, 0, 0, 261, 189, 1, 0, 0, 0, 261, 202, 1, 0, 0, 0, 261, 207, 1, 0, 0, 0, 261, 209, 1, 0, 0, 0, 261, 211, 1, 0, 0, 0, 261, 213, 1, 0, 0, 0, 261, 215, 1, 0, 0, 0, 261, 218, 1, 0, 0, 0, 261, 221, 1, 0, 0, 0, 261, 225, 1, 0, 0, 0, 261, 229, 1, 0, 0, 0, 261, 233, 1, 0, 0, 0, 261, 237, 1, 0, 0, 0, 261, 241, 1, 0, 0, 0, 261, 245, 1, 0, 0, 0, 261, 249, 1, 0, 0, 0, 261, 253, 1, 0, 0, 0, 261, 257, 1, 0, 0, 0, 262, 325, 1, 0, 0, 0, 263, 264, 10, 29, 0, 0, 264, 265, 5, 19, 0, 0, 265, 324, 3, 12, 6, 30, 266, 267, 10, 28, 0, 0, 267, 268, 5, 25, 0, 0, 268, 324, 3, 12, 6, 29, 269, 270, 10, 27, 0, 0, 270, 271, 5, 26, 0, 0, 271, 324, 3, 12, 6, 28, 272, 273, 10, 26, 0, 0, 273, 274, 5, 27, 0, 0, 274, 324, 3, 12, 6, 27, 275, 276, 10, 25, 0, 0, 276, 277, 5, 28, 0, 0, 277, 324, 3, 12, 6, 26, 278, 279, 10, 24, 0, 0, 279, 280, 5, 29, 0, 0, 280, 324, 3, 12, 6, 25, 281, 282, 10, 23, 0, 0, 282, 283, 5, 30, 0, 0, 283, 324, 3, 12, 6, 24, 284, 285, 10, 22, 0, 0, 285, 286, 5, 31, 0, 0, 286, 324, 3, 12, 6, 23, 287, 288, 10, 21, 0, 0, 288, 289, 5, 32, 0, 0, 289, 324, 3, 12, 6, 22, 290, 291, 10, 20, 0, 0, 291, 292, 5, 33, 0, 0, 292, 324, 3, 12, 6, 21, 293, 294, 10, 19, 0, 0, 294, 295, 5, 34, 0, 0, 295, 324, 3, 12, 6, 20, 296, 297, 10, 18, 0, 0, 297, 298, 5, 20, 0, 0, 298, 324, 3, 12, 6, 19, 299, 300, 10, 17, 0, 0, 300, 301, 5, 35, 0, 0, 301, 324, 3, 12, 6, 18, 302, 303, 10, 16, 0, 0, 303, 304, 5, 36, 0, 0, 304, 324, 3, 12, 6, 17, 305, 306, 10, 15, 0, 0, 306, 307, 5, 37, 0, 0, 307, 324, 3, 12, 6, 16, 308, 309, 10, 14, 0, 0, 309, 310, 5, 38, 0, 0, 310, 324, 3, 12, 6, 15, 311, 312, 10, 13, 0, 0, 312, 313, 5, 39, 0, 0, 313, 324, 3, 12, 6, 14, 314, 315, 10, 12, 0, 0, 315, 316, 5, 40, 0, 0, 316, 324, 3, 12, 6, 13, 317, 318, 10, 1, 0, 0, 318, 319, 5, 51, 0, 0, 319, 320, 3, 12, 6, 0, 320, 321, 5, 52, 0, 0, 321, 322, 3, 12, 6, 2, 322, 324, 1, 0, 0, 0, 323, 263, 1, 0, 0, 0, 323, 266, 1, 0, 0, 0, 323, 269, 1, 0, 0, 0, 323, 272, 1, 0, 0, 0, 323, 275, 1, 0, 0, 0, 323, 278, 1, 0, 0, 0, 323, 281, 1, 0, 0, 0, 323, 284, 1, 0, 0, 0, 323, 287, 1, 0, 0, 0, 323, 290, 1, 0, 0, 0, 323, 293, 1, 0, 0, 0, 323, 296, 1, 0, 0, 0, 323, 299, 1, 0, 0, 0, 323, 302, 1, 0, 0, 0, 323, 305, 1, 0, 0, 0, 323, 308, 1, 0, 0, 0, 323, 311, 1, 0, 0, 0, 323, 314, 1, 0, 0, 0, 323, 317, 1, 0, 0, 0, 324, 327, 1, 0, 0, 0, 325, 323, 1, 0, 0, 0, 325, 326, 1, 0, 0, 0, 326, 13, 1, 0, 0, 0, 327, 325, 1, 0, 0, 0, 328, 333, 5, 57, 0, 0, 329, 333, 5, 55, 0, 0, 330, 333, 5, 61, 0, 0, 331, 333, 5, 62, 0, 0, 332, 328, 1, 0, 0, 0, 332, 329, 1, 0, 0, 0, 332, 330, 1, 0, 0, 0, 332, 331, 1, 0, 0, 0, 333, 15, 1, 0, 0, 0, 334, 335, 6, 8, -1, 0, 335, 338, 5, 53, 0, 0, 336, 338, 5, 54, 0, 0, 337, 334, 1, 0, 0, 0, 337, 336, 1, 0, 0, 0, 338, 343, 1, 0, 0, 0, 339, 340, 10, 1, 0, 0, 340, 342, 5, 19, 0, 0, 341, 339, 1, 0, 0, 0, 342, 345, 1, 0, 0, 0, 343, 341, 1, 0, 0, 0, 343, 344, 1, 0, 0, 0, 344, 17, 1, 0, 0, 0, 345, 343, 1, 0, 0, 0, 346, 347, 6, 9, -1, 0, 347, 348, 5, 56, 0, 0, 348, 356, 1, 0, 0, 0, 349, 350, 10, 1, 0, 0, 350, 351, 5, 17, 0, 0, 351, 352, 3, 12, 6, 0, 352, 353, 5, 18, 0, 0, 353, 355, 1, 0, 0, 0, 354, 349, 1, 0, 0, 0, 355, 358, 1, 0, 0, 0, 356, 354, 1, 0, 0, 0, 356, 357, 1, 0, 0, 0, 357, 19, 1, 0, 0, 0, 358, 356, 1, 0, 0, 0, 28, 23, 38, 41, 57, 60, 65, 71, 78, 91, 96, 100, 104, 112, 116, 144, 150, 163, 172, 175, 196, 199, 261, 323, 325, 332, 337, 343, 356]
\ No newline at end of file diff --git a/Compiler/gen/CGrammar.tokens b/Compiler/gen/CGrammar.tokens index e57eab2..b6c3179 100644 --- a/Compiler/gen/CGrammar.tokens +++ b/Compiler/gen/CGrammar.tokens @@ -51,11 +51,15 @@ T__49=50 T__50=51 T__51=52 T__52=53 -HEX=54 -ID=55 -INT=56 -WS=57 -COMMENT=58 +T__53=54 +HEX=55 +ID=56 +INT=57 +WS=58 +COMMENT=59 +DIRECTIVE=60 +LETTER=61 +STRING=62 '('=1 ','=2 ')'=3 @@ -71,41 +75,42 @@ COMMENT=58 'break'=13 'continue'=14 '='=15 -'*'=16 -'&'=17 -'['=18 -']'=19 -'!'=20 -'~'=21 -'++'=22 -'--'=23 -'/'=24 -'%'=25 -'+'=26 -'-'=27 -'<'=28 -'>'=29 -'<='=30 -'>='=31 -'=='=32 -'!='=33 -'|'=34 -'^'=35 -'<<'=36 -'>>'=37 -'&&'=38 -'||'=39 -'*='=40 -'/='=41 -'%='=42 -'+='=43 -'-='=44 -'&='=45 -'|='=46 -'^='=47 -'<<='=48 -'>>='=49 -'?'=50 -':'=51 -'int'=52 -'char'=53 +'new'=16 +'['=17 +']'=18 +'*'=19 +'&'=20 +'!'=21 +'~'=22 +'++'=23 +'--'=24 +'/'=25 +'%'=26 +'+'=27 +'-'=28 +'<'=29 +'>'=30 +'<='=31 +'>='=32 +'=='=33 +'!='=34 +'|'=35 +'^'=36 +'<<'=37 +'>>'=38 +'&&'=39 +'||'=40 +'*='=41 +'/='=42 +'%='=43 +'+='=44 +'-='=45 +'&='=46 +'|='=47 +'^='=48 +'<<='=49 +'>>='=50 +'?'=51 +':'=52 +'int'=53 +'char'=54 diff --git a/Compiler/gen/CGrammarBaseVisitor.cs b/Compiler/gen/CGrammarBaseVisitor.cs index 857e6ff..a9dde6b 100644 --- a/Compiler/gen/CGrammarBaseVisitor.cs +++ b/Compiler/gen/CGrammarBaseVisitor.cs @@ -472,6 +472,17 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu /// <return>The visitor result.</return> public virtual Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context) { return VisitChildren(context); } /// <summary> + /// Visit a parse tree produced by the <c>arrayExpression</c> + /// labeled alternative in <see cref="CGrammarParser.expression"/>. + /// <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 VisitArrayExpression([NotNull] CGrammarParser.ArrayExpressionContext context) { return VisitChildren(context); } + /// <summary> /// Visit a parse tree produced by the <c>constantExpression</c> /// labeled alternative in <see cref="CGrammarParser.expression"/>. /// <para> @@ -714,6 +725,28 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu /// <return>The visitor result.</return> public virtual Result VisitHexConstant([NotNull] CGrammarParser.HexConstantContext context) { return VisitChildren(context); } /// <summary> + /// Visit a parse tree produced by the <c>charConstant</c> + /// labeled alternative in <see cref="CGrammarParser.constant"/>. + /// <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 VisitCharConstant([NotNull] CGrammarParser.CharConstantContext context) { return VisitChildren(context); } + /// <summary> + /// Visit a parse tree produced by the <c>stringConstant</c> + /// labeled alternative in <see cref="CGrammarParser.constant"/>. + /// <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 VisitStringConstant([NotNull] CGrammarParser.StringConstantContext context) { return VisitChildren(context); } + /// <summary> /// Visit a parse tree produced by <see cref="CGrammarParser.type"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> @@ -724,6 +757,17 @@ public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Resu /// <return>The visitor result.</return> public virtual Result VisitType([NotNull] CGrammarParser.TypeContext context) { return VisitChildren(context); } /// <summary> + /// Visit a parse tree produced by the <c>indexerTarget</c> + /// labeled alternative in <see cref="CGrammarParser.target"/>. + /// <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 VisitIndexerTarget([NotNull] CGrammarParser.IndexerTargetContext context) { return VisitChildren(context); } + /// <summary> /// Visit a parse tree produced by the <c>variableTarget</c> /// labeled alternative in <see cref="CGrammarParser.target"/>. /// <para> diff --git a/Compiler/gen/CGrammarLexer.cs b/Compiler/gen/CGrammarLexer.cs index 50e1668..368ad2c 100644 --- a/Compiler/gen/CGrammarLexer.cs +++ b/Compiler/gen/CGrammarLexer.cs @@ -40,7 +40,8 @@ public partial class CGrammarLexer : Lexer { 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, T__45=46, T__46=47, T__47=48, T__48=49, T__49=50, T__50=51, T__51=52, - T__52=53, HEX=54, ID=55, INT=56, WS=57, COMMENT=58; + T__52=53, T__53=54, HEX=55, ID=56, INT=57, WS=58, COMMENT=59, DIRECTIVE=60, + LETTER=61, STRING=62; public static string[] channelNames = { "DEFAULT_TOKEN_CHANNEL", "HIDDEN" }; @@ -56,7 +57,8 @@ public partial class CGrammarLexer : Lexer { "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", "T__45", "T__46", "T__47", "T__48", - "T__49", "T__50", "T__51", "T__52", "HEX", "ID", "INT", "WS", "COMMENT" + "T__49", "T__50", "T__51", "T__52", "T__53", "HEX", "ID", "INT", "WS", + "COMMENT", "DIRECTIVE", "LETTER", "STRING" }; @@ -71,18 +73,19 @@ public partial class CGrammarLexer : Lexer { private static readonly string[] _LiteralNames = { null, "'('", "','", "')'", "';'", "'{'", "'}'", "'return'", "'if'", "'else'", - "'for'", "'while'", "'do'", "'break'", "'continue'", "'='", "'*'", "'&'", - "'['", "']'", "'!'", "'~'", "'++'", "'--'", "'/'", "'%'", "'+'", "'-'", - "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'|'", "'^'", "'<<'", "'>>'", - "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", "'|='", - "'^='", "'<<='", "'>>='", "'?'", "':'", "'int'", "'char'" + "'for'", "'while'", "'do'", "'break'", "'continue'", "'='", "'new'", "'['", + "']'", "'*'", "'&'", "'!'", "'~'", "'++'", "'--'", "'/'", "'%'", "'+'", + "'-'", "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'|'", "'^'", "'<<'", + "'>>'", "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", + "'|='", "'^='", "'<<='", "'>>='", "'?'", "':'", "'int'", "'char'" }; 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, null, null, - null, null, null, null, null, null, "HEX", "ID", "INT", "WS", "COMMENT" + null, null, null, null, null, null, null, "HEX", "ID", "INT", "WS", "COMMENT", + "DIRECTIVE", "LETTER", "STRING" }; public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); @@ -112,7 +115,7 @@ public partial class CGrammarLexer : Lexer { } } private static int[] _serializedATN = { - 4,0,58,315,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,62,355,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, @@ -120,98 +123,112 @@ public partial class CGrammarLexer : Lexer { 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,2,54,7,54,2,55,7,55,2,56, - 7,56,2,57,7,57,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,6,1,6,1,6,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,9,1,9,1, - 10,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1, - 12,1,13,1,13,1,13,1,13,1,13,1,13,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,24,1,24,1,25,1,25,1,26,1,26,1,27,1,27,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, - 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,47,1,47,1,47,1,47,1, - 48,1,48,1,48,1,48,1,49,1,49,1,50,1,50,1,51,1,51,1,51,1,51,1,52,1,52,1, - 52,1,52,1,52,1,53,1,53,1,53,1,53,1,53,1,54,1,54,5,54,285,8,54,10,54,12, - 54,288,9,54,1,55,4,55,291,8,55,11,55,12,55,292,1,56,4,56,296,8,56,11,56, - 12,56,297,1,56,1,56,1,57,1,57,1,57,1,57,5,57,306,8,57,10,57,12,57,309, - 9,57,1,57,3,57,312,8,57,1,57,1,57,1,307,0,58,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,109,55,111,56,113,57,115,58,1,0,6,3,0,48,57,65,70,97,102,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,318,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,0,109,1,0,0,0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,0,0,1,117,1, - 0,0,0,3,119,1,0,0,0,5,121,1,0,0,0,7,123,1,0,0,0,9,125,1,0,0,0,11,127,1, - 0,0,0,13,129,1,0,0,0,15,136,1,0,0,0,17,139,1,0,0,0,19,144,1,0,0,0,21,148, - 1,0,0,0,23,154,1,0,0,0,25,157,1,0,0,0,27,163,1,0,0,0,29,172,1,0,0,0,31, - 174,1,0,0,0,33,176,1,0,0,0,35,178,1,0,0,0,37,180,1,0,0,0,39,182,1,0,0, - 0,41,184,1,0,0,0,43,186,1,0,0,0,45,189,1,0,0,0,47,192,1,0,0,0,49,194,1, - 0,0,0,51,196,1,0,0,0,53,198,1,0,0,0,55,200,1,0,0,0,57,202,1,0,0,0,59,204, - 1,0,0,0,61,207,1,0,0,0,63,210,1,0,0,0,65,213,1,0,0,0,67,216,1,0,0,0,69, - 218,1,0,0,0,71,220,1,0,0,0,73,223,1,0,0,0,75,226,1,0,0,0,77,229,1,0,0, - 0,79,232,1,0,0,0,81,235,1,0,0,0,83,238,1,0,0,0,85,241,1,0,0,0,87,244,1, - 0,0,0,89,247,1,0,0,0,91,250,1,0,0,0,93,253,1,0,0,0,95,256,1,0,0,0,97,260, - 1,0,0,0,99,264,1,0,0,0,101,266,1,0,0,0,103,268,1,0,0,0,105,272,1,0,0,0, - 107,277,1,0,0,0,109,282,1,0,0,0,111,290,1,0,0,0,113,295,1,0,0,0,115,301, - 1,0,0,0,117,118,5,40,0,0,118,2,1,0,0,0,119,120,5,44,0,0,120,4,1,0,0,0, - 121,122,5,41,0,0,122,6,1,0,0,0,123,124,5,59,0,0,124,8,1,0,0,0,125,126, - 5,123,0,0,126,10,1,0,0,0,127,128,5,125,0,0,128,12,1,0,0,0,129,130,5,114, - 0,0,130,131,5,101,0,0,131,132,5,116,0,0,132,133,5,117,0,0,133,134,5,114, - 0,0,134,135,5,110,0,0,135,14,1,0,0,0,136,137,5,105,0,0,137,138,5,102,0, - 0,138,16,1,0,0,0,139,140,5,101,0,0,140,141,5,108,0,0,141,142,5,115,0,0, - 142,143,5,101,0,0,143,18,1,0,0,0,144,145,5,102,0,0,145,146,5,111,0,0,146, - 147,5,114,0,0,147,20,1,0,0,0,148,149,5,119,0,0,149,150,5,104,0,0,150,151, - 5,105,0,0,151,152,5,108,0,0,152,153,5,101,0,0,153,22,1,0,0,0,154,155,5, - 100,0,0,155,156,5,111,0,0,156,24,1,0,0,0,157,158,5,98,0,0,158,159,5,114, - 0,0,159,160,5,101,0,0,160,161,5,97,0,0,161,162,5,107,0,0,162,26,1,0,0, - 0,163,164,5,99,0,0,164,165,5,111,0,0,165,166,5,110,0,0,166,167,5,116,0, - 0,167,168,5,105,0,0,168,169,5,110,0,0,169,170,5,117,0,0,170,171,5,101, - 0,0,171,28,1,0,0,0,172,173,5,61,0,0,173,30,1,0,0,0,174,175,5,42,0,0,175, - 32,1,0,0,0,176,177,5,38,0,0,177,34,1,0,0,0,178,179,5,91,0,0,179,36,1,0, - 0,0,180,181,5,93,0,0,181,38,1,0,0,0,182,183,5,33,0,0,183,40,1,0,0,0,184, - 185,5,126,0,0,185,42,1,0,0,0,186,187,5,43,0,0,187,188,5,43,0,0,188,44, - 1,0,0,0,189,190,5,45,0,0,190,191,5,45,0,0,191,46,1,0,0,0,192,193,5,47, - 0,0,193,48,1,0,0,0,194,195,5,37,0,0,195,50,1,0,0,0,196,197,5,43,0,0,197, - 52,1,0,0,0,198,199,5,45,0,0,199,54,1,0,0,0,200,201,5,60,0,0,201,56,1,0, - 0,0,202,203,5,62,0,0,203,58,1,0,0,0,204,205,5,60,0,0,205,206,5,61,0,0, - 206,60,1,0,0,0,207,208,5,62,0,0,208,209,5,61,0,0,209,62,1,0,0,0,210,211, - 5,61,0,0,211,212,5,61,0,0,212,64,1,0,0,0,213,214,5,33,0,0,214,215,5,61, - 0,0,215,66,1,0,0,0,216,217,5,124,0,0,217,68,1,0,0,0,218,219,5,94,0,0,219, - 70,1,0,0,0,220,221,5,60,0,0,221,222,5,60,0,0,222,72,1,0,0,0,223,224,5, - 62,0,0,224,225,5,62,0,0,225,74,1,0,0,0,226,227,5,38,0,0,227,228,5,38,0, - 0,228,76,1,0,0,0,229,230,5,124,0,0,230,231,5,124,0,0,231,78,1,0,0,0,232, - 233,5,42,0,0,233,234,5,61,0,0,234,80,1,0,0,0,235,236,5,47,0,0,236,237, - 5,61,0,0,237,82,1,0,0,0,238,239,5,37,0,0,239,240,5,61,0,0,240,84,1,0,0, - 0,241,242,5,43,0,0,242,243,5,61,0,0,243,86,1,0,0,0,244,245,5,45,0,0,245, - 246,5,61,0,0,246,88,1,0,0,0,247,248,5,38,0,0,248,249,5,61,0,0,249,90,1, - 0,0,0,250,251,5,124,0,0,251,252,5,61,0,0,252,92,1,0,0,0,253,254,5,94,0, - 0,254,255,5,61,0,0,255,94,1,0,0,0,256,257,5,60,0,0,257,258,5,60,0,0,258, - 259,5,61,0,0,259,96,1,0,0,0,260,261,5,62,0,0,261,262,5,62,0,0,262,263, - 5,61,0,0,263,98,1,0,0,0,264,265,5,63,0,0,265,100,1,0,0,0,266,267,5,58, - 0,0,267,102,1,0,0,0,268,269,5,105,0,0,269,270,5,110,0,0,270,271,5,116, - 0,0,271,104,1,0,0,0,272,273,5,99,0,0,273,274,5,104,0,0,274,275,5,97,0, - 0,275,276,5,114,0,0,276,106,1,0,0,0,277,278,5,48,0,0,278,279,5,120,0,0, - 279,280,1,0,0,0,280,281,7,0,0,0,281,108,1,0,0,0,282,286,7,1,0,0,283,285, - 7,2,0,0,284,283,1,0,0,0,285,288,1,0,0,0,286,284,1,0,0,0,286,287,1,0,0, - 0,287,110,1,0,0,0,288,286,1,0,0,0,289,291,7,3,0,0,290,289,1,0,0,0,291, - 292,1,0,0,0,292,290,1,0,0,0,292,293,1,0,0,0,293,112,1,0,0,0,294,296,7, - 4,0,0,295,294,1,0,0,0,296,297,1,0,0,0,297,295,1,0,0,0,297,298,1,0,0,0, - 298,299,1,0,0,0,299,300,6,56,0,0,300,114,1,0,0,0,301,302,5,47,0,0,302, - 303,5,47,0,0,303,307,1,0,0,0,304,306,9,0,0,0,305,304,1,0,0,0,306,309,1, - 0,0,0,307,308,1,0,0,0,307,305,1,0,0,0,308,311,1,0,0,0,309,307,1,0,0,0, - 310,312,7,5,0,0,311,310,1,0,0,0,312,313,1,0,0,0,313,314,6,57,1,0,314,116, - 1,0,0,0,6,0,286,292,297,307,311,2,6,0,0,0,1,0 + 7,56,2,57,7,57,2,58,7,58,2,59,7,59,2,60,7,60,2,61,7,61,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,6,1,6,1,6,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,9,1,9,1,10,1,10,1,10,1,10,1,10,1,10,1, + 11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1, + 13,1,13,1,13,1,13,1,14,1,14,1,15,1,15,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,22,1,22,1,22,1,23,1,23,1,23,1, + 24,1,24,1,25,1,25,1,26,1,26,1,27,1,27,1,28,1,28,1,29,1,29,1,30,1,30,1, + 30,1,31,1,31,1,31,1,32,1,32,1,32,1,33,1,33,1,33,1,34,1,34,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,47,1,47,1,47,1,48,1,48,1,48,1,48,1,49,1,49,1, + 49,1,49,1,50,1,50,1,51,1,51,1,52,1,52,1,52,1,52,1,53,1,53,1,53,1,53,1, + 53,1,54,1,54,1,54,1,54,4,54,294,8,54,11,54,12,54,295,1,55,1,55,5,55,300, + 8,55,10,55,12,55,303,9,55,1,56,4,56,306,8,56,11,56,12,56,307,1,57,4,57, + 311,8,57,11,57,12,57,312,1,57,1,57,1,58,1,58,1,58,1,58,5,58,321,8,58,10, + 58,12,58,324,9,58,1,58,3,58,327,8,58,1,58,1,58,1,59,1,59,5,59,333,8,59, + 10,59,12,59,336,9,59,1,59,3,59,339,8,59,1,59,1,59,1,60,1,60,1,60,1,60, + 1,61,1,61,5,61,349,8,61,10,61,12,61,352,9,61,1,61,1,61,3,322,334,350,0, + 62,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,109,55,111,56,113,57,115,58,117,59,119, + 60,121,61,123,62,1,0,6,3,0,48,57,65,70,97,102,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,361, + 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,0,109,1,0,0, + 0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,0,0,0,117,1,0,0,0,0,119,1,0,0, + 0,0,121,1,0,0,0,0,123,1,0,0,0,1,125,1,0,0,0,3,127,1,0,0,0,5,129,1,0,0, + 0,7,131,1,0,0,0,9,133,1,0,0,0,11,135,1,0,0,0,13,137,1,0,0,0,15,144,1,0, + 0,0,17,147,1,0,0,0,19,152,1,0,0,0,21,156,1,0,0,0,23,162,1,0,0,0,25,165, + 1,0,0,0,27,171,1,0,0,0,29,180,1,0,0,0,31,182,1,0,0,0,33,186,1,0,0,0,35, + 188,1,0,0,0,37,190,1,0,0,0,39,192,1,0,0,0,41,194,1,0,0,0,43,196,1,0,0, + 0,45,198,1,0,0,0,47,201,1,0,0,0,49,204,1,0,0,0,51,206,1,0,0,0,53,208,1, + 0,0,0,55,210,1,0,0,0,57,212,1,0,0,0,59,214,1,0,0,0,61,216,1,0,0,0,63,219, + 1,0,0,0,65,222,1,0,0,0,67,225,1,0,0,0,69,228,1,0,0,0,71,230,1,0,0,0,73, + 232,1,0,0,0,75,235,1,0,0,0,77,238,1,0,0,0,79,241,1,0,0,0,81,244,1,0,0, + 0,83,247,1,0,0,0,85,250,1,0,0,0,87,253,1,0,0,0,89,256,1,0,0,0,91,259,1, + 0,0,0,93,262,1,0,0,0,95,265,1,0,0,0,97,268,1,0,0,0,99,272,1,0,0,0,101, + 276,1,0,0,0,103,278,1,0,0,0,105,280,1,0,0,0,107,284,1,0,0,0,109,289,1, + 0,0,0,111,297,1,0,0,0,113,305,1,0,0,0,115,310,1,0,0,0,117,316,1,0,0,0, + 119,330,1,0,0,0,121,342,1,0,0,0,123,346,1,0,0,0,125,126,5,40,0,0,126,2, + 1,0,0,0,127,128,5,44,0,0,128,4,1,0,0,0,129,130,5,41,0,0,130,6,1,0,0,0, + 131,132,5,59,0,0,132,8,1,0,0,0,133,134,5,123,0,0,134,10,1,0,0,0,135,136, + 5,125,0,0,136,12,1,0,0,0,137,138,5,114,0,0,138,139,5,101,0,0,139,140,5, + 116,0,0,140,141,5,117,0,0,141,142,5,114,0,0,142,143,5,110,0,0,143,14,1, + 0,0,0,144,145,5,105,0,0,145,146,5,102,0,0,146,16,1,0,0,0,147,148,5,101, + 0,0,148,149,5,108,0,0,149,150,5,115,0,0,150,151,5,101,0,0,151,18,1,0,0, + 0,152,153,5,102,0,0,153,154,5,111,0,0,154,155,5,114,0,0,155,20,1,0,0,0, + 156,157,5,119,0,0,157,158,5,104,0,0,158,159,5,105,0,0,159,160,5,108,0, + 0,160,161,5,101,0,0,161,22,1,0,0,0,162,163,5,100,0,0,163,164,5,111,0,0, + 164,24,1,0,0,0,165,166,5,98,0,0,166,167,5,114,0,0,167,168,5,101,0,0,168, + 169,5,97,0,0,169,170,5,107,0,0,170,26,1,0,0,0,171,172,5,99,0,0,172,173, + 5,111,0,0,173,174,5,110,0,0,174,175,5,116,0,0,175,176,5,105,0,0,176,177, + 5,110,0,0,177,178,5,117,0,0,178,179,5,101,0,0,179,28,1,0,0,0,180,181,5, + 61,0,0,181,30,1,0,0,0,182,183,5,110,0,0,183,184,5,101,0,0,184,185,5,119, + 0,0,185,32,1,0,0,0,186,187,5,91,0,0,187,34,1,0,0,0,188,189,5,93,0,0,189, + 36,1,0,0,0,190,191,5,42,0,0,191,38,1,0,0,0,192,193,5,38,0,0,193,40,1,0, + 0,0,194,195,5,33,0,0,195,42,1,0,0,0,196,197,5,126,0,0,197,44,1,0,0,0,198, + 199,5,43,0,0,199,200,5,43,0,0,200,46,1,0,0,0,201,202,5,45,0,0,202,203, + 5,45,0,0,203,48,1,0,0,0,204,205,5,47,0,0,205,50,1,0,0,0,206,207,5,37,0, + 0,207,52,1,0,0,0,208,209,5,43,0,0,209,54,1,0,0,0,210,211,5,45,0,0,211, + 56,1,0,0,0,212,213,5,60,0,0,213,58,1,0,0,0,214,215,5,62,0,0,215,60,1,0, + 0,0,216,217,5,60,0,0,217,218,5,61,0,0,218,62,1,0,0,0,219,220,5,62,0,0, + 220,221,5,61,0,0,221,64,1,0,0,0,222,223,5,61,0,0,223,224,5,61,0,0,224, + 66,1,0,0,0,225,226,5,33,0,0,226,227,5,61,0,0,227,68,1,0,0,0,228,229,5, + 124,0,0,229,70,1,0,0,0,230,231,5,94,0,0,231,72,1,0,0,0,232,233,5,60,0, + 0,233,234,5,60,0,0,234,74,1,0,0,0,235,236,5,62,0,0,236,237,5,62,0,0,237, + 76,1,0,0,0,238,239,5,38,0,0,239,240,5,38,0,0,240,78,1,0,0,0,241,242,5, + 124,0,0,242,243,5,124,0,0,243,80,1,0,0,0,244,245,5,42,0,0,245,246,5,61, + 0,0,246,82,1,0,0,0,247,248,5,47,0,0,248,249,5,61,0,0,249,84,1,0,0,0,250, + 251,5,37,0,0,251,252,5,61,0,0,252,86,1,0,0,0,253,254,5,43,0,0,254,255, + 5,61,0,0,255,88,1,0,0,0,256,257,5,45,0,0,257,258,5,61,0,0,258,90,1,0,0, + 0,259,260,5,38,0,0,260,261,5,61,0,0,261,92,1,0,0,0,262,263,5,124,0,0,263, + 264,5,61,0,0,264,94,1,0,0,0,265,266,5,94,0,0,266,267,5,61,0,0,267,96,1, + 0,0,0,268,269,5,60,0,0,269,270,5,60,0,0,270,271,5,61,0,0,271,98,1,0,0, + 0,272,273,5,62,0,0,273,274,5,62,0,0,274,275,5,61,0,0,275,100,1,0,0,0,276, + 277,5,63,0,0,277,102,1,0,0,0,278,279,5,58,0,0,279,104,1,0,0,0,280,281, + 5,105,0,0,281,282,5,110,0,0,282,283,5,116,0,0,283,106,1,0,0,0,284,285, + 5,99,0,0,285,286,5,104,0,0,286,287,5,97,0,0,287,288,5,114,0,0,288,108, + 1,0,0,0,289,290,5,48,0,0,290,291,5,120,0,0,291,293,1,0,0,0,292,294,7,0, + 0,0,293,292,1,0,0,0,294,295,1,0,0,0,295,293,1,0,0,0,295,296,1,0,0,0,296, + 110,1,0,0,0,297,301,7,1,0,0,298,300,7,2,0,0,299,298,1,0,0,0,300,303,1, + 0,0,0,301,299,1,0,0,0,301,302,1,0,0,0,302,112,1,0,0,0,303,301,1,0,0,0, + 304,306,7,3,0,0,305,304,1,0,0,0,306,307,1,0,0,0,307,305,1,0,0,0,307,308, + 1,0,0,0,308,114,1,0,0,0,309,311,7,4,0,0,310,309,1,0,0,0,311,312,1,0,0, + 0,312,310,1,0,0,0,312,313,1,0,0,0,313,314,1,0,0,0,314,315,6,57,0,0,315, + 116,1,0,0,0,316,317,5,47,0,0,317,318,5,47,0,0,318,322,1,0,0,0,319,321, + 9,0,0,0,320,319,1,0,0,0,321,324,1,0,0,0,322,323,1,0,0,0,322,320,1,0,0, + 0,323,326,1,0,0,0,324,322,1,0,0,0,325,327,7,5,0,0,326,325,1,0,0,0,327, + 328,1,0,0,0,328,329,6,58,1,0,329,118,1,0,0,0,330,334,5,35,0,0,331,333, + 9,0,0,0,332,331,1,0,0,0,333,336,1,0,0,0,334,335,1,0,0,0,334,332,1,0,0, + 0,335,338,1,0,0,0,336,334,1,0,0,0,337,339,7,5,0,0,338,337,1,0,0,0,339, + 340,1,0,0,0,340,341,6,59,1,0,341,120,1,0,0,0,342,343,5,39,0,0,343,344, + 9,0,0,0,344,345,5,39,0,0,345,122,1,0,0,0,346,350,5,34,0,0,347,349,9,0, + 0,0,348,347,1,0,0,0,349,352,1,0,0,0,350,351,1,0,0,0,350,348,1,0,0,0,351, + 353,1,0,0,0,352,350,1,0,0,0,353,354,5,34,0,0,354,124,1,0,0,0,10,0,295, + 301,307,312,322,326,334,338,350,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 eb8f008..4aea344 100644 --- a/Compiler/gen/CGrammarLexer.interp +++ b/Compiler/gen/CGrammarLexer.interp @@ -15,10 +15,11 @@ null 'break' 'continue' '=' -'*' -'&' +'new' '[' ']' +'*' +'&' '!' '~' '++' @@ -58,6 +59,9 @@ null null null null +null +null +null token symbolic names: null @@ -114,11 +118,15 @@ null null null null +null HEX ID INT WS COMMENT +DIRECTIVE +LETTER +STRING rule names: T__0 @@ -174,11 +182,15 @@ T__49 T__50 T__51 T__52 +T__53 HEX ID INT WS COMMENT +DIRECTIVE +LETTER +STRING channel names: DEFAULT_TOKEN_CHANNEL @@ -188,4 +200,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 58, 315, 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, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, 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, 6, 1, 6, 1, 6, 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, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 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, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 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, 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, 47, 1, 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 1, 50, 1, 50, 1, 51, 1, 51, 1, 51, 1, 51, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 54, 1, 54, 5, 54, 285, 8, 54, 10, 54, 12, 54, 288, 9, 54, 1, 55, 4, 55, 291, 8, 55, 11, 55, 12, 55, 292, 1, 56, 4, 56, 296, 8, 56, 11, 56, 12, 56, 297, 1, 56, 1, 56, 1, 57, 1, 57, 1, 57, 1, 57, 5, 57, 306, 8, 57, 10, 57, 12, 57, 309, 9, 57, 1, 57, 3, 57, 312, 8, 57, 1, 57, 1, 57, 1, 307, 0, 58, 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, 109, 55, 111, 56, 113, 57, 115, 58, 1, 0, 6, 3, 0, 48, 57, 65, 70, 97, 102, 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, 318, 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, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 0, 115, 1, 0, 0, 0, 1, 117, 1, 0, 0, 0, 3, 119, 1, 0, 0, 0, 5, 121, 1, 0, 0, 0, 7, 123, 1, 0, 0, 0, 9, 125, 1, 0, 0, 0, 11, 127, 1, 0, 0, 0, 13, 129, 1, 0, 0, 0, 15, 136, 1, 0, 0, 0, 17, 139, 1, 0, 0, 0, 19, 144, 1, 0, 0, 0, 21, 148, 1, 0, 0, 0, 23, 154, 1, 0, 0, 0, 25, 157, 1, 0, 0, 0, 27, 163, 1, 0, 0, 0, 29, 172, 1, 0, 0, 0, 31, 174, 1, 0, 0, 0, 33, 176, 1, 0, 0, 0, 35, 178, 1, 0, 0, 0, 37, 180, 1, 0, 0, 0, 39, 182, 1, 0, 0, 0, 41, 184, 1, 0, 0, 0, 43, 186, 1, 0, 0, 0, 45, 189, 1, 0, 0, 0, 47, 192, 1, 0, 0, 0, 49, 194, 1, 0, 0, 0, 51, 196, 1, 0, 0, 0, 53, 198, 1, 0, 0, 0, 55, 200, 1, 0, 0, 0, 57, 202, 1, 0, 0, 0, 59, 204, 1, 0, 0, 0, 61, 207, 1, 0, 0, 0, 63, 210, 1, 0, 0, 0, 65, 213, 1, 0, 0, 0, 67, 216, 1, 0, 0, 0, 69, 218, 1, 0, 0, 0, 71, 220, 1, 0, 0, 0, 73, 223, 1, 0, 0, 0, 75, 226, 1, 0, 0, 0, 77, 229, 1, 0, 0, 0, 79, 232, 1, 0, 0, 0, 81, 235, 1, 0, 0, 0, 83, 238, 1, 0, 0, 0, 85, 241, 1, 0, 0, 0, 87, 244, 1, 0, 0, 0, 89, 247, 1, 0, 0, 0, 91, 250, 1, 0, 0, 0, 93, 253, 1, 0, 0, 0, 95, 256, 1, 0, 0, 0, 97, 260, 1, 0, 0, 0, 99, 264, 1, 0, 0, 0, 101, 266, 1, 0, 0, 0, 103, 268, 1, 0, 0, 0, 105, 272, 1, 0, 0, 0, 107, 277, 1, 0, 0, 0, 109, 282, 1, 0, 0, 0, 111, 290, 1, 0, 0, 0, 113, 295, 1, 0, 0, 0, 115, 301, 1, 0, 0, 0, 117, 118, 5, 40, 0, 0, 118, 2, 1, 0, 0, 0, 119, 120, 5, 44, 0, 0, 120, 4, 1, 0, 0, 0, 121, 122, 5, 41, 0, 0, 122, 6, 1, 0, 0, 0, 123, 124, 5, 59, 0, 0, 124, 8, 1, 0, 0, 0, 125, 126, 5, 123, 0, 0, 126, 10, 1, 0, 0, 0, 127, 128, 5, 125, 0, 0, 128, 12, 1, 0, 0, 0, 129, 130, 5, 114, 0, 0, 130, 131, 5, 101, 0, 0, 131, 132, 5, 116, 0, 0, 132, 133, 5, 117, 0, 0, 133, 134, 5, 114, 0, 0, 134, 135, 5, 110, 0, 0, 135, 14, 1, 0, 0, 0, 136, 137, 5, 105, 0, 0, 137, 138, 5, 102, 0, 0, 138, 16, 1, 0, 0, 0, 139, 140, 5, 101, 0, 0, 140, 141, 5, 108, 0, 0, 141, 142, 5, 115, 0, 0, 142, 143, 5, 101, 0, 0, 143, 18, 1, 0, 0, 0, 144, 145, 5, 102, 0, 0, 145, 146, 5, 111, 0, 0, 146, 147, 5, 114, 0, 0, 147, 20, 1, 0, 0, 0, 148, 149, 5, 119, 0, 0, 149, 150, 5, 104, 0, 0, 150, 151, 5, 105, 0, 0, 151, 152, 5, 108, 0, 0, 152, 153, 5, 101, 0, 0, 153, 22, 1, 0, 0, 0, 154, 155, 5, 100, 0, 0, 155, 156, 5, 111, 0, 0, 156, 24, 1, 0, 0, 0, 157, 158, 5, 98, 0, 0, 158, 159, 5, 114, 0, 0, 159, 160, 5, 101, 0, 0, 160, 161, 5, 97, 0, 0, 161, 162, 5, 107, 0, 0, 162, 26, 1, 0, 0, 0, 163, 164, 5, 99, 0, 0, 164, 165, 5, 111, 0, 0, 165, 166, 5, 110, 0, 0, 166, 167, 5, 116, 0, 0, 167, 168, 5, 105, 0, 0, 168, 169, 5, 110, 0, 0, 169, 170, 5, 117, 0, 0, 170, 171, 5, 101, 0, 0, 171, 28, 1, 0, 0, 0, 172, 173, 5, 61, 0, 0, 173, 30, 1, 0, 0, 0, 174, 175, 5, 42, 0, 0, 175, 32, 1, 0, 0, 0, 176, 177, 5, 38, 0, 0, 177, 34, 1, 0, 0, 0, 178, 179, 5, 91, 0, 0, 179, 36, 1, 0, 0, 0, 180, 181, 5, 93, 0, 0, 181, 38, 1, 0, 0, 0, 182, 183, 5, 33, 0, 0, 183, 40, 1, 0, 0, 0, 184, 185, 5, 126, 0, 0, 185, 42, 1, 0, 0, 0, 186, 187, 5, 43, 0, 0, 187, 188, 5, 43, 0, 0, 188, 44, 1, 0, 0, 0, 189, 190, 5, 45, 0, 0, 190, 191, 5, 45, 0, 0, 191, 46, 1, 0, 0, 0, 192, 193, 5, 47, 0, 0, 193, 48, 1, 0, 0, 0, 194, 195, 5, 37, 0, 0, 195, 50, 1, 0, 0, 0, 196, 197, 5, 43, 0, 0, 197, 52, 1, 0, 0, 0, 198, 199, 5, 45, 0, 0, 199, 54, 1, 0, 0, 0, 200, 201, 5, 60, 0, 0, 201, 56, 1, 0, 0, 0, 202, 203, 5, 62, 0, 0, 203, 58, 1, 0, 0, 0, 204, 205, 5, 60, 0, 0, 205, 206, 5, 61, 0, 0, 206, 60, 1, 0, 0, 0, 207, 208, 5, 62, 0, 0, 208, 209, 5, 61, 0, 0, 209, 62, 1, 0, 0, 0, 210, 211, 5, 61, 0, 0, 211, 212, 5, 61, 0, 0, 212, 64, 1, 0, 0, 0, 213, 214, 5, 33, 0, 0, 214, 215, 5, 61, 0, 0, 215, 66, 1, 0, 0, 0, 216, 217, 5, 124, 0, 0, 217, 68, 1, 0, 0, 0, 218, 219, 5, 94, 0, 0, 219, 70, 1, 0, 0, 0, 220, 221, 5, 60, 0, 0, 221, 222, 5, 60, 0, 0, 222, 72, 1, 0, 0, 0, 223, 224, 5, 62, 0, 0, 224, 225, 5, 62, 0, 0, 225, 74, 1, 0, 0, 0, 226, 227, 5, 38, 0, 0, 227, 228, 5, 38, 0, 0, 228, 76, 1, 0, 0, 0, 229, 230, 5, 124, 0, 0, 230, 231, 5, 124, 0, 0, 231, 78, 1, 0, 0, 0, 232, 233, 5, 42, 0, 0, 233, 234, 5, 61, 0, 0, 234, 80, 1, 0, 0, 0, 235, 236, 5, 47, 0, 0, 236, 237, 5, 61, 0, 0, 237, 82, 1, 0, 0, 0, 238, 239, 5, 37, 0, 0, 239, 240, 5, 61, 0, 0, 240, 84, 1, 0, 0, 0, 241, 242, 5, 43, 0, 0, 242, 243, 5, 61, 0, 0, 243, 86, 1, 0, 0, 0, 244, 245, 5, 45, 0, 0, 245, 246, 5, 61, 0, 0, 246, 88, 1, 0, 0, 0, 247, 248, 5, 38, 0, 0, 248, 249, 5, 61, 0, 0, 249, 90, 1, 0, 0, 0, 250, 251, 5, 124, 0, 0, 251, 252, 5, 61, 0, 0, 252, 92, 1, 0, 0, 0, 253, 254, 5, 94, 0, 0, 254, 255, 5, 61, 0, 0, 255, 94, 1, 0, 0, 0, 256, 257, 5, 60, 0, 0, 257, 258, 5, 60, 0, 0, 258, 259, 5, 61, 0, 0, 259, 96, 1, 0, 0, 0, 260, 261, 5, 62, 0, 0, 261, 262, 5, 62, 0, 0, 262, 263, 5, 61, 0, 0, 263, 98, 1, 0, 0, 0, 264, 265, 5, 63, 0, 0, 265, 100, 1, 0, 0, 0, 266, 267, 5, 58, 0, 0, 267, 102, 1, 0, 0, 0, 268, 269, 5, 105, 0, 0, 269, 270, 5, 110, 0, 0, 270, 271, 5, 116, 0, 0, 271, 104, 1, 0, 0, 0, 272, 273, 5, 99, 0, 0, 273, 274, 5, 104, 0, 0, 274, 275, 5, 97, 0, 0, 275, 276, 5, 114, 0, 0, 276, 106, 1, 0, 0, 0, 277, 278, 5, 48, 0, 0, 278, 279, 5, 120, 0, 0, 279, 280, 1, 0, 0, 0, 280, 281, 7, 0, 0, 0, 281, 108, 1, 0, 0, 0, 282, 286, 7, 1, 0, 0, 283, 285, 7, 2, 0, 0, 284, 283, 1, 0, 0, 0, 285, 288, 1, 0, 0, 0, 286, 284, 1, 0, 0, 0, 286, 287, 1, 0, 0, 0, 287, 110, 1, 0, 0, 0, 288, 286, 1, 0, 0, 0, 289, 291, 7, 3, 0, 0, 290, 289, 1, 0, 0, 0, 291, 292, 1, 0, 0, 0, 292, 290, 1, 0, 0, 0, 292, 293, 1, 0, 0, 0, 293, 112, 1, 0, 0, 0, 294, 296, 7, 4, 0, 0, 295, 294, 1, 0, 0, 0, 296, 297, 1, 0, 0, 0, 297, 295, 1, 0, 0, 0, 297, 298, 1, 0, 0, 0, 298, 299, 1, 0, 0, 0, 299, 300, 6, 56, 0, 0, 300, 114, 1, 0, 0, 0, 301, 302, 5, 47, 0, 0, 302, 303, 5, 47, 0, 0, 303, 307, 1, 0, 0, 0, 304, 306, 9, 0, 0, 0, 305, 304, 1, 0, 0, 0, 306, 309, 1, 0, 0, 0, 307, 308, 1, 0, 0, 0, 307, 305, 1, 0, 0, 0, 308, 311, 1, 0, 0, 0, 309, 307, 1, 0, 0, 0, 310, 312, 7, 5, 0, 0, 311, 310, 1, 0, 0, 0, 312, 313, 1, 0, 0, 0, 313, 314, 6, 57, 1, 0, 314, 116, 1, 0, 0, 0, 6, 0, 286, 292, 297, 307, 311, 2, 6, 0, 0, 0, 1, 0]
\ No newline at end of file +[4, 0, 62, 355, 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, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, 2, 58, 7, 58, 2, 59, 7, 59, 2, 60, 7, 60, 2, 61, 7, 61, 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, 6, 1, 6, 1, 6, 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, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 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, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 1, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 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, 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 1, 49, 1, 49, 1, 50, 1, 50, 1, 51, 1, 51, 1, 52, 1, 52, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 54, 1, 54, 1, 54, 1, 54, 4, 54, 294, 8, 54, 11, 54, 12, 54, 295, 1, 55, 1, 55, 5, 55, 300, 8, 55, 10, 55, 12, 55, 303, 9, 55, 1, 56, 4, 56, 306, 8, 56, 11, 56, 12, 56, 307, 1, 57, 4, 57, 311, 8, 57, 11, 57, 12, 57, 312, 1, 57, 1, 57, 1, 58, 1, 58, 1, 58, 1, 58, 5, 58, 321, 8, 58, 10, 58, 12, 58, 324, 9, 58, 1, 58, 3, 58, 327, 8, 58, 1, 58, 1, 58, 1, 59, 1, 59, 5, 59, 333, 8, 59, 10, 59, 12, 59, 336, 9, 59, 1, 59, 3, 59, 339, 8, 59, 1, 59, 1, 59, 1, 60, 1, 60, 1, 60, 1, 60, 1, 61, 1, 61, 5, 61, 349, 8, 61, 10, 61, 12, 61, 352, 9, 61, 1, 61, 1, 61, 3, 322, 334, 350, 0, 62, 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, 109, 55, 111, 56, 113, 57, 115, 58, 117, 59, 119, 60, 121, 61, 123, 62, 1, 0, 6, 3, 0, 48, 57, 65, 70, 97, 102, 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, 361, 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, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 0, 115, 1, 0, 0, 0, 0, 117, 1, 0, 0, 0, 0, 119, 1, 0, 0, 0, 0, 121, 1, 0, 0, 0, 0, 123, 1, 0, 0, 0, 1, 125, 1, 0, 0, 0, 3, 127, 1, 0, 0, 0, 5, 129, 1, 0, 0, 0, 7, 131, 1, 0, 0, 0, 9, 133, 1, 0, 0, 0, 11, 135, 1, 0, 0, 0, 13, 137, 1, 0, 0, 0, 15, 144, 1, 0, 0, 0, 17, 147, 1, 0, 0, 0, 19, 152, 1, 0, 0, 0, 21, 156, 1, 0, 0, 0, 23, 162, 1, 0, 0, 0, 25, 165, 1, 0, 0, 0, 27, 171, 1, 0, 0, 0, 29, 180, 1, 0, 0, 0, 31, 182, 1, 0, 0, 0, 33, 186, 1, 0, 0, 0, 35, 188, 1, 0, 0, 0, 37, 190, 1, 0, 0, 0, 39, 192, 1, 0, 0, 0, 41, 194, 1, 0, 0, 0, 43, 196, 1, 0, 0, 0, 45, 198, 1, 0, 0, 0, 47, 201, 1, 0, 0, 0, 49, 204, 1, 0, 0, 0, 51, 206, 1, 0, 0, 0, 53, 208, 1, 0, 0, 0, 55, 210, 1, 0, 0, 0, 57, 212, 1, 0, 0, 0, 59, 214, 1, 0, 0, 0, 61, 216, 1, 0, 0, 0, 63, 219, 1, 0, 0, 0, 65, 222, 1, 0, 0, 0, 67, 225, 1, 0, 0, 0, 69, 228, 1, 0, 0, 0, 71, 230, 1, 0, 0, 0, 73, 232, 1, 0, 0, 0, 75, 235, 1, 0, 0, 0, 77, 238, 1, 0, 0, 0, 79, 241, 1, 0, 0, 0, 81, 244, 1, 0, 0, 0, 83, 247, 1, 0, 0, 0, 85, 250, 1, 0, 0, 0, 87, 253, 1, 0, 0, 0, 89, 256, 1, 0, 0, 0, 91, 259, 1, 0, 0, 0, 93, 262, 1, 0, 0, 0, 95, 265, 1, 0, 0, 0, 97, 268, 1, 0, 0, 0, 99, 272, 1, 0, 0, 0, 101, 276, 1, 0, 0, 0, 103, 278, 1, 0, 0, 0, 105, 280, 1, 0, 0, 0, 107, 284, 1, 0, 0, 0, 109, 289, 1, 0, 0, 0, 111, 297, 1, 0, 0, 0, 113, 305, 1, 0, 0, 0, 115, 310, 1, 0, 0, 0, 117, 316, 1, 0, 0, 0, 119, 330, 1, 0, 0, 0, 121, 342, 1, 0, 0, 0, 123, 346, 1, 0, 0, 0, 125, 126, 5, 40, 0, 0, 126, 2, 1, 0, 0, 0, 127, 128, 5, 44, 0, 0, 128, 4, 1, 0, 0, 0, 129, 130, 5, 41, 0, 0, 130, 6, 1, 0, 0, 0, 131, 132, 5, 59, 0, 0, 132, 8, 1, 0, 0, 0, 133, 134, 5, 123, 0, 0, 134, 10, 1, 0, 0, 0, 135, 136, 5, 125, 0, 0, 136, 12, 1, 0, 0, 0, 137, 138, 5, 114, 0, 0, 138, 139, 5, 101, 0, 0, 139, 140, 5, 116, 0, 0, 140, 141, 5, 117, 0, 0, 141, 142, 5, 114, 0, 0, 142, 143, 5, 110, 0, 0, 143, 14, 1, 0, 0, 0, 144, 145, 5, 105, 0, 0, 145, 146, 5, 102, 0, 0, 146, 16, 1, 0, 0, 0, 147, 148, 5, 101, 0, 0, 148, 149, 5, 108, 0, 0, 149, 150, 5, 115, 0, 0, 150, 151, 5, 101, 0, 0, 151, 18, 1, 0, 0, 0, 152, 153, 5, 102, 0, 0, 153, 154, 5, 111, 0, 0, 154, 155, 5, 114, 0, 0, 155, 20, 1, 0, 0, 0, 156, 157, 5, 119, 0, 0, 157, 158, 5, 104, 0, 0, 158, 159, 5, 105, 0, 0, 159, 160, 5, 108, 0, 0, 160, 161, 5, 101, 0, 0, 161, 22, 1, 0, 0, 0, 162, 163, 5, 100, 0, 0, 163, 164, 5, 111, 0, 0, 164, 24, 1, 0, 0, 0, 165, 166, 5, 98, 0, 0, 166, 167, 5, 114, 0, 0, 167, 168, 5, 101, 0, 0, 168, 169, 5, 97, 0, 0, 169, 170, 5, 107, 0, 0, 170, 26, 1, 0, 0, 0, 171, 172, 5, 99, 0, 0, 172, 173, 5, 111, 0, 0, 173, 174, 5, 110, 0, 0, 174, 175, 5, 116, 0, 0, 175, 176, 5, 105, 0, 0, 176, 177, 5, 110, 0, 0, 177, 178, 5, 117, 0, 0, 178, 179, 5, 101, 0, 0, 179, 28, 1, 0, 0, 0, 180, 181, 5, 61, 0, 0, 181, 30, 1, 0, 0, 0, 182, 183, 5, 110, 0, 0, 183, 184, 5, 101, 0, 0, 184, 185, 5, 119, 0, 0, 185, 32, 1, 0, 0, 0, 186, 187, 5, 91, 0, 0, 187, 34, 1, 0, 0, 0, 188, 189, 5, 93, 0, 0, 189, 36, 1, 0, 0, 0, 190, 191, 5, 42, 0, 0, 191, 38, 1, 0, 0, 0, 192, 193, 5, 38, 0, 0, 193, 40, 1, 0, 0, 0, 194, 195, 5, 33, 0, 0, 195, 42, 1, 0, 0, 0, 196, 197, 5, 126, 0, 0, 197, 44, 1, 0, 0, 0, 198, 199, 5, 43, 0, 0, 199, 200, 5, 43, 0, 0, 200, 46, 1, 0, 0, 0, 201, 202, 5, 45, 0, 0, 202, 203, 5, 45, 0, 0, 203, 48, 1, 0, 0, 0, 204, 205, 5, 47, 0, 0, 205, 50, 1, 0, 0, 0, 206, 207, 5, 37, 0, 0, 207, 52, 1, 0, 0, 0, 208, 209, 5, 43, 0, 0, 209, 54, 1, 0, 0, 0, 210, 211, 5, 45, 0, 0, 211, 56, 1, 0, 0, 0, 212, 213, 5, 60, 0, 0, 213, 58, 1, 0, 0, 0, 214, 215, 5, 62, 0, 0, 215, 60, 1, 0, 0, 0, 216, 217, 5, 60, 0, 0, 217, 218, 5, 61, 0, 0, 218, 62, 1, 0, 0, 0, 219, 220, 5, 62, 0, 0, 220, 221, 5, 61, 0, 0, 221, 64, 1, 0, 0, 0, 222, 223, 5, 61, 0, 0, 223, 224, 5, 61, 0, 0, 224, 66, 1, 0, 0, 0, 225, 226, 5, 33, 0, 0, 226, 227, 5, 61, 0, 0, 227, 68, 1, 0, 0, 0, 228, 229, 5, 124, 0, 0, 229, 70, 1, 0, 0, 0, 230, 231, 5, 94, 0, 0, 231, 72, 1, 0, 0, 0, 232, 233, 5, 60, 0, 0, 233, 234, 5, 60, 0, 0, 234, 74, 1, 0, 0, 0, 235, 236, 5, 62, 0, 0, 236, 237, 5, 62, 0, 0, 237, 76, 1, 0, 0, 0, 238, 239, 5, 38, 0, 0, 239, 240, 5, 38, 0, 0, 240, 78, 1, 0, 0, 0, 241, 242, 5, 124, 0, 0, 242, 243, 5, 124, 0, 0, 243, 80, 1, 0, 0, 0, 244, 245, 5, 42, 0, 0, 245, 246, 5, 61, 0, 0, 246, 82, 1, 0, 0, 0, 247, 248, 5, 47, 0, 0, 248, 249, 5, 61, 0, 0, 249, 84, 1, 0, 0, 0, 250, 251, 5, 37, 0, 0, 251, 252, 5, 61, 0, 0, 252, 86, 1, 0, 0, 0, 253, 254, 5, 43, 0, 0, 254, 255, 5, 61, 0, 0, 255, 88, 1, 0, 0, 0, 256, 257, 5, 45, 0, 0, 257, 258, 5, 61, 0, 0, 258, 90, 1, 0, 0, 0, 259, 260, 5, 38, 0, 0, 260, 261, 5, 61, 0, 0, 261, 92, 1, 0, 0, 0, 262, 263, 5, 124, 0, 0, 263, 264, 5, 61, 0, 0, 264, 94, 1, 0, 0, 0, 265, 266, 5, 94, 0, 0, 266, 267, 5, 61, 0, 0, 267, 96, 1, 0, 0, 0, 268, 269, 5, 60, 0, 0, 269, 270, 5, 60, 0, 0, 270, 271, 5, 61, 0, 0, 271, 98, 1, 0, 0, 0, 272, 273, 5, 62, 0, 0, 273, 274, 5, 62, 0, 0, 274, 275, 5, 61, 0, 0, 275, 100, 1, 0, 0, 0, 276, 277, 5, 63, 0, 0, 277, 102, 1, 0, 0, 0, 278, 279, 5, 58, 0, 0, 279, 104, 1, 0, 0, 0, 280, 281, 5, 105, 0, 0, 281, 282, 5, 110, 0, 0, 282, 283, 5, 116, 0, 0, 283, 106, 1, 0, 0, 0, 284, 285, 5, 99, 0, 0, 285, 286, 5, 104, 0, 0, 286, 287, 5, 97, 0, 0, 287, 288, 5, 114, 0, 0, 288, 108, 1, 0, 0, 0, 289, 290, 5, 48, 0, 0, 290, 291, 5, 120, 0, 0, 291, 293, 1, 0, 0, 0, 292, 294, 7, 0, 0, 0, 293, 292, 1, 0, 0, 0, 294, 295, 1, 0, 0, 0, 295, 293, 1, 0, 0, 0, 295, 296, 1, 0, 0, 0, 296, 110, 1, 0, 0, 0, 297, 301, 7, 1, 0, 0, 298, 300, 7, 2, 0, 0, 299, 298, 1, 0, 0, 0, 300, 303, 1, 0, 0, 0, 301, 299, 1, 0, 0, 0, 301, 302, 1, 0, 0, 0, 302, 112, 1, 0, 0, 0, 303, 301, 1, 0, 0, 0, 304, 306, 7, 3, 0, 0, 305, 304, 1, 0, 0, 0, 306, 307, 1, 0, 0, 0, 307, 305, 1, 0, 0, 0, 307, 308, 1, 0, 0, 0, 308, 114, 1, 0, 0, 0, 309, 311, 7, 4, 0, 0, 310, 309, 1, 0, 0, 0, 311, 312, 1, 0, 0, 0, 312, 310, 1, 0, 0, 0, 312, 313, 1, 0, 0, 0, 313, 314, 1, 0, 0, 0, 314, 315, 6, 57, 0, 0, 315, 116, 1, 0, 0, 0, 316, 317, 5, 47, 0, 0, 317, 318, 5, 47, 0, 0, 318, 322, 1, 0, 0, 0, 319, 321, 9, 0, 0, 0, 320, 319, 1, 0, 0, 0, 321, 324, 1, 0, 0, 0, 322, 323, 1, 0, 0, 0, 322, 320, 1, 0, 0, 0, 323, 326, 1, 0, 0, 0, 324, 322, 1, 0, 0, 0, 325, 327, 7, 5, 0, 0, 326, 325, 1, 0, 0, 0, 327, 328, 1, 0, 0, 0, 328, 329, 6, 58, 1, 0, 329, 118, 1, 0, 0, 0, 330, 334, 5, 35, 0, 0, 331, 333, 9, 0, 0, 0, 332, 331, 1, 0, 0, 0, 333, 336, 1, 0, 0, 0, 334, 335, 1, 0, 0, 0, 334, 332, 1, 0, 0, 0, 335, 338, 1, 0, 0, 0, 336, 334, 1, 0, 0, 0, 337, 339, 7, 5, 0, 0, 338, 337, 1, 0, 0, 0, 339, 340, 1, 0, 0, 0, 340, 341, 6, 59, 1, 0, 341, 120, 1, 0, 0, 0, 342, 343, 5, 39, 0, 0, 343, 344, 9, 0, 0, 0, 344, 345, 5, 39, 0, 0, 345, 122, 1, 0, 0, 0, 346, 350, 5, 34, 0, 0, 347, 349, 9, 0, 0, 0, 348, 347, 1, 0, 0, 0, 349, 352, 1, 0, 0, 0, 350, 351, 1, 0, 0, 0, 350, 348, 1, 0, 0, 0, 351, 353, 1, 0, 0, 0, 352, 350, 1, 0, 0, 0, 353, 354, 5, 34, 0, 0, 354, 124, 1, 0, 0, 0, 10, 0, 295, 301, 307, 312, 322, 326, 334, 338, 350, 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 e57eab2..b6c3179 100644 --- a/Compiler/gen/CGrammarLexer.tokens +++ b/Compiler/gen/CGrammarLexer.tokens @@ -51,11 +51,15 @@ T__49=50 T__50=51 T__51=52 T__52=53 -HEX=54 -ID=55 -INT=56 -WS=57 -COMMENT=58 +T__53=54 +HEX=55 +ID=56 +INT=57 +WS=58 +COMMENT=59 +DIRECTIVE=60 +LETTER=61 +STRING=62 '('=1 ','=2 ')'=3 @@ -71,41 +75,42 @@ COMMENT=58 'break'=13 'continue'=14 '='=15 -'*'=16 -'&'=17 -'['=18 -']'=19 -'!'=20 -'~'=21 -'++'=22 -'--'=23 -'/'=24 -'%'=25 -'+'=26 -'-'=27 -'<'=28 -'>'=29 -'<='=30 -'>='=31 -'=='=32 -'!='=33 -'|'=34 -'^'=35 -'<<'=36 -'>>'=37 -'&&'=38 -'||'=39 -'*='=40 -'/='=41 -'%='=42 -'+='=43 -'-='=44 -'&='=45 -'|='=46 -'^='=47 -'<<='=48 -'>>='=49 -'?'=50 -':'=51 -'int'=52 -'char'=53 +'new'=16 +'['=17 +']'=18 +'*'=19 +'&'=20 +'!'=21 +'~'=22 +'++'=23 +'--'=24 +'/'=25 +'%'=26 +'+'=27 +'-'=28 +'<'=29 +'>'=30 +'<='=31 +'>='=32 +'=='=33 +'!='=34 +'|'=35 +'^'=36 +'<<'=37 +'>>'=38 +'&&'=39 +'||'=40 +'*='=41 +'/='=42 +'%='=43 +'+='=44 +'-='=45 +'&='=46 +'|='=47 +'^='=48 +'<<='=49 +'>>='=50 +'?'=51 +':'=52 +'int'=53 +'char'=54 diff --git a/Compiler/gen/CGrammarParser.cs b/Compiler/gen/CGrammarParser.cs index 9d4e217..1b8a393 100644 --- a/Compiler/gen/CGrammarParser.cs +++ b/Compiler/gen/CGrammarParser.cs @@ -43,7 +43,8 @@ public partial class CGrammarParser : Parser { 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, T__45=46, T__46=47, T__47=48, T__48=49, T__49=50, T__50=51, T__51=52, - T__52=53, HEX=54, ID=55, INT=56, WS=57, COMMENT=58; + T__52=53, T__53=54, HEX=55, ID=56, INT=57, WS=58, COMMENT=59, DIRECTIVE=60, + LETTER=61, STRING=62; 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, @@ -55,18 +56,19 @@ public partial class CGrammarParser : Parser { private static readonly string[] _LiteralNames = { null, "'('", "','", "')'", "';'", "'{'", "'}'", "'return'", "'if'", "'else'", - "'for'", "'while'", "'do'", "'break'", "'continue'", "'='", "'*'", "'&'", - "'['", "']'", "'!'", "'~'", "'++'", "'--'", "'/'", "'%'", "'+'", "'-'", - "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'|'", "'^'", "'<<'", "'>>'", - "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", "'|='", - "'^='", "'<<='", "'>>='", "'?'", "':'", "'int'", "'char'" + "'for'", "'while'", "'do'", "'break'", "'continue'", "'='", "'new'", "'['", + "']'", "'*'", "'&'", "'!'", "'~'", "'++'", "'--'", "'/'", "'%'", "'+'", + "'-'", "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'|'", "'^'", "'<<'", + "'>>'", "'&&'", "'||'", "'*='", "'/='", "'%='", "'+='", "'-='", "'&='", + "'|='", "'^='", "'<<='", "'>>='", "'?'", "':'", "'int'", "'char'" }; 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, null, null, - null, null, null, null, null, null, "HEX", "ID", "INT", "WS", "COMMENT" + null, null, null, null, null, null, null, "HEX", "ID", "INT", "WS", "COMMENT", + "DIRECTIVE", "LETTER", "STRING" }; public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); @@ -142,7 +144,7 @@ public partial class CGrammarParser : Parser { State = 23; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - } while ( _la==T__51 || _la==T__52 ); + } while ( _la==T__52 || _la==T__53 ); State = 25; Match(Eof); } @@ -246,7 +248,7 @@ public partial class CGrammarParser : Parser { State = 41; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if (_la==T__51 || _la==T__52) { + if (_la==T__52 || _la==T__53) { { State = 30; ((FunctionPrototypeContext)_localctx)._type = type(0); @@ -296,7 +298,7 @@ public partial class CGrammarParser : Parser { State = 60; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if (_la==T__51 || _la==T__52) { + if (_la==T__52 || _la==T__53) { { State = 49; ((FunctionDefinitionContext)_localctx)._type = type(0); @@ -379,7 +381,7 @@ public partial class CGrammarParser : Parser { State = 71; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 139611588464442802L) != 0)) { + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7196752204571180466L) != 0)) { { { State = 68; @@ -444,22 +446,25 @@ public partial class CGrammarParser : Parser { case T__12: case T__13: case T__15: - case T__16: + case T__18: case T__19: case T__20: case T__21: case T__22: + case T__23: case HEX: case ID: case INT: + case LETTER: + case STRING: EnterOuterAlt(_localctx, 1); { State = 76; statement(); } break; - case T__51: case T__52: + case T__53: EnterOuterAlt(_localctx, 2); { State = 77; @@ -718,7 +723,7 @@ public partial class CGrammarParser : Parser { State = 96; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 126100789582299138L) != 0)) { + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { { State = 95; ((ForExprStatementContext)_localctx).initializer = expression(0); @@ -730,7 +735,7 @@ public partial class CGrammarParser : Parser { State = 100; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 126100789582299138L) != 0)) { + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { { State = 99; ((ForExprStatementContext)_localctx).cond = expression(0); @@ -742,7 +747,7 @@ public partial class CGrammarParser : Parser { State = 104; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 126100789582299138L) != 0)) { + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { { State = 103; ((ForExprStatementContext)_localctx).post = expression(0); @@ -768,7 +773,7 @@ public partial class CGrammarParser : Parser { State = 112; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 126100789582299138L) != 0)) { + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { { State = 111; ((ForDeclStatementContext)_localctx).cond = expression(0); @@ -780,7 +785,7 @@ public partial class CGrammarParser : Parser { State = 116; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 126100789582299138L) != 0)) { + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { { State = 115; ((ForDeclStatementContext)_localctx).post = expression(0); @@ -1241,13 +1246,13 @@ public partial class CGrammarParser : Parser { } } public partial class IndexExpressionContext : ExpressionContext { - public ExpressionContext obj; + public TargetContext obj; public ExpressionContext indexer; - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { - return GetRuleContexts<ExpressionContext>(); + [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { + return GetRuleContext<TargetContext>(0); } - [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { - return GetRuleContext<ExpressionContext>(i); + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { + return GetRuleContext<ExpressionContext>(0); } public IndexExpressionContext(ExpressionContext context) { CopyFrom(context); } [System.Diagnostics.DebuggerNonUserCode] @@ -1315,6 +1320,27 @@ public partial class CGrammarParser : Parser { else return visitor.VisitChildren(this); } } + public partial class ArrayExpressionContext : ExpressionContext { + public ExpressionContext _expression; + public IList<ExpressionContext> _params = new List<ExpressionContext>(); + [System.Diagnostics.DebuggerNonUserCode] public TypeContext type() { + return GetRuleContext<TypeContext>(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode INT() { return GetToken(CGrammarParser.INT, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() { + return GetRuleContexts<ExpressionContext>(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext<ExpressionContext>(i); + } + public ArrayExpressionContext(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.VisitArrayExpression(this); + else return visitor.VisitChildren(this); + } + } public partial class ConstantExpressionContext : ExpressionContext { [System.Diagnostics.DebuggerNonUserCode] public ConstantContext constant() { return GetRuleContext<ConstantContext>(0); @@ -1643,9 +1669,9 @@ public partial class CGrammarParser : Parser { int _alt; EnterOuterAlt(_localctx, 1); { - State = 236; + State = 261; ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,18,Context) ) { + switch ( Interpreter.AdaptivePredict(TokenStream,21,Context) ) { case 1: { _localctx = new ParenthesizedExpressionContext(_localctx); @@ -1662,318 +1688,390 @@ public partial class CGrammarParser : Parser { break; case 2: { - _localctx = new ConstantExpressionContext(_localctx); + _localctx = new ArrayExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 159; - constant(); + Match(T__15); + State = 160; + type(0); + State = 161; + Match(T__16); + State = 163; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + if (_la==INT) { + { + State = 162; + Match(INT); + } + } + + State = 165; + Match(T__17); + State = 166; + Match(T__4); + State = 175; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { + { + State = 167; + ((ArrayExpressionContext)_localctx)._expression = expression(0); + ((ArrayExpressionContext)_localctx)._params.Add(((ArrayExpressionContext)_localctx)._expression); + State = 172; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while (_la==T__1) { + { + { + State = 168; + Match(T__1); + State = 169; + ((ArrayExpressionContext)_localctx)._expression = expression(0); + ((ArrayExpressionContext)_localctx)._params.Add(((ArrayExpressionContext)_localctx)._expression); + } + } + State = 174; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + } + } + + State = 177; + Match(T__5); } break; case 3: { + _localctx = new ConstantExpressionContext(_localctx); + Context = _localctx; + _prevctx = _localctx; + State = 179; + constant(); + } + break; + case 4: + { _localctx = new AssignmentExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 160; - target(); - State = 161; + State = 180; + target(0); + State = 181; Match(T__14); - State = 162; + State = 182; expression(41); } break; - case 4: + case 5: { _localctx = new DereferenceExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 164; - Match(T__15); - State = 165; + State = 184; + Match(T__18); + State = 185; expression(40); } break; - case 5: + case 6: { _localctx = new AddressOfExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 166; - Match(T__16); - State = 167; - target(); + State = 186; + Match(T__19); + State = 187; + target(0); } break; - case 6: + case 7: { _localctx = new VariableExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 168; + State = 188; Match(ID); } break; - case 7: + case 8: { _localctx = new CallExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 169; + State = 189; Match(ID); - State = 170; + State = 190; Match(T__0); - State = 179; + State = 199; ErrorHandler.Sync(this); _la = TokenStream.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 126100789582299138L) != 0)) { + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7169730606806925314L) != 0)) { { - State = 171; + State = 191; ((CallExpressionContext)_localctx)._expression = expression(0); ((CallExpressionContext)_localctx)._params.Add(((CallExpressionContext)_localctx)._expression); - State = 176; + State = 196; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la==T__1) { { { - State = 172; + State = 192; Match(T__1); - State = 173; + State = 193; ((CallExpressionContext)_localctx)._expression = expression(0); ((CallExpressionContext)_localctx)._params.Add(((CallExpressionContext)_localctx)._expression); } } - State = 178; + State = 198; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } } } - State = 181; + State = 201; Match(T__2); } break; - case 8: + case 9: + { + _localctx = new IndexExpressionContext(_localctx); + Context = _localctx; + _prevctx = _localctx; + State = 202; + ((IndexExpressionContext)_localctx).obj = target(0); + State = 203; + Match(T__16); + State = 204; + ((IndexExpressionContext)_localctx).indexer = expression(0); + State = 205; + Match(T__17); + } + break; + case 10: { _localctx = new NotExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 182; - Match(T__19); - State = 183; + State = 207; + Match(T__20); + State = 208; expression(35); } break; - case 9: + case 11: { _localctx = new InvertExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 184; - Match(T__20); - State = 185; + State = 209; + Match(T__21); + State = 210; expression(34); } break; - case 10: + case 12: { _localctx = new IncrementPrefixExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 186; - Match(T__21); - State = 187; - target(); + State = 211; + Match(T__22); + State = 212; + target(0); } break; - case 11: + case 13: { _localctx = new DecrementPrefixExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 188; - Match(T__22); - State = 189; - target(); + State = 213; + Match(T__23); + State = 214; + target(0); } break; - case 12: + case 14: { _localctx = new IncrementPostfixExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 190; - target(); - State = 191; - Match(T__21); + State = 215; + target(0); + State = 216; + Match(T__22); } break; - case 13: + case 15: { _localctx = new DecrementPostfixExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 193; - target(); - State = 194; - Match(T__22); + State = 218; + target(0); + State = 219; + Match(T__23); } break; - case 14: + case 16: { _localctx = new CompoundMultiplyExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 196; - target(); - State = 197; - Match(T__39); - State = 198; + State = 221; + target(0); + State = 222; + Match(T__40); + State = 223; expression(11); } break; - case 15: + case 17: { _localctx = new CompoundDivideExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 200; - target(); - State = 201; - Match(T__40); - State = 202; + State = 225; + target(0); + State = 226; + Match(T__41); + State = 227; expression(10); } break; - case 16: + case 18: { _localctx = new CompoundModulusExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 204; - target(); - State = 205; - Match(T__41); - State = 206; + State = 229; + target(0); + State = 230; + Match(T__42); + State = 231; expression(9); } break; - case 17: + case 19: { _localctx = new CompoundAddExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 208; - target(); - State = 209; - Match(T__42); - State = 210; + State = 233; + target(0); + State = 234; + Match(T__43); + State = 235; expression(8); } break; - case 18: + case 20: { _localctx = new CompoundSubtractExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 212; - target(); - State = 213; - Match(T__43); - State = 214; + State = 237; + target(0); + State = 238; + Match(T__44); + State = 239; expression(7); } break; - case 19: + case 21: { _localctx = new CompoundBitwiseAndExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 216; - target(); - State = 217; - Match(T__44); - State = 218; + State = 241; + target(0); + State = 242; + Match(T__45); + State = 243; expression(6); } break; - case 20: + case 22: { _localctx = new CompoundBitwiseOrExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 220; - target(); - State = 221; - Match(T__45); - State = 222; + State = 245; + target(0); + State = 246; + Match(T__46); + State = 247; expression(5); } break; - case 21: + case 23: { _localctx = new CompoundBitwiseXorExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 224; - target(); - State = 225; - Match(T__46); - State = 226; + State = 249; + target(0); + State = 250; + Match(T__47); + State = 251; expression(4); } break; - case 22: + case 24: { _localctx = new CompoundBitwiseLeftShiftExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 228; - target(); - State = 229; - Match(T__47); - State = 230; + State = 253; + target(0); + State = 254; + Match(T__48); + State = 255; expression(3); } break; - case 23: + case 25: { _localctx = new CompoundBitwiseRightShiftExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; - State = 232; - target(); - State = 233; - Match(T__48); - State = 234; + State = 257; + target(0); + State = 258; + Match(T__49); + State = 259; expression(2); } break; } Context.Stop = TokenStream.LT(-1); - State = 305; + State = 325; ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,20,Context); + _alt = Interpreter.AdaptivePredict(TokenStream,23,Context); while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { if ( ParseListeners!=null ) TriggerExitRuleEvent(); _prevctx = _localctx; { - State = 303; + State = 323; ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,19,Context) ) { + switch ( Interpreter.AdaptivePredict(TokenStream,22,Context) ) { case 1: { _localctx = new MultiplyExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((MultiplyExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 238; + State = 263; if (!(Precpred(Context, 29))) throw new FailedPredicateException(this, "Precpred(Context, 29)"); - State = 239; - Match(T__15); - State = 240; + State = 264; + Match(T__18); + State = 265; ((MultiplyExpressionContext)_localctx).right = expression(30); } break; @@ -1982,11 +2080,11 @@ public partial class CGrammarParser : Parser { _localctx = new DivideExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((DivideExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 241; + State = 266; if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)"); - State = 242; - Match(T__23); - State = 243; + State = 267; + Match(T__24); + State = 268; ((DivideExpressionContext)_localctx).right = expression(29); } break; @@ -1995,11 +2093,11 @@ public partial class CGrammarParser : Parser { _localctx = new ModulusExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((ModulusExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 244; + State = 269; if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)"); - State = 245; - Match(T__24); - State = 246; + State = 270; + Match(T__25); + State = 271; ((ModulusExpressionContext)_localctx).right = expression(28); } break; @@ -2008,11 +2106,11 @@ public partial class CGrammarParser : Parser { _localctx = new AddExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((AddExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 247; + State = 272; if (!(Precpred(Context, 26))) throw new FailedPredicateException(this, "Precpred(Context, 26)"); - State = 248; - Match(T__25); - State = 249; + State = 273; + Match(T__26); + State = 274; ((AddExpressionContext)_localctx).right = expression(27); } break; @@ -2021,11 +2119,11 @@ public partial class CGrammarParser : Parser { _localctx = new SubtractExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((SubtractExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 250; + State = 275; if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)"); - State = 251; - Match(T__26); - State = 252; + State = 276; + Match(T__27); + State = 277; ((SubtractExpressionContext)_localctx).right = expression(26); } break; @@ -2034,11 +2132,11 @@ public partial class CGrammarParser : Parser { _localctx = new LessThanExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((LessThanExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 253; + State = 278; if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)"); - State = 254; - Match(T__27); - State = 255; + State = 279; + Match(T__28); + State = 280; ((LessThanExpressionContext)_localctx).right = expression(25); } break; @@ -2047,11 +2145,11 @@ public partial class CGrammarParser : Parser { _localctx = new GreaterThanExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((GreaterThanExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 256; + State = 281; if (!(Precpred(Context, 23))) throw new FailedPredicateException(this, "Precpred(Context, 23)"); - State = 257; - Match(T__28); - State = 258; + State = 282; + Match(T__29); + State = 283; ((GreaterThanExpressionContext)_localctx).right = expression(24); } break; @@ -2060,11 +2158,11 @@ public partial class CGrammarParser : Parser { _localctx = new LessThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((LessThanOrEqualExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 259; + State = 284; if (!(Precpred(Context, 22))) throw new FailedPredicateException(this, "Precpred(Context, 22)"); - State = 260; - Match(T__29); - State = 261; + State = 285; + Match(T__30); + State = 286; ((LessThanOrEqualExpressionContext)_localctx).right = expression(23); } break; @@ -2073,11 +2171,11 @@ public partial class CGrammarParser : Parser { _localctx = new GreaterThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((GreaterThanOrEqualExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 262; + State = 287; if (!(Precpred(Context, 21))) throw new FailedPredicateException(this, "Precpred(Context, 21)"); - State = 263; - Match(T__30); - State = 264; + State = 288; + Match(T__31); + State = 289; ((GreaterThanOrEqualExpressionContext)_localctx).right = expression(22); } break; @@ -2086,11 +2184,11 @@ public partial class CGrammarParser : Parser { _localctx = new EqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((EqualExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 265; + State = 290; if (!(Precpred(Context, 20))) throw new FailedPredicateException(this, "Precpred(Context, 20)"); - State = 266; - Match(T__31); - State = 267; + State = 291; + Match(T__32); + State = 292; ((EqualExpressionContext)_localctx).right = expression(21); } break; @@ -2099,11 +2197,11 @@ public partial class CGrammarParser : Parser { _localctx = new NotEqualExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((NotEqualExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 268; + State = 293; if (!(Precpred(Context, 19))) throw new FailedPredicateException(this, "Precpred(Context, 19)"); - State = 269; - Match(T__32); - State = 270; + State = 294; + Match(T__33); + State = 295; ((NotEqualExpressionContext)_localctx).right = expression(20); } break; @@ -2112,11 +2210,11 @@ public partial class CGrammarParser : Parser { _localctx = new BitwiseAndExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((BitwiseAndExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 271; + State = 296; if (!(Precpred(Context, 18))) throw new FailedPredicateException(this, "Precpred(Context, 18)"); - State = 272; - Match(T__16); - State = 273; + State = 297; + Match(T__19); + State = 298; ((BitwiseAndExpressionContext)_localctx).right = expression(19); } break; @@ -2125,11 +2223,11 @@ public partial class CGrammarParser : Parser { _localctx = new BitwiseOrExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((BitwiseOrExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 274; + State = 299; if (!(Precpred(Context, 17))) throw new FailedPredicateException(this, "Precpred(Context, 17)"); - State = 275; - Match(T__33); - State = 276; + State = 300; + Match(T__34); + State = 301; ((BitwiseOrExpressionContext)_localctx).right = expression(18); } break; @@ -2138,11 +2236,11 @@ public partial class CGrammarParser : Parser { _localctx = new BitwiseXorExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((BitwiseXorExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 277; + State = 302; if (!(Precpred(Context, 16))) throw new FailedPredicateException(this, "Precpred(Context, 16)"); - State = 278; - Match(T__34); - State = 279; + State = 303; + Match(T__35); + State = 304; ((BitwiseXorExpressionContext)_localctx).right = expression(17); } break; @@ -2151,11 +2249,11 @@ public partial class CGrammarParser : Parser { _localctx = new BitwiseLeftShiftExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((BitwiseLeftShiftExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 280; + State = 305; if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)"); - State = 281; - Match(T__35); - State = 282; + State = 306; + Match(T__36); + State = 307; ((BitwiseLeftShiftExpressionContext)_localctx).right = expression(16); } break; @@ -2164,11 +2262,11 @@ public partial class CGrammarParser : Parser { _localctx = new BitwiseRightShiftExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((BitwiseRightShiftExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 283; + State = 308; if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)"); - State = 284; - Match(T__36); - State = 285; + State = 309; + Match(T__37); + State = 310; ((BitwiseRightShiftExpressionContext)_localctx).right = expression(15); } break; @@ -2177,11 +2275,11 @@ public partial class CGrammarParser : Parser { _localctx = new LogicalAndExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((LogicalAndExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 286; + State = 311; if (!(Precpred(Context, 13))) throw new FailedPredicateException(this, "Precpred(Context, 13)"); - State = 287; - Match(T__37); - State = 288; + State = 312; + Match(T__38); + State = 313; ((LogicalAndExpressionContext)_localctx).right = expression(14); } break; @@ -2190,11 +2288,11 @@ public partial class CGrammarParser : Parser { _localctx = new LogicalOrExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((LogicalOrExpressionContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 289; + State = 314; if (!(Precpred(Context, 12))) throw new FailedPredicateException(this, "Precpred(Context, 12)"); - State = 290; - Match(T__38); - State = 291; + State = 315; + Match(T__39); + State = 316; ((LogicalOrExpressionContext)_localctx).right = expression(13); } break; @@ -2203,39 +2301,24 @@ public partial class CGrammarParser : Parser { _localctx = new TernaryExpressionContext(new ExpressionContext(_parentctx, _parentState)); ((TernaryExpressionContext)_localctx).cond = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 292; + State = 317; if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); - State = 293; - Match(T__49); - State = 294; - ((TernaryExpressionContext)_localctx).then = expression(0); - State = 295; + State = 318; Match(T__50); - State = 296; + State = 319; + ((TernaryExpressionContext)_localctx).then = expression(0); + State = 320; + Match(T__51); + State = 321; ((TernaryExpressionContext)_localctx).@else = expression(2); } break; - case 20: - { - _localctx = new IndexExpressionContext(new ExpressionContext(_parentctx, _parentState)); - ((IndexExpressionContext)_localctx).obj = _prevctx; - PushNewRecursionContext(_localctx, _startState, RULE_expression); - State = 298; - if (!(Precpred(Context, 36))) throw new FailedPredicateException(this, "Precpred(Context, 36)"); - State = 299; - Match(T__17); - State = 300; - ((IndexExpressionContext)_localctx).indexer = expression(0); - State = 301; - Match(T__18); - } - break; } } } - State = 307; + State = 327; ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,20,Context); + _alt = Interpreter.AdaptivePredict(TokenStream,23,Context); } } } @@ -2262,6 +2345,16 @@ public partial class CGrammarParser : Parser { base.CopyFrom(context); } } + public partial class CharConstantContext : ConstantContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode LETTER() { return GetToken(CGrammarParser.LETTER, 0); } + public CharConstantContext(ConstantContext 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.VisitCharConstant(this); + else return visitor.VisitChildren(this); + } + } public partial class IntConstantContext : ConstantContext { [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode INT() { return GetToken(CGrammarParser.INT, 0); } public IntConstantContext(ConstantContext context) { CopyFrom(context); } @@ -2272,6 +2365,16 @@ public partial class CGrammarParser : Parser { else return visitor.VisitChildren(this); } } + public partial class StringConstantContext : ConstantContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode STRING() { return GetToken(CGrammarParser.STRING, 0); } + public StringConstantContext(ConstantContext 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.VisitStringConstant(this); + else return visitor.VisitChildren(this); + } + } public partial class HexConstantContext : ConstantContext { [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(CGrammarParser.HEX, 0); } public HexConstantContext(ConstantContext context) { CopyFrom(context); } @@ -2288,14 +2391,14 @@ public partial class CGrammarParser : Parser { ConstantContext _localctx = new ConstantContext(Context, State); EnterRule(_localctx, 14, RULE_constant); try { - State = 310; + State = 332; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case INT: _localctx = new IntConstantContext(_localctx); EnterOuterAlt(_localctx, 1); { - State = 308; + State = 328; Match(INT); } break; @@ -2303,10 +2406,26 @@ public partial class CGrammarParser : Parser { _localctx = new HexConstantContext(_localctx); EnterOuterAlt(_localctx, 2); { - State = 309; + State = 329; Match(HEX); } break; + case LETTER: + _localctx = new CharConstantContext(_localctx); + EnterOuterAlt(_localctx, 3); + { + State = 330; + Match(LETTER); + } + break; + case STRING: + _localctx = new StringConstantContext(_localctx); + EnterOuterAlt(_localctx, 4); + { + State = 331; + Match(STRING); + } + break; default: throw new NoViableAltException(this); } @@ -2355,28 +2474,28 @@ public partial class CGrammarParser : Parser { int _alt; EnterOuterAlt(_localctx, 1); { - State = 315; + State = 337; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { - case T__51: + case T__52: { - State = 313; - Match(T__51); + State = 335; + Match(T__52); } break; - case T__52: + case T__53: { - State = 314; - Match(T__52); + State = 336; + Match(T__53); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); - State = 321; + State = 343; ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,23,Context); + _alt = Interpreter.AdaptivePredict(TokenStream,26,Context); while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { if ( ParseListeners!=null ) @@ -2386,16 +2505,16 @@ public partial class CGrammarParser : Parser { { _localctx = new TypeContext(_parentctx, _parentState); PushNewRecursionContext(_localctx, _startState, RULE_type); - State = 317; + State = 339; if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); - State = 318; - Match(T__15); + State = 340; + Match(T__18); } } } - State = 323; + State = 345; ErrorHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(TokenStream,23,Context); + _alt = Interpreter.AdaptivePredict(TokenStream,26,Context); } } } @@ -2422,6 +2541,23 @@ public partial class CGrammarParser : Parser { base.CopyFrom(context); } } + public partial class IndexerTargetContext : TargetContext { + public TargetContext obj; + public ExpressionContext indexer; + [System.Diagnostics.DebuggerNonUserCode] public TargetContext target() { + return GetRuleContext<TargetContext>(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() { + return GetRuleContext<ExpressionContext>(0); + } + public IndexerTargetContext(TargetContext 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.VisitIndexerTarget(this); + else return visitor.VisitChildren(this); + } + } public partial class VariableTargetContext : TargetContext { [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); } public VariableTargetContext(TargetContext context) { CopyFrom(context); } @@ -2435,15 +2571,58 @@ public partial class CGrammarParser : Parser { [RuleVersion(0)] public TargetContext target() { - TargetContext _localctx = new TargetContext(Context, State); - EnterRule(_localctx, 18, RULE_target); + return target(0); + } + + private TargetContext target(int _p) { + ParserRuleContext _parentctx = Context; + int _parentState = State; + TargetContext _localctx = new TargetContext(Context, _parentState); + TargetContext _prevctx = _localctx; + int _startState = 18; + EnterRecursionRule(_localctx, 18, RULE_target, _p); try { - _localctx = new VariableTargetContext(_localctx); + int _alt; EnterOuterAlt(_localctx, 1); { - State = 324; + { + _localctx = new VariableTargetContext(_localctx); + Context = _localctx; + _prevctx = _localctx; + + State = 347; Match(ID); } + Context.Stop = TokenStream.LT(-1); + State = 356; + ErrorHandler.Sync(this); + _alt = Interpreter.AdaptivePredict(TokenStream,27,Context); + while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + if ( ParseListeners!=null ) + TriggerExitRuleEvent(); + _prevctx = _localctx; + { + { + _localctx = new IndexerTargetContext(new TargetContext(_parentctx, _parentState)); + ((IndexerTargetContext)_localctx).obj = _prevctx; + PushNewRecursionContext(_localctx, _startState, RULE_target); + State = 349; + if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); + State = 350; + Match(T__16); + State = 351; + ((IndexerTargetContext)_localctx).indexer = expression(0); + State = 352; + Match(T__17); + } + } + } + State = 358; + ErrorHandler.Sync(this); + _alt = Interpreter.AdaptivePredict(TokenStream,27,Context); + } + } } catch (RecognitionException re) { _localctx.exception = re; @@ -2451,7 +2630,7 @@ public partial class CGrammarParser : Parser { ErrorHandler.Recover(this, re); } finally { - ExitRule(); + UnrollRecursionContexts(_parentctx); } return _localctx; } @@ -2460,6 +2639,7 @@ public partial class CGrammarParser : Parser { switch (ruleIndex) { case 6: return expression_sempred((ExpressionContext)_localctx, predIndex); case 8: return type_sempred((TypeContext)_localctx, predIndex); + case 9: return target_sempred((TargetContext)_localctx, predIndex); } return true; } @@ -2484,19 +2664,24 @@ public partial class CGrammarParser : Parser { case 16: return Precpred(Context, 13); case 17: return Precpred(Context, 12); case 18: return Precpred(Context, 1); - case 19: return Precpred(Context, 36); } return true; } private bool type_sempred(TypeContext _localctx, int predIndex) { switch (predIndex) { + case 19: return Precpred(Context, 1); + } + return true; + } + private bool target_sempred(TargetContext _localctx, int predIndex) { + switch (predIndex) { case 20: return Precpred(Context, 1); } return true; } private static int[] _serializedATN = { - 4,1,58,327,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, + 4,1,62,360,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7, 7,7,2,8,7,8,2,9,7,9,1,0,4,0,22,8,0,11,0,12,0,23,1,0,1,0,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,5,1,37,8,1,10,1,12,1,40,9,1,3,1,42,8,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,56,8,1,10,1,12,1,59,9,1,3,1, @@ -2506,106 +2691,118 @@ public partial class CGrammarParser : Parser { 1,4,1,4,1,4,1,4,1,4,1,4,3,4,113,8,4,1,4,1,4,3,4,117,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,145,8,4,1,5,1,5,1,5,1,5,3,5,151,8,5,1,5,1,5,1, + 6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,3,6,164,8,6,1,6,1,6,1,6,1,6,1,6,5,6, + 171,8,6,10,6,12,6,174,9,6,3,6,176,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,5,6,195,8,6,10,6,12,6,198,9,6,3,6, + 200,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,5,6,175,8,6,10,6,12,6,178,9,6,3,6,180,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,237,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, + 6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,3,6,262,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,5,6,304,8,6,10,6,12, - 6,307,9,6,1,7,1,7,3,7,311,8,7,1,8,1,8,1,8,3,8,316,8,8,1,8,1,8,5,8,320, - 8,8,10,8,12,8,323,9,8,1,9,1,9,1,9,0,2,12,16,10,0,2,4,6,8,10,12,14,16,18, - 0,0,388,0,21,1,0,0,0,2,65,1,0,0,0,4,67,1,0,0,0,6,78,1,0,0,0,8,144,1,0, - 0,0,10,146,1,0,0,0,12,236,1,0,0,0,14,310,1,0,0,0,16,315,1,0,0,0,18,324, - 1,0,0,0,20,22,3,2,1,0,21,20,1,0,0,0,22,23,1,0,0,0,23,21,1,0,0,0,23,24, - 1,0,0,0,24,25,1,0,0,0,25,26,5,0,0,1,26,1,1,0,0,0,27,28,3,16,8,0,28,29, - 5,55,0,0,29,41,5,1,0,0,30,31,3,16,8,0,31,38,5,55,0,0,32,33,5,2,0,0,33, - 34,3,16,8,0,34,35,5,55,0,0,35,37,1,0,0,0,36,32,1,0,0,0,37,40,1,0,0,0,38, - 36,1,0,0,0,38,39,1,0,0,0,39,42,1,0,0,0,40,38,1,0,0,0,41,30,1,0,0,0,41, - 42,1,0,0,0,42,43,1,0,0,0,43,44,5,3,0,0,44,45,5,4,0,0,45,66,1,0,0,0,46, - 47,3,16,8,0,47,48,5,55,0,0,48,60,5,1,0,0,49,50,3,16,8,0,50,57,5,55,0,0, - 51,52,5,2,0,0,52,53,3,16,8,0,53,54,5,55,0,0,54,56,1,0,0,0,55,51,1,0,0, - 0,56,59,1,0,0,0,57,55,1,0,0,0,57,58,1,0,0,0,58,61,1,0,0,0,59,57,1,0,0, - 0,60,49,1,0,0,0,60,61,1,0,0,0,61,62,1,0,0,0,62,63,5,3,0,0,63,64,3,4,2, - 0,64,66,1,0,0,0,65,27,1,0,0,0,65,46,1,0,0,0,66,3,1,0,0,0,67,71,5,5,0,0, - 68,70,3,6,3,0,69,68,1,0,0,0,70,73,1,0,0,0,71,69,1,0,0,0,71,72,1,0,0,0, - 72,74,1,0,0,0,73,71,1,0,0,0,74,75,5,6,0,0,75,5,1,0,0,0,76,79,3,8,4,0,77, - 79,3,10,5,0,78,76,1,0,0,0,78,77,1,0,0,0,79,7,1,0,0,0,80,81,5,7,0,0,81, - 82,3,12,6,0,82,83,5,4,0,0,83,145,1,0,0,0,84,85,5,8,0,0,85,86,5,1,0,0,86, - 87,3,12,6,0,87,88,5,3,0,0,88,91,3,8,4,0,89,90,5,9,0,0,90,92,3,8,4,0,91, - 89,1,0,0,0,91,92,1,0,0,0,92,145,1,0,0,0,93,94,5,10,0,0,94,96,5,1,0,0,95, - 97,3,12,6,0,96,95,1,0,0,0,96,97,1,0,0,0,97,98,1,0,0,0,98,100,5,4,0,0,99, - 101,3,12,6,0,100,99,1,0,0,0,100,101,1,0,0,0,101,102,1,0,0,0,102,104,5, - 4,0,0,103,105,3,12,6,0,104,103,1,0,0,0,104,105,1,0,0,0,105,106,1,0,0,0, - 106,107,5,3,0,0,107,145,3,8,4,0,108,109,5,10,0,0,109,110,5,1,0,0,110,112, - 3,10,5,0,111,113,3,12,6,0,112,111,1,0,0,0,112,113,1,0,0,0,113,114,1,0, - 0,0,114,116,5,4,0,0,115,117,3,12,6,0,116,115,1,0,0,0,116,117,1,0,0,0,117, - 118,1,0,0,0,118,119,5,3,0,0,119,120,3,8,4,0,120,145,1,0,0,0,121,122,5, - 11,0,0,122,123,5,1,0,0,123,124,3,12,6,0,124,125,5,3,0,0,125,126,3,8,4, - 0,126,145,1,0,0,0,127,128,5,12,0,0,128,129,3,8,4,0,129,130,5,11,0,0,130, - 131,5,1,0,0,131,132,3,12,6,0,132,133,5,3,0,0,133,134,5,4,0,0,134,145,1, - 0,0,0,135,136,5,13,0,0,136,145,5,4,0,0,137,138,5,14,0,0,138,145,5,4,0, - 0,139,140,3,12,6,0,140,141,5,4,0,0,141,145,1,0,0,0,142,145,3,4,2,0,143, - 145,5,4,0,0,144,80,1,0,0,0,144,84,1,0,0,0,144,93,1,0,0,0,144,108,1,0,0, - 0,144,121,1,0,0,0,144,127,1,0,0,0,144,135,1,0,0,0,144,137,1,0,0,0,144, - 139,1,0,0,0,144,142,1,0,0,0,144,143,1,0,0,0,145,9,1,0,0,0,146,147,3,16, - 8,0,147,150,5,55,0,0,148,149,5,15,0,0,149,151,3,12,6,0,150,148,1,0,0,0, - 150,151,1,0,0,0,151,152,1,0,0,0,152,153,5,4,0,0,153,11,1,0,0,0,154,155, - 6,6,-1,0,155,156,5,1,0,0,156,157,3,12,6,0,157,158,5,3,0,0,158,237,1,0, - 0,0,159,237,3,14,7,0,160,161,3,18,9,0,161,162,5,15,0,0,162,163,3,12,6, - 41,163,237,1,0,0,0,164,165,5,16,0,0,165,237,3,12,6,40,166,167,5,17,0,0, - 167,237,3,18,9,0,168,237,5,55,0,0,169,170,5,55,0,0,170,179,5,1,0,0,171, - 176,3,12,6,0,172,173,5,2,0,0,173,175,3,12,6,0,174,172,1,0,0,0,175,178, - 1,0,0,0,176,174,1,0,0,0,176,177,1,0,0,0,177,180,1,0,0,0,178,176,1,0,0, - 0,179,171,1,0,0,0,179,180,1,0,0,0,180,181,1,0,0,0,181,237,5,3,0,0,182, - 183,5,20,0,0,183,237,3,12,6,35,184,185,5,21,0,0,185,237,3,12,6,34,186, - 187,5,22,0,0,187,237,3,18,9,0,188,189,5,23,0,0,189,237,3,18,9,0,190,191, - 3,18,9,0,191,192,5,22,0,0,192,237,1,0,0,0,193,194,3,18,9,0,194,195,5,23, - 0,0,195,237,1,0,0,0,196,197,3,18,9,0,197,198,5,40,0,0,198,199,3,12,6,11, - 199,237,1,0,0,0,200,201,3,18,9,0,201,202,5,41,0,0,202,203,3,12,6,10,203, - 237,1,0,0,0,204,205,3,18,9,0,205,206,5,42,0,0,206,207,3,12,6,9,207,237, - 1,0,0,0,208,209,3,18,9,0,209,210,5,43,0,0,210,211,3,12,6,8,211,237,1,0, - 0,0,212,213,3,18,9,0,213,214,5,44,0,0,214,215,3,12,6,7,215,237,1,0,0,0, - 216,217,3,18,9,0,217,218,5,45,0,0,218,219,3,12,6,6,219,237,1,0,0,0,220, - 221,3,18,9,0,221,222,5,46,0,0,222,223,3,12,6,5,223,237,1,0,0,0,224,225, - 3,18,9,0,225,226,5,47,0,0,226,227,3,12,6,4,227,237,1,0,0,0,228,229,3,18, - 9,0,229,230,5,48,0,0,230,231,3,12,6,3,231,237,1,0,0,0,232,233,3,18,9,0, - 233,234,5,49,0,0,234,235,3,12,6,2,235,237,1,0,0,0,236,154,1,0,0,0,236, - 159,1,0,0,0,236,160,1,0,0,0,236,164,1,0,0,0,236,166,1,0,0,0,236,168,1, - 0,0,0,236,169,1,0,0,0,236,182,1,0,0,0,236,184,1,0,0,0,236,186,1,0,0,0, - 236,188,1,0,0,0,236,190,1,0,0,0,236,193,1,0,0,0,236,196,1,0,0,0,236,200, - 1,0,0,0,236,204,1,0,0,0,236,208,1,0,0,0,236,212,1,0,0,0,236,216,1,0,0, - 0,236,220,1,0,0,0,236,224,1,0,0,0,236,228,1,0,0,0,236,232,1,0,0,0,237, - 305,1,0,0,0,238,239,10,29,0,0,239,240,5,16,0,0,240,304,3,12,6,30,241,242, - 10,28,0,0,242,243,5,24,0,0,243,304,3,12,6,29,244,245,10,27,0,0,245,246, - 5,25,0,0,246,304,3,12,6,28,247,248,10,26,0,0,248,249,5,26,0,0,249,304, - 3,12,6,27,250,251,10,25,0,0,251,252,5,27,0,0,252,304,3,12,6,26,253,254, - 10,24,0,0,254,255,5,28,0,0,255,304,3,12,6,25,256,257,10,23,0,0,257,258, - 5,29,0,0,258,304,3,12,6,24,259,260,10,22,0,0,260,261,5,30,0,0,261,304, - 3,12,6,23,262,263,10,21,0,0,263,264,5,31,0,0,264,304,3,12,6,22,265,266, - 10,20,0,0,266,267,5,32,0,0,267,304,3,12,6,21,268,269,10,19,0,0,269,270, - 5,33,0,0,270,304,3,12,6,20,271,272,10,18,0,0,272,273,5,17,0,0,273,304, - 3,12,6,19,274,275,10,17,0,0,275,276,5,34,0,0,276,304,3,12,6,18,277,278, - 10,16,0,0,278,279,5,35,0,0,279,304,3,12,6,17,280,281,10,15,0,0,281,282, - 5,36,0,0,282,304,3,12,6,16,283,284,10,14,0,0,284,285,5,37,0,0,285,304, - 3,12,6,15,286,287,10,13,0,0,287,288,5,38,0,0,288,304,3,12,6,14,289,290, - 10,12,0,0,290,291,5,39,0,0,291,304,3,12,6,13,292,293,10,1,0,0,293,294, - 5,50,0,0,294,295,3,12,6,0,295,296,5,51,0,0,296,297,3,12,6,2,297,304,1, - 0,0,0,298,299,10,36,0,0,299,300,5,18,0,0,300,301,3,12,6,0,301,302,5,19, - 0,0,302,304,1,0,0,0,303,238,1,0,0,0,303,241,1,0,0,0,303,244,1,0,0,0,303, - 247,1,0,0,0,303,250,1,0,0,0,303,253,1,0,0,0,303,256,1,0,0,0,303,259,1, - 0,0,0,303,262,1,0,0,0,303,265,1,0,0,0,303,268,1,0,0,0,303,271,1,0,0,0, - 303,274,1,0,0,0,303,277,1,0,0,0,303,280,1,0,0,0,303,283,1,0,0,0,303,286, - 1,0,0,0,303,289,1,0,0,0,303,292,1,0,0,0,303,298,1,0,0,0,304,307,1,0,0, - 0,305,303,1,0,0,0,305,306,1,0,0,0,306,13,1,0,0,0,307,305,1,0,0,0,308,311, - 5,56,0,0,309,311,5,54,0,0,310,308,1,0,0,0,310,309,1,0,0,0,311,15,1,0,0, - 0,312,313,6,8,-1,0,313,316,5,52,0,0,314,316,5,53,0,0,315,312,1,0,0,0,315, - 314,1,0,0,0,316,321,1,0,0,0,317,318,10,1,0,0,318,320,5,16,0,0,319,317, - 1,0,0,0,320,323,1,0,0,0,321,319,1,0,0,0,321,322,1,0,0,0,322,17,1,0,0,0, - 323,321,1,0,0,0,324,325,5,55,0,0,325,19,1,0,0,0,24,23,38,41,57,60,65,71, - 78,91,96,100,104,112,116,144,150,176,179,236,303,305,310,315,321 + 1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,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,324,8,6,10,6,12,6,327,9,6,1,7,1,7,1,7,1,7,3,7,333,8,7,1, + 8,1,8,1,8,3,8,338,8,8,1,8,1,8,5,8,342,8,8,10,8,12,8,345,9,8,1,9,1,9,1, + 9,1,9,1,9,1,9,1,9,1,9,5,9,355,8,9,10,9,12,9,358,9,9,1,9,0,3,12,16,18,10, + 0,2,4,6,8,10,12,14,16,18,0,0,428,0,21,1,0,0,0,2,65,1,0,0,0,4,67,1,0,0, + 0,6,78,1,0,0,0,8,144,1,0,0,0,10,146,1,0,0,0,12,261,1,0,0,0,14,332,1,0, + 0,0,16,337,1,0,0,0,18,346,1,0,0,0,20,22,3,2,1,0,21,20,1,0,0,0,22,23,1, + 0,0,0,23,21,1,0,0,0,23,24,1,0,0,0,24,25,1,0,0,0,25,26,5,0,0,1,26,1,1,0, + 0,0,27,28,3,16,8,0,28,29,5,56,0,0,29,41,5,1,0,0,30,31,3,16,8,0,31,38,5, + 56,0,0,32,33,5,2,0,0,33,34,3,16,8,0,34,35,5,56,0,0,35,37,1,0,0,0,36,32, + 1,0,0,0,37,40,1,0,0,0,38,36,1,0,0,0,38,39,1,0,0,0,39,42,1,0,0,0,40,38, + 1,0,0,0,41,30,1,0,0,0,41,42,1,0,0,0,42,43,1,0,0,0,43,44,5,3,0,0,44,45, + 5,4,0,0,45,66,1,0,0,0,46,47,3,16,8,0,47,48,5,56,0,0,48,60,5,1,0,0,49,50, + 3,16,8,0,50,57,5,56,0,0,51,52,5,2,0,0,52,53,3,16,8,0,53,54,5,56,0,0,54, + 56,1,0,0,0,55,51,1,0,0,0,56,59,1,0,0,0,57,55,1,0,0,0,57,58,1,0,0,0,58, + 61,1,0,0,0,59,57,1,0,0,0,60,49,1,0,0,0,60,61,1,0,0,0,61,62,1,0,0,0,62, + 63,5,3,0,0,63,64,3,4,2,0,64,66,1,0,0,0,65,27,1,0,0,0,65,46,1,0,0,0,66, + 3,1,0,0,0,67,71,5,5,0,0,68,70,3,6,3,0,69,68,1,0,0,0,70,73,1,0,0,0,71,69, + 1,0,0,0,71,72,1,0,0,0,72,74,1,0,0,0,73,71,1,0,0,0,74,75,5,6,0,0,75,5,1, + 0,0,0,76,79,3,8,4,0,77,79,3,10,5,0,78,76,1,0,0,0,78,77,1,0,0,0,79,7,1, + 0,0,0,80,81,5,7,0,0,81,82,3,12,6,0,82,83,5,4,0,0,83,145,1,0,0,0,84,85, + 5,8,0,0,85,86,5,1,0,0,86,87,3,12,6,0,87,88,5,3,0,0,88,91,3,8,4,0,89,90, + 5,9,0,0,90,92,3,8,4,0,91,89,1,0,0,0,91,92,1,0,0,0,92,145,1,0,0,0,93,94, + 5,10,0,0,94,96,5,1,0,0,95,97,3,12,6,0,96,95,1,0,0,0,96,97,1,0,0,0,97,98, + 1,0,0,0,98,100,5,4,0,0,99,101,3,12,6,0,100,99,1,0,0,0,100,101,1,0,0,0, + 101,102,1,0,0,0,102,104,5,4,0,0,103,105,3,12,6,0,104,103,1,0,0,0,104,105, + 1,0,0,0,105,106,1,0,0,0,106,107,5,3,0,0,107,145,3,8,4,0,108,109,5,10,0, + 0,109,110,5,1,0,0,110,112,3,10,5,0,111,113,3,12,6,0,112,111,1,0,0,0,112, + 113,1,0,0,0,113,114,1,0,0,0,114,116,5,4,0,0,115,117,3,12,6,0,116,115,1, + 0,0,0,116,117,1,0,0,0,117,118,1,0,0,0,118,119,5,3,0,0,119,120,3,8,4,0, + 120,145,1,0,0,0,121,122,5,11,0,0,122,123,5,1,0,0,123,124,3,12,6,0,124, + 125,5,3,0,0,125,126,3,8,4,0,126,145,1,0,0,0,127,128,5,12,0,0,128,129,3, + 8,4,0,129,130,5,11,0,0,130,131,5,1,0,0,131,132,3,12,6,0,132,133,5,3,0, + 0,133,134,5,4,0,0,134,145,1,0,0,0,135,136,5,13,0,0,136,145,5,4,0,0,137, + 138,5,14,0,0,138,145,5,4,0,0,139,140,3,12,6,0,140,141,5,4,0,0,141,145, + 1,0,0,0,142,145,3,4,2,0,143,145,5,4,0,0,144,80,1,0,0,0,144,84,1,0,0,0, + 144,93,1,0,0,0,144,108,1,0,0,0,144,121,1,0,0,0,144,127,1,0,0,0,144,135, + 1,0,0,0,144,137,1,0,0,0,144,139,1,0,0,0,144,142,1,0,0,0,144,143,1,0,0, + 0,145,9,1,0,0,0,146,147,3,16,8,0,147,150,5,56,0,0,148,149,5,15,0,0,149, + 151,3,12,6,0,150,148,1,0,0,0,150,151,1,0,0,0,151,152,1,0,0,0,152,153,5, + 4,0,0,153,11,1,0,0,0,154,155,6,6,-1,0,155,156,5,1,0,0,156,157,3,12,6,0, + 157,158,5,3,0,0,158,262,1,0,0,0,159,160,5,16,0,0,160,161,3,16,8,0,161, + 163,5,17,0,0,162,164,5,57,0,0,163,162,1,0,0,0,163,164,1,0,0,0,164,165, + 1,0,0,0,165,166,5,18,0,0,166,175,5,5,0,0,167,172,3,12,6,0,168,169,5,2, + 0,0,169,171,3,12,6,0,170,168,1,0,0,0,171,174,1,0,0,0,172,170,1,0,0,0,172, + 173,1,0,0,0,173,176,1,0,0,0,174,172,1,0,0,0,175,167,1,0,0,0,175,176,1, + 0,0,0,176,177,1,0,0,0,177,178,5,6,0,0,178,262,1,0,0,0,179,262,3,14,7,0, + 180,181,3,18,9,0,181,182,5,15,0,0,182,183,3,12,6,41,183,262,1,0,0,0,184, + 185,5,19,0,0,185,262,3,12,6,40,186,187,5,20,0,0,187,262,3,18,9,0,188,262, + 5,56,0,0,189,190,5,56,0,0,190,199,5,1,0,0,191,196,3,12,6,0,192,193,5,2, + 0,0,193,195,3,12,6,0,194,192,1,0,0,0,195,198,1,0,0,0,196,194,1,0,0,0,196, + 197,1,0,0,0,197,200,1,0,0,0,198,196,1,0,0,0,199,191,1,0,0,0,199,200,1, + 0,0,0,200,201,1,0,0,0,201,262,5,3,0,0,202,203,3,18,9,0,203,204,5,17,0, + 0,204,205,3,12,6,0,205,206,5,18,0,0,206,262,1,0,0,0,207,208,5,21,0,0,208, + 262,3,12,6,35,209,210,5,22,0,0,210,262,3,12,6,34,211,212,5,23,0,0,212, + 262,3,18,9,0,213,214,5,24,0,0,214,262,3,18,9,0,215,216,3,18,9,0,216,217, + 5,23,0,0,217,262,1,0,0,0,218,219,3,18,9,0,219,220,5,24,0,0,220,262,1,0, + 0,0,221,222,3,18,9,0,222,223,5,41,0,0,223,224,3,12,6,11,224,262,1,0,0, + 0,225,226,3,18,9,0,226,227,5,42,0,0,227,228,3,12,6,10,228,262,1,0,0,0, + 229,230,3,18,9,0,230,231,5,43,0,0,231,232,3,12,6,9,232,262,1,0,0,0,233, + 234,3,18,9,0,234,235,5,44,0,0,235,236,3,12,6,8,236,262,1,0,0,0,237,238, + 3,18,9,0,238,239,5,45,0,0,239,240,3,12,6,7,240,262,1,0,0,0,241,242,3,18, + 9,0,242,243,5,46,0,0,243,244,3,12,6,6,244,262,1,0,0,0,245,246,3,18,9,0, + 246,247,5,47,0,0,247,248,3,12,6,5,248,262,1,0,0,0,249,250,3,18,9,0,250, + 251,5,48,0,0,251,252,3,12,6,4,252,262,1,0,0,0,253,254,3,18,9,0,254,255, + 5,49,0,0,255,256,3,12,6,3,256,262,1,0,0,0,257,258,3,18,9,0,258,259,5,50, + 0,0,259,260,3,12,6,2,260,262,1,0,0,0,261,154,1,0,0,0,261,159,1,0,0,0,261, + 179,1,0,0,0,261,180,1,0,0,0,261,184,1,0,0,0,261,186,1,0,0,0,261,188,1, + 0,0,0,261,189,1,0,0,0,261,202,1,0,0,0,261,207,1,0,0,0,261,209,1,0,0,0, + 261,211,1,0,0,0,261,213,1,0,0,0,261,215,1,0,0,0,261,218,1,0,0,0,261,221, + 1,0,0,0,261,225,1,0,0,0,261,229,1,0,0,0,261,233,1,0,0,0,261,237,1,0,0, + 0,261,241,1,0,0,0,261,245,1,0,0,0,261,249,1,0,0,0,261,253,1,0,0,0,261, + 257,1,0,0,0,262,325,1,0,0,0,263,264,10,29,0,0,264,265,5,19,0,0,265,324, + 3,12,6,30,266,267,10,28,0,0,267,268,5,25,0,0,268,324,3,12,6,29,269,270, + 10,27,0,0,270,271,5,26,0,0,271,324,3,12,6,28,272,273,10,26,0,0,273,274, + 5,27,0,0,274,324,3,12,6,27,275,276,10,25,0,0,276,277,5,28,0,0,277,324, + 3,12,6,26,278,279,10,24,0,0,279,280,5,29,0,0,280,324,3,12,6,25,281,282, + 10,23,0,0,282,283,5,30,0,0,283,324,3,12,6,24,284,285,10,22,0,0,285,286, + 5,31,0,0,286,324,3,12,6,23,287,288,10,21,0,0,288,289,5,32,0,0,289,324, + 3,12,6,22,290,291,10,20,0,0,291,292,5,33,0,0,292,324,3,12,6,21,293,294, + 10,19,0,0,294,295,5,34,0,0,295,324,3,12,6,20,296,297,10,18,0,0,297,298, + 5,20,0,0,298,324,3,12,6,19,299,300,10,17,0,0,300,301,5,35,0,0,301,324, + 3,12,6,18,302,303,10,16,0,0,303,304,5,36,0,0,304,324,3,12,6,17,305,306, + 10,15,0,0,306,307,5,37,0,0,307,324,3,12,6,16,308,309,10,14,0,0,309,310, + 5,38,0,0,310,324,3,12,6,15,311,312,10,13,0,0,312,313,5,39,0,0,313,324, + 3,12,6,14,314,315,10,12,0,0,315,316,5,40,0,0,316,324,3,12,6,13,317,318, + 10,1,0,0,318,319,5,51,0,0,319,320,3,12,6,0,320,321,5,52,0,0,321,322,3, + 12,6,2,322,324,1,0,0,0,323,263,1,0,0,0,323,266,1,0,0,0,323,269,1,0,0,0, + 323,272,1,0,0,0,323,275,1,0,0,0,323,278,1,0,0,0,323,281,1,0,0,0,323,284, + 1,0,0,0,323,287,1,0,0,0,323,290,1,0,0,0,323,293,1,0,0,0,323,296,1,0,0, + 0,323,299,1,0,0,0,323,302,1,0,0,0,323,305,1,0,0,0,323,308,1,0,0,0,323, + 311,1,0,0,0,323,314,1,0,0,0,323,317,1,0,0,0,324,327,1,0,0,0,325,323,1, + 0,0,0,325,326,1,0,0,0,326,13,1,0,0,0,327,325,1,0,0,0,328,333,5,57,0,0, + 329,333,5,55,0,0,330,333,5,61,0,0,331,333,5,62,0,0,332,328,1,0,0,0,332, + 329,1,0,0,0,332,330,1,0,0,0,332,331,1,0,0,0,333,15,1,0,0,0,334,335,6,8, + -1,0,335,338,5,53,0,0,336,338,5,54,0,0,337,334,1,0,0,0,337,336,1,0,0,0, + 338,343,1,0,0,0,339,340,10,1,0,0,340,342,5,19,0,0,341,339,1,0,0,0,342, + 345,1,0,0,0,343,341,1,0,0,0,343,344,1,0,0,0,344,17,1,0,0,0,345,343,1,0, + 0,0,346,347,6,9,-1,0,347,348,5,56,0,0,348,356,1,0,0,0,349,350,10,1,0,0, + 350,351,5,17,0,0,351,352,3,12,6,0,352,353,5,18,0,0,353,355,1,0,0,0,354, + 349,1,0,0,0,355,358,1,0,0,0,356,354,1,0,0,0,356,357,1,0,0,0,357,19,1,0, + 0,0,358,356,1,0,0,0,28,23,38,41,57,60,65,71,78,91,96,100,104,112,116,144, + 150,163,172,175,196,199,261,323,325,332,337,343,356 }; public static readonly ATN _ATN = diff --git a/Compiler/gen/CGrammarVisitor.cs b/Compiler/gen/CGrammarVisitor.cs index 9722229..be6f92e 100644 --- a/Compiler/gen/CGrammarVisitor.cs +++ b/Compiler/gen/CGrammarVisitor.cs @@ -309,6 +309,13 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> { /// <return>The visitor result.</return> Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context); /// <summary> + /// Visit a parse tree produced by the <c>arrayExpression</c> + /// labeled alternative in <see cref="CGrammarParser.expression"/>. + /// </summary> + /// <param name="context">The parse tree.</param> + /// <return>The visitor result.</return> + Result VisitArrayExpression([NotNull] CGrammarParser.ArrayExpressionContext context); + /// <summary> /// Visit a parse tree produced by the <c>constantExpression</c> /// labeled alternative in <see cref="CGrammarParser.expression"/>. /// </summary> @@ -463,12 +470,33 @@ public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> { /// <return>The visitor result.</return> Result VisitHexConstant([NotNull] CGrammarParser.HexConstantContext context); /// <summary> + /// Visit a parse tree produced by the <c>charConstant</c> + /// labeled alternative in <see cref="CGrammarParser.constant"/>. + /// </summary> + /// <param name="context">The parse tree.</param> + /// <return>The visitor result.</return> + Result VisitCharConstant([NotNull] CGrammarParser.CharConstantContext context); + /// <summary> + /// Visit a parse tree produced by the <c>stringConstant</c> + /// labeled alternative in <see cref="CGrammarParser.constant"/>. + /// </summary> + /// <param name="context">The parse tree.</param> + /// <return>The visitor result.</return> + Result VisitStringConstant([NotNull] CGrammarParser.StringConstantContext context); + /// <summary> /// Visit a parse tree produced by <see cref="CGrammarParser.type"/>. /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> Result VisitType([NotNull] CGrammarParser.TypeContext context); /// <summary> + /// Visit a parse tree produced by the <c>indexerTarget</c> + /// labeled alternative in <see cref="CGrammarParser.target"/>. + /// </summary> + /// <param name="context">The parse tree.</param> + /// <return>The visitor result.</return> + Result VisitIndexerTarget([NotNull] CGrammarParser.IndexerTargetContext context); + /// <summary> /// Visit a parse tree produced by the <c>variableTarget</c> /// labeled alternative in <see cref="CGrammarParser.target"/>. /// </summary> diff --git a/Compiler/visitors/Constants.cs b/Compiler/visitors/Constants.cs new file mode 100644 index 0000000..598c642 --- /dev/null +++ b/Compiler/visitors/Constants.cs @@ -0,0 +1,50 @@ +namespace Q1.Compiler.visitors; + +using System.Text; + +public partial class CCompilerVisitor +{ + public Encoding Encoding; + public override string VisitIntConstant(CGrammarParser.IntConstantContext context) + { + string valueString = context.INT().GetText(); + if (int.TryParse(valueString, out int value)) + return $"{value}"; + else + throw new CompilerException($"Invalid integer value: {valueString}"); + } + public override string VisitHexConstant(CGrammarParser.HexConstantContext context) + { + string valueString = context.HEX().GetText(); + valueString = valueString[2..]; // Remove 0x + return $"${valueString}"; + } + + public override object? VisitCharConstant(CGrammarParser.CharConstantContext context) + { + char c = context.LETTER().GetText()[1]; + return $"{this.Encoding.GetBytes(c.ToString())[0]}"; + } + + public override object? VisitStringConstant(CGrammarParser.StringConstantContext context) + { + string text = context.STRING().GetText()[1..^1]; + + int? arrPtr = null; + + if (text.Length == 0) + throw new CompilerException("Cannot create empty string"); + + foreach (char c in text) + { + int itemPtr = Alloc(CType.Int.Size); + + if (arrPtr == null) + arrPtr = itemPtr; + + this.DynamicMove(CType.Int, $"{this.Encoding.GetBytes(c.ToString())[0]}", $"[${itemPtr:X4}]"); + } + + return $"${arrPtr:X4}"; + } +}
\ No newline at end of file diff --git a/Compiler/visitors/Definitions.cs b/Compiler/visitors/Definitions.cs new file mode 100644 index 0000000..e4cf797 --- /dev/null +++ b/Compiler/visitors/Definitions.cs @@ -0,0 +1,123 @@ +namespace Q1.Compiler.visitors; + +public partial class CCompilerVisitor +{ + private List<(CGrammarParser.FunctionDefinitionContext context, + FunctionReference function, FunctionOverload overload, + List<string> paramNames, List<CType> paramTypes)> _functionBodies = new(); + + private VariableReference FindVariable(string varName) + { + foreach (Dictionary<string, VariableReference> variables in this._variableStack) + { + if (variables.TryGetValue(varName, out VariableReference? reference)) + return reference; + } + + throw new CompilerException($"Variable {varName} could not be found in current scope."); + } + private int Alloc(int size) + { + int loc = CCompilerVisitor._memPointer; + CCompilerVisitor._memPointer += size; + + return loc; + } + private FunctionReference CreateOrGetFunctionReference(string name, CType 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; + CType type = this.VisitCType(context._type); + + List<CType> parameterTypes = context._types.Select(this.VisitCType).ToList(); + List<string> parameterNames = context._params.Select(x => x.Text).ToList(); + + 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; + CType type = this.VisitCType(context.rtype); + + List<CType> paramTypes = context._types.Select(this.VisitCType).ToList(); + List<string> paramNames = context._params.Select(x => x.Text).ToList(); + + FunctionReference function = this.CreateOrGetFunctionReference(functionName, type); + FunctionOverload overload = function.CreateOverloadWithBody(paramNames, paramTypes); + + this._functionBodies.Add((context, function, overload, paramNames, paramTypes)); + + return null; + } + private void VisitFunctionBody(CGrammarParser.FunctionDefinitionContext context, FunctionReference function, FunctionOverload overload, List<string> paramNames, List<CType> 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, CType paramType) in paramNames.Zip(paramTypes)) + { + int addr = this.Alloc(paramType.Size); + scope[paramName] = new(addr, paramType); + 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(); + } + public override string? VisitVariableDeclaration(CGrammarParser.VariableDeclarationContext context) + { + CType type = this.VisitCType(context.type()); + int addr = this.Alloc(CType.Int.Size); + string name = context.name.Text; + + Dictionary<string, VariableReference> scope = this._variableStack.Peek(); + if (scope.ContainsKey(name)) + throw new CompilerException($"Variable {name} already exists in current scope."); + + scope[name] = new VariableReference(addr, type); + string initialValue = "0"; + + if (context.value != null) + { + initialValue = this.VisitExpression(context.value); + } + + this.DynamicMove(CType.Int, initialValue, $"[${addr:X4}]", $"int {name} = {initialValue}"); + + return null; + } +}
\ No newline at end of file diff --git a/Compiler/visitors/Expressions.cs b/Compiler/visitors/Expressions.cs new file mode 100644 index 0000000..e67688d --- /dev/null +++ b/Compiler/visitors/Expressions.cs @@ -0,0 +1,134 @@ +namespace Q1.Compiler.visitors; + +public partial class CCompilerVisitor +{ + private string VisitExpression(CGrammarParser.ExpressionContext expression) + { + string? expressionString = this.Visit(expression) as string; + if (expressionString == null) + throw new CompilerException("Expression did not return a string"); + + return expressionString; + } + + 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.VisitExpression(argument); + + 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 VisitParenthesizedExpression(CGrammarParser.ParenthesizedExpressionContext context) + { + return this.VisitExpression(context.expression()); + } + public override string VisitVariableExpression(CGrammarParser.VariableExpressionContext context) + { + string varName = context.ID().GetText(); + VariableReference reference = this.FindVariable(varName); + + return $"[${reference.Address:X4}]"; + } + public override string VisitAssignmentExpression(CGrammarParser.AssignmentExpressionContext context) + { + Target target = this.VisitTarget(context.target()); + string value = this.VisitExpression(context.expression()); + + this.DynamicMove(target.Type, value, target.Value, $"{target.Value} = {value}"); + return target.Value; + } + public override string VisitTernaryExpression(CGrammarParser.TernaryExpressionContext context) + { + string cond = this.VisitExpression(context.cond); + + string thenBranch = this.GenerateBranchLabel("then"); + string endBranch = this.GenerateBranchLabel("end"); + string result; + + // 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 + + this.Instruction($"bz {cond}", "check ternary condition"); + this.Instruction($"jmp {thenBranch}"); + + result = this.VisitExpression(context.@else); + this.Instruction($"mov {result}, V0", "store ternary fail result"); + this.Instruction($"jmp {endBranch}"); + + this.Branch(thenBranch); + result = this.VisitExpression(context.then); + this.Instruction($"mov {result}, V0", "store ternary success result"); + + this.Branch(endBranch); + + return "V0"; + } + public override string VisitAddressOfExpression(CGrammarParser.AddressOfExpressionContext context) + { + Target target = this.VisitTarget(context.target()); + + return target.Address; + } + public override string VisitDereferenceExpression(CGrammarParser.DereferenceExpressionContext context) + { + string value = this.VisitExpression(context.expression()); + + this.Instruction($"mov {value}, V0", "move pointer into register for dereference"); + return "[V0]"; + } + + public override object? VisitIndexExpression(CGrammarParser.IndexExpressionContext context) + { + Target obj = this.VisitTarget(context.obj); + if (obj.Type is not CTypePtr ptr) + throw new CompilerException("Indexer target was not a pointer!"); + + this.Instruction($"push {obj.Value}", "store index obj"); + + string indexer = this.VisitExpression(context.indexer); + + this.Instruction($"mov {indexer}, V1", "store indexer"); + this.Instruction($"pop V0", "restore index obj"); + this.Instruction($"mul V1, {ptr.Sub.Size}", $"multiply indexer by {ptr.Sub.Size}"); + this.Instruction($"add AX, V0", "add indexer and index obj"); + this.Instruction($"mov AX, V0", "move to general purpose register"); + return "[V0]"; + } + + public override object? VisitArrayExpression(CGrammarParser.ArrayExpressionContext context) + { + CType type = this.VisitCType(context.type()); + int? arrPtr = null; + + if (context._params.Count == 0) + throw new CompilerException("Cannot create empty array"); + + foreach (CGrammarParser.ExpressionContext? param in context._params) + { + int itemPtr = Alloc(type.Size); + + if (arrPtr == null) + arrPtr = itemPtr; + + string value = this.VisitExpression(param); + this.DynamicMove(type, value, $"[${itemPtr:X4}]"); + } + + return $"${arrPtr:X4}"; + } +}
\ No newline at end of file diff --git a/Compiler/visitors/FlowControl.cs b/Compiler/visitors/FlowControl.cs new file mode 100644 index 0000000..944595d --- /dev/null +++ b/Compiler/visitors/FlowControl.cs @@ -0,0 +1,177 @@ +namespace Q1.Compiler.visitors; + +public partial class CCompilerVisitor +{ + public override string? VisitBlock(CGrammarParser.BlockContext context) + { + this.EnterScope(); + + this.VisitChildren(context); + + this.ExitScope(); + + return null; + } + public override string? VisitReturnStatement(CGrammarParser.ReturnStatementContext context) + { + if (context.expression() != null) + { + string expression = this.VisitExpression(context.expression()); + this.Instruction($"mov {expression}, V0", "return value"); + this.Instruction($"ret"); + } + else + this.Instruction("ret"); + + return null; + } + public override string? VisitIfStatement(CGrammarParser.IfStatementContext context) + { + string cond = this.VisitExpression(context.expression()); + string endBranch = this.GenerateBranchLabel("end"); + + if (context.@else != null) + { + this.Instruction($"bz {cond}", "check if condition"); + // 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.Branch(thenBranch, "if succeeded"); + this.Visit(context.then); + } + else + { + this.Instruction($"not {cond}"); + this.Instruction($"bz", "check if condition"); + this.Instruction($"jmp {endBranch}", "if succeeds, continue, else jump to end"); + this.Visit(context.then); + } + + 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.VisitExpression(context.cond); + + 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.VisitExpression(context.cond); + + 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.Instruction($"jmp {bodyBranch}"); + + 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.VisitExpression(context.cond); + + this.Instruction($"not {cond}"); + this.Instruction($"bz"); + this.Instruction($"jmp {endBranch}", "if while condition fails, jump to end"); + + this.Visit(context.body); + this.Instruction($"jmp {bodyBranch}"); + + 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.VisitExpression(context.cond); + + 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; + } +}
\ No newline at end of file diff --git a/Compiler/visitors/Main.cs b/Compiler/visitors/Main.cs new file mode 100644 index 0000000..cbd468f --- /dev/null +++ b/Compiler/visitors/Main.cs @@ -0,0 +1,183 @@ +namespace Q1.Compiler.visitors; + +using System.Text; +using Antlr4.Runtime.Tree; +using Q1.Emulator; + +public partial class CCompilerVisitor : CGrammarBaseVisitor<object?> +{ + 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, Encoding encoding) + { + this.CommentMode = commentMode; + this.Encoding = encoding; + } + + private string GenerateBranchLabel(string type) + { + return $"_{type}_{this._branchCount++}"; + } + private void Instruction(string instruction, string? generatedComment = null) + { + this._instructions.Add($" {instruction}"); + if (generatedComment != null) + this.CommentLastInstruction(generatedComment); + } + private void Blank() + { + this._instructions.Add(""); + } + private void Branch(string name, string? generatedComment = null) + { + this._instructions.Add($"{name}:"); + if (generatedComment != null) + this.CommentLastInstruction(generatedComment); + } + private void UserComment(string comment) + { + if (this.CommentMode.HasFlag(CommentCompilationMode.UserDefined)) + this._instructions.Add($" ; {comment}"); + } + + private void GeneratedComment(string comment) + { + if (this.CommentMode.HasFlag(CommentCompilationMode.Generated)) + this._instructions.Add($"{"".PadRight(CCompilerVisitor.ColumnWidth)}; {comment}"); + } + + private void CommentLastInstruction(string comment) + { + if (!this.CommentMode.HasFlag(CommentCompilationMode.Generated)) + return; + + if (this._instructions.Count == 0) + throw new Exception("Cannot add comment to last instruction, there are none"); + + string lastInstruction = this._instructions[^1]; + lastInstruction = $"{lastInstruction.PadRight(CCompilerVisitor.ColumnWidth)}; {comment}"; + + this._instructions[^1] = lastInstruction; + } + + + public IEnumerable<string> Compile(CGrammarParser.ProgramContext program) + { + this.Instruction("jmp _main"); + this.Visit(program); + + foreach ((CGrammarParser.FunctionDefinitionContext context, + FunctionReference function, FunctionOverload overload, + List<string> paramNames, List<CType> paramTypes) in this._functionBodies) + this.VisitFunctionBody(context, function, overload, paramNames, paramTypes); + + return this._instructions; + } + + 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.Type.Size; + // if (CCompilerVisitor._memPointer < CCompilerVisitor._memLowest) + // throw new CompilerException("Memory pointer is lower than mem lowest!"); + } + + // Delete scope + this._variableStack.Pop(); + } + + public void DynamicMove(CType type, string source, string dest, string? comment = null) + { + if (type.Size == 1) + this.Instruction($"movb {source}, {dest}", comment); + else if (type.Size == 2) + this.Instruction($"mov {source}, {dest}", comment); + else + throw new CompilerException($"Cannot move {type.Size} bytes {source} to {dest}"); + } + + private CType VisitCType(CGrammarParser.TypeContext typeContext) + { + return GetCType(typeContext.GetText().Trim()); + } + + private CType GetCType(string type) + { + return type switch + { + "int" => CType.Int, + "char" => CType.Char, + _ when type.EndsWith("*") => new CTypePtr(this.GetCType(type[..^1])), + _ => throw new CompilerException($"Unknown CTYPE '{type}'") + }; + } + + public override object? VisitErrorNode(IErrorNode node) + { + if (node.Symbol.Type == CGrammarParser.COMMENT) + { + // strip // and \n and whitespace + string comment = node + .Symbol.Text + .TrimStart("//") + .TrimEnd('\n') + .Trim(); + + this.UserComment(comment); + } + + if (node.Symbol.Type == CGrammarParser.DIRECTIVE) + { + // strip // and \n and whitespace + string directive = node + .Symbol.Text + .TrimStart("#") + .TrimEnd('\n') + .Trim(); + + this.Instruction("." + directive); + } + + return base.VisitErrorNode(node); + } + + public override object? Visit(IParseTree tree) + { + if (tree is Context childCtx && tree.Parent is Context ctx) + ctx.SyncProps(childCtx); + + return base.Visit(tree); + } + + /// <summary> + /// Basically identical to base version, except calls Visit on each child, making Visit not redundant. + /// </summary> + public override object? VisitChildren(IRuleNode node) + { + object? result = this.DefaultResult; + int childCount = node.ChildCount; + for (int i = 0; i < childCount && this.ShouldVisitNextChild(node, result); ++i) + { + object? nextResult = this.Visit(node.GetChild(i)); + result = this.AggregateResult(result, nextResult); + } + return result; + } +}
\ No newline at end of file diff --git a/Compiler/visitors/Operations.cs b/Compiler/visitors/Operations.cs new file mode 100644 index 0000000..8483747 --- /dev/null +++ b/Compiler/visitors/Operations.cs @@ -0,0 +1,305 @@ +namespace Q1.Compiler.visitors; + +public partial class CCompilerVisitor +{ + private void BaseBinaryOperation(CGrammarParser.ExpressionContext leftExpr, CGrammarParser.ExpressionContext rightExpr, string operation, string operationFriendlyName) + { + string left = this.VisitExpression(leftExpr); + + this.Instruction($"push {left}", "left operand"); + + string right = this.VisitExpression(rightExpr); + + 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) + { + Target left = this.VisitTarget(leftTarget); + + this.Instruction($"push {left.Value}", "left operand"); + + string? right = this.VisitExpression(rightExpr); + 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($"{operation} V0, V1", $"compute {operationFriendlyName}"); + + this.Instruction($"push {operationOutput}", "computation results"); + + left = this.VisitTarget(leftTarget); + this.Instruction("pop V1", "get computation results back"); + this.DynamicMove(left.Type, "V1", left.Value, "store back into left param"); + + return left.Value; + } + + public override string VisitNotExpression(CGrammarParser.NotExpressionContext context) + { + string value = this.VisitExpression(context.expression()); + + this.Instruction($"not {value}"); + return "LX"; + } + public override string VisitInvertExpression(CGrammarParser.InvertExpressionContext context) + { + string value = this.VisitExpression(context.expression()); + + this.Instruction($"inv {value}"); + return "DX"; + } + public override string VisitAddExpression(CGrammarParser.AddExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "add", "addition"); + return "AX"; + } + public override string VisitSubtractExpression(CGrammarParser.SubtractExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "sub", "subtraction"); + return "AX"; + } + public override string VisitMultiplyExpression(CGrammarParser.MultiplyExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "mul", "multiplication"); + return "AX"; + } + public override string VisitDivideExpression(CGrammarParser.DivideExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "div", "division"); + return "AX"; + } + public override string VisitModulusExpression(CGrammarParser.ModulusExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "mod", "modulus"); + return "AX"; + } + public override string VisitEqualExpression(CGrammarParser.EqualExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); + return "LX"; + } + public override string VisitNotEqualExpression(CGrammarParser.NotEqualExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "cmp", "inequality check"); + this.Instruction($"not"); // lx is implicit + return "LX"; + } + public override string VisitGreaterThanExpression(CGrammarParser.GreaterThanExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "gt", "greater than check"); + return "LX"; + } + public override string VisitLessThanExpression(CGrammarParser.LessThanExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "lt", "less than check"); + return "LX"; + } + public override string VisitLogicalOrExpression(CGrammarParser.LogicalOrExpressionContext context) + { + string left = this.VisitExpression(context.left); + + string clauseBranch = this.GenerateBranchLabel("clause"); + string endBranch = this.GenerateBranchLabel("end"); + + this.Instruction($"cmp {left}, 0", "logical or"); + this.Instruction("bz"); // implicit LX + 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.Branch(clauseBranch); + + string right = this.VisitExpression(context.right); + + 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.Branch(endBranch); + + return "V0"; + } + public override string VisitLogicalAndExpression(CGrammarParser.LogicalAndExpressionContext context) + { + string left = this.VisitExpression(context.left); + + string clauseBranch = this.GenerateBranchLabel("clause"); + string endBranch = this.GenerateBranchLabel("end"); + + this.Instruction($"cmp {left}, 0", "logical and"); + this.Instruction("not"); + this.Instruction("bz"); // implicit LX + 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.Branch(clauseBranch); + + string right = this.VisitExpression(context.right); + + 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.Branch(endBranch); + + return "V0"; + } + public override string VisitGreaterThanOrEqualExpression(CGrammarParser.GreaterThanOrEqualExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); + string endBranch = this.GenerateBranchLabel("end"); + + this.Instruction("bz"); + this.Instruction($"jmp {endBranch}"); + this.Instruction($"gt V0, V1"); + this.Branch(endBranch); + + return "LX"; + } + public override string VisitLessThanOrEqualExpression(CGrammarParser.LessThanOrEqualExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "cmp", "equality check"); + string endBranch = this.GenerateBranchLabel("end"); + + this.Instruction("bz"); + this.Instruction($"jmp {endBranch}"); + this.Instruction($"lt V0, V1"); + this.Branch(endBranch); + + return "LX"; + } + public override string VisitBitwiseXorExpression(CGrammarParser.BitwiseXorExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "xor", "exclusive or"); + return "DX"; + } + public override string VisitBitwiseOrExpression(CGrammarParser.BitwiseOrExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "or", "or"); + return "DX"; + } + public override string VisitBitwiseAndExpression(CGrammarParser.BitwiseAndExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "and", "and"); + return "DX"; + } + public override string VisitBitwiseLeftShiftExpression(CGrammarParser.BitwiseLeftShiftExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "shl", "left shift"); + return "DX"; + } + public override string VisitBitwiseRightShiftExpression(CGrammarParser.BitwiseRightShiftExpressionContext context) + { + this.BaseBinaryOperation(context.left, context.right, "shr", "right shift"); + return "DX"; + } + public override string VisitCompoundAddExpression(CGrammarParser.CompoundAddExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "add", + "addition", + "AX"); + } + public override string VisitCompoundSubtractExpression(CGrammarParser.CompoundSubtractExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "sub", + "subtraction", + "AX"); + } + public override string VisitCompoundMultiplyExpression(CGrammarParser.CompoundMultiplyExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "mul", + "multiplication", + "AX"); + } + public override string VisitCompoundDivideExpression(CGrammarParser.CompoundDivideExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "div", + "division", + "AX"); + } + public override string VisitCompoundModulusExpression(CGrammarParser.CompoundModulusExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "mod", + "modulus", + "AX"); + } + public override string VisitCompoundBitwiseOrExpression(CGrammarParser.CompoundBitwiseOrExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "or", + "or", + "DX"); + } + public override string VisitCompoundBitwiseXorExpression(CGrammarParser.CompoundBitwiseXorExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "xor", + "exclusive or", + "DX"); + } + public override string VisitCompoundBitwiseAndExpression(CGrammarParser.CompoundBitwiseAndExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "and", + "and", + "DX"); + } + public override string VisitCompoundBitwiseLeftShiftExpression(CGrammarParser.CompoundBitwiseLeftShiftExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "shl", + "left shift", + "DX"); + } + public override string VisitCompoundBitwiseRightShiftExpression(CGrammarParser.CompoundBitwiseRightShiftExpressionContext context) + { + return this.BaseBinaryCompoundOperation(context.target(), + context.expression(), + "shr", + "right shift", + "DX"); + } + public override string VisitIncrementPrefixExpression(CGrammarParser.IncrementPrefixExpressionContext context) + { + Target target = this.VisitTarget(context.target()); + this.Instruction($"inc {target.Value}", "++i"); + return target.Value; + } + public override string VisitDecrementPrefixExpression(CGrammarParser.DecrementPrefixExpressionContext context) + { + Target target = this.VisitTarget(context.target()); + this.Instruction($"dec {target.Value}", "--i"); + return target.Value; + } + public override string VisitIncrementPostfixExpression(CGrammarParser.IncrementPostfixExpressionContext context) + { + Target target = this.VisitTarget(context.target()); + this.Instruction($"push {target.Value}", "i++"); + this.Instruction($"inc {target.Value}"); + this.Instruction("pop V0"); + return "V0"; + } + public override string VisitDecrementPostfixExpression(CGrammarParser.DecrementPostfixExpressionContext context) + { + Target target = this.VisitTarget(context.target()); + this.Instruction($"push {target.Value}", "i--"); + this.Instruction($"dec {target.Value}"); + this.Instruction($"pop V0"); + return "V0"; + } +}
\ No newline at end of file diff --git a/Compiler/visitors/Targets.cs b/Compiler/visitors/Targets.cs new file mode 100644 index 0000000..10d97f4 --- /dev/null +++ b/Compiler/visitors/Targets.cs @@ -0,0 +1,40 @@ +namespace Q1.Compiler.visitors; + +public partial class CCompilerVisitor +{ + private Target VisitTarget(CGrammarParser.TargetContext target) + { + Target? expressionString = this.Visit(target) as Target; + if (expressionString == null) + throw new CompilerException("Target did not return a target"); + + return expressionString; + } + + public override Target VisitVariableTarget(CGrammarParser.VariableTargetContext context) + { + string varName = context.ID().GetText(); + VariableReference reference = this.FindVariable(varName); + + return new Target(reference.Type, $"[${reference.Address:X4}]", $"${reference.Address:X4}"); + } + + public override object? VisitIndexerTarget(CGrammarParser.IndexerTargetContext context) + { + Target obj = this.VisitTarget(context.obj); + if (obj.Type is not CTypePtr ptr) + throw new CompilerException("Indexer target was not a pointer!"); + + this.Instruction($"push {obj.Value}", "store index obj"); + + string indexer = this.VisitExpression(context.indexer); + + this.Instruction($"mov {indexer}, V1", "store indexer"); + this.Instruction($"pop V0", "restore index obj"); + this.Instruction($"mul V1, {ptr.Sub.Size}", $"multiply indexer by {ptr.Sub.Size}"); + this.Instruction($"add AX, V0", "add indexer and index obj"); + this.Instruction($"mov AX, V0", "move to general purpose register"); + + return new Target(ptr.Sub, $"[V0]", $"V0"); + } +}
\ No newline at end of file |
