├── .gitattributes ├── .gitignore ├── LICENSE ├── Profane.Core ├── Profane.Core.csproj ├── Profane.g4 ├── Profane.tokens ├── ProfaneBaseListener.cs ├── ProfaneLexer.cs ├── ProfaneLexer.tokens ├── ProfaneListener.cs ├── ProfaneParser.cs ├── Transpile │ ├── ProfaneListener.cs │ ├── ProfaneTranspiler.cs │ └── TranspileResult.cs └── antlr-4.7-complete.jar ├── Profane.sln ├── Profane ├── Profane.csproj ├── ProfaneModule.cs ├── Program.cs ├── Startup.cs └── index.html └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | .vscode 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | *.VC.db 86 | *.VC.VC.opendb 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # DocProject is a documentation generator add-in 130 | DocProject/buildhelp/ 131 | DocProject/Help/*.HxT 132 | DocProject/Help/*.HxC 133 | DocProject/Help/*.hhc 134 | DocProject/Help/*.hhk 135 | DocProject/Help/*.hhp 136 | DocProject/Help/Html2 137 | DocProject/Help/html 138 | 139 | # Click-Once directory 140 | publish/ 141 | 142 | # Publish Web Output 143 | *.[Pp]ublish.xml 144 | *.azurePubxml 145 | # TODO: Comment the next line if you want to checkin your web deploy settings 146 | # but database connection strings (with potential passwords) will be unencrypted 147 | *.pubxml 148 | *.publishproj 149 | 150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 151 | # checkin your Azure Web App publish settings, but sensitive information contained 152 | # in these scripts will be unencrypted 153 | PublishScripts/ 154 | 155 | # NuGet Packages 156 | *.nupkg 157 | # The packages folder can be ignored because of Package Restore 158 | **/packages/* 159 | # except build/, which is used as an MSBuild target. 160 | !**/packages/build/ 161 | # Uncomment if necessary however generally it will be regenerated when needed 162 | #!**/packages/repositories.config 163 | # NuGet v3's project.json files produces more ignoreable files 164 | *.nuget.props 165 | *.nuget.targets 166 | 167 | # Microsoft Azure Build Output 168 | csx/ 169 | *.build.csdef 170 | 171 | # Microsoft Azure Emulator 172 | ecf/ 173 | rcf/ 174 | 175 | # Windows Store app package directories and files 176 | AppPackages/ 177 | BundleArtifacts/ 178 | Package.StoreAssociation.xml 179 | _pkginfo.txt 180 | 181 | # Visual Studio cache files 182 | # files ending in .cache can be ignored 183 | *.[Cc]ache 184 | # but keep track of directories ending in .cache 185 | !*.[Cc]ache/ 186 | 187 | # Others 188 | ClientBin/ 189 | ~$* 190 | *~ 191 | *.dbmdl 192 | *.dbproj.schemaview 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | .antlr 257 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 NerdCats 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Profane.Core/Profane.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Profane.Core/Profane.g4: -------------------------------------------------------------------------------- 1 | grammar Profane; 2 | 3 | compilationUnit: statement* EOF; 4 | 5 | statement: 6 | printstmt 7 | | assignstmt 8 | | ifstmt 9 | | setstmt; 10 | 11 | printstmt : 'dump' expr? SMILEY; 12 | assignstmt : 'derp' ID ASSIGN expr SMILEY; 13 | setstmt : ID ASSIGN expr SMILEY; 14 | 15 | ifstmt : 16 | conditionExpr '???' 17 | 'yep ->' 18 | statement* 19 | 'kbye'; 20 | 21 | 22 | conditionExpr: expr relop expr; 23 | expr: term | opExpression; 24 | opExpression: term op term; 25 | op: PLUS | ASSIGN | MINUS; 26 | relop: EQUAL | NOTEQUAL | GT | LT | GTEQ | LTEQ; 27 | 28 | term: ID | number | STRING; 29 | 30 | number: NUMBER; 31 | 32 | // Keywords 33 | ID: [a-zA-Z_] [a-zA-Z0-9_]*; 34 | SMILEY: ':)'; 35 | WS: [ \n\t\r]+ -> skip; 36 | 37 | PLUS :'+'; 38 | EQUAL : '===='; 39 | ASSIGN : '='; 40 | NOTEQUAL: '!!=='; 41 | MINUS : '-'; 42 | GT : '>'; 43 | LT : '<'; 44 | GTEQ : '>='; 45 | LTEQ : '<='; 46 | 47 | fragment INT: [0-9]+; 48 | NUMBER: INT ('.'(INT)?)?; 49 | STRING: '"' (~('\n' | '"'))* '"'; -------------------------------------------------------------------------------- /Profane.Core/Profane.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | ID=6 7 | SMILEY=7 8 | WS=8 9 | PLUS=9 10 | EQUAL=10 11 | ASSIGN=11 12 | NOTEQUAL=12 13 | MINUS=13 14 | GT=14 15 | LT=15 16 | GTEQ=16 17 | LTEQ=17 18 | NUMBER=18 19 | STRING=19 20 | 'dump'=1 21 | 'derp'=2 22 | '???'=3 23 | 'yep ->'=4 24 | 'kbye'=5 25 | ':)'=7 26 | '+'=9 27 | '===='=10 28 | '='=11 29 | '!!=='=12 30 | '-'=13 31 | '>'=14 32 | '<'=15 33 | '>='=16 34 | '<='=17 35 | -------------------------------------------------------------------------------- /Profane.Core/ProfaneBaseListener.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // ANTLR Version: 4.7 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | // Generated from Profane.g4 by ANTLR 4.7 12 | 13 | // Unreachable code detected 14 | #pragma warning disable 0162 15 | // The variable '...' is assigned but its value is never used 16 | #pragma warning disable 0219 17 | // Missing XML comment for publicly visible type or member '...' 18 | #pragma warning disable 1591 19 | // Ambiguous reference in cref attribute 20 | #pragma warning disable 419 21 | 22 | 23 | using Antlr4.Runtime.Misc; 24 | using IErrorNode = Antlr4.Runtime.Tree.IErrorNode; 25 | using ITerminalNode = Antlr4.Runtime.Tree.ITerminalNode; 26 | using IToken = Antlr4.Runtime.IToken; 27 | using ParserRuleContext = Antlr4.Runtime.ParserRuleContext; 28 | 29 | /// 30 | /// This class provides an empty implementation of , 31 | /// which can be extended to create a listener which only needs to handle a subset 32 | /// of the available methods. 33 | /// 34 | [System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.7")] 35 | [System.CLSCompliant(false)] 36 | public partial class ProfaneBaseListener : IProfaneListener { 37 | /// 38 | /// Enter a parse tree produced by . 39 | /// The default implementation does nothing. 40 | /// 41 | /// The parse tree. 42 | public virtual void EnterCompilationUnit([NotNull] ProfaneParser.CompilationUnitContext context) { } 43 | /// 44 | /// Exit a parse tree produced by . 45 | /// The default implementation does nothing. 46 | /// 47 | /// The parse tree. 48 | public virtual void ExitCompilationUnit([NotNull] ProfaneParser.CompilationUnitContext context) { } 49 | /// 50 | /// Enter a parse tree produced by . 51 | /// The default implementation does nothing. 52 | /// 53 | /// The parse tree. 54 | public virtual void EnterStatement([NotNull] ProfaneParser.StatementContext context) { } 55 | /// 56 | /// Exit a parse tree produced by . 57 | /// The default implementation does nothing. 58 | /// 59 | /// The parse tree. 60 | public virtual void ExitStatement([NotNull] ProfaneParser.StatementContext context) { } 61 | /// 62 | /// Enter a parse tree produced by . 63 | /// The default implementation does nothing. 64 | /// 65 | /// The parse tree. 66 | public virtual void EnterPrintstmt([NotNull] ProfaneParser.PrintstmtContext context) { } 67 | /// 68 | /// Exit a parse tree produced by . 69 | /// The default implementation does nothing. 70 | /// 71 | /// The parse tree. 72 | public virtual void ExitPrintstmt([NotNull] ProfaneParser.PrintstmtContext context) { } 73 | /// 74 | /// Enter a parse tree produced by . 75 | /// The default implementation does nothing. 76 | /// 77 | /// The parse tree. 78 | public virtual void EnterAssignstmt([NotNull] ProfaneParser.AssignstmtContext context) { } 79 | /// 80 | /// Exit a parse tree produced by . 81 | /// The default implementation does nothing. 82 | /// 83 | /// The parse tree. 84 | public virtual void ExitAssignstmt([NotNull] ProfaneParser.AssignstmtContext context) { } 85 | /// 86 | /// Enter a parse tree produced by . 87 | /// The default implementation does nothing. 88 | /// 89 | /// The parse tree. 90 | public virtual void EnterSetstmt([NotNull] ProfaneParser.SetstmtContext context) { } 91 | /// 92 | /// Exit a parse tree produced by . 93 | /// The default implementation does nothing. 94 | /// 95 | /// The parse tree. 96 | public virtual void ExitSetstmt([NotNull] ProfaneParser.SetstmtContext context) { } 97 | /// 98 | /// Enter a parse tree produced by . 99 | /// The default implementation does nothing. 100 | /// 101 | /// The parse tree. 102 | public virtual void EnterIfstmt([NotNull] ProfaneParser.IfstmtContext context) { } 103 | /// 104 | /// Exit a parse tree produced by . 105 | /// The default implementation does nothing. 106 | /// 107 | /// The parse tree. 108 | public virtual void ExitIfstmt([NotNull] ProfaneParser.IfstmtContext context) { } 109 | /// 110 | /// Enter a parse tree produced by . 111 | /// The default implementation does nothing. 112 | /// 113 | /// The parse tree. 114 | public virtual void EnterConditionExpr([NotNull] ProfaneParser.ConditionExprContext context) { } 115 | /// 116 | /// Exit a parse tree produced by . 117 | /// The default implementation does nothing. 118 | /// 119 | /// The parse tree. 120 | public virtual void ExitConditionExpr([NotNull] ProfaneParser.ConditionExprContext context) { } 121 | /// 122 | /// Enter a parse tree produced by . 123 | /// The default implementation does nothing. 124 | /// 125 | /// The parse tree. 126 | public virtual void EnterExpr([NotNull] ProfaneParser.ExprContext context) { } 127 | /// 128 | /// Exit a parse tree produced by . 129 | /// The default implementation does nothing. 130 | /// 131 | /// The parse tree. 132 | public virtual void ExitExpr([NotNull] ProfaneParser.ExprContext context) { } 133 | /// 134 | /// Enter a parse tree produced by . 135 | /// The default implementation does nothing. 136 | /// 137 | /// The parse tree. 138 | public virtual void EnterOpExpression([NotNull] ProfaneParser.OpExpressionContext context) { } 139 | /// 140 | /// Exit a parse tree produced by . 141 | /// The default implementation does nothing. 142 | /// 143 | /// The parse tree. 144 | public virtual void ExitOpExpression([NotNull] ProfaneParser.OpExpressionContext context) { } 145 | /// 146 | /// Enter a parse tree produced by . 147 | /// The default implementation does nothing. 148 | /// 149 | /// The parse tree. 150 | public virtual void EnterOp([NotNull] ProfaneParser.OpContext context) { } 151 | /// 152 | /// Exit a parse tree produced by . 153 | /// The default implementation does nothing. 154 | /// 155 | /// The parse tree. 156 | public virtual void ExitOp([NotNull] ProfaneParser.OpContext context) { } 157 | /// 158 | /// Enter a parse tree produced by . 159 | /// The default implementation does nothing. 160 | /// 161 | /// The parse tree. 162 | public virtual void EnterRelop([NotNull] ProfaneParser.RelopContext context) { } 163 | /// 164 | /// Exit a parse tree produced by . 165 | /// The default implementation does nothing. 166 | /// 167 | /// The parse tree. 168 | public virtual void ExitRelop([NotNull] ProfaneParser.RelopContext context) { } 169 | /// 170 | /// Enter a parse tree produced by . 171 | /// The default implementation does nothing. 172 | /// 173 | /// The parse tree. 174 | public virtual void EnterTerm([NotNull] ProfaneParser.TermContext context) { } 175 | /// 176 | /// Exit a parse tree produced by . 177 | /// The default implementation does nothing. 178 | /// 179 | /// The parse tree. 180 | public virtual void ExitTerm([NotNull] ProfaneParser.TermContext context) { } 181 | /// 182 | /// Enter a parse tree produced by . 183 | /// The default implementation does nothing. 184 | /// 185 | /// The parse tree. 186 | public virtual void EnterNumber([NotNull] ProfaneParser.NumberContext context) { } 187 | /// 188 | /// Exit a parse tree produced by . 189 | /// The default implementation does nothing. 190 | /// 191 | /// The parse tree. 192 | public virtual void ExitNumber([NotNull] ProfaneParser.NumberContext context) { } 193 | 194 | /// 195 | /// The default implementation does nothing. 196 | public virtual void EnterEveryRule([NotNull] ParserRuleContext context) { } 197 | /// 198 | /// The default implementation does nothing. 199 | public virtual void ExitEveryRule([NotNull] ParserRuleContext context) { } 200 | /// 201 | /// The default implementation does nothing. 202 | public virtual void VisitTerminal([NotNull] ITerminalNode node) { } 203 | /// 204 | /// The default implementation does nothing. 205 | public virtual void VisitErrorNode([NotNull] IErrorNode node) { } 206 | } 207 | -------------------------------------------------------------------------------- /Profane.Core/ProfaneLexer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // ANTLR Version: 4.7 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | // Generated from Profane.g4 by ANTLR 4.7 12 | 13 | // Unreachable code detected 14 | #pragma warning disable 0162 15 | // The variable '...' is assigned but its value is never used 16 | #pragma warning disable 0219 17 | // Missing XML comment for publicly visible type or member '...' 18 | #pragma warning disable 1591 19 | // Ambiguous reference in cref attribute 20 | #pragma warning disable 419 21 | 22 | using System; 23 | using System.IO; 24 | using System.Text; 25 | using Antlr4.Runtime; 26 | using Antlr4.Runtime.Atn; 27 | using Antlr4.Runtime.Misc; 28 | using DFA = Antlr4.Runtime.Dfa.DFA; 29 | 30 | [System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.7")] 31 | [System.CLSCompliant(false)] 32 | public partial class ProfaneLexer : Lexer { 33 | protected static DFA[] decisionToDFA; 34 | protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); 35 | public const int 36 | T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, ID=6, SMILEY=7, WS=8, PLUS=9, 37 | EQUAL=10, ASSIGN=11, NOTEQUAL=12, MINUS=13, GT=14, LT=15, GTEQ=16, LTEQ=17, 38 | NUMBER=18, STRING=19; 39 | public static string[] channelNames = { 40 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN" 41 | }; 42 | 43 | public static string[] modeNames = { 44 | "DEFAULT_MODE" 45 | }; 46 | 47 | public static readonly string[] ruleNames = { 48 | "T__0", "T__1", "T__2", "T__3", "T__4", "ID", "SMILEY", "WS", "PLUS", 49 | "EQUAL", "ASSIGN", "NOTEQUAL", "MINUS", "GT", "LT", "GTEQ", "LTEQ", "INT", 50 | "NUMBER", "STRING" 51 | }; 52 | 53 | 54 | public ProfaneLexer(ICharStream input) 55 | : this(input, Console.Out, Console.Error) { } 56 | 57 | public ProfaneLexer(ICharStream input, TextWriter output, TextWriter errorOutput) 58 | : base(input, output, errorOutput) 59 | { 60 | Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); 61 | } 62 | 63 | private static readonly string[] _LiteralNames = { 64 | null, "'dump'", "'derp'", "'???'", "'yep ->'", "'kbye'", null, "':)'", 65 | null, "'+'", "'===='", "'='", "'!!=='", "'-'", "'>'", "'<'", "'>='", "'<='" 66 | }; 67 | private static readonly string[] _SymbolicNames = { 68 | null, null, null, null, null, null, "ID", "SMILEY", "WS", "PLUS", "EQUAL", 69 | "ASSIGN", "NOTEQUAL", "MINUS", "GT", "LT", "GTEQ", "LTEQ", "NUMBER", "STRING" 70 | }; 71 | public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); 72 | 73 | [NotNull] 74 | public override IVocabulary Vocabulary 75 | { 76 | get 77 | { 78 | return DefaultVocabulary; 79 | } 80 | } 81 | 82 | public override string GrammarFileName { get { return "Profane.g4"; } } 83 | 84 | public override string[] RuleNames { get { return ruleNames; } } 85 | 86 | public override string[] ChannelNames { get { return channelNames; } } 87 | 88 | public override string[] ModeNames { get { return modeNames; } } 89 | 90 | public override string SerializedAtn { get { return new string(_serializedATN); } } 91 | 92 | static ProfaneLexer() { 93 | decisionToDFA = new DFA[_ATN.NumberOfDecisions]; 94 | for (int i = 0; i < _ATN.NumberOfDecisions; i++) { 95 | decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); 96 | } 97 | } 98 | private static char[] _serializedATN = { 99 | '\x3', '\x608B', '\xA72A', '\x8133', '\xB9ED', '\x417C', '\x3BE7', '\x7786', 100 | '\x5964', '\x2', '\x15', '\x85', '\b', '\x1', '\x4', '\x2', '\t', '\x2', 101 | '\x4', '\x3', '\t', '\x3', '\x4', '\x4', '\t', '\x4', '\x4', '\x5', '\t', 102 | '\x5', '\x4', '\x6', '\t', '\x6', '\x4', '\a', '\t', '\a', '\x4', '\b', 103 | '\t', '\b', '\x4', '\t', '\t', '\t', '\x4', '\n', '\t', '\n', '\x4', '\v', 104 | '\t', '\v', '\x4', '\f', '\t', '\f', '\x4', '\r', '\t', '\r', '\x4', '\xE', 105 | '\t', '\xE', '\x4', '\xF', '\t', '\xF', '\x4', '\x10', '\t', '\x10', '\x4', 106 | '\x11', '\t', '\x11', '\x4', '\x12', '\t', '\x12', '\x4', '\x13', '\t', 107 | '\x13', '\x4', '\x14', '\t', '\x14', '\x4', '\x15', '\t', '\x15', '\x3', 108 | '\x2', '\x3', '\x2', '\x3', '\x2', '\x3', '\x2', '\x3', '\x2', '\x3', 109 | '\x3', '\x3', '\x3', '\x3', '\x3', '\x3', '\x3', '\x3', '\x3', '\x3', 110 | '\x4', '\x3', '\x4', '\x3', '\x4', '\x3', '\x4', '\x3', '\x5', '\x3', 111 | '\x5', '\x3', '\x5', '\x3', '\x5', '\x3', '\x5', '\x3', '\x5', '\x3', 112 | '\x5', '\x3', '\x6', '\x3', '\x6', '\x3', '\x6', '\x3', '\x6', '\x3', 113 | '\x6', '\x3', '\a', '\x3', '\a', '\a', '\a', 'H', '\n', '\a', '\f', '\a', 114 | '\xE', '\a', 'K', '\v', '\a', '\x3', '\b', '\x3', '\b', '\x3', '\b', '\x3', 115 | '\t', '\x6', '\t', 'Q', '\n', '\t', '\r', '\t', '\xE', '\t', 'R', '\x3', 116 | '\t', '\x3', '\t', '\x3', '\n', '\x3', '\n', '\x3', '\v', '\x3', '\v', 117 | '\x3', '\v', '\x3', '\v', '\x3', '\v', '\x3', '\f', '\x3', '\f', '\x3', 118 | '\r', '\x3', '\r', '\x3', '\r', '\x3', '\r', '\x3', '\r', '\x3', '\xE', 119 | '\x3', '\xE', '\x3', '\xF', '\x3', '\xF', '\x3', '\x10', '\x3', '\x10', 120 | '\x3', '\x11', '\x3', '\x11', '\x3', '\x11', '\x3', '\x12', '\x3', '\x12', 121 | '\x3', '\x12', '\x3', '\x13', '\x6', '\x13', 'r', '\n', '\x13', '\r', 122 | '\x13', '\xE', '\x13', 's', '\x3', '\x14', '\x3', '\x14', '\x3', '\x14', 123 | '\x5', '\x14', 'y', '\n', '\x14', '\x5', '\x14', '{', '\n', '\x14', '\x3', 124 | '\x15', '\x3', '\x15', '\a', '\x15', '\x7F', '\n', '\x15', '\f', '\x15', 125 | '\xE', '\x15', '\x82', '\v', '\x15', '\x3', '\x15', '\x3', '\x15', '\x2', 126 | '\x2', '\x16', '\x3', '\x3', '\x5', '\x4', '\a', '\x5', '\t', '\x6', '\v', 127 | '\a', '\r', '\b', '\xF', '\t', '\x11', '\n', '\x13', '\v', '\x15', '\f', 128 | '\x17', '\r', '\x19', '\xE', '\x1B', '\xF', '\x1D', '\x10', '\x1F', '\x11', 129 | '!', '\x12', '#', '\x13', '%', '\x2', '\'', '\x14', ')', '\x15', '\x3', 130 | '\x2', '\a', '\x5', '\x2', '\x43', '\\', '\x61', '\x61', '\x63', '|', 131 | '\x6', '\x2', '\x32', ';', '\x43', '\\', '\x61', '\x61', '\x63', '|', 132 | '\x5', '\x2', '\v', '\f', '\xF', '\xF', '\"', '\"', '\x3', '\x2', '\x32', 133 | ';', '\x4', '\x2', '\f', '\f', '$', '$', '\x2', '\x89', '\x2', '\x3', 134 | '\x3', '\x2', '\x2', '\x2', '\x2', '\x5', '\x3', '\x2', '\x2', '\x2', 135 | '\x2', '\a', '\x3', '\x2', '\x2', '\x2', '\x2', '\t', '\x3', '\x2', '\x2', 136 | '\x2', '\x2', '\v', '\x3', '\x2', '\x2', '\x2', '\x2', '\r', '\x3', '\x2', 137 | '\x2', '\x2', '\x2', '\xF', '\x3', '\x2', '\x2', '\x2', '\x2', '\x11', 138 | '\x3', '\x2', '\x2', '\x2', '\x2', '\x13', '\x3', '\x2', '\x2', '\x2', 139 | '\x2', '\x15', '\x3', '\x2', '\x2', '\x2', '\x2', '\x17', '\x3', '\x2', 140 | '\x2', '\x2', '\x2', '\x19', '\x3', '\x2', '\x2', '\x2', '\x2', '\x1B', 141 | '\x3', '\x2', '\x2', '\x2', '\x2', '\x1D', '\x3', '\x2', '\x2', '\x2', 142 | '\x2', '\x1F', '\x3', '\x2', '\x2', '\x2', '\x2', '!', '\x3', '\x2', '\x2', 143 | '\x2', '\x2', '#', '\x3', '\x2', '\x2', '\x2', '\x2', '\'', '\x3', '\x2', 144 | '\x2', '\x2', '\x2', ')', '\x3', '\x2', '\x2', '\x2', '\x3', '+', '\x3', 145 | '\x2', '\x2', '\x2', '\x5', '\x30', '\x3', '\x2', '\x2', '\x2', '\a', 146 | '\x35', '\x3', '\x2', '\x2', '\x2', '\t', '\x39', '\x3', '\x2', '\x2', 147 | '\x2', '\v', '@', '\x3', '\x2', '\x2', '\x2', '\r', '\x45', '\x3', '\x2', 148 | '\x2', '\x2', '\xF', 'L', '\x3', '\x2', '\x2', '\x2', '\x11', 'P', '\x3', 149 | '\x2', '\x2', '\x2', '\x13', 'V', '\x3', '\x2', '\x2', '\x2', '\x15', 150 | 'X', '\x3', '\x2', '\x2', '\x2', '\x17', ']', '\x3', '\x2', '\x2', '\x2', 151 | '\x19', '_', '\x3', '\x2', '\x2', '\x2', '\x1B', '\x64', '\x3', '\x2', 152 | '\x2', '\x2', '\x1D', '\x66', '\x3', '\x2', '\x2', '\x2', '\x1F', 'h', 153 | '\x3', '\x2', '\x2', '\x2', '!', 'j', '\x3', '\x2', '\x2', '\x2', '#', 154 | 'm', '\x3', '\x2', '\x2', '\x2', '%', 'q', '\x3', '\x2', '\x2', '\x2', 155 | '\'', 'u', '\x3', '\x2', '\x2', '\x2', ')', '|', '\x3', '\x2', '\x2', 156 | '\x2', '+', ',', '\a', '\x66', '\x2', '\x2', ',', '-', '\a', 'w', '\x2', 157 | '\x2', '-', '.', '\a', 'o', '\x2', '\x2', '.', '/', '\a', 'r', '\x2', 158 | '\x2', '/', '\x4', '\x3', '\x2', '\x2', '\x2', '\x30', '\x31', '\a', '\x66', 159 | '\x2', '\x2', '\x31', '\x32', '\a', 'g', '\x2', '\x2', '\x32', '\x33', 160 | '\a', 't', '\x2', '\x2', '\x33', '\x34', '\a', 'r', '\x2', '\x2', '\x34', 161 | '\x6', '\x3', '\x2', '\x2', '\x2', '\x35', '\x36', '\a', '\x41', '\x2', 162 | '\x2', '\x36', '\x37', '\a', '\x41', '\x2', '\x2', '\x37', '\x38', '\a', 163 | '\x41', '\x2', '\x2', '\x38', '\b', '\x3', '\x2', '\x2', '\x2', '\x39', 164 | ':', '\a', '{', '\x2', '\x2', ':', ';', '\a', 'g', '\x2', '\x2', ';', 165 | '<', '\a', 'r', '\x2', '\x2', '<', '=', '\a', '\"', '\x2', '\x2', '=', 166 | '>', '\a', '/', '\x2', '\x2', '>', '?', '\a', '@', '\x2', '\x2', '?', 167 | '\n', '\x3', '\x2', '\x2', '\x2', '@', '\x41', '\a', 'm', '\x2', '\x2', 168 | '\x41', '\x42', '\a', '\x64', '\x2', '\x2', '\x42', '\x43', '\a', '{', 169 | '\x2', '\x2', '\x43', '\x44', '\a', 'g', '\x2', '\x2', '\x44', '\f', '\x3', 170 | '\x2', '\x2', '\x2', '\x45', 'I', '\t', '\x2', '\x2', '\x2', '\x46', 'H', 171 | '\t', '\x3', '\x2', '\x2', 'G', '\x46', '\x3', '\x2', '\x2', '\x2', 'H', 172 | 'K', '\x3', '\x2', '\x2', '\x2', 'I', 'G', '\x3', '\x2', '\x2', '\x2', 173 | 'I', 'J', '\x3', '\x2', '\x2', '\x2', 'J', '\xE', '\x3', '\x2', '\x2', 174 | '\x2', 'K', 'I', '\x3', '\x2', '\x2', '\x2', 'L', 'M', '\a', '<', '\x2', 175 | '\x2', 'M', 'N', '\a', '+', '\x2', '\x2', 'N', '\x10', '\x3', '\x2', '\x2', 176 | '\x2', 'O', 'Q', '\t', '\x4', '\x2', '\x2', 'P', 'O', '\x3', '\x2', '\x2', 177 | '\x2', 'Q', 'R', '\x3', '\x2', '\x2', '\x2', 'R', 'P', '\x3', '\x2', '\x2', 178 | '\x2', 'R', 'S', '\x3', '\x2', '\x2', '\x2', 'S', 'T', '\x3', '\x2', '\x2', 179 | '\x2', 'T', 'U', '\b', '\t', '\x2', '\x2', 'U', '\x12', '\x3', '\x2', 180 | '\x2', '\x2', 'V', 'W', '\a', '-', '\x2', '\x2', 'W', '\x14', '\x3', '\x2', 181 | '\x2', '\x2', 'X', 'Y', '\a', '?', '\x2', '\x2', 'Y', 'Z', '\a', '?', 182 | '\x2', '\x2', 'Z', '[', '\a', '?', '\x2', '\x2', '[', '\\', '\a', '?', 183 | '\x2', '\x2', '\\', '\x16', '\x3', '\x2', '\x2', '\x2', ']', '^', '\a', 184 | '?', '\x2', '\x2', '^', '\x18', '\x3', '\x2', '\x2', '\x2', '_', '`', 185 | '\a', '#', '\x2', '\x2', '`', '\x61', '\a', '#', '\x2', '\x2', '\x61', 186 | '\x62', '\a', '?', '\x2', '\x2', '\x62', '\x63', '\a', '?', '\x2', '\x2', 187 | '\x63', '\x1A', '\x3', '\x2', '\x2', '\x2', '\x64', '\x65', '\a', '/', 188 | '\x2', '\x2', '\x65', '\x1C', '\x3', '\x2', '\x2', '\x2', '\x66', 'g', 189 | '\a', '@', '\x2', '\x2', 'g', '\x1E', '\x3', '\x2', '\x2', '\x2', 'h', 190 | 'i', '\a', '>', '\x2', '\x2', 'i', ' ', '\x3', '\x2', '\x2', '\x2', 'j', 191 | 'k', '\a', '@', '\x2', '\x2', 'k', 'l', '\a', '?', '\x2', '\x2', 'l', 192 | '\"', '\x3', '\x2', '\x2', '\x2', 'm', 'n', '\a', '>', '\x2', '\x2', 'n', 193 | 'o', '\a', '?', '\x2', '\x2', 'o', '$', '\x3', '\x2', '\x2', '\x2', 'p', 194 | 'r', '\t', '\x5', '\x2', '\x2', 'q', 'p', '\x3', '\x2', '\x2', '\x2', 195 | 'r', 's', '\x3', '\x2', '\x2', '\x2', 's', 'q', '\x3', '\x2', '\x2', '\x2', 196 | 's', 't', '\x3', '\x2', '\x2', '\x2', 't', '&', '\x3', '\x2', '\x2', '\x2', 197 | 'u', 'z', '\x5', '%', '\x13', '\x2', 'v', 'x', '\a', '\x30', '\x2', '\x2', 198 | 'w', 'y', '\x5', '%', '\x13', '\x2', 'x', 'w', '\x3', '\x2', '\x2', '\x2', 199 | 'x', 'y', '\x3', '\x2', '\x2', '\x2', 'y', '{', '\x3', '\x2', '\x2', '\x2', 200 | 'z', 'v', '\x3', '\x2', '\x2', '\x2', 'z', '{', '\x3', '\x2', '\x2', '\x2', 201 | '{', '(', '\x3', '\x2', '\x2', '\x2', '|', '\x80', '\a', '$', '\x2', '\x2', 202 | '}', '\x7F', '\n', '\x6', '\x2', '\x2', '~', '}', '\x3', '\x2', '\x2', 203 | '\x2', '\x7F', '\x82', '\x3', '\x2', '\x2', '\x2', '\x80', '~', '\x3', 204 | '\x2', '\x2', '\x2', '\x80', '\x81', '\x3', '\x2', '\x2', '\x2', '\x81', 205 | '\x83', '\x3', '\x2', '\x2', '\x2', '\x82', '\x80', '\x3', '\x2', '\x2', 206 | '\x2', '\x83', '\x84', '\a', '$', '\x2', '\x2', '\x84', '*', '\x3', '\x2', 207 | '\x2', '\x2', '\t', '\x2', 'I', 'R', 's', 'x', 'z', '\x80', '\x3', '\b', 208 | '\x2', '\x2', 209 | }; 210 | 211 | public static readonly ATN _ATN = 212 | new ATNDeserializer().Deserialize(_serializedATN); 213 | 214 | 215 | } 216 | -------------------------------------------------------------------------------- /Profane.Core/ProfaneLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | ID=6 7 | SMILEY=7 8 | WS=8 9 | PLUS=9 10 | EQUAL=10 11 | ASSIGN=11 12 | NOTEQUAL=12 13 | MINUS=13 14 | GT=14 15 | LT=15 16 | GTEQ=16 17 | LTEQ=17 18 | NUMBER=18 19 | STRING=19 20 | 'dump'=1 21 | 'derp'=2 22 | '???'=3 23 | 'yep ->'=4 24 | 'kbye'=5 25 | ':)'=7 26 | '+'=9 27 | '===='=10 28 | '='=11 29 | '!!=='=12 30 | '-'=13 31 | '>'=14 32 | '<'=15 33 | '>='=16 34 | '<='=17 35 | -------------------------------------------------------------------------------- /Profane.Core/ProfaneListener.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // ANTLR Version: 4.7 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | // Generated from Profane.g4 by ANTLR 4.7 12 | 13 | // Unreachable code detected 14 | #pragma warning disable 0162 15 | // The variable '...' is assigned but its value is never used 16 | #pragma warning disable 0219 17 | // Missing XML comment for publicly visible type or member '...' 18 | #pragma warning disable 1591 19 | // Ambiguous reference in cref attribute 20 | #pragma warning disable 419 21 | 22 | using Antlr4.Runtime.Misc; 23 | using IParseTreeListener = Antlr4.Runtime.Tree.IParseTreeListener; 24 | using IToken = Antlr4.Runtime.IToken; 25 | 26 | /// 27 | /// This interface defines a complete listener for a parse tree produced by 28 | /// . 29 | /// 30 | [System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.7")] 31 | [System.CLSCompliant(false)] 32 | public interface IProfaneListener : IParseTreeListener { 33 | /// 34 | /// Enter a parse tree produced by . 35 | /// 36 | /// The parse tree. 37 | void EnterCompilationUnit([NotNull] ProfaneParser.CompilationUnitContext context); 38 | /// 39 | /// Exit a parse tree produced by . 40 | /// 41 | /// The parse tree. 42 | void ExitCompilationUnit([NotNull] ProfaneParser.CompilationUnitContext context); 43 | /// 44 | /// Enter a parse tree produced by . 45 | /// 46 | /// The parse tree. 47 | void EnterStatement([NotNull] ProfaneParser.StatementContext context); 48 | /// 49 | /// Exit a parse tree produced by . 50 | /// 51 | /// The parse tree. 52 | void ExitStatement([NotNull] ProfaneParser.StatementContext context); 53 | /// 54 | /// Enter a parse tree produced by . 55 | /// 56 | /// The parse tree. 57 | void EnterPrintstmt([NotNull] ProfaneParser.PrintstmtContext context); 58 | /// 59 | /// Exit a parse tree produced by . 60 | /// 61 | /// The parse tree. 62 | void ExitPrintstmt([NotNull] ProfaneParser.PrintstmtContext context); 63 | /// 64 | /// Enter a parse tree produced by . 65 | /// 66 | /// The parse tree. 67 | void EnterAssignstmt([NotNull] ProfaneParser.AssignstmtContext context); 68 | /// 69 | /// Exit a parse tree produced by . 70 | /// 71 | /// The parse tree. 72 | void ExitAssignstmt([NotNull] ProfaneParser.AssignstmtContext context); 73 | /// 74 | /// Enter a parse tree produced by . 75 | /// 76 | /// The parse tree. 77 | void EnterSetstmt([NotNull] ProfaneParser.SetstmtContext context); 78 | /// 79 | /// Exit a parse tree produced by . 80 | /// 81 | /// The parse tree. 82 | void ExitSetstmt([NotNull] ProfaneParser.SetstmtContext context); 83 | /// 84 | /// Enter a parse tree produced by . 85 | /// 86 | /// The parse tree. 87 | void EnterIfstmt([NotNull] ProfaneParser.IfstmtContext context); 88 | /// 89 | /// Exit a parse tree produced by . 90 | /// 91 | /// The parse tree. 92 | void ExitIfstmt([NotNull] ProfaneParser.IfstmtContext context); 93 | /// 94 | /// Enter a parse tree produced by . 95 | /// 96 | /// The parse tree. 97 | void EnterConditionExpr([NotNull] ProfaneParser.ConditionExprContext context); 98 | /// 99 | /// Exit a parse tree produced by . 100 | /// 101 | /// The parse tree. 102 | void ExitConditionExpr([NotNull] ProfaneParser.ConditionExprContext context); 103 | /// 104 | /// Enter a parse tree produced by . 105 | /// 106 | /// The parse tree. 107 | void EnterExpr([NotNull] ProfaneParser.ExprContext context); 108 | /// 109 | /// Exit a parse tree produced by . 110 | /// 111 | /// The parse tree. 112 | void ExitExpr([NotNull] ProfaneParser.ExprContext context); 113 | /// 114 | /// Enter a parse tree produced by . 115 | /// 116 | /// The parse tree. 117 | void EnterOpExpression([NotNull] ProfaneParser.OpExpressionContext context); 118 | /// 119 | /// Exit a parse tree produced by . 120 | /// 121 | /// The parse tree. 122 | void ExitOpExpression([NotNull] ProfaneParser.OpExpressionContext context); 123 | /// 124 | /// Enter a parse tree produced by . 125 | /// 126 | /// The parse tree. 127 | void EnterOp([NotNull] ProfaneParser.OpContext context); 128 | /// 129 | /// Exit a parse tree produced by . 130 | /// 131 | /// The parse tree. 132 | void ExitOp([NotNull] ProfaneParser.OpContext context); 133 | /// 134 | /// Enter a parse tree produced by . 135 | /// 136 | /// The parse tree. 137 | void EnterRelop([NotNull] ProfaneParser.RelopContext context); 138 | /// 139 | /// Exit a parse tree produced by . 140 | /// 141 | /// The parse tree. 142 | void ExitRelop([NotNull] ProfaneParser.RelopContext context); 143 | /// 144 | /// Enter a parse tree produced by . 145 | /// 146 | /// The parse tree. 147 | void EnterTerm([NotNull] ProfaneParser.TermContext context); 148 | /// 149 | /// Exit a parse tree produced by . 150 | /// 151 | /// The parse tree. 152 | void ExitTerm([NotNull] ProfaneParser.TermContext context); 153 | /// 154 | /// Enter a parse tree produced by . 155 | /// 156 | /// The parse tree. 157 | void EnterNumber([NotNull] ProfaneParser.NumberContext context); 158 | /// 159 | /// Exit a parse tree produced by . 160 | /// 161 | /// The parse tree. 162 | void ExitNumber([NotNull] ProfaneParser.NumberContext context); 163 | } 164 | -------------------------------------------------------------------------------- /Profane.Core/ProfaneParser.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // ANTLR Version: 4.7 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | // Generated from Profane.g4 by ANTLR 4.7 12 | 13 | // Unreachable code detected 14 | #pragma warning disable 0162 15 | // The variable '...' is assigned but its value is never used 16 | #pragma warning disable 0219 17 | // Missing XML comment for publicly visible type or member '...' 18 | #pragma warning disable 1591 19 | // Ambiguous reference in cref attribute 20 | #pragma warning disable 419 21 | 22 | using System; 23 | using System.IO; 24 | using System.Text; 25 | using System.Diagnostics; 26 | using System.Collections.Generic; 27 | using Antlr4.Runtime; 28 | using Antlr4.Runtime.Atn; 29 | using Antlr4.Runtime.Misc; 30 | using Antlr4.Runtime.Tree; 31 | using DFA = Antlr4.Runtime.Dfa.DFA; 32 | 33 | [System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.7")] 34 | [System.CLSCompliant(false)] 35 | public partial class ProfaneParser : Parser { 36 | protected static DFA[] decisionToDFA; 37 | protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); 38 | public const int 39 | T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, ID=6, SMILEY=7, WS=8, PLUS=9, 40 | EQUAL=10, ASSIGN=11, NOTEQUAL=12, MINUS=13, GT=14, LT=15, GTEQ=16, LTEQ=17, 41 | NUMBER=18, STRING=19; 42 | public const int 43 | RULE_compilationUnit = 0, RULE_statement = 1, RULE_printstmt = 2, RULE_assignstmt = 3, 44 | RULE_setstmt = 4, RULE_ifstmt = 5, RULE_conditionExpr = 6, RULE_expr = 7, 45 | RULE_opExpression = 8, RULE_op = 9, RULE_relop = 10, RULE_term = 11, RULE_number = 12; 46 | public static readonly string[] ruleNames = { 47 | "compilationUnit", "statement", "printstmt", "assignstmt", "setstmt", 48 | "ifstmt", "conditionExpr", "expr", "opExpression", "op", "relop", "term", 49 | "number" 50 | }; 51 | 52 | private static readonly string[] _LiteralNames = { 53 | null, "'dump'", "'derp'", "'???'", "'yep ->'", "'kbye'", null, "':)'", 54 | null, "'+'", "'===='", "'='", "'!!=='", "'-'", "'>'", "'<'", "'>='", "'<='" 55 | }; 56 | private static readonly string[] _SymbolicNames = { 57 | null, null, null, null, null, null, "ID", "SMILEY", "WS", "PLUS", "EQUAL", 58 | "ASSIGN", "NOTEQUAL", "MINUS", "GT", "LT", "GTEQ", "LTEQ", "NUMBER", "STRING" 59 | }; 60 | public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); 61 | 62 | [NotNull] 63 | public override IVocabulary Vocabulary 64 | { 65 | get 66 | { 67 | return DefaultVocabulary; 68 | } 69 | } 70 | 71 | public override string GrammarFileName { get { return "Profane.g4"; } } 72 | 73 | public override string[] RuleNames { get { return ruleNames; } } 74 | 75 | public override string SerializedAtn { get { return new string(_serializedATN); } } 76 | 77 | static ProfaneParser() { 78 | decisionToDFA = new DFA[_ATN.NumberOfDecisions]; 79 | for (int i = 0; i < _ATN.NumberOfDecisions; i++) { 80 | decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); 81 | } 82 | } 83 | 84 | public ProfaneParser(ITokenStream input) : this(input, Console.Out, Console.Error) { } 85 | 86 | public ProfaneParser(ITokenStream input, TextWriter output, TextWriter errorOutput) 87 | : base(input, output, errorOutput) 88 | { 89 | Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); 90 | } 91 | public partial class CompilationUnitContext : ParserRuleContext { 92 | public ITerminalNode Eof() { return GetToken(ProfaneParser.Eof, 0); } 93 | public StatementContext[] statement() { 94 | return GetRuleContexts(); 95 | } 96 | public StatementContext statement(int i) { 97 | return GetRuleContext(i); 98 | } 99 | public CompilationUnitContext(ParserRuleContext parent, int invokingState) 100 | : base(parent, invokingState) 101 | { 102 | } 103 | public override int RuleIndex { get { return RULE_compilationUnit; } } 104 | public override void EnterRule(IParseTreeListener listener) { 105 | IProfaneListener typedListener = listener as IProfaneListener; 106 | if (typedListener != null) typedListener.EnterCompilationUnit(this); 107 | } 108 | public override void ExitRule(IParseTreeListener listener) { 109 | IProfaneListener typedListener = listener as IProfaneListener; 110 | if (typedListener != null) typedListener.ExitCompilationUnit(this); 111 | } 112 | } 113 | 114 | [RuleVersion(0)] 115 | public CompilationUnitContext compilationUnit() { 116 | CompilationUnitContext _localctx = new CompilationUnitContext(Context, State); 117 | EnterRule(_localctx, 0, RULE_compilationUnit); 118 | int _la; 119 | try { 120 | EnterOuterAlt(_localctx, 1); 121 | { 122 | State = 29; 123 | ErrorHandler.Sync(this); 124 | _la = TokenStream.LA(1); 125 | while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__1) | (1L << ID) | (1L << NUMBER) | (1L << STRING))) != 0)) { 126 | { 127 | { 128 | State = 26; statement(); 129 | } 130 | } 131 | State = 31; 132 | ErrorHandler.Sync(this); 133 | _la = TokenStream.LA(1); 134 | } 135 | State = 32; Match(Eof); 136 | } 137 | } 138 | catch (RecognitionException re) { 139 | _localctx.exception = re; 140 | ErrorHandler.ReportError(this, re); 141 | ErrorHandler.Recover(this, re); 142 | } 143 | finally { 144 | ExitRule(); 145 | } 146 | return _localctx; 147 | } 148 | 149 | public partial class StatementContext : ParserRuleContext { 150 | public PrintstmtContext printstmt() { 151 | return GetRuleContext(0); 152 | } 153 | public AssignstmtContext assignstmt() { 154 | return GetRuleContext(0); 155 | } 156 | public IfstmtContext ifstmt() { 157 | return GetRuleContext(0); 158 | } 159 | public SetstmtContext setstmt() { 160 | return GetRuleContext(0); 161 | } 162 | public StatementContext(ParserRuleContext parent, int invokingState) 163 | : base(parent, invokingState) 164 | { 165 | } 166 | public override int RuleIndex { get { return RULE_statement; } } 167 | public override void EnterRule(IParseTreeListener listener) { 168 | IProfaneListener typedListener = listener as IProfaneListener; 169 | if (typedListener != null) typedListener.EnterStatement(this); 170 | } 171 | public override void ExitRule(IParseTreeListener listener) { 172 | IProfaneListener typedListener = listener as IProfaneListener; 173 | if (typedListener != null) typedListener.ExitStatement(this); 174 | } 175 | } 176 | 177 | [RuleVersion(0)] 178 | public StatementContext statement() { 179 | StatementContext _localctx = new StatementContext(Context, State); 180 | EnterRule(_localctx, 2, RULE_statement); 181 | try { 182 | State = 38; 183 | ErrorHandler.Sync(this); 184 | switch ( Interpreter.AdaptivePredict(TokenStream,1,Context) ) { 185 | case 1: 186 | EnterOuterAlt(_localctx, 1); 187 | { 188 | State = 34; printstmt(); 189 | } 190 | break; 191 | case 2: 192 | EnterOuterAlt(_localctx, 2); 193 | { 194 | State = 35; assignstmt(); 195 | } 196 | break; 197 | case 3: 198 | EnterOuterAlt(_localctx, 3); 199 | { 200 | State = 36; ifstmt(); 201 | } 202 | break; 203 | case 4: 204 | EnterOuterAlt(_localctx, 4); 205 | { 206 | State = 37; setstmt(); 207 | } 208 | break; 209 | } 210 | } 211 | catch (RecognitionException re) { 212 | _localctx.exception = re; 213 | ErrorHandler.ReportError(this, re); 214 | ErrorHandler.Recover(this, re); 215 | } 216 | finally { 217 | ExitRule(); 218 | } 219 | return _localctx; 220 | } 221 | 222 | public partial class PrintstmtContext : ParserRuleContext { 223 | public ITerminalNode SMILEY() { return GetToken(ProfaneParser.SMILEY, 0); } 224 | public ExprContext expr() { 225 | return GetRuleContext(0); 226 | } 227 | public PrintstmtContext(ParserRuleContext parent, int invokingState) 228 | : base(parent, invokingState) 229 | { 230 | } 231 | public override int RuleIndex { get { return RULE_printstmt; } } 232 | public override void EnterRule(IParseTreeListener listener) { 233 | IProfaneListener typedListener = listener as IProfaneListener; 234 | if (typedListener != null) typedListener.EnterPrintstmt(this); 235 | } 236 | public override void ExitRule(IParseTreeListener listener) { 237 | IProfaneListener typedListener = listener as IProfaneListener; 238 | if (typedListener != null) typedListener.ExitPrintstmt(this); 239 | } 240 | } 241 | 242 | [RuleVersion(0)] 243 | public PrintstmtContext printstmt() { 244 | PrintstmtContext _localctx = new PrintstmtContext(Context, State); 245 | EnterRule(_localctx, 4, RULE_printstmt); 246 | int _la; 247 | try { 248 | EnterOuterAlt(_localctx, 1); 249 | { 250 | State = 40; Match(T__0); 251 | State = 42; 252 | ErrorHandler.Sync(this); 253 | _la = TokenStream.LA(1); 254 | if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << ID) | (1L << NUMBER) | (1L << STRING))) != 0)) { 255 | { 256 | State = 41; expr(); 257 | } 258 | } 259 | 260 | State = 44; Match(SMILEY); 261 | } 262 | } 263 | catch (RecognitionException re) { 264 | _localctx.exception = re; 265 | ErrorHandler.ReportError(this, re); 266 | ErrorHandler.Recover(this, re); 267 | } 268 | finally { 269 | ExitRule(); 270 | } 271 | return _localctx; 272 | } 273 | 274 | public partial class AssignstmtContext : ParserRuleContext { 275 | public ITerminalNode ID() { return GetToken(ProfaneParser.ID, 0); } 276 | public ITerminalNode ASSIGN() { return GetToken(ProfaneParser.ASSIGN, 0); } 277 | public ExprContext expr() { 278 | return GetRuleContext(0); 279 | } 280 | public ITerminalNode SMILEY() { return GetToken(ProfaneParser.SMILEY, 0); } 281 | public AssignstmtContext(ParserRuleContext parent, int invokingState) 282 | : base(parent, invokingState) 283 | { 284 | } 285 | public override int RuleIndex { get { return RULE_assignstmt; } } 286 | public override void EnterRule(IParseTreeListener listener) { 287 | IProfaneListener typedListener = listener as IProfaneListener; 288 | if (typedListener != null) typedListener.EnterAssignstmt(this); 289 | } 290 | public override void ExitRule(IParseTreeListener listener) { 291 | IProfaneListener typedListener = listener as IProfaneListener; 292 | if (typedListener != null) typedListener.ExitAssignstmt(this); 293 | } 294 | } 295 | 296 | [RuleVersion(0)] 297 | public AssignstmtContext assignstmt() { 298 | AssignstmtContext _localctx = new AssignstmtContext(Context, State); 299 | EnterRule(_localctx, 6, RULE_assignstmt); 300 | try { 301 | EnterOuterAlt(_localctx, 1); 302 | { 303 | State = 46; Match(T__1); 304 | State = 47; Match(ID); 305 | State = 48; Match(ASSIGN); 306 | State = 49; expr(); 307 | State = 50; Match(SMILEY); 308 | } 309 | } 310 | catch (RecognitionException re) { 311 | _localctx.exception = re; 312 | ErrorHandler.ReportError(this, re); 313 | ErrorHandler.Recover(this, re); 314 | } 315 | finally { 316 | ExitRule(); 317 | } 318 | return _localctx; 319 | } 320 | 321 | public partial class SetstmtContext : ParserRuleContext { 322 | public ITerminalNode ID() { return GetToken(ProfaneParser.ID, 0); } 323 | public ITerminalNode ASSIGN() { return GetToken(ProfaneParser.ASSIGN, 0); } 324 | public ExprContext expr() { 325 | return GetRuleContext(0); 326 | } 327 | public ITerminalNode SMILEY() { return GetToken(ProfaneParser.SMILEY, 0); } 328 | public SetstmtContext(ParserRuleContext parent, int invokingState) 329 | : base(parent, invokingState) 330 | { 331 | } 332 | public override int RuleIndex { get { return RULE_setstmt; } } 333 | public override void EnterRule(IParseTreeListener listener) { 334 | IProfaneListener typedListener = listener as IProfaneListener; 335 | if (typedListener != null) typedListener.EnterSetstmt(this); 336 | } 337 | public override void ExitRule(IParseTreeListener listener) { 338 | IProfaneListener typedListener = listener as IProfaneListener; 339 | if (typedListener != null) typedListener.ExitSetstmt(this); 340 | } 341 | } 342 | 343 | [RuleVersion(0)] 344 | public SetstmtContext setstmt() { 345 | SetstmtContext _localctx = new SetstmtContext(Context, State); 346 | EnterRule(_localctx, 8, RULE_setstmt); 347 | try { 348 | EnterOuterAlt(_localctx, 1); 349 | { 350 | State = 52; Match(ID); 351 | State = 53; Match(ASSIGN); 352 | State = 54; expr(); 353 | State = 55; Match(SMILEY); 354 | } 355 | } 356 | catch (RecognitionException re) { 357 | _localctx.exception = re; 358 | ErrorHandler.ReportError(this, re); 359 | ErrorHandler.Recover(this, re); 360 | } 361 | finally { 362 | ExitRule(); 363 | } 364 | return _localctx; 365 | } 366 | 367 | public partial class IfstmtContext : ParserRuleContext { 368 | public ConditionExprContext conditionExpr() { 369 | return GetRuleContext(0); 370 | } 371 | public StatementContext[] statement() { 372 | return GetRuleContexts(); 373 | } 374 | public StatementContext statement(int i) { 375 | return GetRuleContext(i); 376 | } 377 | public IfstmtContext(ParserRuleContext parent, int invokingState) 378 | : base(parent, invokingState) 379 | { 380 | } 381 | public override int RuleIndex { get { return RULE_ifstmt; } } 382 | public override void EnterRule(IParseTreeListener listener) { 383 | IProfaneListener typedListener = listener as IProfaneListener; 384 | if (typedListener != null) typedListener.EnterIfstmt(this); 385 | } 386 | public override void ExitRule(IParseTreeListener listener) { 387 | IProfaneListener typedListener = listener as IProfaneListener; 388 | if (typedListener != null) typedListener.ExitIfstmt(this); 389 | } 390 | } 391 | 392 | [RuleVersion(0)] 393 | public IfstmtContext ifstmt() { 394 | IfstmtContext _localctx = new IfstmtContext(Context, State); 395 | EnterRule(_localctx, 10, RULE_ifstmt); 396 | int _la; 397 | try { 398 | EnterOuterAlt(_localctx, 1); 399 | { 400 | State = 57; conditionExpr(); 401 | State = 58; Match(T__2); 402 | State = 59; Match(T__3); 403 | State = 63; 404 | ErrorHandler.Sync(this); 405 | _la = TokenStream.LA(1); 406 | while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__1) | (1L << ID) | (1L << NUMBER) | (1L << STRING))) != 0)) { 407 | { 408 | { 409 | State = 60; statement(); 410 | } 411 | } 412 | State = 65; 413 | ErrorHandler.Sync(this); 414 | _la = TokenStream.LA(1); 415 | } 416 | State = 66; Match(T__4); 417 | } 418 | } 419 | catch (RecognitionException re) { 420 | _localctx.exception = re; 421 | ErrorHandler.ReportError(this, re); 422 | ErrorHandler.Recover(this, re); 423 | } 424 | finally { 425 | ExitRule(); 426 | } 427 | return _localctx; 428 | } 429 | 430 | public partial class ConditionExprContext : ParserRuleContext { 431 | public ExprContext[] expr() { 432 | return GetRuleContexts(); 433 | } 434 | public ExprContext expr(int i) { 435 | return GetRuleContext(i); 436 | } 437 | public RelopContext relop() { 438 | return GetRuleContext(0); 439 | } 440 | public ConditionExprContext(ParserRuleContext parent, int invokingState) 441 | : base(parent, invokingState) 442 | { 443 | } 444 | public override int RuleIndex { get { return RULE_conditionExpr; } } 445 | public override void EnterRule(IParseTreeListener listener) { 446 | IProfaneListener typedListener = listener as IProfaneListener; 447 | if (typedListener != null) typedListener.EnterConditionExpr(this); 448 | } 449 | public override void ExitRule(IParseTreeListener listener) { 450 | IProfaneListener typedListener = listener as IProfaneListener; 451 | if (typedListener != null) typedListener.ExitConditionExpr(this); 452 | } 453 | } 454 | 455 | [RuleVersion(0)] 456 | public ConditionExprContext conditionExpr() { 457 | ConditionExprContext _localctx = new ConditionExprContext(Context, State); 458 | EnterRule(_localctx, 12, RULE_conditionExpr); 459 | try { 460 | EnterOuterAlt(_localctx, 1); 461 | { 462 | State = 68; expr(); 463 | State = 69; relop(); 464 | State = 70; expr(); 465 | } 466 | } 467 | catch (RecognitionException re) { 468 | _localctx.exception = re; 469 | ErrorHandler.ReportError(this, re); 470 | ErrorHandler.Recover(this, re); 471 | } 472 | finally { 473 | ExitRule(); 474 | } 475 | return _localctx; 476 | } 477 | 478 | public partial class ExprContext : ParserRuleContext { 479 | public TermContext term() { 480 | return GetRuleContext(0); 481 | } 482 | public OpExpressionContext opExpression() { 483 | return GetRuleContext(0); 484 | } 485 | public ExprContext(ParserRuleContext parent, int invokingState) 486 | : base(parent, invokingState) 487 | { 488 | } 489 | public override int RuleIndex { get { return RULE_expr; } } 490 | public override void EnterRule(IParseTreeListener listener) { 491 | IProfaneListener typedListener = listener as IProfaneListener; 492 | if (typedListener != null) typedListener.EnterExpr(this); 493 | } 494 | public override void ExitRule(IParseTreeListener listener) { 495 | IProfaneListener typedListener = listener as IProfaneListener; 496 | if (typedListener != null) typedListener.ExitExpr(this); 497 | } 498 | } 499 | 500 | [RuleVersion(0)] 501 | public ExprContext expr() { 502 | ExprContext _localctx = new ExprContext(Context, State); 503 | EnterRule(_localctx, 14, RULE_expr); 504 | try { 505 | State = 74; 506 | ErrorHandler.Sync(this); 507 | switch ( Interpreter.AdaptivePredict(TokenStream,4,Context) ) { 508 | case 1: 509 | EnterOuterAlt(_localctx, 1); 510 | { 511 | State = 72; term(); 512 | } 513 | break; 514 | case 2: 515 | EnterOuterAlt(_localctx, 2); 516 | { 517 | State = 73; opExpression(); 518 | } 519 | break; 520 | } 521 | } 522 | catch (RecognitionException re) { 523 | _localctx.exception = re; 524 | ErrorHandler.ReportError(this, re); 525 | ErrorHandler.Recover(this, re); 526 | } 527 | finally { 528 | ExitRule(); 529 | } 530 | return _localctx; 531 | } 532 | 533 | public partial class OpExpressionContext : ParserRuleContext { 534 | public TermContext[] term() { 535 | return GetRuleContexts(); 536 | } 537 | public TermContext term(int i) { 538 | return GetRuleContext(i); 539 | } 540 | public OpContext op() { 541 | return GetRuleContext(0); 542 | } 543 | public OpExpressionContext(ParserRuleContext parent, int invokingState) 544 | : base(parent, invokingState) 545 | { 546 | } 547 | public override int RuleIndex { get { return RULE_opExpression; } } 548 | public override void EnterRule(IParseTreeListener listener) { 549 | IProfaneListener typedListener = listener as IProfaneListener; 550 | if (typedListener != null) typedListener.EnterOpExpression(this); 551 | } 552 | public override void ExitRule(IParseTreeListener listener) { 553 | IProfaneListener typedListener = listener as IProfaneListener; 554 | if (typedListener != null) typedListener.ExitOpExpression(this); 555 | } 556 | } 557 | 558 | [RuleVersion(0)] 559 | public OpExpressionContext opExpression() { 560 | OpExpressionContext _localctx = new OpExpressionContext(Context, State); 561 | EnterRule(_localctx, 16, RULE_opExpression); 562 | try { 563 | EnterOuterAlt(_localctx, 1); 564 | { 565 | State = 76; term(); 566 | State = 77; op(); 567 | State = 78; term(); 568 | } 569 | } 570 | catch (RecognitionException re) { 571 | _localctx.exception = re; 572 | ErrorHandler.ReportError(this, re); 573 | ErrorHandler.Recover(this, re); 574 | } 575 | finally { 576 | ExitRule(); 577 | } 578 | return _localctx; 579 | } 580 | 581 | public partial class OpContext : ParserRuleContext { 582 | public ITerminalNode PLUS() { return GetToken(ProfaneParser.PLUS, 0); } 583 | public ITerminalNode ASSIGN() { return GetToken(ProfaneParser.ASSIGN, 0); } 584 | public ITerminalNode MINUS() { return GetToken(ProfaneParser.MINUS, 0); } 585 | public OpContext(ParserRuleContext parent, int invokingState) 586 | : base(parent, invokingState) 587 | { 588 | } 589 | public override int RuleIndex { get { return RULE_op; } } 590 | public override void EnterRule(IParseTreeListener listener) { 591 | IProfaneListener typedListener = listener as IProfaneListener; 592 | if (typedListener != null) typedListener.EnterOp(this); 593 | } 594 | public override void ExitRule(IParseTreeListener listener) { 595 | IProfaneListener typedListener = listener as IProfaneListener; 596 | if (typedListener != null) typedListener.ExitOp(this); 597 | } 598 | } 599 | 600 | [RuleVersion(0)] 601 | public OpContext op() { 602 | OpContext _localctx = new OpContext(Context, State); 603 | EnterRule(_localctx, 18, RULE_op); 604 | int _la; 605 | try { 606 | EnterOuterAlt(_localctx, 1); 607 | { 608 | State = 80; 609 | _la = TokenStream.LA(1); 610 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PLUS) | (1L << ASSIGN) | (1L << MINUS))) != 0)) ) { 611 | ErrorHandler.RecoverInline(this); 612 | } 613 | else { 614 | ErrorHandler.ReportMatch(this); 615 | Consume(); 616 | } 617 | } 618 | } 619 | catch (RecognitionException re) { 620 | _localctx.exception = re; 621 | ErrorHandler.ReportError(this, re); 622 | ErrorHandler.Recover(this, re); 623 | } 624 | finally { 625 | ExitRule(); 626 | } 627 | return _localctx; 628 | } 629 | 630 | public partial class RelopContext : ParserRuleContext { 631 | public ITerminalNode EQUAL() { return GetToken(ProfaneParser.EQUAL, 0); } 632 | public ITerminalNode NOTEQUAL() { return GetToken(ProfaneParser.NOTEQUAL, 0); } 633 | public ITerminalNode GT() { return GetToken(ProfaneParser.GT, 0); } 634 | public ITerminalNode LT() { return GetToken(ProfaneParser.LT, 0); } 635 | public ITerminalNode GTEQ() { return GetToken(ProfaneParser.GTEQ, 0); } 636 | public ITerminalNode LTEQ() { return GetToken(ProfaneParser.LTEQ, 0); } 637 | public RelopContext(ParserRuleContext parent, int invokingState) 638 | : base(parent, invokingState) 639 | { 640 | } 641 | public override int RuleIndex { get { return RULE_relop; } } 642 | public override void EnterRule(IParseTreeListener listener) { 643 | IProfaneListener typedListener = listener as IProfaneListener; 644 | if (typedListener != null) typedListener.EnterRelop(this); 645 | } 646 | public override void ExitRule(IParseTreeListener listener) { 647 | IProfaneListener typedListener = listener as IProfaneListener; 648 | if (typedListener != null) typedListener.ExitRelop(this); 649 | } 650 | } 651 | 652 | [RuleVersion(0)] 653 | public RelopContext relop() { 654 | RelopContext _localctx = new RelopContext(Context, State); 655 | EnterRule(_localctx, 20, RULE_relop); 656 | int _la; 657 | try { 658 | EnterOuterAlt(_localctx, 1); 659 | { 660 | State = 82; 661 | _la = TokenStream.LA(1); 662 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << EQUAL) | (1L << NOTEQUAL) | (1L << GT) | (1L << LT) | (1L << GTEQ) | (1L << LTEQ))) != 0)) ) { 663 | ErrorHandler.RecoverInline(this); 664 | } 665 | else { 666 | ErrorHandler.ReportMatch(this); 667 | Consume(); 668 | } 669 | } 670 | } 671 | catch (RecognitionException re) { 672 | _localctx.exception = re; 673 | ErrorHandler.ReportError(this, re); 674 | ErrorHandler.Recover(this, re); 675 | } 676 | finally { 677 | ExitRule(); 678 | } 679 | return _localctx; 680 | } 681 | 682 | public partial class TermContext : ParserRuleContext { 683 | public ITerminalNode ID() { return GetToken(ProfaneParser.ID, 0); } 684 | public NumberContext number() { 685 | return GetRuleContext(0); 686 | } 687 | public ITerminalNode STRING() { return GetToken(ProfaneParser.STRING, 0); } 688 | public TermContext(ParserRuleContext parent, int invokingState) 689 | : base(parent, invokingState) 690 | { 691 | } 692 | public override int RuleIndex { get { return RULE_term; } } 693 | public override void EnterRule(IParseTreeListener listener) { 694 | IProfaneListener typedListener = listener as IProfaneListener; 695 | if (typedListener != null) typedListener.EnterTerm(this); 696 | } 697 | public override void ExitRule(IParseTreeListener listener) { 698 | IProfaneListener typedListener = listener as IProfaneListener; 699 | if (typedListener != null) typedListener.ExitTerm(this); 700 | } 701 | } 702 | 703 | [RuleVersion(0)] 704 | public TermContext term() { 705 | TermContext _localctx = new TermContext(Context, State); 706 | EnterRule(_localctx, 22, RULE_term); 707 | try { 708 | State = 87; 709 | ErrorHandler.Sync(this); 710 | switch (TokenStream.LA(1)) { 711 | case ID: 712 | EnterOuterAlt(_localctx, 1); 713 | { 714 | State = 84; Match(ID); 715 | } 716 | break; 717 | case NUMBER: 718 | EnterOuterAlt(_localctx, 2); 719 | { 720 | State = 85; number(); 721 | } 722 | break; 723 | case STRING: 724 | EnterOuterAlt(_localctx, 3); 725 | { 726 | State = 86; Match(STRING); 727 | } 728 | break; 729 | default: 730 | throw new NoViableAltException(this); 731 | } 732 | } 733 | catch (RecognitionException re) { 734 | _localctx.exception = re; 735 | ErrorHandler.ReportError(this, re); 736 | ErrorHandler.Recover(this, re); 737 | } 738 | finally { 739 | ExitRule(); 740 | } 741 | return _localctx; 742 | } 743 | 744 | public partial class NumberContext : ParserRuleContext { 745 | public ITerminalNode NUMBER() { return GetToken(ProfaneParser.NUMBER, 0); } 746 | public NumberContext(ParserRuleContext parent, int invokingState) 747 | : base(parent, invokingState) 748 | { 749 | } 750 | public override int RuleIndex { get { return RULE_number; } } 751 | public override void EnterRule(IParseTreeListener listener) { 752 | IProfaneListener typedListener = listener as IProfaneListener; 753 | if (typedListener != null) typedListener.EnterNumber(this); 754 | } 755 | public override void ExitRule(IParseTreeListener listener) { 756 | IProfaneListener typedListener = listener as IProfaneListener; 757 | if (typedListener != null) typedListener.ExitNumber(this); 758 | } 759 | } 760 | 761 | [RuleVersion(0)] 762 | public NumberContext number() { 763 | NumberContext _localctx = new NumberContext(Context, State); 764 | EnterRule(_localctx, 24, RULE_number); 765 | try { 766 | EnterOuterAlt(_localctx, 1); 767 | { 768 | State = 89; Match(NUMBER); 769 | } 770 | } 771 | catch (RecognitionException re) { 772 | _localctx.exception = re; 773 | ErrorHandler.ReportError(this, re); 774 | ErrorHandler.Recover(this, re); 775 | } 776 | finally { 777 | ExitRule(); 778 | } 779 | return _localctx; 780 | } 781 | 782 | private static char[] _serializedATN = { 783 | '\x3', '\x608B', '\xA72A', '\x8133', '\xB9ED', '\x417C', '\x3BE7', '\x7786', 784 | '\x5964', '\x3', '\x15', '^', '\x4', '\x2', '\t', '\x2', '\x4', '\x3', 785 | '\t', '\x3', '\x4', '\x4', '\t', '\x4', '\x4', '\x5', '\t', '\x5', '\x4', 786 | '\x6', '\t', '\x6', '\x4', '\a', '\t', '\a', '\x4', '\b', '\t', '\b', 787 | '\x4', '\t', '\t', '\t', '\x4', '\n', '\t', '\n', '\x4', '\v', '\t', '\v', 788 | '\x4', '\f', '\t', '\f', '\x4', '\r', '\t', '\r', '\x4', '\xE', '\t', 789 | '\xE', '\x3', '\x2', '\a', '\x2', '\x1E', '\n', '\x2', '\f', '\x2', '\xE', 790 | '\x2', '!', '\v', '\x2', '\x3', '\x2', '\x3', '\x2', '\x3', '\x3', '\x3', 791 | '\x3', '\x3', '\x3', '\x3', '\x3', '\x5', '\x3', ')', '\n', '\x3', '\x3', 792 | '\x4', '\x3', '\x4', '\x5', '\x4', '-', '\n', '\x4', '\x3', '\x4', '\x3', 793 | '\x4', '\x3', '\x5', '\x3', '\x5', '\x3', '\x5', '\x3', '\x5', '\x3', 794 | '\x5', '\x3', '\x5', '\x3', '\x6', '\x3', '\x6', '\x3', '\x6', '\x3', 795 | '\x6', '\x3', '\x6', '\x3', '\a', '\x3', '\a', '\x3', '\a', '\x3', '\a', 796 | '\a', '\a', '@', '\n', '\a', '\f', '\a', '\xE', '\a', '\x43', '\v', '\a', 797 | '\x3', '\a', '\x3', '\a', '\x3', '\b', '\x3', '\b', '\x3', '\b', '\x3', 798 | '\b', '\x3', '\t', '\x3', '\t', '\x5', '\t', 'M', '\n', '\t', '\x3', '\n', 799 | '\x3', '\n', '\x3', '\n', '\x3', '\n', '\x3', '\v', '\x3', '\v', '\x3', 800 | '\f', '\x3', '\f', '\x3', '\r', '\x3', '\r', '\x3', '\r', '\x5', '\r', 801 | 'Z', '\n', '\r', '\x3', '\xE', '\x3', '\xE', '\x3', '\xE', '\x2', '\x2', 802 | '\xF', '\x2', '\x4', '\x6', '\b', '\n', '\f', '\xE', '\x10', '\x12', '\x14', 803 | '\x16', '\x18', '\x1A', '\x2', '\x4', '\x5', '\x2', '\v', '\v', '\r', 804 | '\r', '\xF', '\xF', '\x5', '\x2', '\f', '\f', '\xE', '\xE', '\x10', '\x13', 805 | '\x2', 'Y', '\x2', '\x1F', '\x3', '\x2', '\x2', '\x2', '\x4', '(', '\x3', 806 | '\x2', '\x2', '\x2', '\x6', '*', '\x3', '\x2', '\x2', '\x2', '\b', '\x30', 807 | '\x3', '\x2', '\x2', '\x2', '\n', '\x36', '\x3', '\x2', '\x2', '\x2', 808 | '\f', ';', '\x3', '\x2', '\x2', '\x2', '\xE', '\x46', '\x3', '\x2', '\x2', 809 | '\x2', '\x10', 'L', '\x3', '\x2', '\x2', '\x2', '\x12', 'N', '\x3', '\x2', 810 | '\x2', '\x2', '\x14', 'R', '\x3', '\x2', '\x2', '\x2', '\x16', 'T', '\x3', 811 | '\x2', '\x2', '\x2', '\x18', 'Y', '\x3', '\x2', '\x2', '\x2', '\x1A', 812 | '[', '\x3', '\x2', '\x2', '\x2', '\x1C', '\x1E', '\x5', '\x4', '\x3', 813 | '\x2', '\x1D', '\x1C', '\x3', '\x2', '\x2', '\x2', '\x1E', '!', '\x3', 814 | '\x2', '\x2', '\x2', '\x1F', '\x1D', '\x3', '\x2', '\x2', '\x2', '\x1F', 815 | ' ', '\x3', '\x2', '\x2', '\x2', ' ', '\"', '\x3', '\x2', '\x2', '\x2', 816 | '!', '\x1F', '\x3', '\x2', '\x2', '\x2', '\"', '#', '\a', '\x2', '\x2', 817 | '\x3', '#', '\x3', '\x3', '\x2', '\x2', '\x2', '$', ')', '\x5', '\x6', 818 | '\x4', '\x2', '%', ')', '\x5', '\b', '\x5', '\x2', '&', ')', '\x5', '\f', 819 | '\a', '\x2', '\'', ')', '\x5', '\n', '\x6', '\x2', '(', '$', '\x3', '\x2', 820 | '\x2', '\x2', '(', '%', '\x3', '\x2', '\x2', '\x2', '(', '&', '\x3', '\x2', 821 | '\x2', '\x2', '(', '\'', '\x3', '\x2', '\x2', '\x2', ')', '\x5', '\x3', 822 | '\x2', '\x2', '\x2', '*', ',', '\a', '\x3', '\x2', '\x2', '+', '-', '\x5', 823 | '\x10', '\t', '\x2', ',', '+', '\x3', '\x2', '\x2', '\x2', ',', '-', '\x3', 824 | '\x2', '\x2', '\x2', '-', '.', '\x3', '\x2', '\x2', '\x2', '.', '/', '\a', 825 | '\t', '\x2', '\x2', '/', '\a', '\x3', '\x2', '\x2', '\x2', '\x30', '\x31', 826 | '\a', '\x4', '\x2', '\x2', '\x31', '\x32', '\a', '\b', '\x2', '\x2', '\x32', 827 | '\x33', '\a', '\r', '\x2', '\x2', '\x33', '\x34', '\x5', '\x10', '\t', 828 | '\x2', '\x34', '\x35', '\a', '\t', '\x2', '\x2', '\x35', '\t', '\x3', 829 | '\x2', '\x2', '\x2', '\x36', '\x37', '\a', '\b', '\x2', '\x2', '\x37', 830 | '\x38', '\a', '\r', '\x2', '\x2', '\x38', '\x39', '\x5', '\x10', '\t', 831 | '\x2', '\x39', ':', '\a', '\t', '\x2', '\x2', ':', '\v', '\x3', '\x2', 832 | '\x2', '\x2', ';', '<', '\x5', '\xE', '\b', '\x2', '<', '=', '\a', '\x5', 833 | '\x2', '\x2', '=', '\x41', '\a', '\x6', '\x2', '\x2', '>', '@', '\x5', 834 | '\x4', '\x3', '\x2', '?', '>', '\x3', '\x2', '\x2', '\x2', '@', '\x43', 835 | '\x3', '\x2', '\x2', '\x2', '\x41', '?', '\x3', '\x2', '\x2', '\x2', '\x41', 836 | '\x42', '\x3', '\x2', '\x2', '\x2', '\x42', '\x44', '\x3', '\x2', '\x2', 837 | '\x2', '\x43', '\x41', '\x3', '\x2', '\x2', '\x2', '\x44', '\x45', '\a', 838 | '\a', '\x2', '\x2', '\x45', '\r', '\x3', '\x2', '\x2', '\x2', '\x46', 839 | 'G', '\x5', '\x10', '\t', '\x2', 'G', 'H', '\x5', '\x16', '\f', '\x2', 840 | 'H', 'I', '\x5', '\x10', '\t', '\x2', 'I', '\xF', '\x3', '\x2', '\x2', 841 | '\x2', 'J', 'M', '\x5', '\x18', '\r', '\x2', 'K', 'M', '\x5', '\x12', 842 | '\n', '\x2', 'L', 'J', '\x3', '\x2', '\x2', '\x2', 'L', 'K', '\x3', '\x2', 843 | '\x2', '\x2', 'M', '\x11', '\x3', '\x2', '\x2', '\x2', 'N', 'O', '\x5', 844 | '\x18', '\r', '\x2', 'O', 'P', '\x5', '\x14', '\v', '\x2', 'P', 'Q', '\x5', 845 | '\x18', '\r', '\x2', 'Q', '\x13', '\x3', '\x2', '\x2', '\x2', 'R', 'S', 846 | '\t', '\x2', '\x2', '\x2', 'S', '\x15', '\x3', '\x2', '\x2', '\x2', 'T', 847 | 'U', '\t', '\x3', '\x2', '\x2', 'U', '\x17', '\x3', '\x2', '\x2', '\x2', 848 | 'V', 'Z', '\a', '\b', '\x2', '\x2', 'W', 'Z', '\x5', '\x1A', '\xE', '\x2', 849 | 'X', 'Z', '\a', '\x15', '\x2', '\x2', 'Y', 'V', '\x3', '\x2', '\x2', '\x2', 850 | 'Y', 'W', '\x3', '\x2', '\x2', '\x2', 'Y', 'X', '\x3', '\x2', '\x2', '\x2', 851 | 'Z', '\x19', '\x3', '\x2', '\x2', '\x2', '[', '\\', '\a', '\x14', '\x2', 852 | '\x2', '\\', '\x1B', '\x3', '\x2', '\x2', '\x2', '\b', '\x1F', '(', ',', 853 | '\x41', 'L', 'Y', 854 | }; 855 | 856 | public static readonly ATN _ATN = 857 | new ATNDeserializer().Deserialize(_serializedATN); 858 | 859 | 860 | } 861 | -------------------------------------------------------------------------------- /Profane.Core/Transpile/ProfaneListener.cs: -------------------------------------------------------------------------------- 1 | namespace Profane.Core.Transpile 2 | { 3 | using Antlr4.Runtime.Misc; 4 | using System.Linq; 5 | using System.Text.RegularExpressions; 6 | using System; 7 | 8 | public class ProfaneListener : ProfaneBaseListener 9 | { 10 | public ProfaneListener() 11 | { 12 | this.Output = string.Empty; 13 | } 14 | 15 | public string Output { get; private set; } 16 | 17 | public override void EnterAssignstmt([NotNull] ProfaneParser.AssignstmtContext context) 18 | { 19 | string target = context.ID().GetText(); 20 | dynamic value = this.ResolveExpression(context.expr()); 21 | this.Output += "dynamic " + target + " = " + value + ";\n"; 22 | } 23 | 24 | public override void EnterPrintstmt([NotNull] ProfaneParser.PrintstmtContext context) 25 | { 26 | var resolvedExp = context.expr() == null ? string.Empty : this.ResolveExpression(context.expr()); 27 | this.Output += $"System.Console.WriteLine({resolvedExp});\n"; 28 | } 29 | 30 | public override void EnterSetstmt([NotNull] ProfaneParser.SetstmtContext context) 31 | { 32 | string target = context.ID().GetText(); 33 | dynamic value = this.ResolveExpression(context.expr()); 34 | this.Output += target + " = " + value + ";\n"; 35 | } 36 | 37 | public override void EnterIfstmt([NotNull] ProfaneParser.IfstmtContext context) 38 | { 39 | var conditionalExpression = ResolveConditionalExpression(context.conditionExpr()); 40 | 41 | this.Output += $"if({conditionalExpression})"; 42 | this.Output += "{\n"; 43 | } 44 | 45 | public override void ExitIfstmt([NotNull] ProfaneParser.IfstmtContext context) 46 | { 47 | this.Output += "}\n"; 48 | } 49 | 50 | private object ResolveConditionalExpression(ProfaneParser.ConditionExprContext conditionExprContext) 51 | { 52 | var leftExpr = conditionExprContext.expr().First(); 53 | var rightExpr = conditionExprContext.expr().Last(); 54 | 55 | var left = ResolveExpression(leftExpr); 56 | var right = ResolveExpression(rightExpr); 57 | 58 | return left + conditionExprContext.relop().GetText() + right; 59 | } 60 | 61 | private dynamic ResolveExpression(ProfaneParser.ExprContext exprContext) 62 | { 63 | var opExpression = exprContext.opExpression(); 64 | if (opExpression != null) 65 | { 66 | return ResolveOpExpression(opExpression); 67 | } 68 | else 69 | { 70 | return ResolveTerm(exprContext.term()); 71 | } 72 | } 73 | 74 | private dynamic ResolveOpExpression(ProfaneParser.OpExpressionContext plusContext) 75 | { 76 | var leftTerm = plusContext.term().First(); 77 | var rightTerm = plusContext.term().Last(); 78 | 79 | var left = ResolveTerm(leftTerm); 80 | var right = ResolveTerm(rightTerm); 81 | 82 | return left + plusContext.op().GetText() + right; 83 | } 84 | 85 | private dynamic ResolveTerm(ProfaneParser.TermContext termContext) 86 | { 87 | if (termContext.number() != null) 88 | { 89 | return termContext.number().GetText(); 90 | } 91 | else if (termContext.ID() != null) 92 | { 93 | return termContext.ID().GetText(); 94 | } 95 | else if (termContext.STRING() != null) 96 | { 97 | Regex regex = new Regex("/\\$\\{([^\\}]+)\\}/g"); 98 | var contextText = termContext.GetText(); 99 | var replacedString = regex.Replace(contextText, "$1"); 100 | return replacedString; 101 | } 102 | else return default(dynamic); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Profane.Core/Transpile/ProfaneTranspiler.cs: -------------------------------------------------------------------------------- 1 | namespace Profane.Core.Transpile 2 | { 3 | using Antlr4.Runtime; 4 | using Antlr4.Runtime.Tree; 5 | using Microsoft.CodeAnalysis; 6 | using Microsoft.CodeAnalysis.CSharp.Scripting; 7 | using Microsoft.CodeAnalysis.Scripting; 8 | using Microsoft.CSharp.RuntimeBinder; 9 | using System; 10 | using System.Diagnostics; 11 | using System.IO; 12 | using System.Linq.Expressions; 13 | using System.Reflection; 14 | using System.Text; 15 | using System.Threading.Tasks; 16 | 17 | public class ProfaneTranspiler 18 | { 19 | private ProfaneListener listener; 20 | private static readonly MetadataReference[] References = 21 | { 22 | MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), 23 | MetadataReference.CreateFromFile(typeof(RuntimeBinderException).GetTypeInfo().Assembly.Location), 24 | MetadataReference.CreateFromFile(typeof(System.Runtime.CompilerServices.DynamicAttribute).GetTypeInfo().Assembly.Location), 25 | MetadataReference.CreateFromFile(typeof(ExpressionType).GetTypeInfo().Assembly.Location), 26 | MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("mscorlib")).Location), 27 | MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Runtime")).Location) 28 | }; 29 | 30 | public ProfaneTranspiler() 31 | { 32 | this.listener = new ProfaneListener(); 33 | } 34 | 35 | public ProfaneParser.CompilationUnitContext GenerateAST(string input) 36 | { 37 | var inputStream = new AntlrInputStream(input); 38 | var lexer = new ProfaneLexer(inputStream); 39 | var tokens = new CommonTokenStream(lexer); 40 | var parser = new ProfaneParser(tokens); 41 | parser.ErrorHandler = new BailErrorStrategy(); 42 | 43 | return parser.compilationUnit(); 44 | } 45 | 46 | public string GenerateTranspiledCode(string inputText) 47 | { 48 | var astree = this.GenerateAST(inputText); 49 | ParseTreeWalker.Default.Walk(listener, astree); 50 | return listener.Output; 51 | } 52 | 53 | public async Task RunAsync(string code) 54 | { 55 | var result = new TranspileResult(); 56 | 57 | if (string.IsNullOrEmpty(code)) 58 | return result; 59 | 60 | Stopwatch watch = new Stopwatch(); 61 | watch.Start(); 62 | 63 | try 64 | { 65 | ScriptOptions scriptOptions = ScriptOptions.Default; 66 | scriptOptions = scriptOptions.AddReferences(References); 67 | scriptOptions = scriptOptions.AddImports("System"); 68 | 69 | var resultCode = this.GenerateTranspiledCode(code); 70 | if (resultCode == null) 71 | { 72 | watch.Stop(); 73 | result.TimeElapsed = watch.Elapsed.ToString(); 74 | return result; 75 | } 76 | 77 | var outputStrBuilder = new StringBuilder(); 78 | using (var writer = new StringWriter(outputStrBuilder)) 79 | { 80 | Console.SetOut(writer); 81 | var scriptState = await CSharpScript.RunAsync(resultCode, scriptOptions); 82 | result.output = outputStrBuilder.ToString(); 83 | } 84 | } 85 | catch (Exception ex) 86 | { 87 | result.output = ex.Message; 88 | } 89 | finally 90 | { 91 | watch.Stop(); 92 | result.TimeElapsed = watch.Elapsed.ToString(); 93 | } 94 | return result; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Profane.Core/Transpile/TranspileResult.cs: -------------------------------------------------------------------------------- 1 | namespace Profane.Core.Transpile 2 | { 3 | public class TranspileResult 4 | { 5 | public string output { get; internal set; } 6 | public string TimeElapsed { get; internal set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Profane.Core/antlr-4.7-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NerdCats/Profane/b1f94ad0b7d869d31d5a352a4a6ff222b194871f/Profane.Core/antlr-4.7-complete.jar -------------------------------------------------------------------------------- /Profane.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26228.4 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Profane", "Profane\Profane.csproj", "{35142290-5F27-4A0C-AF0C-5A513C18B428}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Profane.Core", "Profane.Core\Profane.Core.csproj", "{9B759651-B076-4E14-BC6C-1E5FDB8DA7CB}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {35142290-5F27-4A0C-AF0C-5A513C18B428}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {35142290-5F27-4A0C-AF0C-5A513C18B428}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {35142290-5F27-4A0C-AF0C-5A513C18B428}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {35142290-5F27-4A0C-AF0C-5A513C18B428}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {9B759651-B076-4E14-BC6C-1E5FDB8DA7CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {9B759651-B076-4E14-BC6C-1E5FDB8DA7CB}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {9B759651-B076-4E14-BC6C-1E5FDB8DA7CB}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {9B759651-B076-4E14-BC6C-1E5FDB8DA7CB}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Profane/Profane.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp1.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Always 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Profane/ProfaneModule.cs: -------------------------------------------------------------------------------- 1 | namespace Profane 2 | { 3 | using Nancy; 4 | using Profane.Core.Transpile; 5 | using Nancy.Extensions; 6 | using Nancy.IO; 7 | 8 | public class ProfaneModule : NancyModule 9 | { 10 | public ProfaneModule() 11 | { 12 | Get("/", args => View["index"]); 13 | Post("/", async (args) => 14 | { 15 | var code = RequestStream.FromStream(Request.Body).AsString(); 16 | var transpiler = new ProfaneTranspiler(); 17 | var result = await transpiler.RunAsync(code); 18 | return Response.AsJson(result); 19 | }); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Profane/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Profane 2 | { 3 | using Microsoft.AspNetCore.Hosting; 4 | using System.IO; 5 | 6 | public class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var host = new WebHostBuilder() 11 | .UseContentRoot(Directory.GetCurrentDirectory()) 12 | .UseKestrel() 13 | .UseStartup() 14 | .Build(); 15 | 16 | host.Run(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Profane/Startup.cs: -------------------------------------------------------------------------------- 1 | namespace Profane 2 | { 3 | using Microsoft.AspNetCore.Builder; 4 | using Nancy.Owin; 5 | 6 | public class Startup 7 | { 8 | public void Configure(IApplicationBuilder app) 9 | { 10 | app.UseOwin(x => x.UseNancy()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Profane/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 43 | NerdCats Profane 44 | 68 | 69 | 70 | 71 |
72 | 73 |
74 |
75 | 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Profane 2 | Profane was written as a sample code / proof of concept of a language that is 3 | 4 | * ANTLR4 lexed and parsed 5 | * Transpiled to C# 6 | * Fed into roslyn C# script engine for execution 7 | 8 | This comes with a very simple and limited grammar so the capabilities are pretty limited too. Please look at the Profane.g4 file under Profane.Core project for better understanding. 9 | 10 | Sample code in Profane: 11 | 12 | ``` 13 | derp a = 20 :) #Initialization 14 | 15 | # basic if-else 16 | a > 2 ??? 17 | yep -> 18 | a = 5 :) 19 | kbye 20 | 21 | # print 22 | dump a :) 23 | ``` 24 | The Profane project comes with a [nancy](https://github.com/NancyFx/Nancy) module that accepts code as plain text in a HTTP POST and compiles it. Was built to put up a simple test code page in mind. 25 | 26 | Everything .net in Profane is written in [.net core](https://github.com/dotnet/core) 27 | --------------------------------------------------------------------------------