Initial commit

This commit is contained in:
The other zerg 2022-09-26 09:43:23 +02:00
commit 23f34bf885
18 changed files with 2056 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
.idea/**

17
README.md Normal file
View File

@ -0,0 +1,17 @@
### Dotnet
- install dotnet 6
- install antlr
- cd WaifuGrammar
- antlr4 -Dlanguage=CSharp \
-o WaifuGrammar/grammar_out/waifu \
-package waifu -listener -visitor \
-lib WaifuGrammar/grammar \
WaifuGrammar/grammar/Waifu2.g4
- Develop in grammar/Waifu2.g4 and Program.cs
### Notes
-
- Final implementation in rust? Althought rantlr4 doesn't have rust support. So we will have to write parser and lexer from sctach

16
WaifuGrammar.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaifuGrammar", "WaifuGrammar\WaifuGrammar.csproj", "{F5212B15-008E-4F83-B61D-7BC83A592D33}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F5212B15-008E-4F83-B61D-7BC83A592D33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5212B15-008E-4F83-B61D-7BC83A592D33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5212B15-008E-4F83-B61D-7BC83A592D33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5212B15-008E-4F83-B61D-7BC83A592D33}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

38
WaifuGrammar/Program.cs Normal file
View File

@ -0,0 +1,38 @@
// See https://aka.ms/new-console-template for more information
using System.Linq.Expressions;
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using waifu;
var input = File.ReadAllText("ex/f.wai");
/*
var input = @"() uwu
51 + 32
'there'
() uwu2
'uwu'
'owo'
##
Multiline comment
##
(x :#) par
x
# Single line comment
(x :.) dec
dec + 5.0
";
*/
var inputStream = CharStreams.fromString(input);
var lexer = new Waifu2Lexer(inputStream);
var tokens = new CommonTokenStream(lexer);
var parser = new Waifu2Parser(tokens);
parser.BuildParseTree = true;
var listener = new BaseErrorListener();
IParseTree tree = parser.waifuFile();
Console.WriteLine(tree.GetText());

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="gen" />
<Folder Include="grammar_out" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Antlr4.Runtime.Standard" Version="4.11.1" />
</ItemGroup>
</Project>

9
WaifuGrammar/ex/f.wai Normal file
View File

