From 7a8d2bcd75d88a5429937bf551878c55e1dcf0fd Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:36:34 +1000 Subject: moved everything to seperate projects, and started compiler work + push and pop instructions added --- Compiler/gen/CGrammar.interp | 70 +++ Compiler/gen/CGrammar.tokens | 52 ++ Compiler/gen/CGrammarBaseVisitor.cs | 299 +++++++++++ Compiler/gen/CGrammarLexer.cs | 149 ++++++ Compiler/gen/CGrammarLexer.interp | 98 ++++ Compiler/gen/CGrammarLexer.tokens | 52 ++ Compiler/gen/CGrammarParser.cs | 1006 +++++++++++++++++++++++++++++++++++ Compiler/gen/CGrammarVisitor.cs | 200 +++++++ 8 files changed, 1926 insertions(+) create mode 100644 Compiler/gen/CGrammar.interp create mode 100644 Compiler/gen/CGrammar.tokens create mode 100644 Compiler/gen/CGrammarBaseVisitor.cs create mode 100644 Compiler/gen/CGrammarLexer.cs create mode 100644 Compiler/gen/CGrammarLexer.interp create mode 100644 Compiler/gen/CGrammarLexer.tokens create mode 100644 Compiler/gen/CGrammarParser.cs create mode 100644 Compiler/gen/CGrammarVisitor.cs (limited to 'Compiler/gen') 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 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +// 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; + +/// +/// This class provides an empty implementation of , +/// which can be extended to create a visitor which only needs to handle a subset +/// of the available methods. +/// +/// The return type of the visit operation. +[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] +[System.Diagnostics.DebuggerNonUserCode] +[System.CLSCompliant(false)] +public partial class CGrammarBaseVisitor : AbstractParseTreeVisitor, ICGrammarVisitor { + /// + /// Visit a parse tree produced by . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitProgram([NotNull] CGrammarParser.ProgramContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitFunction([NotNull] CGrammarParser.FunctionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the returnStatement + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitReturnStatement([NotNull] CGrammarParser.ReturnStatementContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the bitwiseXorExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the constantExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitConstantExpression([NotNull] CGrammarParser.ConstantExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the lessThanOrEqualExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitLessThanOrEqualExpression([NotNull] CGrammarParser.LessThanOrEqualExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the modulusExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitModulusExpression([NotNull] CGrammarParser.ModulusExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the notExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitNotExpression([NotNull] CGrammarParser.NotExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the notEqualExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitNotEqualExpression([NotNull] CGrammarParser.NotEqualExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the multiplyExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitMultiplyExpression([NotNull] CGrammarParser.MultiplyExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the greaterThanExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitGreaterThanExpression([NotNull] CGrammarParser.GreaterThanExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the logicalOrExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the greaterThanOrEqualExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the divideExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the bitwiseOrExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the parenthesizedExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitParenthesizedExpression([NotNull] CGrammarParser.ParenthesizedExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the addExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitAddExpression([NotNull] CGrammarParser.AddExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the subtractExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitSubtractExpression([NotNull] CGrammarParser.SubtractExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the bitwiseAndExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitBitwiseAndExpression([NotNull] CGrammarParser.BitwiseAndExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the lessThanExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitLessThanExpression([NotNull] CGrammarParser.LessThanExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the logicalAndExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitLogicalAndExpression([NotNull] CGrammarParser.LogicalAndExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the invertExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitInvertExpression([NotNull] CGrammarParser.InvertExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the equalExpression + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + public virtual Result VisitEqualExpression([NotNull] CGrammarParser.EqualExpressionContext context) { return VisitChildren(context); } + /// + /// Visit a parse tree produced by the intConstant + /// labeled alternative in . + /// + /// The default implementation returns the result of calling + /// on . + /// + /// + /// The parse tree. + /// The visitor result. + 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 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +// 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 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +// 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(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(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement(int i) { + return GetRuleContext(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(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(0); + } + public ReturnStatementContext(StatementContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public BitwiseXorExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(0); + } + public ConstantExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public LessThanOrEqualExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public ModulusExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(0); + } + public NotExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public NotEqualExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public MultiplyExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public GreaterThanExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public LogicalOrExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public GreaterThanOrEqualExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public DivideExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public BitwiseOrExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(0); + } + public ParenthesizedExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public AddExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public SubtractExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public BitwiseAndExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public LessThanExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public LogicalAndExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(0); + } + public InvertExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(); + } + [System.Diagnostics.DebuggerNonUserCode] public ExpressionContext expression(int i) { + return GetRuleContext(i); + } + public EqualExpressionContext(ExpressionContext context) { CopyFrom(context); } + [System.Diagnostics.DebuggerNonUserCode] + public override TResult Accept(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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(IParseTreeVisitor visitor) { + ICGrammarVisitor typedVisitor = visitor as ICGrammarVisitor; + 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 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +// 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; + +/// +/// This interface defines a complete generic visitor for a parse tree produced +/// by . +/// +/// The return type of the visit operation. +[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] +[System.CLSCompliant(false)] +public interface ICGrammarVisitor : IParseTreeVisitor { + /// + /// Visit a parse tree produced by . + /// + /// The parse tree. + /// The visitor result. + Result VisitProgram([NotNull] CGrammarParser.ProgramContext context); + /// + /// Visit a parse tree produced by . + /// + /// The parse tree. + /// The visitor result. + Result VisitFunction([NotNull] CGrammarParser.FunctionContext context); + /// + /// Visit a parse tree produced by the returnStatement + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitReturnStatement([NotNull] CGrammarParser.ReturnStatementContext context); + /// + /// Visit a parse tree produced by the bitwiseXorExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitBitwiseXorExpression([NotNull] CGrammarParser.BitwiseXorExpressionContext context); + /// + /// Visit a parse tree produced by the constantExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitConstantExpression([NotNull] CGrammarParser.ConstantExpressionContext context); + /// + /// Visit a parse tree produced by the lessThanOrEqualExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitLessThanOrEqualExpression([NotNull] CGrammarParser.LessThanOrEqualExpressionContext context); + /// + /// Visit a parse tree produced by the modulusExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitModulusExpression([NotNull] CGrammarParser.ModulusExpressionContext context); + /// + /// Visit a parse tree produced by the notExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitNotExpression([NotNull] CGrammarParser.NotExpressionContext context); + /// + /// Visit a parse tree produced by the notEqualExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitNotEqualExpression([NotNull] CGrammarParser.NotEqualExpressionContext context); + /// + /// Visit a parse tree produced by the multiplyExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitMultiplyExpression([NotNull] CGrammarParser.MultiplyExpressionContext context); + /// + /// Visit a parse tree produced by the greaterThanExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitGreaterThanExpression([NotNull] CGrammarParser.GreaterThanExpressionContext context); + /// + /// Visit a parse tree produced by the logicalOrExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitLogicalOrExpression([NotNull] CGrammarParser.LogicalOrExpressionContext context); + /// + /// Visit a parse tree produced by the greaterThanOrEqualExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitGreaterThanOrEqualExpression([NotNull] CGrammarParser.GreaterThanOrEqualExpressionContext context); + /// + /// Visit a parse tree produced by the divideExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitDivideExpression([NotNull] CGrammarParser.DivideExpressionContext context); + /// + /// Visit a parse tree produced by the bitwiseOrExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitBitwiseOrExpression([NotNull] CGrammarParser.BitwiseOrExpressionContext context); + /// + /// Visit a parse tree produced by the parenthesizedExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitParenthesizedExpression([NotNull] CGrammarParser.ParenthesizedExpressionContext context); + /// + /// Visit a parse tree produced by the addExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitAddExpression([NotNull] CGrammarParser.AddExpressionContext context); + /// + /// Visit a parse tree produced by the subtractExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitSubtractExpression([NotNull] CGrammarParser.SubtractExpressionContext context); + /// + /// Visit a parse tree produced by the bitwiseAndExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitBitwiseAndExpression([NotNull] CGrammarParser.BitwiseAndExpressionContext context); + /// + /// Visit a parse tree produced by the lessThanExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitLessThanExpression([NotNull] CGrammarParser.LessThanExpressionContext context); + /// + /// Visit a parse tree produced by the logicalAndExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitLogicalAndExpression([NotNull] CGrammarParser.LogicalAndExpressionContext context); + /// + /// Visit a parse tree produced by the invertExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitInvertExpression([NotNull] CGrammarParser.InvertExpressionContext context); + /// + /// Visit a parse tree produced by the equalExpression + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitEqualExpression([NotNull] CGrammarParser.EqualExpressionContext context); + /// + /// Visit a parse tree produced by the intConstant + /// labeled alternative in . + /// + /// The parse tree. + /// The visitor result. + Result VisitIntConstant([NotNull] CGrammarParser.IntConstantContext context); +} -- cgit v1.3.1