summaryrefslogtreecommitdiff
path: root/Compiler
diff options
context:
space:
mode:
Diffstat (limited to 'Compiler')
-rw-r--r--Compiler/CCompilerVisitor.cs172
-rw-r--r--Compiler/CGrammar.g450
-rw-r--r--Compiler/Compiler.csproj20
-rw-r--r--Compiler/CompilerException.cs4
-rw-r--r--Compiler/Options.cs12
-rw-r--r--Compiler/Program.cs31
-rw-r--r--Compiler/gen/CGrammar.interp70
-rw-r--r--Compiler/gen/CGrammar.tokens52
-rw-r--r--Compiler/gen/CGrammarBaseVisitor.cs299
-rw-r--r--Compiler/gen/CGrammarLexer.cs149
-rw-r--r--Compiler/gen/CGrammarLexer.interp98
-rw-r--r--Compiler/gen/CGrammarLexer.tokens52
-rw-r--r--Compiler/gen/CGrammarParser.cs1006
-rw-r--r--Compiler/gen/CGrammarVisitor.cs200
14 files changed, 2215 insertions, 0 deletions
diff --git a/Compiler/CCompilerVisitor.cs b/Compiler/CCompilerVisitor.cs
new file mode 100644
index 0000000..cee69f4
--- /dev/null
+++ b/Compiler/CCompilerVisitor.cs
@@ -0,0 +1,172 @@
+namespace Q1.Compiler;
+
+public class CCompilerVisitor : CGrammarBaseVisitor<string?>
+{
+ private List<string> Instructions = new();
+ public IEnumerable<string> Compile(CGrammarParser.ProgramContext program)
+ {
+ this.Visit(program);
+ return this.Instructions;
+ }
+
+ public override string? VisitFunction(CGrammarParser.FunctionContext context)
+ {
+ string functionName = context.ID().GetText();
+ Instructions.Add($"_{functionName}:");
+ this.VisitChildren(context);
+ this.Instructions.Add("");
+
+ return null;
+ }
+ 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.Instructions.Add($"MOV {expression}, V0");
+ Instructions.Add($"RET");
+ }
+ else
+ throw new CompilerException("Return value was not an expression.");
+ }
+ else
+ Instructions.Add("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? VisitNotExpression(CGrammarParser.NotExpressionContext context)
+ {
+ string? value = this.Visit(context.expression());
+ if (value == null)
+ throw new CompilerException("Value for negating was not an expression.");
+
+ this.Instructions.Add($"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.Instructions.Add($"INV {value}");
+ return "DX";
+ }
+
+ public override string? VisitAddExpression(CGrammarParser.AddExpressionContext context)
+ {
+ string? left = this.Visit(context.left);
+ string? right = this.Visit(context.right);
+
+ if (left == null || right == null)
+ throw new CompilerException("Left or right operand for addition was not an expression.");
+
+ this.Instructions.Add($"ADD {left}, {right}");
+ return "AX";
+ }
+ public override string? VisitSubtractExpression(CGrammarParser.SubtractExpressionContext context)
+ {
+ string? left = this.Visit(context.left);
+ string? right = this.Visit(context.right);
+
+ if (left == null || right == null)
+ throw new CompilerException("Left or right operand for subtraction was not an expression.");
+
+ this.Instructions.Add($"SUB {left}, {right}");
+ return "AX";
+ }
+ public override string? VisitMultiplyExpression(CGrammarParser.MultiplyExpressionContext context)
+ {
+ string? left = this.Visit(context.left);
+ string? right = this.Visit(context.right);
+
+ if (left == null || right == null)
+ throw new CompilerException("Left or right operand for multiplication was not an expression.");
+
+ this.Instructions.Add($"MUL {left}, {right}");
+ return "AX";
+ }
+ public override string? VisitDivideExpression(CGrammarParser.DivideExpressionContext context)
+ {
+ string? left = this.Visit(context.left);
+ string? right = this.Visit(context.right);
+
+ if (left == null || right == null)
+ throw new CompilerException("Left or right operand for division was not an expression.");
+
+ this.Instructions.Add($"DIV {left}, {right}");
+ return "AX";
+ }
+ public override string? VisitModulusExpression(CGrammarParser.ModulusExpressionContext context)
+ {
+ string? left = this.Visit(context.left);
+ string? right = this.Visit(context.right);
+
+ if (left == null || right == null)
+ throw new CompilerException("Left or right operand for modulus was not an expression.");
+
+ this.Instructions.Add($"MOD {left}, {right}");
+ return "AX";
+ }
+
+ public override string? VisitBitwiseXorExpression(CGrammarParser.BitwiseXorExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitLessThanOrEqualExpression(CGrammarParser.LessThanOrEqualExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitNotEqualExpression(CGrammarParser.NotEqualExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitGreaterThanExpression(CGrammarParser.GreaterThanExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitLogicalOrExpression(CGrammarParser.LogicalOrExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitGreaterThanOrEqualExpression(CGrammarParser.GreaterThanOrEqualExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitBitwiseOrExpression(CGrammarParser.BitwiseOrExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitBitwiseAndExpression(CGrammarParser.BitwiseAndExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitLessThanExpression(CGrammarParser.LessThanExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitLogicalAndExpression(CGrammarParser.LogicalAndExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+ public override string? VisitEqualExpression(CGrammarParser.EqualExpressionContext context)
+ {
+ throw new NotImplementedException();
+ }
+} \ No newline at end of file
diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4
new file mode 100644
index 0000000..69b2c0a
--- /dev/null
+++ b/Compiler/CGrammar.g4
@@ -0,0 +1,50 @@
+grammar CGrammar;
+
+ID: [a-zA-Z_][a-zA-Z0-9_]*;
+INT: [0-9]+;
+
+program
+ : function EOF
+ ;
+
+function
+ : 'int' ID '(' ')' '{' statement* '}'
+ ;
+
+statement
+ : 'return' expression ';' #returnStatement
+ ;
+
+expression
+ : '(' expression ')' #parenthesizedExpression
+
+ | '!' expression #notExpression
+ | '~' expression #invertExpression
+
+ | left=expression '*' right=expression #multiplyExpression
+ | left=expression '/' right=expression #divideExpression
+ | left=expression '%' right=expression #modulusExpression
+
+ | left=expression '+' right=expression #addExpression
+ | left=expression '-' right=expression #subtractExpression
+
+ | left=expression '<' right=expression #lessThanExpression
+ | left=expression '>' right=expression #greaterThanExpression
+ | left=expression '<=' right=expression #lessThanOrEqualExpression
+ | left=expression '>=' right=expression #greaterThanOrEqualExpression
+ | left=expression '==' right=expression #equalExpression
+ | left=expression '!=' right=expression #notEqualExpression
+
+ | left=expression '&' right=expression #bitwiseAndExpression
+ | left=expression '|' right=expression #bitwiseOrExpression
+ | left=expression '^' right=expression #bitwiseXorExpression
+
+ | left=expression '&&' right=expression #logicalAndExpression
+ | left=expression '||' right=expression #logicalOrExpression
+
+ | constant #constantExpression
+ ;
+
+constant
+ : INT # intConstant
+ ; \ No newline at end of file
diff --git a/Compiler/Compiler.csproj b/Compiler/Compiler.csproj
new file mode 100644
index 0000000..042331e
--- /dev/null
+++ b/Compiler/Compiler.csproj
@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net9.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ <RootNamespace>Q1.Compiler</RootNamespace>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Antlr4.Runtime.Standard" Version="4.13.1" />
+ <PackageReference Include="CommandLineParser" Version="2.9.1" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <Folder Include="gen\" />
+ </ItemGroup>
+
+</Project>
diff --git a/Compiler/CompilerException.cs b/Compiler/CompilerException.cs
new file mode 100644
index 0000000..f5a78f1
--- /dev/null
+++ b/Compiler/CompilerException.cs
@@ -0,0 +1,4 @@
+namespace Q1.Compiler;
+
+public class CompilerException(string message)
+ : Exception(message); \ No newline at end of file
diff --git a/Compiler/Options.cs b/Compiler/Options.cs
new file mode 100644
index 0000000..c12a4c6
--- /dev/null
+++ b/Compiler/Options.cs
@@ -0,0 +1,12 @@
+namespace Q1.Compiler;
+
+using CommandLine;
+
+public class Options
+{
+ [Option('i', "input", Required = true, HelpText = "Input file to compile.")]
+ public string InputFile { get; set; }
+
+ [Option('o', "output", Required = true, HelpText = "Output file to write the compiled code.")]
+ public string OutputFile { get; set; }
+} \ No newline at end of file
diff --git a/Compiler/Program.cs b/Compiler/Program.cs
new file mode 100644
index 0000000..b832a53
--- /dev/null
+++ b/Compiler/Program.cs
@@ -0,0 +1,31 @@
+namespace Q1.Compiler;
+
+using Antlr4.Runtime;
+using CommandLine;
+using Parser = CommandLine.Parser;
+
+class Program
+{
+ static void Main(string[] args)
+ {
+ Parser.Default.ParseArguments<Options>(args).WithParsed(Program.Main);
+ }
+
+ static void Main(Options options)
+ {
+ Environment.CurrentDirectory = Path.GetDirectoryName(options.InputFile) ?? Environment.CurrentDirectory;
+ options.InputFile = Path.GetFileName(options.InputFile);
+
+ AntlrFileStream inputStream = new(options.InputFile);
+ CGrammarLexer lexer = new(inputStream);
+ lexer.RemoveErrorListeners();
+
+ CommonTokenStream tokenStream = new(lexer);
+ CGrammarParser parser = new(tokenStream);
+ parser.RemoveErrorListeners();
+
+ CCompilerVisitor compiler = new();
+ var result = compiler.Compile(parser.program());
+ File.WriteAllLines(options.OutputFile, result);
+ }
+} \ No newline at end of file
diff --git a/Compiler/gen/CGrammar.interp b/Compiler/gen/CGrammar.interp
new file mode 100644
index 0000000..d5453b2
--- /dev/null
+++ b/Compiler/gen/CGrammar.interp
@@ -0,0 +1,70 @@
+token literal names:
+null
+'int'
+'('
+')'
+'{'
+'}'
+'return'
+';'
+'!'
+'~'
+'*'
+'/'
+'%'
+'+'
+'-'
+'<'
+'>'
+'<='
+'>='
+'=='
+'!='
+'&'
+'|'
+'^'
+'&&'
+'||'
+null
+null
+
+token symbolic names:
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+ID
+INT
+
+rule names:
+program
+function
+statement
+expression
+constant
+
+
+atn:
+[4, 1, 27, 98, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 20, 8, 1, 10, 1, 12, 1, 23, 9, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 41, 8, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 91, 8, 3, 10, 3, 12, 3, 94, 9, 3, 1, 4, 1, 4, 1, 4, 0, 1, 6, 5, 0, 2, 4, 6, 8, 0, 0, 112, 0, 10, 1, 0, 0, 0, 2, 13, 1, 0, 0, 0, 4, 26, 1, 0, 0, 0, 6, 40, 1, 0, 0, 0, 8, 95, 1, 0, 0, 0, 10, 11, 3, 2, 1, 0, 11, 12, 5, 0, 0, 1, 12, 1, 1, 0, 0, 0, 13, 14, 5, 1, 0, 0, 14, 15, 5, 26, 0, 0, 15, 16, 5, 2, 0, 0, 16, 17, 5, 3, 0, 0, 17, 21, 5, 4, 0, 0, 18, 20, 3, 4, 2, 0, 19, 18, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 5, 0, 0, 25, 3, 1, 0, 0, 0, 26, 27, 5, 6, 0, 0, 27, 28, 3, 6, 3, 0, 28, 29, 5, 7, 0, 0, 29, 5, 1, 0, 0, 0, 30, 31, 6, 3, -1, 0, 31, 32, 5, 2, 0, 0, 32, 33, 3, 6, 3, 0, 33, 34, 5, 3, 0, 0, 34, 41, 1, 0, 0, 0, 35, 36, 5, 8, 0, 0, 36, 41, 3, 6, 3, 19, 37, 38, 5, 9, 0, 0, 38, 41, 3, 6, 3, 18, 39, 41, 3, 8, 4, 0, 40, 30, 1, 0, 0, 0, 40, 35, 1, 0, 0, 0, 40, 37, 1, 0, 0, 0, 40, 39, 1, 0, 0, 0, 41, 92, 1, 0, 0, 0, 42, 43, 10, 17, 0, 0, 43, 44, 5, 10, 0, 0, 44, 91, 3, 6, 3, 18, 45, 46, 10, 16, 0, 0, 46, 47, 5, 11, 0, 0, 47, 91, 3, 6, 3, 17, 48, 49, 10, 15, 0, 0, 49, 50, 5, 12, 0, 0, 50, 91, 3, 6, 3, 16, 51, 52, 10, 14, 0, 0, 52, 53, 5, 13, 0, 0, 53, 91, 3, 6, 3, 15, 54, 55, 10, 13, 0, 0, 55, 56, 5, 14, 0, 0, 56, 91, 3, 6, 3, 14, 57, 58, 10, 12, 0, 0, 58, 59, 5, 15, 0, 0, 59, 91, 3, 6, 3, 13, 60, 61, 10, 11, 0, 0, 61, 62, 5, 16, 0, 0, 62, 91, 3, 6, 3, 12, 63, 64, 10, 10, 0, 0, 64, 65, 5, 17, 0, 0, 65, 91, 3, 6, 3, 11, 66, 67, 10, 9, 0, 0, 67, 68, 5, 18, 0, 0, 68, 91, 3, 6, 3, 10, 69, 70, 10, 8, 0, 0, 70, 71, 5, 19, 0, 0, 71, 91, 3, 6, 3, 9, 72, 73, 10, 7, 0, 0, 73, 74, 5, 20, 0, 0, 74, 91, 3, 6, 3, 8, 75, 76, 10, 6, 0, 0, 76, 77, 5, 21, 0, 0, 77, 91, 3, 6, 3, 7, 78, 79, 10, 5, 0, 0, 79, 80, 5, 22, 0, 0, 80, 91, 3, 6, 3, 6, 81, 82, 10, 4, 0, 0, 82, 83, 5, 23, 0, 0, 83, 91, 3, 6, 3, 5, 84, 85, 10, 3, 0, 0, 85, 86, 5, 24, 0, 0, 86, 91, 3, 6, 3, 4, 87, 88, 10, 2, 0, 0, 88, 89, 5, 25, 0, 0, 89, 91, 3, 6, 3, 3, 90, 42, 1, 0, 0, 0, 90, 45, 1, 0, 0, 0, 90, 48, 1, 0, 0, 0, 90, 51, 1, 0, 0, 0, 90, 54, 1, 0, 0, 0, 90, 57, 1, 0, 0, 0, 90, 60, 1, 0, 0, 0, 90, 63, 1, 0, 0, 0, 90, 66, 1, 0, 0, 0, 90, 69, 1, 0, 0, 0, 90, 72, 1, 0, 0, 0, 90, 75, 1, 0, 0, 0, 90, 78, 1, 0, 0, 0, 90, 81, 1, 0, 0, 0, 90, 84, 1, 0, 0, 0, 90, 87, 1, 0, 0, 0, 91, 94, 1, 0, 0, 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 7, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 95, 96, 5, 27, 0, 0, 96, 9, 1, 0, 0, 0, 4, 21, 40, 90, 92] \ No newline at end of file
diff --git a/Compiler/gen/CGrammar.tokens b/Compiler/gen/CGrammar.tokens
new file mode 100644
index 0000000..fc1a392
--- /dev/null
+++ b/Compiler/gen/CGrammar.tokens
@@ -0,0 +1,52 @@
+T__0=1
+T__1=2
+T__2=3
+T__3=4
+T__4=5
+T__5=6
+T__6=7
+T__7=8
+T__8=9
+T__9=10
+T__10=11
+T__11=12
+T__12=13
+T__13=14
+T__14=15
+T__15=16
+T__16=17
+T__17=18
+T__18=19
+T__19=20
+T__20=21
+T__21=22
+T__22=23
+T__23=24
+T__24=25
+ID=26
+INT=27
+'int'=1
+'('=2
+')'=3
+'{'=4
+'}'=5
+'return'=6
+';'=7
+'!'=8
+'~'=9
+'*'=10
+'/'=11
+'%'=12
+'+'=13
+'-'=14
+'<'=15
+'>'=16
+'<='=17
+'>='=18
+'=='=19
+'!='=20
+'&'=21
+'|'=22
+'^'=23
+'&&'=24
+'||'=25
diff --git a/Compiler/gen/CGrammarBaseVisitor.cs b/Compiler/gen/CGrammarBaseVisitor.cs
new file mode 100644
index 0000000..1f864c3
--- /dev/null
+++ b/Compiler/gen/CGrammarBaseVisitor.cs
@@ -0,0 +1,299 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// ANTLR Version: 4.13.2
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2
+
+// Unreachable code detected
+#pragma warning disable 0162
+// The variable '...' is assigned but its value is never used
+#pragma warning disable 0219
+// Missing XML comment for publicly visible type or member '...'
+#pragma warning disable 1591
+// Ambiguous reference in cref attribute
+#pragma warning disable 419
+
+using Antlr4.Runtime.Misc;
+using Antlr4.Runtime.Tree;
+using IToken = Antlr4.Runtime.IToken;
+using ParserRuleContext = Antlr4.Runtime.ParserRuleContext;
+
+/// <summary>
+/// This class provides an empty implementation of <see cref="ICGrammarVisitor{Result}"/>,
+/// which can be extended to create a visitor which only needs to handle a subset
+/// of the available methods.
+/// </summary>
+/// <typeparam name="Result">The return type of the visit operation.</typeparam>
+[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")]
+[System.Diagnostics.DebuggerNonUserCode]
+[System.CLSCompliant(false)]
+public partial class CGrammarBaseVisitor<Result> : AbstractParseTreeVisitor<Result>, ICGrammarVisitor<Result> {
+ /// <summary>
+ /// Visit a parse tree produced by <see cref="CGrammarParser.program"/>.
+ /// <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 VisitProgram([NotNull] CGrammarParser.ProgramContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by <see cref="CGrammarParser.function"/>.
+ /// <para>
+ /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
+ /// on <paramref name="context"/>.
+ /// </para>
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ public virtual Result VisitFunction([NotNull] CGrammarParser.FunctionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>returnStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// <para>
+ /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
+ /// on <paramref name="context"/>.
+ /// </para>
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ public virtual Result VisitReturnStatement([NotNull] CGrammarParser.ReturnStatementContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>bitwiseXorExpression</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 VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>constantExpression</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 VisitConstantExpression([NotNull] CGrammarParser.ConstantExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>lessThanOrEqualExpression</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 VisitLessThanOrEqualExpression([NotNull] CGrammarParser.LessThanOrEqualExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>modulusExpression</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 VisitModulusExpression([NotNull] CGrammarParser.ModulusExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>notExpression</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 VisitNotExpression([NotNull] CGrammarParser.NotExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>notEqualExpression</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 VisitNotEqualExpression([NotNull] CGrammarParser.NotEqualExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>multiplyExpression</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 VisitMultiplyExpression([NotNull] CGrammarParser.MultiplyExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>greaterThanExpression</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 VisitGreaterThanExpression([NotNull] CGrammarParser.GreaterThanExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>logicalOrExpression</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 VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>greaterThanOrEqualExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// <para>
+ /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
+ /// on <paramref name="context"/>.
+ /// </para>
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ public virtual Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>divideExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// <para>
+ /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
+ /// on <paramref name="context"/>.
+ /// </para>
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ public virtual Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>bitwiseOrExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// <para>
+ /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
+ /// on <paramref name="context"/>.
+ /// </para>
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ public virtual Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>parenthesizedExpression</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 VisitParenthesizedExpression([NotNull] CGrammarParser.ParenthesizedExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>addExpression</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 VisitAddExpression([NotNull] CGrammarParser.AddExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>subtractExpression</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 VisitSubtractExpression([NotNull] CGrammarParser.SubtractExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>bitwiseAndExpression</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 VisitBitwiseAndExpression([NotNull] CGrammarParser.BitwiseAndExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>lessThanExpression</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 VisitLessThanExpression([NotNull] CGrammarParser.LessThanExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>logicalAndExpression</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 VisitLogicalAndExpression([NotNull] CGrammarParser.LogicalAndExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>invertExpression</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 VisitInvertExpression([NotNull] CGrammarParser.InvertExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>equalExpression</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 VisitEqualExpression([NotNull] CGrammarParser.EqualExpressionContext context) { return VisitChildren(context); }
+ /// <summary>
+ /// Visit a parse tree produced by the <c>intConstant</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 VisitIntConstant([NotNull] CGrammarParser.IntConstantContext context) { return VisitChildren(context); }
+}
diff --git a/Compiler/gen/CGrammarLexer.cs b/Compiler/gen/CGrammarLexer.cs
new file mode 100644
index 0000000..3bb49f2
--- /dev/null
+++ b/Compiler/gen/CGrammarLexer.cs
@@ -0,0 +1,149 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// ANTLR Version: 4.13.2
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2
+
+// Unreachable code detected
+#pragma warning disable 0162
+// The variable '...' is assigned but its value is never used
+#pragma warning disable 0219
+// Missing XML comment for publicly visible type or member '...'
+#pragma warning disable 1591
+// Ambiguous reference in cref attribute
+#pragma warning disable 419
+
+using System;
+using System.IO;
+using System.Text;
+using Antlr4.Runtime;
+using Antlr4.Runtime.Atn;
+using Antlr4.Runtime.Misc;
+using DFA = Antlr4.Runtime.Dfa.DFA;
+
+[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")]
+[System.CLSCompliant(false)]
+public partial class CGrammarLexer : Lexer {
+ protected static DFA[] decisionToDFA;
+ protected static PredictionContextCache sharedContextCache = new PredictionContextCache();
+ public const int
+ T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9,
+ T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17,
+ T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24,
+ T__24=25, ID=26, INT=27;
+ public static string[] channelNames = {
+ "DEFAULT_TOKEN_CHANNEL", "HIDDEN"
+ };
+
+ public static string[] modeNames = {
+ "DEFAULT_MODE"
+ };
+
+ public static readonly string[] ruleNames = {
+ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8",
+ "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16",
+ "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24",
+ "ID", "INT"
+ };
+
+
+ public CGrammarLexer(ICharStream input)
+ : this(input, Console.Out, Console.Error) { }
+
+ public CGrammarLexer(ICharStream input, TextWriter output, TextWriter errorOutput)
+ : base(input, output, errorOutput)
+ {
+ Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
+ }
+
+ private static readonly string[] _LiteralNames = {
+ null, "'int'", "'('", "')'", "'{'", "'}'", "'return'", "';'", "'!'", "'~'",
+ "'*'", "'/'", "'%'", "'+'", "'-'", "'<'", "'>'", "'<='", "'>='", "'=='",
+ "'!='", "'&'", "'|'", "'^'", "'&&'", "'||'"
+ };
+ 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, "ID", "INT"
+ };
+ public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);
+
+ [NotNull]
+ public override IVocabulary Vocabulary
+ {
+ get
+ {
+ return DefaultVocabulary;
+ }
+ }
+
+ public override string GrammarFileName { get { return "CGrammar.g4"; } }
+
+ public override string[] RuleNames { get { return ruleNames; } }
+
+ public override string[] ChannelNames { get { return channelNames; } }
+
+ public override string[] ModeNames { get { return modeNames; } }
+
+ public override int[] SerializedAtn { get { return _serializedATN; } }
+
+ static CGrammarLexer() {
+ decisionToDFA = new DFA[_ATN.NumberOfDecisions];
+ for (int i = 0; i < _ATN.NumberOfDecisions; i++) {
+ decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i);
+ }
+ }
+ private static int[] _serializedATN = {
+ 4,0,27,130,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,1,0,1,0,1,0,1,0,
+ 1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1,
+ 7,1,7,1,8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,14,1,14,
+ 1,15,1,15,1,16,1,16,1,16,1,17,1,17,1,17,1,18,1,18,1,18,1,19,1,19,1,19,
+ 1,20,1,20,1,21,1,21,1,22,1,22,1,23,1,23,1,23,1,24,1,24,1,24,1,25,1,25,
+ 5,25,121,8,25,10,25,12,25,124,9,25,1,26,4,26,127,8,26,11,26,12,26,128,
+ 0,0,27,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,1,0,3,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,
+ 1,0,48,57,131,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,1,55,1,0,0,0,3,59,1,0,0,0,5,61,1,0,0,0,7,63,1,0,0,0,9,65,1,0,0,
+ 0,11,67,1,0,0,0,13,74,1,0,0,0,15,76,1,0,0,0,17,78,1,0,0,0,19,80,1,0,0,
+ 0,21,82,1,0,0,0,23,84,1,0,0,0,25,86,1,0,0,0,27,88,1,0,0,0,29,90,1,0,0,
+ 0,31,92,1,0,0,0,33,94,1,0,0,0,35,97,1,0,0,0,37,100,1,0,0,0,39,103,1,0,
+ 0,0,41,106,1,0,0,0,43,108,1,0,0,0,45,110,1,0,0,0,47,112,1,0,0,0,49,115,
+ 1,0,0,0,51,118,1,0,0,0,53,126,1,0,0,0,55,56,5,105,0,0,56,57,5,110,0,0,
+ 57,58,5,116,0,0,58,2,1,0,0,0,59,60,5,40,0,0,60,4,1,0,0,0,61,62,5,41,0,
+ 0,62,6,1,0,0,0,63,64,5,123,0,0,64,8,1,0,0,0,65,66,5,125,0,0,66,10,1,0,
+ 0,0,67,68,5,114,0,0,68,69,5,101,0,0,69,70,5,116,0,0,70,71,5,117,0,0,71,
+ 72,5,114,0,0,72,73,5,110,0,0,73,12,1,0,0,0,74,75,5,59,0,0,75,14,1,0,0,
+ 0,76,77,5,33,0,0,77,16,1,0,0,0,78,79,5,126,0,0,79,18,1,0,0,0,80,81,5,42,
+ 0,0,81,20,1,0,0,0,82,83,5,47,0,0,83,22,1,0,0,0,84,85,5,37,0,0,85,24,1,
+ 0,0,0,86,87,5,43,0,0,87,26,1,0,0,0,88,89,5,45,0,0,89,28,1,0,0,0,90,91,
+ 5,60,0,0,91,30,1,0,0,0,92,93,5,62,0,0,93,32,1,0,0,0,94,95,5,60,0,0,95,
+ 96,5,61,0,0,96,34,1,0,0,0,97,98,5,62,0,0,98,99,5,61,0,0,99,36,1,0,0,0,
+ 100,101,5,61,0,0,101,102,5,61,0,0,102,38,1,0,0,0,103,104,5,33,0,0,104,
+ 105,5,61,0,0,105,40,1,0,0,0,106,107,5,38,0,0,107,42,1,0,0,0,108,109,5,
+ 124,0,0,109,44,1,0,0,0,110,111,5,94,0,0,111,46,1,0,0,0,112,113,5,38,0,
+ 0,113,114,5,38,0,0,114,48,1,0,0,0,115,116,5,124,0,0,116,117,5,124,0,0,
+ 117,50,1,0,0,0,118,122,7,0,0,0,119,121,7,1,0,0,120,119,1,0,0,0,121,124,
+ 1,0,0,0,122,120,1,0,0,0,122,123,1,0,0,0,123,52,1,0,0,0,124,122,1,0,0,0,
+ 125,127,7,2,0,0,126,125,1,0,0,0,127,128,1,0,0,0,128,126,1,0,0,0,128,129,
+ 1,0,0,0,129,54,1,0,0,0,3,0,122,128,0
+ };
+
+ public static readonly ATN _ATN =
+ new ATNDeserializer().Deserialize(_serializedATN);
+
+
+}
diff --git a/Compiler/gen/CGrammarLexer.interp b/Compiler/gen/CGrammarLexer.interp
new file mode 100644
index 0000000..d041f13
--- /dev/null
+++ b/Compiler/gen/CGrammarLexer.interp
@@ -0,0 +1,98 @@
+token literal names:
+null
+'int'
+'('
+')'
+'{'
+'}'
+'return'
+';'
+'!'
+'~'
+'*'
+'/'
+'%'
+'+'
+'-'
+'<'
+'>'
+'<='
+'>='
+'=='
+'!='
+'&'
+'|'
+'^'
+'&&'
+'||'
+null
+null
+
+token symbolic names:
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+null
+ID
+INT
+
+rule names:
+T__0
+T__1
+T__2
+T__3
+T__4
+T__5
+T__6
+T__7
+T__8
+T__9
+T__10
+T__11
+T__12
+T__13
+T__14
+T__15
+T__16
+T__17
+T__18
+T__19
+T__20
+T__21
+T__22
+T__23
+T__24
+ID
+INT
+
+channel names:
+DEFAULT_TOKEN_CHANNEL
+HIDDEN
+
+mode names:
+DEFAULT_MODE
+
+atn:
+[4, 0, 27, 130, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 24, 1, 25, 1, 25, 5, 25, 121, 8, 25, 10, 25, 12, 25, 124, 9, 25, 1, 26, 4, 26, 127, 8, 26, 11, 26, 12, 26, 128, 0, 0, 27, 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, 1, 0, 3, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 48, 57, 131, 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, 1, 55, 1, 0, 0, 0, 3, 59, 1, 0, 0, 0, 5, 61, 1, 0, 0, 0, 7, 63, 1, 0, 0, 0, 9, 65, 1, 0, 0, 0, 11, 67, 1, 0, 0, 0, 13, 74, 1, 0, 0, 0, 15, 76, 1, 0, 0, 0, 17, 78, 1, 0, 0, 0, 19, 80, 1, 0, 0, 0, 21, 82, 1, 0, 0, 0, 23, 84, 1, 0, 0, 0, 25, 86, 1, 0, 0, 0, 27, 88, 1, 0, 0, 0, 29, 90, 1, 0, 0, 0, 31, 92, 1, 0, 0, 0, 33, 94, 1, 0, 0, 0, 35, 97, 1, 0, 0, 0, 37, 100, 1, 0, 0, 0, 39, 103, 1, 0, 0, 0, 41, 106, 1, 0, 0, 0, 43, 108, 1, 0, 0, 0, 45, 110, 1, 0, 0, 0, 47, 112, 1, 0, 0, 0, 49, 115, 1, 0, 0, 0, 51, 118, 1, 0, 0, 0, 53, 126, 1, 0, 0, 0, 55, 56, 5, 105, 0, 0, 56, 57, 5, 110, 0, 0, 57, 58, 5, 116, 0, 0, 58, 2, 1, 0, 0, 0, 59, 60, 5, 40, 0, 0, 60, 4, 1, 0, 0, 0, 61, 62, 5, 41, 0, 0, 62, 6, 1, 0, 0, 0, 63, 64, 5, 123, 0, 0, 64, 8, 1, 0, 0, 0, 65, 66, 5, 125, 0, 0, 66, 10, 1, 0, 0, 0, 67, 68, 5, 114, 0, 0, 68, 69, 5, 101, 0, 0, 69, 70, 5, 116, 0, 0, 70, 71, 5, 117, 0, 0, 71, 72, 5, 114, 0, 0, 72, 73, 5, 110, 0, 0, 73, 12, 1, 0, 0, 0, 74, 75, 5, 59, 0, 0, 75, 14, 1, 0, 0, 0, 76, 77, 5, 33, 0, 0, 77, 16, 1, 0, 0, 0, 78, 79, 5, 126, 0, 0, 79, 18, 1, 0, 0, 0, 80, 81, 5, 42, 0, 0, 81, 20, 1, 0, 0, 0, 82, 83, 5, 47, 0, 0, 83, 22, 1, 0, 0, 0, 84, 85, 5, 37, 0, 0, 85, 24, 1, 0, 0, 0, 86, 87, 5, 43, 0, 0, 87, 26, 1, 0, 0, 0, 88, 89, 5, 45, 0, 0, 89, 28, 1, 0, 0, 0, 90, 91, 5, 60, 0, 0, 91, 30, 1, 0, 0, 0, 92, 93, 5, 62, 0, 0, 93, 32, 1, 0, 0, 0, 94, 95, 5, 60, 0, 0, 95, 96, 5, 61, 0, 0, 96, 34, 1, 0, 0, 0, 97, 98, 5, 62, 0, 0, 98, 99, 5, 61, 0, 0, 99, 36, 1, 0, 0, 0, 100, 101, 5, 61, 0, 0, 101, 102, 5, 61, 0, 0, 102, 38, 1, 0, 0, 0, 103, 104, 5, 33, 0, 0, 104, 105, 5, 61, 0, 0, 105, 40, 1, 0, 0, 0, 106, 107, 5, 38, 0, 0, 107, 42, 1, 0, 0, 0, 108, 109, 5, 124, 0, 0, 109, 44, 1, 0, 0, 0, 110, 111, 5, 94, 0, 0, 111, 46, 1, 0, 0, 0, 112, 113, 5, 38, 0, 0, 113, 114, 5, 38, 0, 0, 114, 48, 1, 0, 0, 0, 115, 116, 5, 124, 0, 0, 116, 117, 5, 124, 0, 0, 117, 50, 1, 0, 0, 0, 118, 122, 7, 0, 0, 0, 119, 121, 7, 1, 0, 0, 120, 119, 1, 0, 0, 0, 121, 124, 1, 0, 0, 0, 122, 120, 1, 0, 0, 0, 122, 123, 1, 0, 0, 0, 123, 52, 1, 0, 0, 0, 124, 122, 1, 0, 0, 0, 125, 127, 7, 2, 0, 0, 126, 125, 1, 0, 0, 0, 127, 128, 1, 0, 0, 0, 128, 126, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 54, 1, 0, 0, 0, 3, 0, 122, 128, 0] \ No newline at end of file
diff --git a/Compiler/gen/CGrammarLexer.tokens b/Compiler/gen/CGrammarLexer.tokens
new file mode 100644
index 0000000..fc1a392
--- /dev/null
+++ b/Compiler/gen/CGrammarLexer.tokens
@@ -0,0 +1,52 @@
+T__0=1
+T__1=2
+T__2=3
+T__3=4
+T__4=5
+T__5=6
+T__6=7
+T__7=8
+T__8=9
+T__9=10
+T__10=11
+T__11=12
+T__12=13
+T__13=14
+T__14=15
+T__15=16
+T__16=17
+T__17=18
+T__18=19
+T__19=20
+T__20=21
+T__21=22
+T__22=23
+T__23=24
+T__24=25
+ID=26
+INT=27
+'int'=1
+'('=2
+')'=3
+'{'=4
+'}'=5
+'return'=6
+';'=7
+'!'=8
+'~'=9
+'*'=10
+'/'=11
+'%'=12
+'+'=13
+'-'=14
+'<'=15
+'>'=16
+'<='=17
+'>='=18
+'=='=19
+'!='=20
+'&'=21
+'|'=22
+'^'=23
+'&&'=24
+'||'=25
diff --git a/Compiler/gen/CGrammarParser.cs b/Compiler/gen/CGrammarParser.cs
new file mode 100644
index 0000000..88f1740
--- /dev/null
+++ b/Compiler/gen/CGrammarParser.cs
@@ -0,0 +1,1006 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// ANTLR Version: 4.13.2
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2
+
+// Unreachable code detected
+#pragma warning disable 0162
+// The variable '...' is assigned but its value is never used
+#pragma warning disable 0219
+// Missing XML comment for publicly visible type or member '...'
+#pragma warning disable 1591
+// Ambiguous reference in cref attribute
+#pragma warning disable 419
+
+using System;
+using System.IO;
+using System.Text;
+using System.Diagnostics;
+using System.Collections.Generic;
+using Antlr4.Runtime;
+using Antlr4.Runtime.Atn;
+using Antlr4.Runtime.Misc;
+using Antlr4.Runtime.Tree;
+using DFA = Antlr4.Runtime.Dfa.DFA;
+
+[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")]
+[System.CLSCompliant(false)]
+public partial class CGrammarParser : Parser {
+ protected static DFA[] decisionToDFA;
+ protected static PredictionContextCache sharedContextCache = new PredictionContextCache();
+ public const int
+ T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9,
+ T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17,
+ T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24,
+ T__24=25, ID=26, INT=27;
+ public const int
+ RULE_program = 0, RULE_function = 1, RULE_statement = 2, RULE_expression = 3,
+ RULE_constant = 4;
+ public static readonly string[] ruleNames = {
+ "program", "function", "statement", "expression", "constant"
+ };
+
+ private static readonly string[] _LiteralNames = {
+ null, "'int'", "'('", "')'", "'{'", "'}'", "'return'", "';'", "'!'", "'~'",
+ "'*'", "'/'", "'%'", "'+'", "'-'", "'<'", "'>'", "'<='", "'>='", "'=='",
+ "'!='", "'&'", "'|'", "'^'", "'&&'", "'||'"
+ };
+ 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, "ID", "INT"
+ };
+ public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);
+
+ [NotNull]
+ public override IVocabulary Vocabulary
+ {
+ get
+ {
+ return DefaultVocabulary;
+ }
+ }
+
+ public override string GrammarFileName { get { return "CGrammar.g4"; } }
+
+ public override string[] RuleNames { get { return ruleNames; } }
+
+ public override int[] SerializedAtn { get { return _serializedATN; } }
+
+ static CGrammarParser() {
+ decisionToDFA = new DFA[_ATN.NumberOfDecisions];
+ for (int i = 0; i < _ATN.NumberOfDecisions; i++) {
+ decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i);
+ }
+ }
+
+ public CGrammarParser(ITokenStream input) : this(input, Console.Out, Console.Error) { }
+
+ public CGrammarParser(ITokenStream input, TextWriter output, TextWriter errorOutput)
+ : base(input, output, errorOutput)
+ {
+ Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
+ }
+
+ public partial class ProgramContext : ParserRuleContext {
+ [System.Diagnostics.DebuggerNonUserCode] public FunctionContext function() {
+ return GetRuleContext<FunctionContext>(0);
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode Eof() { return GetToken(CGrammarParser.Eof, 0); }
+ public ProgramContext(ParserRuleContext parent, int invokingState)
+ : base(parent, invokingState)
+ {
+ }
+ public override int RuleIndex { get { return RULE_program; } }
+ [System.Diagnostics.DebuggerNonUserCode]
+ public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
+ ICGrammarVisitor<TResult> typedVisitor = visitor as ICGrammarVisitor<TResult>;
+ if (typedVisitor != null) return typedVisitor.VisitProgram(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+
+ [RuleVersion(0)]
+ public ProgramContext program() {
+ ProgramContext _localctx = new ProgramContext(Context, State);
+ EnterRule(_localctx, 0, RULE_program);
+ try {
+ EnterOuterAlt(_localctx, 1);
+ {
+ State = 10;
+ function();
+ State = 11;
+ Match(Eof);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ ErrorHandler.ReportError(this, re);
+ ErrorHandler.Recover(this, re);
+ }
+ finally {
+ ExitRule();
+ }
+ return _localctx;
+ }
+
+ public partial class FunctionContext : ParserRuleContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(CGrammarParser.ID, 0); }
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext[] statement() {
+ return GetRuleContexts<StatementContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement(int i) {
+ return GetRuleContext<StatementContext>(i);
+ }
+ public FunctionContext(ParserRuleContext parent, int invokingState)
+ : base(parent, invokingState)
+ {
+ }
+ public override int RuleIndex { get { return RULE_function; } }
+ [System.Diagnostics.DebuggerNonUserCode]
+ public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
+ ICGrammarVisitor<TResult> typedVisitor = visitor as ICGrammarVisitor<TResult>;
+ if (typedVisitor != null) return typedVisitor.VisitFunction(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+
+ [RuleVersion(0)]
+ public FunctionContext function() {
+ FunctionContext _localctx = new FunctionContext(Context, State);
+ EnterRule(_localctx, 2, RULE_function);
+ int _la;
+ try {
+ EnterOuterAlt(_localctx, 1);
+ {
+ State = 13;
+ Match(T__0);
+ State = 14;
+ Match(ID);
+ State = 15;
+ Match(T__1);
+ State = 16;
+ Match(T__2);
+ State = 17;
+ Match(T__3);
+ State = 21;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ while (_la==T__5) {
+ {
+ {
+ State = 18;
+ statement();
+ }
+ }
+ State = 23;
+ ErrorHandler.Sync(this);
+ _la = TokenStream.LA(1);
+ }
+ State = 24;
+ Match(T__4);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ ErrorHandler.ReportError(this, re);
+ ErrorHandler.Recover(this, re);
+ }
+ finally {
+ ExitRule();
+ }
+ return _localctx;
+ }
+
+ public partial class StatementContext : ParserRuleContext {
+ public StatementContext(ParserRuleContext parent, int invokingState)
+ : base(parent, invokingState)
+ {
+ }
+ public override int RuleIndex { get { return RULE_statement; } }
+
+ public StatementContext() { }
+ public virtual void CopyFrom(StatementContext context) {
+ base.CopyFrom(context);
+ }
+ }
+ public partial class ReturnStatementContext : StatementContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
+ return GetRuleContext<ExpressionContext>(0);
+ }
+ public ReturnStatementContext(StatementContext context) { CopyFrom(context); }
+ [System.Diagnostics.DebuggerNonUserCode]
+ public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
+ ICGrammarVisitor<TResult> typedVisitor = visitor as ICGrammarVisitor<TResult>;
+ if (typedVisitor != null) return typedVisitor.VisitReturnStatement(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+
+ [RuleVersion(0)]
+ public StatementContext statement() {
+ StatementContext _localctx = new StatementContext(Context, State);
+ EnterRule(_localctx, 4, RULE_statement);
+ try {
+ _localctx = new ReturnStatementContext(_localctx);
+ EnterOuterAlt(_localctx, 1);
+ {
+ State = 26;
+ Match(T__5);
+ State = 27;
+ expression(0);
+ State = 28;
+ Match(T__6);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ ErrorHandler.ReportError(this, re);
+ ErrorHandler.Recover(this, re);
+ }
+ finally {
+ ExitRule();
+ }
+ return _localctx;
+ }
+
+ public partial class ExpressionContext : ParserRuleContext {
+ public ExpressionContext(ParserRuleContext parent, int invokingState)
+ : base(parent, invokingState)
+ {
+ }
+ public override int RuleIndex { get { return RULE_expression; } }
+
+ public ExpressionContext() { }
+ public virtual void CopyFrom(ExpressionContext context) {
+ base.CopyFrom(context);
+ }
+ }
+ public partial class BitwiseXorExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public BitwiseXorExpressionContext(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.VisitBitwiseXorExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class ConstantExpressionContext : ExpressionContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ConstantContext constant() {
+ return GetRuleContext<ConstantContext>(0);
+ }
+ public ConstantExpressionContext(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.VisitConstantExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class LessThanOrEqualExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public LessThanOrEqualExpressionContext(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.VisitLessThanOrEqualExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class ModulusExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public ModulusExpressionContext(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.VisitModulusExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class NotExpressionContext : ExpressionContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
+ return GetRuleContext<ExpressionContext>(0);
+ }
+ public NotExpressionContext(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.VisitNotExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class NotEqualExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public NotEqualExpressionContext(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.VisitNotEqualExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class MultiplyExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public MultiplyExpressionContext(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.VisitMultiplyExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class GreaterThanExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public GreaterThanExpressionContext(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.VisitGreaterThanExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class LogicalOrExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public LogicalOrExpressionContext(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.VisitLogicalOrExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class GreaterThanOrEqualExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public GreaterThanOrEqualExpressionContext(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.VisitGreaterThanOrEqualExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class DivideExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public DivideExpressionContext(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.VisitDivideExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class BitwiseOrExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public BitwiseOrExpressionContext(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.VisitBitwiseOrExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class ParenthesizedExpressionContext : ExpressionContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
+ return GetRuleContext<ExpressionContext>(0);
+ }
+ public ParenthesizedExpressionContext(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.VisitParenthesizedExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class AddExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public AddExpressionContext(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.VisitAddExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class SubtractExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public SubtractExpressionContext(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.VisitSubtractExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class BitwiseAndExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public BitwiseAndExpressionContext(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.VisitBitwiseAndExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class LessThanExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public LessThanExpressionContext(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.VisitLessThanExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class LogicalAndExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public LogicalAndExpressionContext(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.VisitLogicalAndExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class InvertExpressionContext : ExpressionContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression() {
+ return GetRuleContext<ExpressionContext>(0);
+ }
+ public InvertExpressionContext(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.VisitInvertExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+ public partial class EqualExpressionContext : ExpressionContext {
+ public ExpressionContext left;
+ public ExpressionContext right;
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext[] expression() {
+ return GetRuleContexts<ExpressionContext>();
+ }
+ [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) {
+ return GetRuleContext<ExpressionContext>(i);
+ }
+ public EqualExpressionContext(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.VisitEqualExpression(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+
+ [RuleVersion(0)]
+ public ExpressionContext expression() {
+ return expression(0);
+ }
+
+ private ExpressionContext expression(int _p) {
+ ParserRuleContext _parentctx = Context;
+ int _parentState = State;
+ ExpressionContext _localctx = new ExpressionContext(Context, _parentState);
+ ExpressionContext _prevctx = _localctx;
+ int _startState = 6;
+ EnterRecursionRule(_localctx, 6, RULE_expression, _p);
+ try {
+ int _alt;
+ EnterOuterAlt(_localctx, 1);
+ {
+ State = 40;
+ ErrorHandler.Sync(this);
+ switch (TokenStream.LA(1)) {
+ case T__1:
+ {
+ _localctx = new ParenthesizedExpressionContext(_localctx);
+ Context = _localctx;
+ _prevctx = _localctx;
+
+ State = 31;
+ Match(T__1);
+ State = 32;
+ expression(0);
+ State = 33;
+ Match(T__2);
+ }
+ break;
+ case T__7:
+ {
+ _localctx = new NotExpressionContext(_localctx);
+ Context = _localctx;
+ _prevctx = _localctx;
+ State = 35;
+ Match(T__7);
+ State = 36;
+ expression(19);
+ }
+ break;
+ case T__8:
+ {
+ _localctx = new InvertExpressionContext(_localctx);
+ Context = _localctx;
+ _prevctx = _localctx;
+ State = 37;
+ Match(T__8);
+ State = 38;
+ expression(18);
+ }
+ break;
+ case INT:
+ {
+ _localctx = new ConstantExpressionContext(_localctx);
+ Context = _localctx;
+ _prevctx = _localctx;
+ State = 39;
+ constant();
+ }
+ break;
+ default:
+ throw new NoViableAltException(this);
+ }
+ Context.Stop = TokenStream.LT(-1);
+ State = 92;
+ ErrorHandler.Sync(this);
+ _alt = Interpreter.AdaptivePredict(TokenStream,3,Context);
+ while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
+ if ( _alt==1 ) {
+ if ( ParseListeners!=null )
+ TriggerExitRuleEvent();
+ _prevctx = _localctx;
+ {
+ State = 90;
+ ErrorHandler.Sync(this);
+ switch ( Interpreter.AdaptivePredict(TokenStream,2,Context) ) {
+ case 1:
+ {
+ _localctx = new MultiplyExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((MultiplyExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 42;
+ if (!(Precpred(Context, 17))) throw new FailedPredicateException(this, "Precpred(Context, 17)");
+ State = 43;
+ Match(T__9);
+ State = 44;
+ ((MultiplyExpressionContext)_localctx).right = expression(18);
+ }
+ break;
+ case 2:
+ {
+ _localctx = new DivideExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((DivideExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 45;
+ if (!(Precpred(Context, 16))) throw new FailedPredicateException(this, "Precpred(Context, 16)");
+ State = 46;
+ Match(T__10);
+ State = 47;
+ ((DivideExpressionContext)_localctx).right = expression(17);
+ }
+ break;
+ case 3:
+ {
+ _localctx = new ModulusExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((ModulusExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 48;
+ if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)");
+ State = 49;
+ Match(T__11);
+ State = 50;
+ ((ModulusExpressionContext)_localctx).right = expression(16);
+ }
+ break;
+ case 4:
+ {
+ _localctx = new AddExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((AddExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 51;
+ if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)");
+ State = 52;
+ Match(T__12);
+ State = 53;
+ ((AddExpressionContext)_localctx).right = expression(15);
+ }
+ break;
+ case 5:
+ {
+ _localctx = new SubtractExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((SubtractExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 54;
+ if (!(Precpred(Context, 13))) throw new FailedPredicateException(this, "Precpred(Context, 13)");
+ State = 55;
+ Match(T__13);
+ State = 56;
+ ((SubtractExpressionContext)_localctx).right = expression(14);
+ }
+ break;
+ case 6:
+ {
+ _localctx = new LessThanExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((LessThanExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 57;
+ if (!(Precpred(Context, 12))) throw new FailedPredicateException(this, "Precpred(Context, 12)");
+ State = 58;
+ Match(T__14);
+ State = 59;
+ ((LessThanExpressionContext)_localctx).right = expression(13);
+ }
+ break;
+ case 7:
+ {
+ _localctx = new GreaterThanExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((GreaterThanExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 60;
+ if (!(Precpred(Context, 11))) throw new FailedPredicateException(this, "Precpred(Context, 11)");
+ State = 61;
+ Match(T__15);
+ State = 62;
+ ((GreaterThanExpressionContext)_localctx).right = expression(12);
+ }
+ break;
+ case 8:
+ {
+ _localctx = new LessThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((LessThanOrEqualExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 63;
+ if (!(Precpred(Context, 10))) throw new FailedPredicateException(this, "Precpred(Context, 10)");
+ State = 64;
+ Match(T__16);
+ State = 65;
+ ((LessThanOrEqualExpressionContext)_localctx).right = expression(11);
+ }
+ break;
+ case 9:
+ {
+ _localctx = new GreaterThanOrEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((GreaterThanOrEqualExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 66;
+ if (!(Precpred(Context, 9))) throw new FailedPredicateException(this, "Precpred(Context, 9)");
+ State = 67;
+ Match(T__17);
+ State = 68;
+ ((GreaterThanOrEqualExpressionContext)_localctx).right = expression(10);
+ }
+ break;
+ case 10:
+ {
+ _localctx = new EqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((EqualExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 69;
+ if (!(Precpred(Context, 8))) throw new FailedPredicateException(this, "Precpred(Context, 8)");
+ State = 70;
+ Match(T__18);
+ State = 71;
+ ((EqualExpressionContext)_localctx).right = expression(9);
+ }
+ break;
+ case 11:
+ {
+ _localctx = new NotEqualExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((NotEqualExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 72;
+ if (!(Precpred(Context, 7))) throw new FailedPredicateException(this, "Precpred(Context, 7)");
+ State = 73;
+ Match(T__19);
+ State = 74;
+ ((NotEqualExpressionContext)_localctx).right = expression(8);
+ }
+ break;
+ case 12:
+ {
+ _localctx = new BitwiseAndExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((BitwiseAndExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 75;
+ if (!(Precpred(Context, 6))) throw new FailedPredicateException(this, "Precpred(Context, 6)");
+ State = 76;
+ Match(T__20);
+ State = 77;
+ ((BitwiseAndExpressionContext)_localctx).right = expression(7);
+ }
+ break;
+ case 13:
+ {
+ _localctx = new BitwiseOrExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((BitwiseOrExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 78;
+ if (!(Precpred(Context, 5))) throw new FailedPredicateException(this, "Precpred(Context, 5)");
+ State = 79;
+ Match(T__21);
+ State = 80;
+ ((BitwiseOrExpressionContext)_localctx).right = expression(6);
+ }
+ break;
+ case 14:
+ {
+ _localctx = new BitwiseXorExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((BitwiseXorExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 81;
+ if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)");
+ State = 82;
+ Match(T__22);
+ State = 83;
+ ((BitwiseXorExpressionContext)_localctx).right = expression(5);
+ }
+ break;
+ case 15:
+ {
+ _localctx = new LogicalAndExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((LogicalAndExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 84;
+ if (!(Precpred(Context, 3))) throw new FailedPredicateException(this, "Precpred(Context, 3)");
+ State = 85;
+ Match(T__23);
+ State = 86;
+ ((LogicalAndExpressionContext)_localctx).right = expression(4);
+ }
+ break;
+ case 16:
+ {
+ _localctx = new LogicalOrExpressionContext(new ExpressionContext(_parentctx, _parentState));
+ ((LogicalOrExpressionContext)_localctx).left = _prevctx;
+ PushNewRecursionContext(_localctx, _startState, RULE_expression);
+ State = 87;
+ if (!(Precpred(Context, 2))) throw new FailedPredicateException(this, "Precpred(Context, 2)");
+ State = 88;
+ Match(T__24);
+ State = 89;
+ ((LogicalOrExpressionContext)_localctx).right = expression(3);
+ }
+ break;
+ }
+ }
+ }
+ State = 94;
+ ErrorHandler.Sync(this);
+ _alt = Interpreter.AdaptivePredict(TokenStream,3,Context);
+ }
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ ErrorHandler.ReportError(this, re);
+ ErrorHandler.Recover(this, re);
+ }
+ finally {
+ UnrollRecursionContexts(_parentctx);
+ }
+ return _localctx;
+ }
+
+ public partial class ConstantContext : ParserRuleContext {
+ public ConstantContext(ParserRuleContext parent, int invokingState)
+ : base(parent, invokingState)
+ {
+ }
+ public override int RuleIndex { get { return RULE_constant; } }
+
+ public ConstantContext() { }
+ public virtual void CopyFrom(ConstantContext context) {
+ base.CopyFrom(context);
+ }
+ }
+ public partial class IntConstantContext : ConstantContext {
+ [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode INT() { return GetToken(CGrammarParser.INT, 0); }
+ public IntConstantContext(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.VisitIntConstant(this);
+ else return visitor.VisitChildren(this);
+ }
+ }
+
+ [RuleVersion(0)]
+ public ConstantContext constant() {
+ ConstantContext _localctx = new ConstantContext(Context, State);
+ EnterRule(_localctx, 8, RULE_constant);
+ try {
+ _localctx = new IntConstantContext(_localctx);
+ EnterOuterAlt(_localctx, 1);
+ {
+ State = 95;
+ Match(INT);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ ErrorHandler.ReportError(this, re);
+ ErrorHandler.Recover(this, re);
+ }
+ finally {
+ ExitRule();
+ }
+ return _localctx;
+ }
+
+ public override bool Sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
+ switch (ruleIndex) {
+ case 3: return expression_sempred((ExpressionContext)_localctx, predIndex);
+ }
+ return true;
+ }
+ private bool expression_sempred(ExpressionContext _localctx, int predIndex) {
+ switch (predIndex) {
+ case 0: return Precpred(Context, 17);
+ case 1: return Precpred(Context, 16);
+ case 2: return Precpred(Context, 15);
+ case 3: return Precpred(Context, 14);
+ case 4: return Precpred(Context, 13);
+ case 5: return Precpred(Context, 12);
+ case 6: return Precpred(Context, 11);
+ case 7: return Precpred(Context, 10);
+ case 8: return Precpred(Context, 9);
+ case 9: return Precpred(Context, 8);
+ case 10: return Precpred(Context, 7);
+ case 11: return Precpred(Context, 6);
+ case 12: return Precpred(Context, 5);
+ case 13: return Precpred(Context, 4);
+ case 14: return Precpred(Context, 3);
+ case 15: return Precpred(Context, 2);
+ }
+ return true;
+ }
+
+ private static int[] _serializedATN = {
+ 4,1,27,98,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,1,0,1,0,1,0,1,1,1,1,
+ 1,1,1,1,1,1,1,1,5,1,20,8,1,10,1,12,1,23,9,1,1,1,1,1,1,2,1,2,1,2,1,2,1,
+ 3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,3,3,41,8,3,1,3,1,3,1,3,1,3,1,3,1,
+ 3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,
+ 1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,
+ 3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,5,3,91,8,3,10,3,12,3,94,9,3,1,4,1,4,1,4,
+ 0,1,6,5,0,2,4,6,8,0,0,112,0,10,1,0,0,0,2,13,1,0,0,0,4,26,1,0,0,0,6,40,
+ 1,0,0,0,8,95,1,0,0,0,10,11,3,2,1,0,11,12,5,0,0,1,12,1,1,0,0,0,13,14,5,
+ 1,0,0,14,15,5,26,0,0,15,16,5,2,0,0,16,17,5,3,0,0,17,21,5,4,0,0,18,20,3,
+ 4,2,0,19,18,1,0,0,0,20,23,1,0,0,0,21,19,1,0,0,0,21,22,1,0,0,0,22,24,1,
+ 0,0,0,23,21,1,0,0,0,24,25,5,5,0,0,25,3,1,0,0,0,26,27,5,6,0,0,27,28,3,6,
+ 3,0,28,29,5,7,0,0,29,5,1,0,0,0,30,31,6,3,-1,0,31,32,5,2,0,0,32,33,3,6,
+ 3,0,33,34,5,3,0,0,34,41,1,0,0,0,35,36,5,8,0,0,36,41,3,6,3,19,37,38,5,9,
+ 0,0,38,41,3,6,3,18,39,41,3,8,4,0,40,30,1,0,0,0,40,35,1,0,0,0,40,37,1,0,
+ 0,0,40,39,1,0,0,0,41,92,1,0,0,0,42,43,10,17,0,0,43,44,5,10,0,0,44,91,3,
+ 6,3,18,45,46,10,16,0,0,46,47,5,11,0,0,47,91,3,6,3,17,48,49,10,15,0,0,49,
+ 50,5,12,0,0,50,91,3,6,3,16,51,52,10,14,0,0,52,53,5,13,0,0,53,91,3,6,3,
+ 15,54,55,10,13,0,0,55,56,5,14,0,0,56,91,3,6,3,14,57,58,10,12,0,0,58,59,
+ 5,15,0,0,59,91,3,6,3,13,60,61,10,11,0,0,61,62,5,16,0,0,62,91,3,6,3,12,
+ 63,64,10,10,0,0,64,65,5,17,0,0,65,91,3,6,3,11,66,67,10,9,0,0,67,68,5,18,
+ 0,0,68,91,3,6,3,10,69,70,10,8,0,0,70,71,5,19,0,0,71,91,3,6,3,9,72,73,10,
+ 7,0,0,73,74,5,20,0,0,74,91,3,6,3,8,75,76,10,6,0,0,76,77,5,21,0,0,77,91,
+ 3,6,3,7,78,79,10,5,0,0,79,80,5,22,0,0,80,91,3,6,3,6,81,82,10,4,0,0,82,
+ 83,5,23,0,0,83,91,3,6,3,5,84,85,10,3,0,0,85,86,5,24,0,0,86,91,3,6,3,4,
+ 87,88,10,2,0,0,88,89,5,25,0,0,89,91,3,6,3,3,90,42,1,0,0,0,90,45,1,0,0,
+ 0,90,48,1,0,0,0,90,51,1,0,0,0,90,54,1,0,0,0,90,57,1,0,0,0,90,60,1,0,0,
+ 0,90,63,1,0,0,0,90,66,1,0,0,0,90,69,1,0,0,0,90,72,1,0,0,0,90,75,1,0,0,
+ 0,90,78,1,0,0,0,90,81,1,0,0,0,90,84,1,0,0,0,90,87,1,0,0,0,91,94,1,0,0,
+ 0,92,90,1,0,0,0,92,93,1,0,0,0,93,7,1,0,0,0,94,92,1,0,0,0,95,96,5,27,0,
+ 0,96,9,1,0,0,0,4,21,40,90,92
+ };
+
+ public static readonly ATN _ATN =
+ new ATNDeserializer().Deserialize(_serializedATN);
+
+
+}
diff --git a/Compiler/gen/CGrammarVisitor.cs b/Compiler/gen/CGrammarVisitor.cs
new file mode 100644
index 0000000..1f9691a
--- /dev/null
+++ b/Compiler/gen/CGrammarVisitor.cs
@@ -0,0 +1,200 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// ANTLR Version: 4.13.2
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+// Generated from /Users/melodidey/Source/csharp/Q1/Compiler/CGrammar.g4 by ANTLR 4.13.2
+
+// Unreachable code detected
+#pragma warning disable 0162
+// The variable '...' is assigned but its value is never used
+#pragma warning disable 0219
+// Missing XML comment for publicly visible type or member '...'
+#pragma warning disable 1591
+// Ambiguous reference in cref attribute
+#pragma warning disable 419
+
+using Antlr4.Runtime.Misc;
+using Antlr4.Runtime.Tree;
+using IToken = Antlr4.Runtime.IToken;
+
+/// <summary>
+/// This interface defines a complete generic visitor for a parse tree produced
+/// by <see cref="CGrammarParser"/>.
+/// </summary>
+/// <typeparam name="Result">The return type of the visit operation.</typeparam>
+[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")]
+[System.CLSCompliant(false)]
+public interface ICGrammarVisitor<Result> : IParseTreeVisitor<Result> {
+ /// <summary>
+ /// Visit a parse tree produced by <see cref="CGrammarParser.program"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitProgram([NotNull] CGrammarParser.ProgramContext context);
+ /// <summary>
+ /// Visit a parse tree produced by <see cref="CGrammarParser.function"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitFunction([NotNull] CGrammarParser.FunctionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>returnStatement</c>
+ /// labeled alternative in <see cref="CGrammarParser.statement"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitReturnStatement([NotNull] CGrammarParser.ReturnStatementContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>bitwiseXorExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>constantExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitConstantExpression([NotNull] CGrammarParser.ConstantExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>lessThanOrEqualExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitLessThanOrEqualExpression([NotNull] CGrammarParser.LessThanOrEqualExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>modulusExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitModulusExpression([NotNull] CGrammarParser.ModulusExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>notExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitNotExpression([NotNull] CGrammarParser.NotExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>notEqualExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitNotEqualExpression([NotNull] CGrammarParser.NotEqualExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>multiplyExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitMultiplyExpression([NotNull] CGrammarParser.MultiplyExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>greaterThanExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitGreaterThanExpression([NotNull] CGrammarParser.GreaterThanExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>logicalOrExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>greaterThanOrEqualExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>divideExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>bitwiseOrExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>parenthesizedExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitParenthesizedExpression([NotNull] CGrammarParser.ParenthesizedExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>addExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitAddExpression([NotNull] CGrammarParser.AddExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>subtractExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitSubtractExpression([NotNull] CGrammarParser.SubtractExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>bitwiseAndExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitBitwiseAndExpression([NotNull] CGrammarParser.BitwiseAndExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>lessThanExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitLessThanExpression([NotNull] CGrammarParser.LessThanExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>logicalAndExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitLogicalAndExpression([NotNull] CGrammarParser.LogicalAndExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>invertExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitInvertExpression([NotNull] CGrammarParser.InvertExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>equalExpression</c>
+ /// labeled alternative in <see cref="CGrammarParser.expression"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitEqualExpression([NotNull] CGrammarParser.EqualExpressionContext context);
+ /// <summary>
+ /// Visit a parse tree produced by the <c>intConstant</c>
+ /// labeled alternative in <see cref="CGrammarParser.constant"/>.
+ /// </summary>
+ /// <param name="context">The parse tree.</param>
+ /// <return>The visitor result.</return>
+ Result VisitIntConstant([NotNull] CGrammarParser.IntConstantContext context);
+}