@ -0,0 +1,9 @@
(x1 :#) f2
# 333 + 433
# x2 <- x1 * 2
# -x2
# () f
# a <- 5
# aa + ba
# ca <- aa + ba
# print ca

View File

@ -0,0 +1,81 @@
grammar Waifu;
// language modes?
// todo single letter id and number doesn't work
prog: func+;
/* expr: assign_expr
// | '(' expr ')'
| fun_call
| ID SEP OP SEP expr
| num_expr
;
*/
expr:
| NUM WS ADD WS NUM
;
func: '(' (ID WS TYPE)* ')' WS TYPE? ID NL
(INDENT expr NL)+;
num_expr: SIGN? NUM;
assign_expr: ID WS ASSIGN WS expr;
fun_call: ID (WS expr)*;
op: (ADD | SUB | MULT | DIV);
SIGN: '+' | '-' ;
INDENT: ' ' ;
NL: '\n' ;
WS: ' ' ;
ASSIGN: '<-';
ID: [a-zA-Z]+[a-zA-Z0-9]*;
LETTER: [a-zA-Z] ;
NUM: [0-9]+ ;
TYPE: ':' .+?;
OP: '+' | '-' | '*' | '/' ;
ADD: '+';
SUB: '-';
MULT: '*';
DIV: '/';
/*
prog: (func | expr)+ EOF;
func: FUNC_DECL SPACE ID NL (INDENT expr NL)+;
expr: paren_expr | assignment | num_expr | str_expr | fun_call | ID;
paren_expr: '(' expr ')';
assignment: ID SPACE ASSIGN SPACE expr;
num_expr: NUMERIC SPACE OP SPACE NUMERIC
;
str_expr: V_STR
| V_WHOLE MULT str_expr
| str_expr MULT V_WHOLE
| str_expr ADD str_expr
;
fun_call: ID (SPACE expr)+;
SPACE: ' ';
LETTER: [a-zA-Z];
ID: LETTER+;
ASSIGN: '<-' ;
FUNC_DECL: '()';
NL: '\n';
INDENT: ' ';
DIGIT : [0-9];
SIGN : '+' | '-';
ADD: '+' ;
SUB: '-' ;
DIV: '/' ;
MOD: '%' ;
MULT: '*' ;
OP: (ADD | SUB | DIV | MOD | MULT);
V_WHOLE : SIGN? DIGIT+;
V_DEC : V_WHOLE '.' DIGIT+;
V_BOOL : '1' | '0' ;
NUMERIC: V_WHOLE | V_DEC | V_BOOL;
V_STR : '\'' .*? '\'';
*/

View File

@ -0,0 +1,80 @@
grammar Waifu2;
WS: ' ';
NL: '\u000A';
ID
: (Letter | '_') (Letter | '_' | DEC_DIGIT)*
;
fragment Letter: [a-zA-Z] ;
// comments
MultiLineComment
: '##' ( MultiLineComment | . )*? '##'
-> channel(HIDDEN)
;
SingleLineComment
: '#' ~[\u000A]*
-> channel(HIDDEN)
;
// operators
MULT: '*' ;
MOD: '%' ;
DIV: '/' ;
ADD: '+' ;
SUB: '-' ;
ASSIGN: '<-';
// RESERVED
LPAREN: '(' ;
RPAREN: ')' ;
COLON: ':' ;
// numerics
fragment DEC_DIGIT:
[0-9]
;
INT: DEC_DIGIT+ ;
DEC: DEC_DIGIT* '.' DEC_DIGIT+ ;
BOOL: [01] ;
STR: '\'' .*? '\'' ;
waifuFile
: NL* func* NL* EOF
;
// todo not right
type: COLON '#' ;
sign
: ADD
| SUB
;
operator: SUB | ADD | MULT | DIV | MOD ;
literal: INT | DEC | BOOL | STR ;
// func
func: functionDeclaration NL functionBody ;
functionDeclaration: LPAREN functionParam RPAREN WS type? WS ID NL ;
functionParam: ID WS type ;
functionBody: (expr NL+)+ ;
// expr
expr: literal
| ID
| expr WS operator WS expr
| sign expr
| MultiLineComment
| SingleLineComment
;

View File

@ -0,0 +1,59 @@
token literal names:
null
'#'
' '
'\u000A'
null
null
null
'*'
'%'
'/'
'+'
'-'
'<-'
'('
')'
':'
null
null
null
null
token symbolic names:
null
null
WS
NL
ID
MultiLineComment
SingleLineComment
MULT
MOD
DIV
ADD
SUB
ASSIGN
LPAREN
RPAREN
COLON
INT
DEC
BOOL
STR
rule names:
waifuFile
type
sign
operator
literal
func
functionDeclaration
functionParam
functionBody
expr
atn:
[4, 1, 19, 100, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 5, 0, 22, 8, 0, 10, 0, 12, 0, 25, 9, 0, 1, 0, 5, 0, 28, 8, 0, 10, 0, 12, 0, 31, 9, 0, 1, 0, 5, 0, 34, 8, 0, 10, 0, 12, 0, 37, 9, 0, 1, 0, 1, 0, 1, 1, 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, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 59, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 4, 8, 71, 8, 8, 11, 8, 12, 8, 72, 4, 8, 75, 8, 8, 11, 8, 12, 8, 76, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 3, 9, 87, 8, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 5, 9, 95, 8, 9, 10, 9, 12, 9, 98, 9, 9, 1, 9, 0, 1, 18, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 3, 1, 0, 10, 11, 1, 0, 7, 11, 1, 0, 16, 19, 100, 0, 23, 1, 0, 0, 0, 2, 40, 1, 0, 0, 0, 4, 43, 1, 0, 0, 0, 6, 45, 1, 0, 0, 0, 8, 47, 1, 0, 0, 0, 10, 49, 1, 0, 0, 0, 12, 53, 1, 0, 0, 0, 14, 64, 1, 0, 0, 0, 16, 74, 1, 0, 0, 0, 18, 86, 1, 0, 0, 0, 20, 22, 5, 3, 0, 0, 21, 20, 1, 0, 0, 0, 22, 25, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 29, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 26, 28, 3, 10, 5, 0, 27, 26, 1, 0, 0, 0, 28, 31, 1, 0, 0, 0, 29, 27, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 35, 1, 0, 0, 0, 31, 29, 1, 0, 0, 0, 32, 34, 5, 3, 0, 0, 33, 32, 1, 0, 0, 0, 34, 37, 1, 0, 0, 0, 35, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 38, 1, 0, 0, 0, 37, 35, 1, 0, 0, 0, 38, 39, 5, 0, 0, 1, 39, 1, 1, 0, 0, 0, 40, 41, 5, 15, 0, 0, 41, 42, 5, 1, 0, 0, 42, 3, 1, 0, 0, 0, 43, 44, 7, 0, 0, 0, 44, 5, 1, 0, 0, 0, 45, 46, 7, 1, 0, 0, 46, 7, 1, 0, 0, 0, 47, 48, 7, 2, 0, 0, 48, 9, 1, 0, 0, 0, 49, 50, 3, 12, 6, 0, 50, 51, 5, 3, 0, 0, 51, 52, 3, 16, 8, 0, 52, 11, 1, 0, 0, 0, 53, 54, 5, 13, 0, 0, 54, 55, 3, 14, 7, 0, 55, 56, 5, 14, 0, 0, 56, 58, 5, 2, 0, 0, 57, 59, 3, 2, 1, 0, 58, 57, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 60, 1, 0, 0, 0, 60, 61, 5, 2, 0, 0, 61, 62, 5, 4, 0, 0, 62, 63, 5, 3, 0, 0, 63, 13, 1, 0, 0, 0, 64, 65, 5, 4, 0, 0, 65, 66, 5, 2, 0, 0, 66, 67, 3, 2, 1, 0, 67, 15, 1, 0, 0, 0, 68, 70, 3, 18, 9, 0, 69, 71, 5, 3, 0, 0, 70, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 75, 1, 0, 0, 0, 74, 68, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 74, 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 17, 1, 0, 0, 0, 78, 79, 6, 9, -1, 0, 79, 87, 3, 8, 4, 0, 80, 87, 5, 4, 0, 0, 81, 82, 3, 4, 2, 0, 82, 83, 3, 18, 9, 3, 83, 87, 1, 0, 0, 0, 84, 87, 5, 5, 0, 0, 85, 87, 5, 6, 0, 0, 86, 78, 1, 0, 0, 0, 86, 80, 1, 0, 0, 0, 86, 81, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 86, 85, 1, 0, 0, 0, 87, 96, 1, 0, 0, 0, 88, 89, 10, 4, 0, 0, 89, 90, 5, 2, 0, 0, 90, 91, 3, 6, 3, 0, 91, 92, 5, 2, 0, 0, 92, 93, 3, 18, 9, 5, 93, 95, 1, 0, 0, 0, 94, 88, 1, 0, 0, 0, 95, 98, 1, 0, 0, 0, 96, 94, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 19, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 8, 23, 29, 35, 58, 72, 76, 86, 96]

View File

@ -0,0 +1,31 @@
T__0=1
WS=2
NL=3
ID=4
MultiLineComment=5
SingleLineComment=6
MULT=7
MOD=8
DIV=9
ADD=10
SUB=11
ASSIGN=12
LPAREN=13
RPAREN=14
COLON=15
INT=16
DEC=17
BOOL=18
STR=19
'#'=1
' '=2
'\u000A'=3
'*'=7
'%'=8
'/'=9
'+'=10
'-'=11
'<-'=12
'('=13
')'=14
':'=15

View File

@ -0,0 +1,173 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.10.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from /home/immi/git/WaifuGrammar/WaifuGrammar/grammar/Waifu2.g4 by ANTLR 4.10.1
// 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
namespace waifu {
using Antlr4.Runtime.Misc;
using IErrorNode = Antlr4.Runtime.Tree.IErrorNode;
using ITerminalNode = Antlr4.Runtime.Tree.ITerminalNode;
using IToken = Antlr4.Runtime.IToken;
using ParserRuleContext = Antlr4.Runtime.ParserRuleContext;
/// <summary>
/// This class provides an empty implementation of <see cref="IWaifu2Listener"/>,
/// which can be extended to create a listener which only needs to handle a subset
/// of the available methods.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.10.1")]
[System.Diagnostics.DebuggerNonUserCode]
[System.CLSCompliant(false)]
public partial class Waifu2BaseListener : IWaifu2Listener {
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.waifuFile"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterWaifuFile([NotNull] Waifu2Parser.WaifuFileContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.waifuFile"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitWaifuFile([NotNull] Waifu2Parser.WaifuFileContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.type"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterType([NotNull] Waifu2Parser.TypeContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.type"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitType([NotNull] Waifu2Parser.TypeContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.sign"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterSign([NotNull] Waifu2Parser.SignContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.sign"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitSign([NotNull] Waifu2Parser.SignContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.operator"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterOperator([NotNull] Waifu2Parser.OperatorContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.operator"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitOperator([NotNull] Waifu2Parser.OperatorContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.literal"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterLiteral([NotNull] Waifu2Parser.LiteralContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.literal"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitLiteral([NotNull] Waifu2Parser.LiteralContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.func"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterFunc([NotNull] Waifu2Parser.FuncContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.func"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitFunc([NotNull] Waifu2Parser.FuncContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.functionDeclaration"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterFunctionDeclaration([NotNull] Waifu2Parser.FunctionDeclarationContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.functionDeclaration"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitFunctionDeclaration([NotNull] Waifu2Parser.FunctionDeclarationContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.functionParam"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterFunctionParam([NotNull] Waifu2Parser.FunctionParamContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.functionParam"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitFunctionParam([NotNull] Waifu2Parser.FunctionParamContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.functionBody"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterFunctionBody([NotNull] Waifu2Parser.FunctionBodyContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.functionBody"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitFunctionBody([NotNull] Waifu2Parser.FunctionBodyContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.expr"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterExpr([NotNull] Waifu2Parser.ExprContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.expr"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitExpr([NotNull] Waifu2Parser.ExprContext context) { }
/// <inheritdoc/>
/// <remarks>The default implementation does nothing.</remarks>
public virtual void EnterEveryRule([NotNull] ParserRuleContext context) { }
/// <inheritdoc/>
/// <remarks>The default implementation does nothing.</remarks>
public virtual void ExitEveryRule([NotNull] ParserRuleContext context) { }
/// <inheritdoc/>
/// <remarks>The default implementation does nothing.</remarks>
public virtual void VisitTerminal([NotNull] ITerminalNode node) { }
/// <inheritdoc/>
/// <remarks>The default implementation does nothing.</remarks>
public virtual void VisitErrorNode([NotNull] IErrorNode node) { }
}
} // namespace waifu

View File

@ -0,0 +1,139 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.10.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from /home/immi/git/WaifuGrammar/WaifuGrammar/grammar/Waifu2.g4 by ANTLR 4.10.1
// 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
namespace waifu {
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="IWaifu2Visitor{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.10.1")]
[System.Diagnostics.DebuggerNonUserCode]
[System.CLSCompliant(false)]
public partial class Waifu2BaseVisitor<Result> : AbstractParseTreeVisitor<Result>, IWaifu2Visitor<Result> {
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.waifuFile"/>.
/// <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 VisitWaifuFile([NotNull] Waifu2Parser.WaifuFileContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.type"/>.
/// <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 VisitType([NotNull] Waifu2Parser.TypeContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.sign"/>.
/// <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 VisitSign([NotNull] Waifu2Parser.SignContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.operator"/>.
/// <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 VisitOperator([NotNull] Waifu2Parser.OperatorContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.literal"/>.
/// <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 VisitLiteral([NotNull] Waifu2Parser.LiteralContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.func"/>.
/// <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 VisitFunc([NotNull] Waifu2Parser.FuncContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.functionDeclaration"/>.
/// <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 VisitFunctionDeclaration([NotNull] Waifu2Parser.FunctionDeclarationContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.functionParam"/>.
/// <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 VisitFunctionParam([NotNull] Waifu2Parser.FunctionParamContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.functionBody"/>.
/// <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 VisitFunctionBody([NotNull] Waifu2Parser.FunctionBodyContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.expr"/>.
/// <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 VisitExpr([NotNull] Waifu2Parser.ExprContext context) { return VisitChildren(context); }
}
} // namespace waifu

View File

@ -0,0 +1,151 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.10.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from /home/immi/git/WaifuGrammar/WaifuGrammar/grammar/Waifu2.g4 by ANTLR 4.10.1
// 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
namespace waifu {
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.10.1")]
[System.CLSCompliant(false)]
public partial class Waifu2Lexer : Lexer {
protected static DFA[] decisionToDFA;
protected static PredictionContextCache sharedContextCache = new PredictionContextCache();
public const int
T__0=1, WS=2, NL=3, ID=4, MultiLineComment=5, SingleLineComment=6, MULT=7,
MOD=8, DIV=9, ADD=10, SUB=11, ASSIGN=12, LPAREN=13, RPAREN=14, COLON=15,
INT=16, DEC=17, BOOL=18, STR=19;
public static string[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
public static string[] modeNames = {
"DEFAULT_MODE"
};
public static readonly string[] ruleNames = {
"T__0", "WS", "NL", "ID", "Letter", "MultiLineComment", "SingleLineComment",
"MULT", "MOD", "DIV", "ADD", "SUB", "ASSIGN", "LPAREN", "RPAREN", "COLON",
"DEC_DIGIT", "INT", "DEC", "BOOL", "STR"
};
public Waifu2Lexer(ICharStream input)
: this(input, Console.Out, Console.Error) { }
public Waifu2Lexer(ICharStream input, TextWriter output, TextWriter errorOutput)
: base(input, output, errorOutput)
{
Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
}
private static readonly string[] _LiteralNames = {
null, "'#'", "' '", "'\\u000A'", null, null, null, "'*'", "'%'", "'/'",
"'+'", "'-'", "'<-'", "'('", "')'", "':'"
};
private static readonly string[] _SymbolicNames = {
null, null, "WS", "NL", "ID", "MultiLineComment", "SingleLineComment",
"MULT", "MOD", "DIV", "ADD", "SUB", "ASSIGN", "LPAREN", "RPAREN", "COLON",
"INT", "DEC", "BOOL", "STR"
};
public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);
[NotNull]
public override IVocabulary Vocabulary
{
get
{
return DefaultVocabulary;
}
}
public override string GrammarFileName { get { return "Waifu2.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 Waifu2Lexer() {
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,19,136,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,1,0,1,
0,1,1,1,1,1,2,1,2,1,3,1,3,3,3,52,8,3,1,3,1,3,1,3,5,3,57,8,3,10,3,12,3,
60,9,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,5,5,69,8,5,10,5,12,5,72,9,5,1,5,1,5,
1,5,1,5,1,5,1,6,1,6,5,6,81,8,6,10,6,12,6,84,9,6,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,12,1,13,1,13,1,14,1,14,1,15,
1,15,1,16,1,16,1,17,4,17,110,8,17,11,17,12,17,111,1,18,5,18,115,8,18,10,
18,12,18,118,9,18,1,18,1,18,4,18,122,8,18,11,18,12,18,123,1,19,1,19,1,
20,1,20,5,20,130,8,20,10,20,12,20,133,9,20,1,20,1,20,2,70,131,0,21,1,1,
3,2,5,3,7,4,9,0,11,5,13,6,15,7,17,8,19,9,21,10,23,11,25,12,27,13,29,14,
31,15,33,0,35,16,37,17,39,18,41,19,1,0,4,2,0,65,90,97,122,1,0,10,10,1,
0,48,57,1,0,48,49,144,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,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,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,1,43,1,0,0,0,3,45,
1,0,0,0,5,47,1,0,0,0,7,51,1,0,0,0,9,61,1,0,0,0,11,63,1,0,0,0,13,78,1,0,
0,0,15,87,1,0,0,0,17,89,1,0,0,0,19,91,1,0,0,0,21,93,1,0,0,0,23,95,1,0,
0,0,25,97,1,0,0,0,27,100,1,0,0,0,29,102,1,0,0,0,31,104,1,0,0,0,33,106,
1,0,0,0,35,109,1,0,0,0,37,116,1,0,0,0,39,125,1,0,0,0,41,127,1,0,0,0,43,
44,5,35,0,0,44,2,1,0,0,0,45,46,5,32,0,0,46,4,1,0,0,0,47,48,5,10,0,0,48,
6,1,0,0,0,49,52,3,9,4,0,50,52,5,95,0,0,51,49,1,0,0,0,51,50,1,0,0,0,52,
58,1,0,0,0,53,57,3,9,4,0,54,57,5,95,0,0,55,57,3,33,16,0,56,53,1,0,0,0,
56,54,1,0,0,0,56,55,1,0,0,0,57,60,1,0,0,0,58,56,1,0,0,0,58,59,1,0,0,0,
59,8,1,0,0,0,60,58,1,0,0,0,61,62,7,0,0,0,62,10,1,0,0,0,63,64,5,35,0,0,
64,65,5,35,0,0,65,70,1,0,0,0,66,69,3,11,5,0,67,69,9,0,0,0,68,66,1,0,0,
0,68,67,1,0,0,0,69,72,1,0,0,0,70,71,1,0,0,0,70,68,1,0,0,0,71,73,1,0,0,
0,72,70,1,0,0,0,73,74,5,35,0,0,74,75,5,35,0,0,75,76,1,0,0,0,76,77,6,5,
0,0,77,12,1,0,0,0,78,82,5,35,0,0,79,81,8,1,0,0,80,79,1,0,0,0,81,84,1,0,
0,0,82,80,1,0,0,0,82,83,1,0,0,0,83,85,1,0,0,0,84,82,1,0,0,0,85,86,6,6,
0,0,86,14,1,0,0,0,87,88,5,42,0,0,88,16,1,0,0,0,89,90,5,37,0,0,90,18,1,
0,0,0,91,92,5,47,0,0,92,20,1,0,0,0,93,94,5,43,0,0,94,22,1,0,0,0,95,96,
5,45,0,0,96,24,1,0,0,0,97,98,5,60,0,0,98,99,5,45,0,0,99,26,1,0,0,0,100,
101,5,40,0,0,101,28,1,0,0,0,102,103,5,41,0,0,103,30,1,0,0,0,104,105,5,
58,0,0,105,32,1,0,0,0,106,107,7,2,0,0,107,34,1,0,0,0,108,110,3,33,16,0,
109,108,1,0,0,0,110,111,1,0,0,0,111,109,1,0,0,0,111,112,1,0,0,0,112,36,
1,0,0,0,113,115,3,33,16,0,114,113,1,0,0,0,115,118,1,0,0,0,116,114,1,0,
0,0,116,117,1,0,0,0,117,119,1,0,0,0,118,116,1,0,0,0,119,121,5,46,0,0,120,
122,3,33,16,0,121,120,1,0,0,0,122,123,1,0,0,0,123,121,1,0,0,0,123,124,
1,0,0,0,124,38,1,0,0,0,125,126,7,3,0,0,126,40,1,0,0,0,127,131,5,39,0,0,
128,130,9,0,0,0,129,128,1,0,0,0,130,133,1,0,0,0,131,132,1,0,0,0,131,129,
1,0,0,0,132,134,1,0,0,0,133,131,1,0,0,0,134,135,5,39,0,0,135,42,1,0,0,
0,11,0,51,56,58,68,70,82,111,116,123,131,1,0,1,0
};
public static readonly ATN _ATN =
new ATNDeserializer().Deserialize(_serializedATN);
}
} // namespace waifu

View File

@ -0,0 +1,76 @@
token literal names:
null
'#'
' '
'\u000A'
null
null
null
'*'
'%'
'/'
'+'
'-'
'<-'
'('
')'
':'
null
null
null
null
token symbolic names:
null
null
WS
NL
ID
MultiLineComment
SingleLineComment
MULT
MOD
DIV
ADD
SUB
ASSIGN
LPAREN
RPAREN
COLON
INT
DEC
BOOL
STR
rule names:
T__0
WS
NL
ID
Letter
MultiLineComment
SingleLineComment
MULT
MOD
DIV
ADD
SUB
ASSIGN
LPAREN
RPAREN
COLON
DEC_DIGIT
INT
DEC
BOOL
STR
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[4, 0, 19, 136, 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, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 52, 8, 3, 1, 3, 1, 3, 1, 3, 5, 3, 57, 8, 3, 10, 3, 12, 3, 60, 9, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 69, 8, 5, 10, 5, 12, 5, 72, 9, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 5, 6, 81, 8, 6, 10, 6, 12, 6, 84, 9, 6, 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, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 4, 17, 110, 8, 17, 11, 17, 12, 17, 111, 1, 18, 5, 18, 115, 8, 18, 10, 18, 12, 18, 118, 9, 18, 1, 18, 1, 18, 4, 18, 122, 8, 18, 11, 18, 12, 18, 123, 1, 19, 1, 19, 1, 20, 1, 20, 5, 20, 130, 8, 20, 10, 20, 12, 20, 133, 9, 20, 1, 20, 1, 20, 2, 70, 131, 0, 21, 1, 1, 3, 2, 5, 3, 7, 4, 9, 0, 11, 5, 13, 6, 15, 7, 17, 8, 19, 9, 21, 10, 23, 11, 25, 12, 27, 13, 29, 14, 31, 15, 33, 0, 35, 16, 37, 17, 39, 18, 41, 19, 1, 0, 4, 2, 0, 65, 90, 97, 122, 1, 0, 10, 10, 1, 0, 48, 57, 1, 0, 48, 49, 144, 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, 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, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 43, 1, 0, 0, 0, 3, 45, 1, 0, 0, 0, 5, 47, 1, 0, 0, 0, 7, 51, 1, 0, 0, 0, 9, 61, 1, 0, 0, 0, 11, 63, 1, 0, 0, 0, 13, 78, 1, 0, 0, 0, 15, 87, 1, 0, 0, 0, 17, 89, 1, 0, 0, 0, 19, 91, 1, 0, 0, 0, 21, 93, 1, 0, 0, 0, 23, 95, 1, 0, 0, 0, 25, 97, 1, 0, 0, 0, 27, 100, 1, 0, 0, 0, 29, 102, 1, 0, 0, 0, 31, 104, 1, 0, 0, 0, 33, 106, 1, 0, 0, 0, 35, 109, 1, 0, 0, 0, 37, 116, 1, 0, 0, 0, 39, 125, 1, 0, 0, 0, 41, 127, 1, 0, 0, 0, 43, 44, 5, 35, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 32, 0, 0, 46, 4, 1, 0, 0, 0, 47, 48, 5, 10, 0, 0, 48, 6, 1, 0, 0, 0, 49, 52, 3, 9, 4, 0, 50, 52, 5, 95, 0, 0, 51, 49, 1, 0, 0, 0, 51, 50, 1, 0, 0, 0, 52, 58, 1, 0, 0, 0, 53, 57, 3, 9, 4, 0, 54, 57, 5, 95, 0, 0, 55, 57, 3, 33, 16, 0, 56, 53, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 8, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 62, 7, 0, 0, 0, 62, 10, 1, 0, 0, 0, 63, 64, 5, 35, 0, 0, 64, 65, 5, 35, 0, 0, 65, 70, 1, 0, 0, 0, 66, 69, 3, 11, 5, 0, 67, 69, 9, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 72, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 73, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 73, 74, 5, 35, 0, 0, 74, 75, 5, 35, 0, 0, 75, 76, 1, 0, 0, 0, 76, 77, 6, 5, 0, 0, 77, 12, 1, 0, 0, 0, 78, 82, 5, 35, 0, 0, 79, 81, 8, 1, 0, 0, 80, 79, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 85, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 85, 86, 6, 6, 0, 0, 86, 14, 1, 0, 0, 0, 87, 88, 5, 42, 0, 0, 88, 16, 1, 0, 0, 0, 89, 90, 5, 37, 0, 0, 90, 18, 1, 0, 0, 0, 91, 92, 5, 47, 0, 0, 92, 20, 1, 0, 0, 0, 93, 94, 5, 43, 0, 0, 94, 22, 1, 0, 0, 0, 95, 96, 5, 45, 0, 0, 96, 24, 1, 0, 0, 0, 97, 98, 5, 60, 0, 0, 98, 99, 5, 45, 0, 0, 99, 26, 1, 0, 0, 0, 100, 101, 5, 40, 0, 0, 101, 28, 1, 0, 0, 0, 102, 103, 5, 41, 0, 0, 103, 30, 1, 0, 0, 0, 104, 105, 5, 58, 0, 0, 105, 32, 1, 0, 0, 0, 106, 107, 7, 2, 0, 0, 107, 34, 1, 0, 0, 0, 108, 110, 3, 33, 16, 0, 109, 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 109, 1, 0, 0, 0, 111, 112, 1, 0, 0, 0, 112, 36, 1, 0, 0, 0, 113, 115, 3, 33, 16, 0, 114, 113, 1, 0, 0, 0, 115, 118, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 119, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 119, 121, 5, 46, 0, 0, 120, 122, 3, 33, 16, 0, 121, 120, 1, 0, 0, 0, 122, 123, 1, 0, 0, 0, 123, 121, 1, 0, 0, 0, 123, 124, 1, 0, 0, 0, 124, 38, 1, 0, 0, 0, 125, 126, 7, 3, 0, 0, 126, 40, 1, 0, 0, 0, 127, 131, 5, 39, 0, 0, 128, 130, 9, 0, 0, 0, 129, 128, 1, 0, 0, 0, 130, 133, 1, 0, 0, 0, 131, 132, 1, 0, 0, 0, 131, 129, 1, 0, 0, 0, 132, 134, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 134, 135, 5, 39, 0, 0, 135, 42, 1, 0, 0, 0, 11, 0, 51, 56, 58, 68, 70, 82, 111, 116, 123, 131, 1, 0, 1, 0]

View File

@ -0,0 +1,31 @@
T__0=1
WS=2
NL=3
ID=4
MultiLineComment=5
SingleLineComment=6
MULT=7
MOD=8
DIV=9
ADD=10
SUB=11
ASSIGN=12
LPAREN=13
RPAREN=14
COLON=15
INT=16
DEC=17
BOOL=18
STR=19
'#'=1
' '=2
'\u000A'=3
'*'=7
'%'=8
'/'=9
'+'=10
'-'=11
'<-'=12
'('=13
')'=14
':'=15

View File

@ -0,0 +1,135 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.10.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from /home/immi/git/WaifuGrammar/WaifuGrammar/grammar/Waifu2.g4 by ANTLR 4.10.1
// 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
namespace waifu {
using Antlr4.Runtime.Misc;
using IParseTreeListener = Antlr4.Runtime.Tree.IParseTreeListener;
using IToken = Antlr4.Runtime.IToken;
/// <summary>
/// This interface defines a complete listener for a parse tree produced by
/// <see cref="Waifu2Parser"/>.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.10.1")]
[System.CLSCompliant(false)]
public interface IWaifu2Listener : IParseTreeListener {
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.waifuFile"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterWaifuFile([NotNull] Waifu2Parser.WaifuFileContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.waifuFile"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitWaifuFile([NotNull] Waifu2Parser.WaifuFileContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.type"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterType([NotNull] Waifu2Parser.TypeContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.type"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitType([NotNull] Waifu2Parser.TypeContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.sign"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterSign([NotNull] Waifu2Parser.SignContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.sign"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitSign([NotNull] Waifu2Parser.SignContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.operator"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterOperator([NotNull] Waifu2Parser.OperatorContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.operator"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitOperator([NotNull] Waifu2Parser.OperatorContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.literal"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterLiteral([NotNull] Waifu2Parser.LiteralContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.literal"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitLiteral([NotNull] Waifu2Parser.LiteralContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.func"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterFunc([NotNull] Waifu2Parser.FuncContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.func"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitFunc([NotNull] Waifu2Parser.FuncContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.functionDeclaration"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterFunctionDeclaration([NotNull] Waifu2Parser.FunctionDeclarationContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.functionDeclaration"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitFunctionDeclaration([NotNull] Waifu2Parser.FunctionDeclarationContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.functionParam"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterFunctionParam([NotNull] Waifu2Parser.FunctionParamContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.functionParam"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitFunctionParam([NotNull] Waifu2Parser.FunctionParamContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.functionBody"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterFunctionBody([NotNull] Waifu2Parser.FunctionBodyContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.functionBody"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitFunctionBody([NotNull] Waifu2Parser.FunctionBodyContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="Waifu2Parser.expr"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterExpr([NotNull] Waifu2Parser.ExprContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="Waifu2Parser.expr"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitExpr([NotNull] Waifu2Parser.ExprContext context);
}
} // namespace waifu

View File

@ -0,0 +1,899 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.10.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from /home/immi/git/WaifuGrammar/WaifuGrammar/grammar/Waifu2.g4 by ANTLR 4.10.1
// 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
namespace waifu {
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.10.1")]
[System.CLSCompliant(false)]
public partial class Waifu2Parser : Parser {
protected static DFA[] decisionToDFA;
protected static PredictionContextCache sharedContextCache = new PredictionContextCache();
public const int
T__0=1, WS=2, NL=3, ID=4, MultiLineComment=5, SingleLineComment=6, MULT=7,
MOD=8, DIV=9, ADD=10, SUB=11, ASSIGN=12, LPAREN=13, RPAREN=14, COLON=15,
INT=16, DEC=17, BOOL=18, STR=19;
public const int
RULE_waifuFile = 0, RULE_type = 1, RULE_sign = 2, RULE_operator = 3, RULE_literal = 4,
RULE_func = 5, RULE_functionDeclaration = 6, RULE_functionParam = 7, RULE_functionBody = 8,
RULE_expr = 9;
public static readonly string[] ruleNames = {
"waifuFile", "type", "sign", "operator", "literal", "func", "functionDeclaration",
"functionParam", "functionBody", "expr"
};
private static readonly string[] _LiteralNames = {
null, "'#'", "' '", "'\\u000A'", null, null, null, "'*'", "'%'", "'/'",
"'+'", "'-'", "'<-'", "'('", "')'", "':'"
};
private static readonly string[] _SymbolicNames = {
null, null, "WS", "NL", "ID", "MultiLineComment", "SingleLineComment",
"MULT", "MOD", "DIV", "ADD", "SUB", "ASSIGN", "LPAREN", "RPAREN", "COLON",
"INT", "DEC", "BOOL", "STR"
};
public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);
[NotNull]
public override IVocabulary Vocabulary
{
get
{
return DefaultVocabulary;
}
}
public override string GrammarFileName { get { return "Waifu2.g4"; } }
public override string[] RuleNames { get { return ruleNames; } }
public override int[] SerializedAtn { get { return _serializedATN; } }
static Waifu2Parser() {
decisionToDFA = new DFA[_ATN.NumberOfDecisions];
for (int i = 0; i < _ATN.NumberOfDecisions; i++) {
decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i);
}
}
public Waifu2Parser(ITokenStream input) : this(input, Console.Out, Console.Error) { }
public Waifu2Parser(ITokenStream input, TextWriter output, TextWriter errorOutput)
: base(input, output, errorOutput)
{
Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache);
}
public partial class WaifuFileContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode Eof() { return GetToken(Waifu2Parser.Eof, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] NL() { return GetTokens(Waifu2Parser.NL); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL(int i) {
return GetToken(Waifu2Parser.NL, i);
}
[System.Diagnostics.DebuggerNonUserCode] public FuncContext[] func() {
return GetRuleContexts<FuncContext>();
}
[System.Diagnostics.DebuggerNonUserCode] public FuncContext func(int i) {
return GetRuleContext<FuncContext>(i);
}
public WaifuFileContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_waifuFile; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterWaifuFile(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitWaifuFile(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitWaifuFile(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public WaifuFileContext waifuFile() {
WaifuFileContext _localctx = new WaifuFileContext(Context, State);
EnterRule(_localctx, 0, RULE_waifuFile);
int _la;
try {
int _alt;
EnterOuterAlt(_localctx, 1);
{
State = 23;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,0,Context);
while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
State = 20;
Match(NL);
}
}
}
State = 25;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,0,Context);
}
State = 29;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
while (_la==LPAREN) {
{
{
State = 26;
func();
}
}
State = 31;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
}
State = 35;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
while (_la==NL) {
{
{
State = 32;
Match(NL);
}
}
State = 37;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
}
State = 38;
Match(Eof);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class TypeContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode COLON() { return GetToken(Waifu2Parser.COLON, 0); }
public TypeContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_type; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterType(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitType(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitType(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public TypeContext type() {
TypeContext _localctx = new TypeContext(Context, State);
EnterRule(_localctx, 2, RULE_type);
try {
EnterOuterAlt(_localctx, 1);
{
State = 40;
Match(COLON);
State = 41;
Match(T__0);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class SignContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ADD() { return GetToken(Waifu2Parser.ADD, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode SUB() { return GetToken(Waifu2Parser.SUB, 0); }
public SignContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_sign; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterSign(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitSign(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitSign(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public SignContext sign() {
SignContext _localctx = new SignContext(Context, State);
EnterRule(_localctx, 4, RULE_sign);
int _la;
try {
EnterOuterAlt(_localctx, 1);
{
State = 43;
_la = TokenStream.LA(1);
if ( !(_la==ADD || _la==SUB) ) {
ErrorHandler.RecoverInline(this);
}
else {
ErrorHandler.ReportMatch(this);
Consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class OperatorContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode SUB() { return GetToken(Waifu2Parser.SUB, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ADD() { return GetToken(Waifu2Parser.ADD, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode MULT() { return GetToken(Waifu2Parser.MULT, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DIV() { return GetToken(Waifu2Parser.DIV, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode MOD() { return GetToken(Waifu2Parser.MOD, 0); }
public OperatorContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_operator; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterOperator(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitOperator(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitOperator(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public OperatorContext @operator() {
OperatorContext _localctx = new OperatorContext(Context, State);
EnterRule(_localctx, 6, RULE_operator);
int _la;
try {
EnterOuterAlt(_localctx, 1);
{
State = 45;
_la = TokenStream.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << MULT) | (1L << MOD) | (1L << DIV) | (1L << ADD) | (1L << SUB))) != 0)) ) {
ErrorHandler.RecoverInline(this);
}
else {
ErrorHandler.ReportMatch(this);
Consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class LiteralContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode INT() { return GetToken(Waifu2Parser.INT, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(Waifu2Parser.DEC, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode BOOL() { return GetToken(Waifu2Parser.BOOL, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode STR() { return GetToken(Waifu2Parser.STR, 0); }
public LiteralContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_literal; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterLiteral(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitLiteral(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitLiteral(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public LiteralContext literal() {
LiteralContext _localctx = new LiteralContext(Context, State);
EnterRule(_localctx, 8, RULE_literal);
int _la;
try {
EnterOuterAlt(_localctx, 1);
{
State = 47;
_la = TokenStream.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << INT) | (1L << DEC) | (1L << BOOL) | (1L << STR))) != 0)) ) {
ErrorHandler.RecoverInline(this);
}
else {
ErrorHandler.ReportMatch(this);
Consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class FuncContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public FunctionDeclarationContext functionDeclaration() {
return GetRuleContext<FunctionDeclarationContext>(0);
}
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(Waifu2Parser.NL, 0); }
[System.Diagnostics.DebuggerNonUserCode] public FunctionBodyContext functionBody() {
return GetRuleContext<FunctionBodyContext>(0);
}
public FuncContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_func; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterFunc(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitFunc(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitFunc(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public FuncContext func() {
FuncContext _localctx = new FuncContext(Context, State);
EnterRule(_localctx, 10, RULE_func);
try {
EnterOuterAlt(_localctx, 1);
{
State = 49;
functionDeclaration();
State = 50;
Match(NL);
State = 51;
functionBody();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class FunctionDeclarationContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode LPAREN() { return GetToken(Waifu2Parser.LPAREN, 0); }
[System.Diagnostics.DebuggerNonUserCode] public FunctionParamContext functionParam() {
return GetRuleContext<FunctionParamContext>(0);
}
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode RPAREN() { return GetToken(Waifu2Parser.RPAREN, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] WS() { return GetTokens(Waifu2Parser.WS); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode WS(int i) {
return GetToken(Waifu2Parser.WS, i);
}
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(Waifu2Parser.ID, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(Waifu2Parser.NL, 0); }
[System.Diagnostics.DebuggerNonUserCode] public TypeContext type() {
return GetRuleContext<TypeContext>(0);
}
public FunctionDeclarationContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_functionDeclaration; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterFunctionDeclaration(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitFunctionDeclaration(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitFunctionDeclaration(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public FunctionDeclarationContext functionDeclaration() {
FunctionDeclarationContext _localctx = new FunctionDeclarationContext(Context, State);
EnterRule(_localctx, 12, RULE_functionDeclaration);
int _la;
try {
EnterOuterAlt(_localctx, 1);
{
State = 53;
Match(LPAREN);
State = 54;
functionParam();
State = 55;
Match(RPAREN);
State = 56;
Match(WS);
State = 58;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
if (_la==COLON) {
{
State = 57;
type();
}
}
State = 60;
Match(WS);
State = 61;
Match(ID);
State = 62;
Match(NL);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class FunctionParamContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(Waifu2Parser.ID, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode WS() { return GetToken(Waifu2Parser.WS, 0); }
[System.Diagnostics.DebuggerNonUserCode] public TypeContext type() {
return GetRuleContext<TypeContext>(0);
}
public FunctionParamContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_functionParam; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterFunctionParam(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitFunctionParam(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitFunctionParam(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public FunctionParamContext functionParam() {
FunctionParamContext _localctx = new FunctionParamContext(Context, State);
EnterRule(_localctx, 14, RULE_functionParam);
try {
EnterOuterAlt(_localctx, 1);
{
State = 64;
Match(ID);
State = 65;
Match(WS);
State = 66;
type();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class FunctionBodyContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ExprContext[] expr() {
return GetRuleContexts<ExprContext>();
}
[System.Diagnostics.DebuggerNonUserCode] public ExprContext expr(int i) {
return GetRuleContext<ExprContext>(i);
}
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] NL() { return GetTokens(Waifu2Parser.NL); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL(int i) {
return GetToken(Waifu2Parser.NL, i);
}
public FunctionBodyContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_functionBody; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterFunctionBody(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitFunctionBody(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitFunctionBody(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public FunctionBodyContext functionBody() {
FunctionBodyContext _localctx = new FunctionBodyContext(Context, State);
EnterRule(_localctx, 16, RULE_functionBody);
int _la;
try {
int _alt;
EnterOuterAlt(_localctx, 1);
{
State = 74;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
do {
{
{
State = 68;
expr(0);
State = 70;
ErrorHandler.Sync(this);
_alt = 1;
do {
switch (_alt) {
case 1:
{
{
State = 69;
Match(NL);
}
}
break;
default:
throw new NoViableAltException(this);
}
State = 72;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,4,Context);
} while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER );
}
}
State = 76;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
} while ( (((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << ID) | (1L << MultiLineComment) | (1L << SingleLineComment) | (1L << ADD) | (1L << SUB) | (1L << INT) | (1L << DEC) | (1L << BOOL) | (1L << STR))) != 0) );
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
ExitRule();
}
return _localctx;
}
public partial class ExprContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public LiteralContext literal() {
return GetRuleContext<LiteralContext>(0);
}
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(Waifu2Parser.ID, 0); }
[System.Diagnostics.DebuggerNonUserCode] public SignContext sign() {
return GetRuleContext<SignContext>(0);
}
[System.Diagnostics.DebuggerNonUserCode] public ExprContext[] expr() {
return GetRuleContexts<ExprContext>();
}
[System.Diagnostics.DebuggerNonUserCode] public ExprContext expr(int i) {
return GetRuleContext<ExprContext>(i);
}
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode MultiLineComment() { return GetToken(Waifu2Parser.MultiLineComment, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode SingleLineComment() { return GetToken(Waifu2Parser.SingleLineComment, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] WS() { return GetTokens(Waifu2Parser.WS); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode WS(int i) {
return GetToken(Waifu2Parser.WS, i);
}
[System.Diagnostics.DebuggerNonUserCode] public OperatorContext @operator() {
return GetRuleContext<OperatorContext>(0);
}
public ExprContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
}
public override int RuleIndex { get { return RULE_expr; } }
[System.Diagnostics.DebuggerNonUserCode]
public override void EnterRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.EnterExpr(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override void ExitRule(IParseTreeListener listener) {
IWaifu2Listener typedListener = listener as IWaifu2Listener;
if (typedListener != null) typedListener.ExitExpr(this);
}
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IWaifu2Visitor<TResult> typedVisitor = visitor as IWaifu2Visitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitExpr(this);
else return visitor.VisitChildren(this);
}
}
[RuleVersion(0)]
public ExprContext expr() {
return expr(0);
}
private ExprContext expr(int _p) {
ParserRuleContext _parentctx = Context;
int _parentState = State;
ExprContext _localctx = new ExprContext(Context, _parentState);
ExprContext _prevctx = _localctx;
int _startState = 18;
EnterRecursionRule(_localctx, 18, RULE_expr, _p);
try {
int _alt;
EnterOuterAlt(_localctx, 1);
{
State = 86;
ErrorHandler.Sync(this);
switch (TokenStream.LA(1)) {
case INT:
case DEC:
case BOOL:
case STR:
{
State = 79;
literal();
}
break;
case ID:
{
State = 80;
Match(ID);
}
break;
case ADD:
case SUB:
{
State = 81;
sign();
State = 82;
expr(3);
}
break;
case MultiLineComment:
{
State = 84;
Match(MultiLineComment);
}
break;
case SingleLineComment:
{
State = 85;
Match(SingleLineComment);
}
break;
default:
throw new NoViableAltException(this);
}
Context.Stop = TokenStream.LT(-1);
State = 96;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,7,Context);
while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( ParseListeners!=null )
TriggerExitRuleEvent();
_prevctx = _localctx;
{
{
_localctx = new ExprContext(_parentctx, _parentState);
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 88;
if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)");
State = 89;
Match(WS);
State = 90;
@operator();
State = 91;
Match(WS);
State = 92;
expr(5);
}
}
}
State = 98;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,7,Context);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
ErrorHandler.ReportError(this, re);
ErrorHandler.Recover(this, re);
}
finally {
UnrollRecursionContexts(_parentctx);
}
return _localctx;
}
public override bool Sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
case 9: return expr_sempred((ExprContext)_localctx, predIndex);
}
return true;
}
private bool expr_sempred(ExprContext _localctx, int predIndex) {
switch (predIndex) {
case 0: return Precpred(Context, 4);
}
return true;
}
private static int[] _serializedATN = {
4,1,19,100,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,
7,7,2,8,7,8,2,9,7,9,1,0,5,0,22,8,0,10,0,12,0,25,9,0,1,0,5,0,28,8,0,10,
0,12,0,31,9,0,1,0,5,0,34,8,0,10,0,12,0,37,9,0,1,0,1,0,1,1,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,6,1,6,1,6,1,6,1,6,3,6,59,8,6,1,6,
1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,4,8,71,8,8,11,8,12,8,72,4,8,75,8,8,
11,8,12,8,76,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,3,9,87,8,9,1,9,1,9,1,9,1,
9,1,9,1,9,5,9,95,8,9,10,9,12,9,98,9,9,1,9,0,1,18,10,0,2,4,6,8,10,12,14,
16,18,0,3,1,0,10,11,1,0,7,11,1,0,16,19,100,0,23,1,0,0,0,2,40,1,0,0,0,4,
43,1,0,0,0,6,45,1,0,0,0,8,47,1,0,0,0,10,49,1,0,0,0,12,53,1,0,0,0,14,64,
1,0,0,0,16,74,1,0,0,0,18,86,1,0,0,0,20,22,5,3,0,0,21,20,1,0,0,0,22,25,
1,0,0,0,23,21,1,0,0,0,23,24,1,0,0,0,24,29,1,0,0,0,25,23,1,0,0,0,26,28,
3,10,5,0,27,26,1,0,0,0,28,31,1,0,0,0,29,27,1,0,0,0,29,30,1,0,0,0,30,35,
1,0,0,0,31,29,1,0,0,0,32,34,5,3,0,0,33,32,1,0,0,0,34,37,1,0,0,0,35,33,
1,0,0,0,35,36,1,0,0,0,36,38,1,0,0,0,37,35,1,0,0,0,38,39,5,0,0,1,39,1,1,
0,0,0,40,41,5,15,0,0,41,42,5,1,0,0,42,3,1,0,0,0,43,44,7,0,0,0,44,5,1,0,
0,0,45,46,7,1,0,0,46,7,1,0,0,0,47,48,7,2,0,0,48,9,1,0,0,0,49,50,3,12,6,
0,50,51,5,3,0,0,51,52,3,16,8,0,52,11,1,0,0,0,53,54,5,13,0,0,54,55,3,14,
7,0,55,56,5,14,0,0,56,58,5,2,0,0,57,59,3,2,1,0,58,57,1,0,0,0,58,59,1,0,
0,0,59,60,1,0,0,0,60,61,5,2,0,0,61,62,5,4,0,0,62,63,5,3,0,0,63,13,1,0,
0,0,64,65,5,4,0,0,65,66,5,2,0,0,66,67,3,2,1,0,67,15,1,0,0,0,68,70,3,18,
9,0,69,71,5,3,0,0,70,69,1,0,0,0,71,72,1,0,0,0,72,70,1,0,0,0,72,73,1,0,
0,0,73,75,1,0,0,0,74,68,1,0,0,0,75,76,1,0,0,0,76,74,1,0,0,0,76,77,1,0,
0,0,77,17,1,0,0,0,78,79,6,9,-1,0,79,87,3,8,4,0,80,87,5,4,0,0,81,82,3,4,
2,0,82,83,3,18,9,3,83,87,1,0,0,0,84,87,5,5,0,0,85,87,5,6,0,0,86,78,1,0,
0,0,86,80,1,0,0,0,86,81,1,0,0,0,86,84,1,0,0,0,86,85,1,0,0,0,87,96,1,0,
0,0,88,89,10,4,0,0,89,90,5,2,0,0,90,91,3,6,3,0,91,92,5,2,0,0,92,93,3,18,
9,5,93,95,1,0,0,0,94,88,1,0,0,0,95,98,1,0,0,0,96,94,1,0,0,0,96,97,1,0,
0,0,97,19,1,0,0,0,98,96,1,0,0,0,8,23,29,35,58,72,76,86,96
};
public static readonly ATN _ATN =
new ATNDeserializer().Deserialize(_serializedATN);
}
} // namespace waifu

View File

@ -0,0 +1,96 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.10.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from /home/immi/git/WaifuGrammar/WaifuGrammar/grammar/Waifu2.g4 by ANTLR 4.10.1
// 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
namespace waifu {
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="Waifu2Parser"/>.
/// </summary>
/// <typeparam name="Result">The return type of the visit operation.</typeparam>
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.10.1")]
[System.CLSCompliant(false)]
public interface IWaifu2Visitor<Result> : IParseTreeVisitor<Result> {
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.waifuFile"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitWaifuFile([NotNull] Waifu2Parser.WaifuFileContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.type"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitType([NotNull] Waifu2Parser.TypeContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.sign"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitSign([NotNull] Waifu2Parser.SignContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.operator"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitOperator([NotNull] Waifu2Parser.OperatorContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.literal"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitLiteral([NotNull] Waifu2Parser.LiteralContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.func"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitFunc([NotNull] Waifu2Parser.FuncContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.functionDeclaration"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitFunctionDeclaration([NotNull] Waifu2Parser.FunctionDeclarationContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.functionParam"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitFunctionParam([NotNull] Waifu2Parser.FunctionParamContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.functionBody"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitFunctionBody([NotNull] Waifu2Parser.FunctionBodyContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="Waifu2Parser.expr"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitExpr([NotNull] Waifu2Parser.ExprContext context);
}
} // namespace waifu