Browse Source

ANTLR FREE! [though, tests are failing]

Xanathar 10 years ago
parent
commit
6be7c42924
55 changed files with 52 additions and 2744 deletions
  1. 0 55
      src/MoonSharp.Interpreter/Diagnostics/AstDump.cs
  2. 0 1
      src/MoonSharp.Interpreter/Errors/InternalErrorException.cs
  3. 0 21
      src/MoonSharp.Interpreter/Errors/InterpreterException.cs
  4. 0 2
      src/MoonSharp.Interpreter/Errors/ScriptRuntimeException.cs
  5. 0 13
      src/MoonSharp.Interpreter/Errors/SyntaxErrorException.cs
  6. 0 302
      src/MoonSharp.Interpreter/Grammar/Lua.g4
  7. 0 6
      src/MoonSharp.Interpreter/Grammar/Lua.g4.lexer.cs
  8. 0 6
      src/MoonSharp.Interpreter/Grammar/Lua.g4.parser.cs
  9. 0 18
      src/MoonSharp.Interpreter/Grammar/LuaGrammar_ExtensionMethods.cs
  10. 1 46
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj
  11. 0 1
      src/MoonSharp.Interpreter/Script.cs
  12. 0 460
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_BinaryOperatorExpression.cs
  13. 0 54
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionCall.cs
  14. 0 58
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionCallChainExpression.cs
  15. 0 36
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionCallStatement.cs
  16. 0 198
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionDefinitionExpression.cs
  17. 0 128
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionDefinitionStatement.cs
  18. 0 291
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_LiteralExpression.cs
  19. 0 44
      src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_PowerOperatorExpression.cs
  20. 0 74
      src/MoonSharp.Interpreter/Tree/Antlr_Interface/AntlrErrorListener.cs
  21. 0 192
      src/MoonSharp.Interpreter/Tree/Antlr_Interface/Loader_Antlr.cs
  22. 5 2
      src/MoonSharp.Interpreter/Tree/Expressions/AdjustmentExpression.cs
  23. 0 2
      src/MoonSharp.Interpreter/Tree/Expressions/BinaryOperatorExpression.cs
  24. 0 8
      src/MoonSharp.Interpreter/Tree/Expressions/DynamicExprExpression.cs
  25. 0 7
      src/MoonSharp.Interpreter/Tree/Expressions/ExprListExpression.cs
  26. 1 1
      src/MoonSharp.Interpreter/Tree/Expressions/FunctionDefinitionExpression.cs
  27. 4 15
      src/MoonSharp.Interpreter/Tree/Expressions/IndexExpression.cs
  28. 0 11
      src/MoonSharp.Interpreter/Tree/Expressions/LiteralExpression.cs
  29. 1 1
      src/MoonSharp.Interpreter/Tree/Expressions/OperatorExpression.cs
  30. 0 44
      src/MoonSharp.Interpreter/Tree/Expressions/SymbolRefExpression.cs
  31. 0 38
      src/MoonSharp.Interpreter/Tree/Expressions/TableConstructor.cs
  32. 0 13
      src/MoonSharp.Interpreter/Tree/Expressions/UnaryOperatorExpression.cs
  33. 21 25
      src/MoonSharp.Interpreter/Tree/NodeBase.cs
  34. 0 283
      src/MoonSharp.Interpreter/Tree/NodeFactory.cs
  35. 1 8
      src/MoonSharp.Interpreter/Tree/Statement.cs
  36. 1 30
      src/MoonSharp.Interpreter/Tree/Statements/AssignmentStatement.cs
  37. 1 9
      src/MoonSharp.Interpreter/Tree/Statements/BreakStatement.cs
  38. 0 15
      src/MoonSharp.Interpreter/Tree/Statements/ChunkStatement.cs
  39. 2 30
      src/MoonSharp.Interpreter/Tree/Statements/CompositeStatement.cs
  40. 1 31
      src/MoonSharp.Interpreter/Tree/Statements/ForEachLoopStatement.cs
  41. 1 23
      src/MoonSharp.Interpreter/Tree/Statements/ForLoopStatement.cs
  42. 1 1
      src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs
  43. 1 39
      src/MoonSharp.Interpreter/Tree/Statements/IfStatement.cs
  44. 5 7
      src/MoonSharp.Interpreter/Tree/Statements/LabelStatement.cs
  45. 0 21
      src/MoonSharp.Interpreter/Tree/Statements/NullStatement.cs
  46. 1 15
      src/MoonSharp.Interpreter/Tree/Statements/RepeatStatement.cs
  47. 1 18
      src/MoonSharp.Interpreter/Tree/Statements/ReturnStatement.cs
  48. 0 12
      src/MoonSharp.Interpreter/Tree/Statements/ScopeBlockStatement.cs
  49. 1 15
      src/MoonSharp.Interpreter/Tree/Statements/WhileStatement.cs
  50. 1 7
      src/MoonSharp.Interpreter/Tree/__Expression.cs
  51. 0 5
      src/MoonSharp.Interpreter/packages.config
  52. 1 1
      src/PerformanceComparison/HugeFile.cs
  53. BIN
      src/packages/Antlr4.4.3.0/Antlr4.4.3.0.nupkg
  54. BIN
      src/packages/Antlr4.4.3.0/tools/antlr4-csharp-4.3-complete.jar
  55. 0 1
      src/packages/repositories.config

+ 0 - 55
src/MoonSharp.Interpreter/Diagnostics/AstDump.cs

@@ -1,55 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-
-namespace MoonSharp.Interpreter.Diagnostics
-{
-	public class AstDump
-	{
-		StringBuilder m_TreeDump = new StringBuilder();
-
-		public void DumpTree(IParseTree tree, string filename)
-		{
-			DumpTree(true, tree, 0);
-			File.WriteAllText(filename, m_TreeDump.ToString());
-		}
-
-		public void WalkTreeForWaste(IParseTree tree)
-		{
-			DumpTree(false, tree, 0);
-		}
-
-		private void DumpTree(bool dooutput, IParseTree tree, int depth = 0)
-		{
-			string tabs;
-
-			if (dooutput)
-			{
-				tabs = new string(' ', depth * 4);
-				m_TreeDump.AppendFormat("{0}{1} : {2}\n", tabs, Purify(tree.GetType()), tree.GetText());
-			}
-
-			for (int i = 0; i < tree.ChildCount; i++)
-			{
-				DumpTree(dooutput, tree.GetChild(i), depth + 1);
-			}
-		}
-
-		private string Purify(Type type)
-		{
-			string t = type.ToString();
-
-			if (t.StartsWith("MoonSharp.Interpreter.Grammar.LuaParser+"))
-			{
-				return t.Replace("MoonSharp.Interpreter.Grammar.LuaParser+", "").Replace("Context", "").ToUpper();
-			}
-			else if (t == "Antlr4.Runtime.Tree.TerminalNodeImpl") return "/TERM";
-
-			return t;
-
-		}
-	}
-}

+ 0 - 1
src/MoonSharp.Interpreter/Errors/InternalErrorException.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 
 namespace MoonSharp.Interpreter
 {

+ 0 - 21
src/MoonSharp.Interpreter/Errors/InterpreterException.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 
 namespace MoonSharp.Interpreter
 {
@@ -26,26 +25,6 @@ namespace MoonSharp.Interpreter
 
 		}
 
-		protected InterpreterException(IParseTree tree, string message)
-			: base(message + FormatTree(tree))
-		{
-
-		}
-
-		protected InterpreterException(IParseTree tree, string format, params object[] args)
-			: base(string.Format(format, args) + FormatTree(tree))
-		{
-
-		}
-
-		private static string FormatTree(IParseTree tree)
-		{
-			if (tree == null)
-				return "";
-
-			return "@ " + tree.GetText();
-		}
-
 		public int InstructionPtr { get; internal set; }
 
 		public IList<MoonSharp.Interpreter.Debugging.WatchItem> CallStack { get; internal set; }

+ 0 - 2
src/MoonSharp.Interpreter/Errors/ScriptRuntimeException.cs

@@ -2,8 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution.VM;
 
 namespace MoonSharp.Interpreter

+ 0 - 13
src/MoonSharp.Interpreter/Errors/SyntaxErrorException.cs

@@ -3,8 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 
-using Antlr4.Runtime.Tree;
-
 namespace MoonSharp.Interpreter
 {
 	[Serializable]
@@ -16,22 +14,11 @@ namespace MoonSharp.Interpreter
 
 		}
 
-		internal SyntaxErrorException(IParseTree tree, string format, params object[] args)
-			: base(tree, format, args)
-		{
-
-		}
-
 		internal SyntaxErrorException(string message)
 			: base(message)
 		{
 
 		}
 
-		internal SyntaxErrorException(IParseTree tree, string message)
-			: base(tree, message)
-		{
-
-		}
 	}
 }

+ 0 - 302
src/MoonSharp.Interpreter/Grammar/Lua.g4

@@ -1,302 +0,0 @@
-grammar Lua;
-
-chunk
-    : block (EOF)
-    ;
-
-dynamicexp
-	: exp EOF
-	;
-
-singlefunc
-	: anonfunctiondef EOF
-	;
-
-
-block
-    : stat* retstat?
-    ;
-
-stat
-    : ';'																			#stat_nulstatement
-    | varlist '=' explist															#stat_assignment
-    | varOrExp nameAndArgs+															#stat_functioncall
-    | label																			#stat_label
-    | BREAK																			#stat_break
-    | GOTO NAME																		#stat_goto
-    | DO block END																	#stat_doblock
-    | WHILE exp DO block END														#stat_whiledoloop
-    | REPEAT block UNTIL exp														#stat_repeatuntilloop
-    | IF exp THEN block (ELSEIF exp THEN block)* (ELSE block)? END					#stat_ifblock
-    | FOR NAME '=' exp ',' exp (',' exp)? DO block END								#stat_forloop
-    | FOR namelist IN explist DO block END											#stat_foreachloop
-    | FUNCTION funcname funcbody													#stat_funcdef
-    | LOCAL FUNCTION NAME funcbody													#stat_localfuncdef
-    | LOCAL namelist ('=' explist)?													#stat_localassignment
-    ;
-
-
-retstat
-    : RETURN explist? ';'?
-    ;
-
-label
-    : '::' NAME '::'
-    ;
-
-// this is an addition
-funcnametableaccessor
-	: ('.' NAME);
-
-funcname
-    : fnname=NAME funcnametableaccessor* (':' methodaccessor=NAME)?
-    ;
-
-varlist
-    : var (',' var)*
-    ;
-
-namelist
-    : NAME (',' NAME)*
-    ; 
-
-explist
-    : exp (',' exp)*
-    ;
-
-
-exp
-    : NIL												#exp_nil
-	| FALSE												#exp_false
-	| TRUE												#exp_true
-	| number											#exp_number
-	| string											#exp_string
-	| vararg											#exp_varargs
-	| FUNCTION funcbody									#exp_anonfunc
-    | prefixexp											#exp_prefixexp
-	| tableconstructor									#exp_tabctor
-	| <assoc=right> exp '^' exp							#exp_power
-	| operatorunary exp									#exp_unary
-	| exp operatorbinary exp							#exp_binary
-	;
-
-var
-    : (NAME | PAREN_OPEN exp PAREN_CLOSE varSuffix) varSuffix*
-    ;
-
-prefixexp
-    : varOrExp nameAndArgs*
-    ;
-
-//
-varOrExp
-    : var | PAREN_OPEN exp PAREN_CLOSE
-    ;
-
-
-nameAndArgs
-    : (':' NAME)? args
-    ;
-
-// Suffix to variable - array/table indexing
-varSuffix
-    : nameAndArgs* ('[' exp ']' | '.' NAME)
-    ;
-
-
-// Possible args to func call : list of expressions, table ctor, string literal
-args
-    : PAREN_OPEN explist? PAREN_CLOSE | tableconstructor | string
-    ;
-
-
-// Definition of func. Note: there is NO function name!
-anonfunctiondef
-    : 'function' funcbody
-    ;
-
-//lambdaexp
-//	: '[' parlist ':' exp ']'
-//	;
-
-//lambdastat
-//	: '[' parlist ':' 'do' block 'end' ']'
-//	;
-
-// A func body from the parlist to end.
-funcbody
-    : PAREN_OPEN parlist? PAREN_CLOSE block END
-    ;
-
-// The list of params in a function def
-parlist
-    : namelist (',' vararg)? | vararg
-    ;
-
-
-// A table ctor
-tableconstructor
-    : CURLY_OPEN fieldlist? CURLY_CLOSE
-    ;
-
-
-// The inside of a table ctor
-fieldlist
-    : field (fieldsep field)* fieldsep?
-    ;
-
-
-// field declaration in table ctor
-field
-    : '[' keyexp=exp ']' '=' keyedexp=exp | NAME '=' namedexp=exp | positionalexp=exp
-    ;
-
-
-// separators for fields in a table ctor
-fieldsep
-    : ',' | ';'
-    ;
-
-
-number
-    : INT | HEX | FLOAT | HEX_FLOAT
-    ;
-
-string
-    : NORMALSTRING | CHARSTRING | LONGSTRING
-    ;
-
-vararg
-	: '...'
-	;
-
-// LEXER
-AND : 'and';
-BREAK : 'break';
-DO : 'do';
-ELSE : 'else';
-ELSEIF : 'elseif';
-END : 'end';
-FALSE : 'false';
-FOR : 'for';
-FUNCTION : 'function';
-GOTO : 'goto';
-IF : 'if';
-IN : 'in';
-LOCAL : 'local';
-NIL : 'nil';
-NOT : 'not';
-OR : 'or';
-REPEAT : 'repeat';
-RETURN : 'return';
-THEN : 'then';
-TRUE : 'true';
-UNTIL : 'until';
-WHILE : 'while';
-
-CURLY_OPEN : '{';
-CURLY_CLOSE : '}';
-PAREN_OPEN : '(';
-PAREN_CLOSE: ')';
-
-operatorbinary 
-	: OR | AND | '<' | '>' | '<=' | '>=' | '~=' | '==' | '..' | '+' | '-' | '*' | '/' | '%' ;
-
-operatorunary
-    : NOT | '#' | '-';
-
-
-NAME
-    : [a-zA-Z_][a-zA-Z_0-9]*
-    ;
-
-NORMALSTRING
-    : '"' ( EscapeSequence | ~('\\'|'"') )* '"' 
-    ;
-
-CHARSTRING
-    : '\'' ( EscapeSequence | ~('\''|'\\') )* '\''
-    ;
-
-LONGSTRING
-    : '[' NESTED_STR ']'
-    ;
-
-fragment
-NESTED_STR
-    : '=' NESTED_STR '='
-    | '[' .*? ']'
-    ;
-
-INT
-    : Digit+
-    ;
-
-HEX
-    : '0' [xX] HexDigit+
-    ;
-
-FLOAT
-    : Digit+ '.' Digit* ExponentPart?
-    | '.' Digit+ ExponentPart?
-    | Digit+ ExponentPart
-    ;
-
-HEX_FLOAT
-    : '0' [xX] HexDigit+ '.' HexDigit* HexExponentPart?
-    | '0' [xX] '.' HexDigit+ HexExponentPart?
-    | '0' [xX] HexDigit+ HexExponentPart
-    ;
-
-fragment
-ExponentPart
-    : [eE] [+-]? Digit+
-    ;
-
-fragment
-HexExponentPart
-    : [pP] [+-]? Digit+
-    ;
-
-fragment
-EscapeSequence
-    : '\\' '\r'? '\n'
-    | '\\' ["']
-	| '\\' .
-    ;
-    
-fragment
-Digit
-    : [0-9]
-    ;
-
-fragment
-HexDigit
-    : [0-9a-fA-F]
-    ;
-
-COMMENT
-    : '--[' NESTED_STR ']' -> channel(HIDDEN)
-    ; 
-    
-LINE_COMMENT
-    : '--'
-    (                                               // --
-    | '[' '='*                                      // --[==
-    | '[' '='* ~('='|'['|'\r'|'\n') ~('\r'|'\n')*   // --[==AA 
-    | ~('['|'\r'|'\n') ~('\r'|'\n')*                // --AAA
-    ) ('\r\n'|'\r'|'\n'|EOF)
-    -> channel(HIDDEN)
-    ;
-    
-WS  
-    : [ \t\u000C\r\n]+ -> skip
-    ;
-
-SHEBANG
-    : '#' '!' ~('\n'|'\r')* -> channel(HIDDEN)
-    ;
-
-
-
-

+ 0 - 6
src/MoonSharp.Interpreter/Grammar/Lua.g4.lexer.cs

@@ -1,6 +0,0 @@
-namespace MoonSharp.Interpreter.Grammar
-{
-	partial class LuaLexer
-	{
-	}
-}

+ 0 - 6
src/MoonSharp.Interpreter/Grammar/Lua.g4.parser.cs

@@ -1,6 +0,0 @@
-namespace MoonSharp.Interpreter.Grammar
-{
-	partial class LuaParser
-	{
-	}
-}

+ 0 - 18
src/MoonSharp.Interpreter/Grammar/LuaGrammar_ExtensionMethods.cs

@@ -1,18 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using Antlr4.Runtime.Tree;
-
-namespace MoonSharp.Interpreter
-{
-	internal static class LuaGrammar_ExtensionMethods
-	{
-		public static IEnumerable<IParseTree> EnumChilds(this IParseTree tree)
-		{
-			for (int i = 0; i < tree.ChildCount; i++)
-				yield return tree.GetChild(i);
-		}
-	}
-}

+ 1 - 46
src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="..\packages\Antlr4.4.3.0\build\Antlr4.props" Condition="Exists('..\packages\Antlr4.4.3.0\build\Antlr4.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -21,7 +20,7 @@
     <SccProvider>
     </SccProvider>
     <TargetFrameworkProfile>Client</TargetFrameworkProfile>
-    <NuGetPackageImportStamp>b17ae9da</NuGetPackageImportStamp>
+    <NuGetPackageImportStamp>ee6b0a8a</NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -71,10 +70,6 @@
     <CodeAnalysisRuleSet>ExtendedDesignGuidelineRules.ruleset</CodeAnalysisRuleSet>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Antlr4.Runtime, Version=4.4.0.0, Culture=neutral, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\net35-client\Release\Antlr4.Runtime.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
   </ItemGroup>
@@ -152,7 +147,6 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="Errors\InternalErrorException.cs" />
-    <Compile Include="Diagnostics\AstDump.cs" />
     <Compile Include="Errors\InterpreterException.cs" />
     <Compile Include="Errors\SyntaxErrorException.cs" />
     <Compile Include="DataTypes\CallbackArguments.cs" />
@@ -233,12 +227,6 @@
     <Compile Include="Execution\VM\Processor\Processor_InstructionLoop.cs" />
     <Compile Include="Execution\VM\Processor\Processor_Scope.cs" />
     <Compile Include="Execution\VM\Processor\Processor_UtilityFunctions.cs" />
-    <Compile Include="Grammar\Lua.g4.lexer.cs">
-      <DependentUpon>Lua.g4</DependentUpon>
-    </Compile>
-    <Compile Include="Grammar\Lua.g4.parser.cs">
-      <DependentUpon>Lua.g4</DependentUpon>
-    </Compile>
     <Compile Include="Modules\CoreModules.cs" />
     <Compile Include="Modules\ModuleRegister.cs">
       <SubType>Code</SubType>
@@ -248,13 +236,10 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="ScriptOptions.cs" />
-    <Compile Include="Tree\Antlr_Interface\AntlrErrorListener.cs" />
     <Compile Include="Tree\Expressions\AdjustmentExpression.cs" />
     <Compile Include="Tree\Expressions\BinaryOperatorExpression.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_BinaryOperatorExpression.cs" />
     <Compile Include="Tree\Expressions\DynamicExprExpression.cs" />
     <Compile Include="Tree\Expressions\FunctionCallExpression.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_PowerOperatorExpression.cs" />
     <Compile Include="Tree\Expressions\FunctionDefinitionExpression.cs" />
     <Compile Include="Tree\Expressions\LiteralExpression.cs" />
     <Compile Include="Tree\Expressions\UnaryOperatorExpression.cs" />
@@ -262,25 +247,19 @@
     <Compile Include="Tree\IVariable.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Tree\Expressions\ExprListExpression.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_FunctionDefinitionExpression.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_LiteralExpression.cs" />
     <Compile Include="Tree\Expressions\IndexExpression.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_FunctionCall.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_FunctionCallChainExpression.cs" />
     <Compile Include="Tree\Statements\EmptyStatement.cs" />
     <Compile Include="Tree\Statements\FunctionCallStatement.cs" />
     <Compile Include="Tree\Statements\FunctionDefinitionStatement.cs" />
     <Compile Include="Tree\__Expression.cs" />
     <Compile Include="Tree\Expressions\OperatorExpression.cs" />
     <Compile Include="Tree\Expressions\SymbolRefExpression.cs" />
-    <Compile Include="Tree\Antlr_Interface\Loader_Antlr.cs" />
     <Compile Include="Tree\Lexer\Lexer.cs" />
     <Compile Include="Tree\Lexer\LexerBackDoor.cs" />
     <Compile Include="Tree\Lexer\Token.cs" />
     <Compile Include="Tree\Lexer\TokenType.cs" />
     <Compile Include="Tree\Loop.cs" />
     <Compile Include="Tree\NodeBase.cs" />
-    <Compile Include="Tree\NodeFactory.cs" />
     <Compile Include="Tree\Statements\AssignmentStatement.cs" />
     <Compile Include="Tree\Statements\ChunkStatement.cs">
       <SubType>Code</SubType>
@@ -289,41 +268,17 @@
     <Compile Include="Tree\Statements\BreakStatement.cs" />
     <Compile Include="Tree\Statements\ForEachLoopStatement.cs" />
     <Compile Include="Tree\Statements\ForLoopStatement.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_FunctionCallStatement.cs" />
-    <Compile Include="Tree\ANTLR_Deprecated\ANTLR_FunctionDefinitionStatement.cs" />
     <Compile Include="Tree\Statements\IfStatement.cs" />
     <Compile Include="Tree\Statement.cs" />
     <Compile Include="Tree\Statements\LabelStatement.cs" />
-    <Compile Include="Tree\Statements\NullStatement.cs" />
     <Compile Include="Tree\Statements\RepeatStatement.cs" />
     <Compile Include="Tree\Statements\ReturnStatement.cs" />
-    <Compile Include="Grammar\LuaGrammar_ExtensionMethods.cs" />
     <Compile Include="Tree\Expressions\TableConstructor.cs" />
     <Compile Include="Tree\Statements\ScopeBlockStatement.cs" />
     <Compile Include="Tree\Statements\WhileStatement.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <Antlr4 Include="Grammar\Lua.g4">
-      <Generator>MSBuild:Compile</Generator>
-      <CustomToolNamespace>MoonSharp.Interpreter.Grammar</CustomToolNamespace>
-      <Listener>False</Listener>
-      <Visitor>False</Visitor>
-      <ForceAtn>False</ForceAtn>
-    </Antlr4>
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="packages.config" />
-  </ItemGroup>
   <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
-    <PropertyGroup>
-      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
-    </PropertyGroup>
-    <Error Condition="!Exists('..\packages\Antlr4.4.3.0\build\Antlr4.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Antlr4.4.3.0\build\Antlr4.props'))" />
-    <Error Condition="!Exists('..\packages\Antlr4.4.3.0\build\Antlr4.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Antlr4.4.3.0\build\Antlr4.targets'))" />
-  </Target>
-  <Import Project="..\packages\Antlr4.4.3.0\build\Antlr4.targets" Condition="Exists('..\packages\Antlr4.4.3.0\build\Antlr4.targets')" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">

+ 0 - 1
src/MoonSharp.Interpreter/Script.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime;
 using MoonSharp.Interpreter.CoreLib;
 using MoonSharp.Interpreter.DataStructs;
 using MoonSharp.Interpreter.Debugging;

+ 0 - 460
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_BinaryOperatorExpression.cs

@@ -1,460 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Expressions
-{
-	/// <summary>
-	/// 
-	/// </summary>
-	class ANTLR_BinaryOperatorExpression : Expression
-	{
-		[Flags]
-		private enum Operator
-		{
-			NotAnOperator = 0, 
-			
-			Or = 0x1, 
-			And = 0x2,
-			Less = 0x4,
-			Greater = 0x8,
-			LessOrEqual = 0x10,
-
-			GreaterOrEqual = 0x20,
-			NotEqual = 0x40,
-			Equal = 0x80,
-			StrConcat = 0x100,
-			Add = 0x200,
-			Sub = 0x400,
-			Mul = 0x1000,
-			Div = 0x2000,
-			Mod = 0x4000,
-		}
-
-
-		class Node
-		{
-			public Expression Expr;
-			public Operator Op;
-			public Node Prev;
-			public Node Next;
-		}
-
-		class LinkedList
-		{
-			public Node Nodes;
-			public Node Last;
-		}
-
-		const Operator MUL_DIV_MOD = Operator.Mul | Operator.Div | Operator.Mod;
-		const Operator ADD_SUB = Operator.Add | Operator.Sub;
-		const Operator STRCAT = Operator.StrConcat;
-		const Operator COMPARES = Operator.Less | Operator.Greater | Operator.GreaterOrEqual | Operator.LessOrEqual | Operator.Equal | Operator.NotEqual;
-		const Operator LOGIC_AND = Operator.And;
-		const Operator LOGIC_OR = Operator.Or;
-
-		private static Operator CreateLinkedList(LinkedList list, IParseTree root, ScriptLoadingContext lcontext)
-		{
-			Operator opfound = 0;
-
-			foreach (IParseTree tt in root.EnumChilds())
-			{
-				Node n = null;
-
-				if (tt is LuaParser.OperatorbinaryContext)
-				{
-					Operator op = ParseBinaryOperator(tt);
-					opfound |= op;
-					n = new Node() { Op = op };
-				}
-				else
-				{
-					if (tt is LuaParser.Exp_binaryContext)
-					{
-						Operator op = CreateLinkedList(list, tt, lcontext);
-						opfound |= op;
-					}
-					else
-					{
-						n = new Node() { Expr = NodeFactory.CreateExpression(tt, lcontext) };
-					}
-				}
-
-				if (n != null)
-				{
-					if (list.Nodes == null)
-					{
-						list.Nodes = list.Last = n;
-					}
-					else
-					{
-						list.Last.Next = n;
-						n.Prev = list.Last;
-						list.Last = n;
-					}
-				}
-			}
-
-			return opfound;
-		}
-
-
-		/// <summary>
-		/// Creates a sub tree of binary expressions
-		/// </summary>
-		public static Expression CreateSubTree(IParseTree tree, ScriptLoadingContext lcontext)
-		{
-			LinkedList list = new LinkedList();
-
-			Operator opfound = CreateLinkedList(list, tree, lcontext);
-
-			Node nodes = list.Nodes;
-
-			if ((opfound & MUL_DIV_MOD) != 0)
-				nodes = PrioritizeLeftAssociative(tree, nodes, lcontext, MUL_DIV_MOD);
-
-			if ((opfound & ADD_SUB) != 0)
-				nodes = PrioritizeLeftAssociative(tree, nodes, lcontext, ADD_SUB);
-
-			if ((opfound & STRCAT) != 0)
-				nodes = PrioritizeRightAssociative(tree, nodes, lcontext, STRCAT);
-
-			if ((opfound & COMPARES) != 0)
-				nodes = PrioritizeLeftAssociative(tree, nodes, lcontext, COMPARES);
-
-			if ((opfound & LOGIC_AND) != 0)
-				nodes = PrioritizeLeftAssociative(tree, nodes, lcontext, LOGIC_AND);
-
-			if ((opfound & LOGIC_OR) != 0)
-				nodes = PrioritizeLeftAssociative(tree, nodes, lcontext, LOGIC_OR);
-
-
-			if (nodes.Next != null || nodes.Prev != null)
-				throw new InternalErrorException("Expression reduction didn't work! - 1");
-			if (nodes.Expr == null)
-				throw new InternalErrorException("Expression reduction didn't work! - 2");
-			
-			return nodes.Expr;
-		}
-
-		private static Node PrioritizeLeftAssociative(IParseTree tree, Node nodes, ScriptLoadingContext lcontext, Operator operatorsToFind)
-		{
-			for (Node N = nodes; N != null; N = N.Next)
-			{
-				Operator o = N.Op;
-
-				if ((o & operatorsToFind) != 0)
-				{
-					N.Op = Operator.NotAnOperator;
-					N.Expr = new ANTLR_BinaryOperatorExpression(tree, N.Prev.Expr, N.Next.Expr, o, lcontext);
-					N.Prev = N.Prev.Prev;
-					N.Next = N.Next.Next;
-
-					if (N.Next != null)
-						N.Next.Prev = N;
-
-					if (N.Prev != null)
-						N.Prev.Next = N;
-					else
-						nodes = N;
-				}
-			}
-
-			return nodes;
-		}
-
-		private static Node PrioritizeRightAssociative(IParseTree tree, Node nodes, ScriptLoadingContext lcontext, Operator operatorsToFind)
-		{
-			Node last;
-			for (last = nodes; last.Next != null; last = last.Next) ;
-
-			for (Node N = last; N != null; N = N.Prev)
-			{
-				Operator o = N.Op;
-
-				if ((o & operatorsToFind) != 0)
-				{
-					N.Op = Operator.NotAnOperator;
-					N.Expr = new ANTLR_BinaryOperatorExpression(tree, N.Prev.Expr, N.Next.Expr, o, lcontext);
-					N.Prev = N.Prev.Prev;
-					N.Next = N.Next.Next;
-
-					if (N.Next != null)
-						N.Next.Prev = N;
-
-					if (N.Prev != null)
-						N.Prev.Next = N;
-					else
-						nodes = N;
-				}
-			}
-
-			return nodes;
-		}
-
-
-
-
-		private static Operator ParseBinaryOperator(IParseTree parseTree)
-		{
-			string txt = parseTree.GetText();
-
-			switch (txt)
-			{
-				case "or":
-					return Operator.Or;
-				case "and":
-					return Operator.And;
-				case "<":
-					return Operator.Less;
-				case ">":
-					return Operator.Greater;
-				case "<=":
-					return Operator.LessOrEqual;
-				case ">=":
-					return Operator.GreaterOrEqual;
-				case "~=":
-					return Operator.NotEqual;
-				case "==":
-					return Operator.Equal;
-				case "..":
-					return Operator.StrConcat;
-				case "+":
-					return Operator.Add;
-				case "-":
-					return Operator.Sub;
-				case "*":
-					return Operator.Mul;
-				case "/":
-					return Operator.Div;
-				case "%":
-					return Operator.Mod;
-				default:
-					throw new InternalErrorException("Unexpected binary operator '{0}'", txt);
-			}
-		}
-
-
-
-
-		Expression m_Exp1, m_Exp2;
-		Operator m_Operator;
-
-
-
-		private ANTLR_BinaryOperatorExpression(IParseTree tree, Expression exp1, Expression exp2, Operator op, ScriptLoadingContext lcontext)
-			: base (tree, lcontext)
-		{
-			m_Exp1 = exp1;
-			m_Exp2 = exp2;
-			m_Operator = op;
-		}
-
-		private static bool ShouldInvertBoolean(Operator op)
-		{
-			return (op == Operator.NotEqual)
-				|| (op == Operator.GreaterOrEqual)
-				|| (op == Operator.Greater);
-		}
-
-		private static OpCode OperatorToOpCode(Operator op)
-		{
-			switch (op)
-			{
-				case Operator.Less:
-				case Operator.GreaterOrEqual:
-					return OpCode.Less;
-				case Operator.LessOrEqual:
-				case Operator.Greater:
-					return OpCode.LessEq;
-				case Operator.Equal:
-				case Operator.NotEqual:
-					return OpCode.Eq;
-				case Operator.StrConcat:
-					return OpCode.Concat;
-				case Operator.Add:
-					return OpCode.Add;
-				case Operator.Sub:
-					return OpCode.Sub;
-				case Operator.Mul:
-					return OpCode.Mul;
-				case Operator.Div:
-					return OpCode.Div;
-				case Operator.Mod:
-					return OpCode.Mod;
-				default:
-					throw new InternalErrorException("Unsupported operator {0}", op);
-			}
-		}
-
-
-		public override void Compile(Execution.VM.ByteCode bc)
-		{
-			m_Exp1.Compile(bc);
-
-			if (m_Operator == Operator.Or)
-			{
-				Instruction i = bc.Emit_Jump(OpCode.JtOrPop, -1);
-				m_Exp2.Compile(bc);
-				i.NumVal = bc.GetJumpPointForNextInstruction();
-				return;
-			}
-
-			if (m_Operator == Operator.And)
-			{
-				Instruction i = bc.Emit_Jump(OpCode.JfOrPop, -1);
-				m_Exp2.Compile(bc);
-				i.NumVal = bc.GetJumpPointForNextInstruction();
-				return;
-			}
-
-
-			if (m_Exp2 != null)
-			{
-				m_Exp2.Compile(bc);
-			}
-
-			bc.Emit_Operator(OperatorToOpCode(m_Operator));
-
-			if (ShouldInvertBoolean(m_Operator))
-				bc.Emit_Operator(OpCode.Not);
-		}
-
-		public override DynValue Eval(ScriptExecutionContext context)
-		{
-			DynValue v1 = m_Exp1.Eval(context).ToScalar();
-
-			if (m_Operator == Operator.Or)
-			{
-				if (v1.CastToBool())
-					return v1;
-				else
-					return m_Exp2.Eval(context).ToScalar();
-			}
-
-			if (m_Operator == Operator.And)
-			{
-				if (!v1.CastToBool())
-					return v1;
-				else
-					return m_Exp2.Eval(context).ToScalar();
-			}
-
-			DynValue v2 = m_Exp2.Eval(context).ToScalar();
-
-			if ((m_Operator & COMPARES) != 0)
-			{
-				return DynValue.NewBoolean(EvalComparison(v1, v2, m_Operator));				
-			}
-			else if (m_Operator == Operator.StrConcat)
-			{
-				string s1 = v1.CastToString();
-				string s2 = v2.CastToString();
-
-				if (s1 == null || s2 == null)
-					throw new DynamicExpressionException("Attempt to perform concatenation on non-strings.");
-
-				return DynValue.NewString(s1 + s2);
-			}
-			else
-			{
-				return DynValue.NewNumber(EvalArithmetic(v1, v2));
-			}
-		}
-
-		private double EvalArithmetic(DynValue v1, DynValue v2)
-		{
-			double? nd1 = v1.CastToNumber();
-			double? nd2 = v2.CastToNumber();
-
-			if (nd1 == null || nd2 == null)
-				throw new DynamicExpressionException("Attempt to perform arithmetic on non-numbers.");
-
-			double d1 = nd1.Value;
-			double d2 = nd2.Value;
-
-			switch (m_Operator)
-			{
-				case Operator.Add:
-					return d1 + d2;
-				case Operator.Sub:
-					return d1 - d2;
-				case Operator.Mul:
-					return d1 * d2;
-				case Operator.Div:
-					return d1 / d2;
-				case Operator.Mod:
-					{
-						double mod = Math.IEEERemainder(d1, d2);
-						if (mod < 0) mod += d2;
-						return mod;
-					}
-				default:
-					throw new DynamicExpressionException("Unsupported operator {0}", m_Operator);
-			}
-		}
-
-		private bool EvalComparison(DynValue l, DynValue r, Operator op)
-		{
-			switch (op)
-			{
-				case Operator.Less:
-					if (l.Type == DataType.Number && r.Type == DataType.Number)
-					{
-						return (l.Number < r.Number);
-					}
-					else if (l.Type == DataType.String && r.Type == DataType.String)
-					{
-						return (l.String.CompareTo(r.String) < 0);
-					}
-					else
-					{
-						throw new DynamicExpressionException("Attempt to compare non-numbers, non-strings.");
-					}
-				case Operator.LessOrEqual:
-					if (l.Type == DataType.Number && r.Type == DataType.Number)
-					{
-						return (l.Number <= r.Number);
-					}
-					else if (l.Type == DataType.String && r.Type == DataType.String)
-					{
-						return (l.String.CompareTo(r.String) <= 0);
-					}
-					else
-					{
-						throw new DynamicExpressionException("Attempt to compare non-numbers, non-strings.");
-					}
-				case Operator.Equal:
-					if (object.ReferenceEquals(r, l))
-					{
-						return true;
-					}
-					else if (r.Type != l.Type)
-					{
-						if ((l.Type == DataType.Nil && r.Type == DataType.Void)
-							|| (l.Type == DataType.Void && r.Type == DataType.Nil))
-							return true;
-						else
-							return false;
-					}
-					else
-					{
-						return r.Equals(l);
-					}
-				case Operator.Greater:
-					return !EvalComparison(l, r, Operator.LessOrEqual);
-				case Operator.GreaterOrEqual:
-					return !EvalComparison(l, r, Operator.Less);
-				case Operator.NotEqual:
-					return !EvalComparison(l, r, Operator.Equal);
-				default:
-					throw new DynamicExpressionException("Unsupported operator {0}", op);
-			}
-		}
-	}
-}

+ 0 - 54
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionCall.cs

@@ -1,54 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-using MoonSharp.Interpreter.Tree.Expressions;
-
-namespace MoonSharp.Interpreter.Tree
-{
-	class ANTLR_FunctionCall : NodeBase
-	{
-		Expression[] m_Arguments;
-		string m_Name;
-		string m_DebugErr;
-
-		public ANTLR_FunctionCall(LuaParser.NameAndArgsContext nameAndArgs, ScriptLoadingContext lcontext)
-			: base(nameAndArgs, lcontext)
-		{
-			var name = nameAndArgs.NAME();
-			m_Name = name != null ? name.GetText().Trim() : null;
-			m_Arguments = nameAndArgs.args().children.SelectMany(t => NodeFactory.CreateExpressions(t, lcontext)).Where(t => t != null).ToArray();
-			m_DebugErr = nameAndArgs.Parent.GetText();
-		}
-
-		public override void Compile(Execution.VM.ByteCode bc)
-		{
-			int argslen = m_Arguments.Length;
-
-			if (!string.IsNullOrEmpty(m_Name))
-			{
-				bc.Emit_Copy(0);
-				bc.Emit_Literal(DynValue.NewString(m_Name));
-				bc.Emit_Index();
-				bc.Emit_Swap(0, 1);
-				++argslen;
-			}
-
-			for (int i = 0; i < m_Arguments.Length; i++)
-				m_Arguments[i].Compile(bc);
-
-			if (!string.IsNullOrEmpty(m_Name))
-			{
-				bc.Emit_ThisCall(argslen, m_DebugErr);
-			}
-			else
-			{
-				bc.Emit_Call(argslen, m_DebugErr);
-			}
-		}
-	}
-}

+ 0 - 58
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionCallChainExpression.cs

@@ -1,58 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Expressions
-{
-	class ANTLR_FunctionCallChainExpression : Expression
-	{
-		Expression m_StartingExpression;
-		List<ANTLR_FunctionCall> m_CallChain;
-
-		private ANTLR_FunctionCallChainExpression(IParseTree context, ScriptLoadingContext lcontext, 
-			LuaParser.VarOrExpContext varOrExp, IEnumerable<LuaParser.NameAndArgsContext> nameAndArgs)
-			: base(context, lcontext)
-		{
-			m_StartingExpression = NodeFactory.CreateExpression(varOrExp, lcontext);
-			m_CallChain = nameAndArgs.Select(naa => new ANTLR_FunctionCall(naa, lcontext)).ToList();
-		}
-
-		public ANTLR_FunctionCallChainExpression(IParseTree context, ScriptLoadingContext lcontext,
-			Expression startingExpression, IEnumerable<LuaParser.NameAndArgsContext> nameAndArgs)
-			: base(context, lcontext)
-		{
-			m_StartingExpression = startingExpression;
-			m_CallChain = nameAndArgs.Select(naa => new ANTLR_FunctionCall(naa, lcontext)).ToList();
-		}
-
-
-		public ANTLR_FunctionCallChainExpression(LuaParser.Stat_functioncallContext context, ScriptLoadingContext lcontext)
-			: this(context, lcontext, context.varOrExp(), context.nameAndArgs())
-		{ }
-
-		public ANTLR_FunctionCallChainExpression(LuaParser.PrefixexpContext context, ScriptLoadingContext lcontext)
-			: this(context, lcontext, context.varOrExp(), context.nameAndArgs())
-		{ }
-
-
-		public override void Compile(Execution.VM.ByteCode bc)
-		{
-			m_StartingExpression.Compile(bc);
-
-			foreach (ANTLR_FunctionCall fn in m_CallChain)
-			{
-				fn.Compile(bc);
-			}
-		}
-
-		public override DynValue Eval(ScriptExecutionContext context)
-		{
-			throw new DynamicExpressionException("Dynamic Expressions cannot call functions.");
-		}
-	}
-}

+ 0 - 36
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionCallStatement.cs

@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Debugging;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-using MoonSharp.Interpreter.Tree.Expressions;
-
-namespace MoonSharp.Interpreter.Tree.Statements
-{
-	class ANTLR_FunctionCallStatement : Statement
-	{
-		ANTLR_FunctionCallChainExpression m_FunctionCallChain;
-		SourceRef m_SourceRef;
-
-		public ANTLR_FunctionCallStatement(LuaParser.Stat_functioncallContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_FunctionCallChain = new ANTLR_FunctionCallChainExpression(context, lcontext);
-			m_SourceRef = BuildSourceRef(context.Start, context.Stop);
-		}
-
-
-		public override void Compile(ByteCode bc)
-		{
-			using (bc.EnterSource(m_SourceRef))
-			{
-				m_FunctionCallChain.Compile(bc);
-				bc.Emit_Pop();
-			}
-		}
-	}
-}

+ 0 - 198
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionDefinitionExpression.cs

@@ -1,198 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime;
-using MoonSharp.Interpreter.Debugging;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Expressions
-{
-	class ANTLR_FunctionDefinitionExpression : Expression, IClosureBuilder
-	{
-		SymbolRef[] m_ParamNames = null;
-		Statement m_Statement;
-		RuntimeScopeFrame m_StackFrame;
-		List<SymbolRef> m_Closure = new List<SymbolRef>();
-		bool m_HasVarArgs = false;
-		Instruction m_ClosureInstruction = null;
-
-		Table m_GlobalEnv;
-		SymbolRef m_Env;
-
-		SourceRef m_Begin, m_End;
-
-		public ANTLR_FunctionDefinitionExpression(LuaParser.AnonfunctiondefContext context, ScriptLoadingContext lcontext, bool pushSelfParam = false, Table globalContext = null)
-			: this(context.funcbody(), lcontext, context, pushSelfParam, globalContext)
-		{ }
-
-
-		public ANTLR_FunctionDefinitionExpression(LuaParser.Exp_anonfuncContext context, ScriptLoadingContext lcontext, bool pushSelfParam = false, Table globalContext = null)
-			: this(context.funcbody(), lcontext, context, pushSelfParam, globalContext)
-		{ }
-
-		public ANTLR_FunctionDefinitionExpression(LuaParser.FuncbodyContext context, ScriptLoadingContext lcontext, 
-			ParserRuleContext declarationContext,
-			bool pushSelfParam = false, Table globalContext = null)
-			: base(context, lcontext)
-		{
-			var parlist = context.parlist();
-			List<string> paramnames = new List<string>();
-
-			if (pushSelfParam)
-			{
-				paramnames.Add("self");
-			}
-
-
-			if (parlist != null)
-			{
-				var namelist = parlist.namelist();
-
-				if (namelist != null)
-				{
-					paramnames.AddRange(namelist.NAME()
-						.Select(t => t.GetText()));
-				}
-			}
-
-			m_HasVarArgs = (parlist != null && parlist.vararg() != null);
-
-			if (m_HasVarArgs)
-				paramnames.Add(WellKnownSymbols.VARARGS);
-
-			lcontext.Scope.PushFunction(this, m_HasVarArgs);
-
-			if (globalContext != null)
-			{
-				m_GlobalEnv = globalContext;
-				m_Env = lcontext.Scope.TryDefineLocal(WellKnownSymbols.ENV);
-			}
-			else
-			{
-				lcontext.Scope.ForceEnvUpValue();
-			}
-
-			m_ParamNames = DefineArguments(paramnames, lcontext);
-
-			m_Statement = NodeFactory.CreateStatement(context.block(), lcontext);
-
-			m_StackFrame = lcontext.Scope.PopFunction();
-
-			m_Begin = BuildSourceRef(declarationContext.Start, context.PAREN_CLOSE().Symbol);
-			m_End = BuildSourceRef(context.Stop, context.END());
-		}
-
-		public SymbolRef CreateUpvalue(BuildTimeScope scope, SymbolRef symbol)
-		{
-			for (int i = 0; i < m_Closure.Count; i++)
-			{
-				if (m_Closure[i].i_Name == symbol.i_Name)
-				{
-					return SymbolRef.Upvalue(symbol.i_Name, i);
-				}
-			}
-
-			m_Closure.Add(symbol);
-
-			if (m_ClosureInstruction != null)
-			{
-				m_ClosureInstruction.SymbolList = m_Closure.ToArray();
-			}
-
-			return SymbolRef.Upvalue(symbol.i_Name, m_Closure.Count - 1);
-		}
-
-		private SymbolRef[] DefineArguments(List<string> paramnames, ScriptLoadingContext lcontext)
-		{
-			HashSet<string> names = new HashSet<string>();
-
-			SymbolRef[] ret = new SymbolRef[paramnames.Count];
-
-			for (int i = paramnames.Count - 1; i >= 0; i--)
-			{
-				if (!names.Add(paramnames[i]))
-					paramnames[i] = paramnames[i] + "@" + i.ToString();
-				
-				ret[i] = lcontext.Scope.DefineLocal(paramnames[i]);
-			}
-
-			return ret;
-		}
-
-		public int CompileBody(ByteCode bc, string friendlyName)
-		{
-			string funcName = friendlyName ?? "<" + this.m_Begin.FormatLocation(this.LoadingContext.Script, true) + ">";
-
-			bc.PushSourceRef(m_Begin);
-
-			Instruction I = bc.Emit_Jump(OpCode.Jump, -1);
-
-			Instruction meta = bc.Emit_FuncMeta(funcName);
-			int metaip = bc.GetJumpPointForLastInstruction();
-
-			bc.Emit_BeginFn(m_StackFrame);
-
-			bc.LoopTracker.Loops.Push(new LoopBoundary());
-
-			int entryPoint = bc.GetJumpPointForLastInstruction();
-
-			if (m_GlobalEnv != null)
-			{
-				bc.Emit_Literal(DynValue.NewTable(m_GlobalEnv));
-				bc.Emit_Store(m_Env, 0, 0);
-				bc.Emit_Pop();
-			} 
-			
-			if (m_ParamNames.Length > 0)
-				bc.Emit_Args(m_ParamNames);
-
-			m_Statement.Compile(bc);
-
-			bc.PopSourceRef();
-			bc.PushSourceRef(m_End);
-
-			bc.Emit_Ret(0);
-
-			bc.LoopTracker.Loops.Pop();
-
-			I.NumVal = bc.GetJumpPointForNextInstruction();
-			meta.NumVal = bc.GetJumpPointForLastInstruction() - metaip;
-
-			bc.PopSourceRef();
-
-			return entryPoint;
-		}
-
-		public int Compile(ByteCode bc, Func<int> afterDecl, string friendlyName)
-		{
-			using (bc.EnterSource(m_Begin))
-			{
-				SymbolRef[] symbs = m_Closure
-					//.Select((s, idx) => s.CloneLocalAndSetFrame(m_ClosureFrames[idx]))
-					.ToArray();
-
-				m_ClosureInstruction = bc.Emit_Closure(symbs, bc.GetJumpPointForNextInstruction());
-				int ops = afterDecl();
-
-				m_ClosureInstruction.NumVal += 2 + ops;
-			}
-
-			return CompileBody(bc, friendlyName);
-		}
-
-
-		public override void Compile(ByteCode bc)
-		{
-			Compile(bc, () => 0, null);
-		}
-
-
-		public override DynValue Eval(ScriptExecutionContext context)
-		{
-			throw new DynamicExpressionException("Dynamic Expressions cannot define new functions.");
-		}
-	}
-}

+ 0 - 128
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_FunctionDefinitionStatement.cs

@@ -1,128 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using MoonSharp.Interpreter.Debugging;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
-using MoonSharp.Interpreter.Tree.Expressions;
-
-namespace MoonSharp.Interpreter.Tree.Statements
-{
-	class ANTLR_FunctionDefinitionStatement : Statement
-	{
-		SymbolRef m_FuncSymbol;
-		List<string> m_TableAccessors;
-		string m_MethodName;
-		string m_FriendlyName;
-		SourceRef m_SourceRef;
-
-		bool m_Local;
-		ANTLR_FunctionDefinitionExpression m_FuncDef;
-
-		public ANTLR_FunctionDefinitionStatement(LuaParser.Stat_localfuncdefContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_Local = true;
-			m_FuncSymbol = lcontext.Scope.TryDefineLocal(context.NAME().GetText());
-			m_FuncDef = new ANTLR_FunctionDefinitionExpression(context.funcbody(), lcontext, context);
-
-			m_SourceRef = BuildSourceRef(context.Start, context.Stop);
-
-			m_FriendlyName = string.Format("{0} (local)", m_FuncSymbol.i_Name);
-		}
-
-		public ANTLR_FunctionDefinitionStatement(LuaParser.Stat_funcdefContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_Local = false;
-			var node_funcname = context.funcname();
-			var fnname = node_funcname.fnname;
-			var methodaccessor = node_funcname.methodaccessor;
-			var tableaccessor = node_funcname.funcnametableaccessor();
-
-			string nameOfMethodAccessor = methodaccessor != null ? methodaccessor.Text : null;
-			m_TableAccessors = tableaccessor != null ? tableaccessor.Select(s => s.NAME().GetText()).ToList() : new List<string>();
-
-			m_SourceRef = BuildSourceRef(context.Start, context.Stop).SetNoBreakPoint();
-
-			m_FuncDef = new ANTLR_FunctionDefinitionExpression(context.funcbody(), lcontext, context, nameOfMethodAccessor != null);
-
-			if (nameOfMethodAccessor != null || m_TableAccessors.Count > 0)
-			{
-				m_FuncSymbol = lcontext.Scope.Find(fnname.Text);
-
-				m_FriendlyName = fnname.Text + "." + string.Join(".", m_TableAccessors.ToArray());
-
-				if (nameOfMethodAccessor != null)
-					m_FriendlyName += ":" + nameOfMethodAccessor;
-			}
-			else
-			{
-				m_FuncSymbol = lcontext.Scope.Find(fnname.Text);
-				m_FriendlyName = fnname.Text;
-			}
-
-			if (nameOfMethodAccessor != null)
-			{
-				m_MethodName = nameOfMethodAccessor;
-			}
-			else if (m_TableAccessors.Count > 0)
-			{
-				m_MethodName = m_TableAccessors[m_TableAccessors.Count - 1];
-				m_TableAccessors.RemoveAt(m_TableAccessors.Count - 1);
-			}
-		}
-
-
-
-		public override void Compile(Execution.VM.ByteCode bc)
-		{
-			using (bc.EnterSource(m_SourceRef))
-			{
-				if (m_Local)
-				{
-					bc.Emit_Literal(DynValue.Nil);
-					bc.Emit_Store(m_FuncSymbol, 0, 0);
-					m_FuncDef.Compile(bc, () => SetFunction(bc, 2), m_FriendlyName);
-				}
-				else if (m_MethodName == null)
-				{
-					m_FuncDef.Compile(bc, () => SetFunction(bc, 1), m_FriendlyName);
-				}
-				else
-				{
-					m_FuncDef.Compile(bc, () => SetMethod(bc), m_FriendlyName);
-				}
-			}
-		}
-
-		private int SetMethod(Execution.VM.ByteCode bc)
-		{
-			int cnt = 0;
-
-			cnt += bc.Emit_Load(m_FuncSymbol);
-
-			foreach (string str in m_TableAccessors)
-			{
-				bc.Emit_Literal(DynValue.NewString(str));
-				bc.Emit_Index();
-				cnt += 2;
-			}
-
-			bc.Emit_Literal(DynValue.NewString(m_MethodName));
-
-			bc.Emit_IndexSet(0, 0);
-
-			return 2 + cnt;
-		}
-
-		private int SetFunction(Execution.VM.ByteCode bc, int numPop)
-		{
-			int num = bc.Emit_Store(m_FuncSymbol, 0, 0);
-			bc.Emit_Pop(numPop);
-			return num + 1;
-		}
-
-	}
-}

+ 0 - 291
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_LiteralExpression.cs

@@ -1,291 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Expressions
-{
-	class ANTLR_LiteralExpression : Expression
-	{
-		DynValue m_Value;
-
-		public DynValue Value
-		{
-			get { return m_Value; }
-		}
-
-		public ANTLR_LiteralExpression(IParseTree context, ScriptLoadingContext lcontext, DynValue rvalue)
-			: base(context, lcontext)
-		{
-			m_Value = rvalue.AsReadOnly();
-		}
-
-
-		public ANTLR_LiteralExpression(LuaParser.NumberContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			if (m_Value == null) TryParse(context.FLOAT(), s => double.Parse(s, CultureInfo.InvariantCulture));
-			if (m_Value == null) TryParse(context.HEX(), s => (double)ulong.Parse(RemoveHexHeader(s), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
-			if (m_Value == null) TryParse(context.INT(), s => double.Parse(s, CultureInfo.InvariantCulture));
-			if (m_Value == null) TryParse(context.HEX_FLOAT(), s => ParseHexFloat(s));
-
-			if (m_Value == null)
-				throw new SyntaxErrorException("unknown number format near '{0}'", context.GetText());
-		}
-
-
-		private string RemoveHexHeader(string s)
-		{
-			s = s.ToUpperInvariant();
-			if (s.StartsWith("0X"))
-				s = s.Substring(2);
-
-			return s;
-		}
-
-
-		public ANTLR_LiteralExpression(LuaParser.StringContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			ITerminalNode charStr = context.CHARSTRING();
-			ITerminalNode longStr = context.LONGSTRING();
-			ITerminalNode normStr = context.NORMALSTRING();
-
-			if (charStr != null)
-				m_Value = DynValue.NewString(NormalizeNormStr(charStr.GetText(), true)).AsReadOnly();
-			else if (longStr != null)
-				m_Value = DynValue.NewString(NormalizeLongStr_ANTLR(longStr.GetText())).AsReadOnly();
-			else if (normStr != null)
-				m_Value = DynValue.NewString(NormalizeNormStr(normStr.GetText(), true)).AsReadOnly();
-		}
-
-
-
-		private string NormalizeNormStr(string str, bool cutPrefix)
-		{
-			if (cutPrefix) // ANTLR ONLY -- TO REMOVE
-				str = str.Substring(1, str.Length - 2); // removes "/'
-
-			if (!str.Contains('\\'))
-				return str;
-
-			StringBuilder sb = new StringBuilder();
-
-			bool escape = false;
-			bool hex = false;
-			int unicode_state = 0;
-			string hexprefix = "";
-			string val = "";
-			bool zmode = false;
-
-			foreach (char c in str)
-			{
-			redo:
-				if (escape)
-				{
-					if (val.Length == 0 && !hex && unicode_state == 0)
-					{
-						if (c == 'a') { sb.Append('\a'); escape = false; zmode = false; }
-						else if (c == '\r') { }  // this makes \\r\n -> \\n
-						else if (c == '\n') { sb.Append('\n'); escape = false; }  
-						else if (c == 'b') { sb.Append('\b'); escape = false; }
-						else if (c == 'f') { sb.Append('\f'); escape = false; }
-						else if (c == 'n') { sb.Append('\n'); escape = false; }
-						else if (c == 'r') { sb.Append('\r'); escape = false; }
-						else if (c == 't') { sb.Append('\t'); escape = false; }
-						else if (c == 'v') { sb.Append('\v'); escape = false; }
-						else if (c == '\\') { sb.Append('\\'); escape = false; zmode = false; }
-						else if (c == '"') { sb.Append('\"'); escape = false; zmode = false; }
-						else if (c == '\'') { sb.Append('\''); escape = false; zmode = false; }
-						else if (c == '[') { sb.Append('['); escape = false; zmode = false; }
-						else if (c == ']') { sb.Append(']'); escape = false; zmode = false; }
-						else if (c == 'x') { hex = true; }
-						else if (c == 'u') { unicode_state = 1; }
-						else if (c == 'z') { zmode = true; escape = false; }
-						else if (char.IsDigit(c)) { val = val + c; }
-						else throw new SyntaxErrorException("invalid escape sequence near '\\{0}'", c);
-					}
-					else
-					{
-						if (unicode_state == 1)
-						{
-							if (c != '{')
-								throw new SyntaxErrorException("'{' expected near '\\u'");
-
-							unicode_state = 2;
-						}
-						else if (unicode_state == 2)
-						{
-							if (c == '}')
-							{
-								int i = int.Parse(val, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
-								sb.Append(char.ConvertFromUtf32(i));
-								unicode_state = 0;
-								val = string.Empty;
-								escape = false;
-							}
-							else if (val.Length >= 8)
-							{
-								throw new SyntaxErrorException("'}' missing, or unicode code point too large after '\\u'");
-							}
-							else
-							{
-								val += c;
-							}
-						}
-						else if (hex)
-						{
-							if (IsHexDigit(c))
-							{
-								val += c;
-								if (val.Length == 2)
-								{
-									int i = int.Parse(val, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
-									sb.Append(char.ConvertFromUtf32(i));
-									zmode = false; 
-									escape = false;
-								}
-							}
-							else
-							{
-								throw new SyntaxErrorException("hexadecimal digit expected near '\\{0}{1}{2}'", hexprefix, val, c);
-							}
-						}
-						else if (val.Length > 0)
-						{
-							if (char.IsDigit(c))
-							{
-								val = val + c;
-							}
-
-							if (val.Length == 3 || !char.IsDigit(c))
-							{
-								int i = int.Parse(val, CultureInfo.InvariantCulture);
-
-								if (i > 255) 
-									throw new SyntaxErrorException("decimal escape too large near '\\{0}'", val);
-
-								sb.Append(char.ConvertFromUtf32(i));
-
-								zmode = false;
-								escape = false;
-
-								if (!char.IsDigit(c))
-									goto redo;
-							}
-						}
-					}
-				}
-				else
-				{
-					if (c == '\\')
-					{
-						escape = true;
-						hex = false;
-						val = "";
-					}
-					else
-					{
-						if (!zmode || !char.IsWhiteSpace(c))
-						{
-							sb.Append(c);
-							zmode = false;
-						}
-					}
-				}
-			}
-
-			if (escape && !hex && val.Length > 0)
-			{
-				int i = int.Parse(val, CultureInfo.InvariantCulture);
-				sb.Append(char.ConvertFromUtf32(i));
-				escape = false;
-			}
-
-			if (escape)
-			{
-				throw new SyntaxErrorException("unfinished string near '\"{0}\"'", sb.ToString());
-			}
-
-			return sb.ToString();
-		}
-
-		private bool IsHexDigit(char c)
-		{
-			return (char.IsDigit(c)) || ("AaBbCcDdEeFf".Contains(c));
-		}
-
-		private string NormalizeLongStr(string str)
-		{
-			if (str.StartsWith("\r\n"))
-				str = str.Substring(2);
-			else if (str.StartsWith("\n"))
-				str = str.Substring(1);
-
-			return str;
-		}
-
-		private string NormalizeLongStr_ANTLR(string str)
-		{
-			int lenOfPrefix = 0;
-			int squareBracketsFound = 0;
-			str = str.Trim();
-
-			for (int i = 0; i < str.Length; i++)
-			{
-				char c = str[i];
-				if (c == '[')
-					++squareBracketsFound;
-
-				++lenOfPrefix;
-
-				if (squareBracketsFound == 2)
-					break;
-			}
-
-			str = str.Substring(lenOfPrefix, str.Length - lenOfPrefix * 2);
-
-			if (str.StartsWith("\r\n"))
-				str = str.Substring(2);
-			else if (str.StartsWith("\n"))
-				str = str.Substring(1);
-
-			return str;
-		}
-
-		private void TryParse(string txt, Func<string, double> parser)
-		{
-			double val = parser(txt);
-			m_Value = DynValue.NewNumber(val).AsReadOnly();
-		}
-
-
-		private void TryParse(ITerminalNode terminalNode, Func<string, double> parser)
-		{
-			if (terminalNode == null)
-				return;
-
-			string txt = terminalNode.GetText();
-			TryParse(txt, parser);
-		}
-
-		public override void Compile(Execution.VM.ByteCode bc)
-		{
-			bc.Emit_Literal(m_Value);
-		}
-
-		private double ParseHexFloat(string s)
-		{
-			throw new SyntaxErrorException("hex floats are not supported: '{0}'", s);
-		}
-
-		public override DynValue Eval(ScriptExecutionContext context)
-		{
-			return m_Value;
-		}
-	}
-}

+ 0 - 44
src/MoonSharp.Interpreter/Tree/ANTLR_Deprecated/ANTLR_PowerOperatorExpression.cs

@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Expressions
-{
-	class ANTLR_PowerOperatorExpression : Expression
-	{
-		Expression m_Exp1, m_Exp2;
-
-		public ANTLR_PowerOperatorExpression(IParseTree tree, ScriptLoadingContext lcontext)
-			: base(tree, lcontext)
-		{
-			m_Exp1 = NodeFactory.CreateExpression(tree.GetChild(0), lcontext);
-			m_Exp2 = NodeFactory.CreateExpression(tree.GetChild(2), lcontext);
-		}
-
-		public override void Compile(ByteCode bc)
-		{
-			m_Exp1.Compile(bc);
-			m_Exp2.Compile(bc);
-			bc.Emit_Operator(OpCode.Power);
-		}
-
-		public override DynValue Eval(ScriptExecutionContext context)
-		{
-			DynValue v1 = m_Exp1.Eval(context).ToScalar();
-			DynValue v2 = m_Exp1.Eval(context).ToScalar();
-
-			double? d1 = v1.CastToNumber();
-			double? d2 = v1.CastToNumber();
-
-			if (d1.HasValue && d2.HasValue)
-				return DynValue.NewNumber(Math.Pow(d1.Value, d2.Value));
-
-			throw new DynamicExpressionException("Attempt to perform arithmetic on non-numbers.");
-		}
-	}
-}

+ 0 - 74
src/MoonSharp.Interpreter/Tree/Antlr_Interface/AntlrErrorListener.cs

@@ -1,74 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime;
-using MoonSharp.Interpreter.Debugging;
-
-namespace MoonSharp.Interpreter.Tree
-{
-	internal class AntlrErrorListener : BaseErrorListener, IAntlrErrorListener<int>
-	{
-		string m_Msg = null;
-		SourceCode m_Source;
-
-
-		public AntlrErrorListener(SourceCode source)
-		{
-			m_Source = source;
-		}
-
-		public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
-		{
-			if (m_Msg == null) m_Msg = "";
-
-			m_Msg += string.Format("{0}[{1},{2}] : Syntax error near '{3} : {4}'\n",
-				m_Source.Name, line, charPositionInLine, offendingSymbol, msg);
-
-			m_Msg += UnderlineError(offendingSymbol.StartIndex, offendingSymbol.StopIndex, line, charPositionInLine);
-		}
-
-		public string Message { get { return m_Msg; } }
-
-		public override string ToString()
-		{
-			return m_Msg ?? "(null)";
-		}
-
-		public void SyntaxError(IRecognizer recognizer, int offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
-		{
-			if (m_Msg == null) m_Msg = "";
-
-			m_Msg += string.Format("{0}[{1},{2}] : Syntax error : {3}'\n",
-				m_Source.Name, line, charPositionInLine, msg);
-
-			m_Msg += UnderlineError(-1, -1, line, charPositionInLine);
-		}
-
-		protected string UnderlineError(int startIndex, int stopIndex, int line, int charPositionInLine)
-		{
-			string[] lines = m_Source.Lines;
-			StringBuilder errorMessage = new StringBuilder();
-			errorMessage.AppendLine(lines[line].Replace('\t', ' ').Replace('\r', ' ').Replace('\n', ' '));
-
-			for (int i = 0; i < charPositionInLine; i++)
-			{
-				errorMessage.Append(' ');
-			}
-
-			if (startIndex >= 0 && stopIndex >= 0)
-			{
-				for (int i = startIndex; i <= stopIndex; i++)
-					errorMessage.Append('^');
-			}
-			else
-			{
-				errorMessage.Append("^...");
-			}
-
-			errorMessage.AppendLine();
-			return errorMessage.ToString();
-		}
-	}
-
-}

+ 0 - 192
src/MoonSharp.Interpreter/Tree/Antlr_Interface/Loader_Antlr.cs

@@ -1,192 +0,0 @@
-//#define DEBUG_COMPILER
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime;
-using Antlr4.Runtime.Atn;
-using Antlr4.Runtime.Misc;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Debugging;
-using MoonSharp.Interpreter.Diagnostics;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-using MoonSharp.Interpreter.Tree.Expressions;
-using MoonSharp.Interpreter.Tree.Statements;
-
-namespace MoonSharp.Interpreter.Tree
-{
-	/// <summary>
-	/// Class managing most of interactions with ANTLR.
-	/// </summary>
-	internal static class Loader_Antlr
-	{
-		internal static DynamicExprExpression LoadDynamicExpr(Script script, SourceCode source)
-		{
-			AntlrErrorListener listener = new AntlrErrorListener(source);
-
-			try
-			{
-				LuaParser parser = CreateParser(script, new AntlrInputStream(source.Code), source.SourceID, p => p.dynamicexp(), listener);
-
-				ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
-				lcontext.IsDynamicExpression = true;
-				lcontext.Anonymous = true;
-
-				DynamicExprExpression stat;
-
-				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
-					stat = new DynamicExprExpression(parser.dynamicexp(), lcontext);
-
-				return stat;
-			}
-			catch (ParseCanceledException ex)
-			{
-				HandleParserError(ex, listener);
-				throw;
-			}
-		}
-
-		internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
-		{
-			AntlrErrorListener listener = new AntlrErrorListener(source);
-
-			try
-			{
-				LuaParser parser = CreateParser(script, new AntlrInputStream(source.Code), source.SourceID, p => p.chunk(), listener);
-
-				ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
-				ChunkStatement stat;
-
-				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
-					stat = new ChunkStatement(parser.chunk(), lcontext, globalContext);
-
-				int beginIp = -1;
-
-				//var srcref = new SourceRef(source.SourceID);
-
-				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
-				using (bytecode.EnterSource(null))
-				{
-					bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name));
-					beginIp = bytecode.GetJumpPointForLastInstruction();
-					stat.Compile(bytecode);
-					bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name));
-				}
-
-				Debug_DumpByteCode(bytecode, source.SourceID);
-
-				return beginIp;
-			}
-			catch (ParseCanceledException ex)
-			{
-				HandleParserError(ex, listener);
-				throw;
-			}
-		}
-
-		internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
-		{
-			AntlrErrorListener listener = new AntlrErrorListener(source);
-			try
-			{
-				LuaParser parser = CreateParser(script, new AntlrInputStream(source.Code), source.SourceID, p => p.singlefunc(), listener);
-
-				ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
-				ANTLR_FunctionDefinitionExpression fndef;
-
-				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
-					fndef = new ANTLR_FunctionDefinitionExpression(parser.anonfunctiondef(), lcontext, false, globalContext);
-
-				int beginIp = -1;
-
-				// var srcref = new SourceRef(source.SourceID);
-
-				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
-				using (bytecode.EnterSource(null))
-				{
-					bytecode.Emit_Nop(string.Format("Begin function {0}", source.Name));
-					beginIp = fndef.CompileBody(bytecode, source.Name);
-					bytecode.Emit_Nop(string.Format("End function {0}", source.Name));
-
-					Debug_DumpByteCode(bytecode, source.SourceID);
-				}
-
-				return beginIp;
-			}
-			catch (ParseCanceledException ex)
-			{
-				HandleParserError(ex, listener);
-				throw;
-			}
-		}
-
-		private static void HandleParserError(ParseCanceledException ex, AntlrErrorListener listener)
-		{
-			string msg = listener.Message ?? (string.Format("Unknown syntax error. <eof> expected ? : {0}", ex.Message));
-
-			throw new SyntaxErrorException(msg);
-		}
-
-
-		[Conditional("DEBUG_COMPILER")]
-		private static void Debug_DumpByteCode(ByteCode bytecode, int sourceIdx)
-		{
-			//bytecode.Dump(string.Format(@"c:\temp\codedump_{0}.txt", sourceIdx));
-		}
-
-		[Conditional("DEBUG_COMPILER")]
-		private static void Debug_DumpAst(LuaParser parser, int sourceIdx, Func<LuaParser, IParseTree> dumper)
-		{
-			try
-			{
-				AstDump astDump = new AstDump();
-				// astDump.DumpTree(dumper(parser), string.Format(@"c:\temp\treedump_{0:000}.txt", sourceIdx));
-				astDump.WalkTreeForWaste(dumper(parser));
-			}
-			catch { }
-			parser.Reset();
-		}
-
-
-		private static ScriptLoadingContext CreateLoadingContext(Script script, SourceCode source)
-		{
-			return new ScriptLoadingContext(script)
-			{
-				Scope = new BuildTimeScope(),
-				Source = source
-			};
-		}
-
-		private static LuaParser CreateParser(Script script, ICharStream charStream, int sourceIdx, Func<LuaParser, IParseTree> dumper, AntlrErrorListener errorListener)
-		{
-			LuaLexer lexer;
-			LuaParser parser;
-
-			using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Parsing))
-			{
-				lexer = new LuaLexer(charStream);
-				lexer.RemoveErrorListeners();
-				lexer.AddErrorListener(errorListener);
-
-				parser = new LuaParser(new CommonTokenStream(lexer))
-				{
-					ErrorHandler = new BailErrorStrategy(),
-				};
-
-				parser.Interpreter.PredictionMode = PredictionMode.Ll;
-				parser.RemoveErrorListeners();
-				parser.AddErrorListener(errorListener);
-				//Debug_DumpAst(parser, sourceIdx, dumper);
-			}
-
-
-			return parser;
-		}
-
-
-	}
-}

+ 5 - 2
src/MoonSharp.Interpreter/Tree/Expressions/AdjustmentExpression.cs

@@ -1,10 +1,11 @@
-using System;
+#if false
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -30,3 +31,5 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 	}
 }
+
+#endif

+ 0 - 2
src/MoonSharp.Interpreter/Tree/Expressions/BinaryOperatorExpression.cs

@@ -2,10 +2,8 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {

+ 0 - 8
src/MoonSharp.Interpreter/Tree/Expressions/DynamicExprExpression.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -19,13 +18,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-		public DynamicExprExpression(LuaParser.DynamicexpContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			lcontext.Anonymous = true;
-			m_Exp = NodeFactory.CreateExpression(context.exp(), lcontext);
-		}
-
 		public override DynValue Eval(ScriptExecutionContext context)
 		{
 			return m_Exp.Eval(context);

+ 0 - 7
src/MoonSharp.Interpreter/Tree/Expressions/ExprListExpression.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -17,12 +16,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			expressions = exps;
 		}
 
-		public ExprListExpression(LuaParser.ExplistContext tree, ScriptLoadingContext lcontext)
-			: base(tree, lcontext)
-		{
-			expressions = NodeFactory.CreateExpessionArray(tree.children, lcontext).ToList();
-		}
-
 
 		public Expression[] GetExpressions()
 		{

+ 1 - 1
src/MoonSharp.Interpreter/Tree/Expressions/FunctionDefinitionExpression.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Statements;
 
 namespace MoonSharp.Interpreter.Tree.Expressions

+ 4 - 15
src/MoonSharp.Interpreter/Tree/Expressions/IndexExpression.cs

@@ -2,10 +2,8 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -23,22 +21,13 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-		public IndexExpression(IParseTree node, ScriptLoadingContext lcontext, Expression baseExp, Expression indexExp)
-			:base(node, lcontext)
-		{
-			m_BaseExp = baseExp;
-			m_IndexExp = indexExp;
-		}
-
-
-
 		public override void Compile(ByteCode bc)
 		{
 			m_BaseExp.Compile(bc);
 
-			if (m_IndexExp is ANTLR_LiteralExpression)
+			if (m_IndexExp is LiteralExpression)
 			{
-				ANTLR_LiteralExpression lit = (ANTLR_LiteralExpression)m_IndexExp;
+				LiteralExpression lit = (LiteralExpression)m_IndexExp;
 				bc.Emit_Index(lit.Value);
 			}
 			else
@@ -52,9 +41,9 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		{
 			m_BaseExp.Compile(bc);
 
-			if (m_IndexExp is ANTLR_LiteralExpression)
+			if (m_IndexExp is LiteralExpression)
 			{
-				ANTLR_LiteralExpression lit = (ANTLR_LiteralExpression)m_IndexExp;
+				LiteralExpression lit = (LiteralExpression)m_IndexExp;
 				bc.Emit_IndexSet(stackofs, tupleidx, lit.Value);
 			}
 			else

+ 0 - 11
src/MoonSharp.Interpreter/Tree/Expressions/LiteralExpression.cs

@@ -3,9 +3,7 @@ using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -270,15 +268,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-		private void TryParse(ITerminalNode terminalNode, Func<string, double> parser)
-		{
-			if (terminalNode == null)
-				return;
-
-			string txt = terminalNode.GetText();
-			TryParse(txt, parser);
-		}
-
 		public override void Compile(Execution.VM.ByteCode bc)
 		{
 			bc.Emit_Literal(m_Value);

+ 1 - 1
src/MoonSharp.Interpreter/Tree/Expressions/OperatorExpression.cs

@@ -7,7 +7,7 @@ using System.Text;
 using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {

+ 0 - 44
src/MoonSharp.Interpreter/Tree/Expressions/SymbolRefExpression.cs

@@ -2,9 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -46,48 +44,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			}
 		}
 
-
-		public SymbolRefExpression(IParseTree context, ScriptLoadingContext lcontext, SymbolRef refr)
-			: base(context, lcontext)
-		{
-			m_Ref = refr;
-
-			if (lcontext.IsDynamicExpression)
-			{
-				throw new DynamicExpressionException("Unsupported symbol reference expression detected.");
-			}
-		}
-
-
-		public SymbolRefExpression(LuaParser.VarargContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_Ref = lcontext.Scope.TryDefineLocal(WellKnownSymbols.VARARGS);
-
-			if (!lcontext.Scope.CurrentFunctionHasVarArgs())
-			{
-				throw new SyntaxErrorException("error:0: cannot use '...' outside a vararg function");
-			}
-
-			if (lcontext.IsDynamicExpression)
-			{
-				throw new DynamicExpressionException("Cannot use '...' in a dynamic expression.");
-			}
-		}
-
-
-		public SymbolRefExpression(ITerminalNode terminalNode, ScriptLoadingContext lcontext)
-			: base(terminalNode, lcontext)
-		{
-			m_VarName = terminalNode.GetText();
-
-			if (!lcontext.IsDynamicExpression)
-			{
-				m_Ref = lcontext.Scope.Find(m_VarName);
-			}
-		}
-
-
 		public override void Compile(Execution.VM.ByteCode bc)
 		{
 			bc.Emit_Load(m_Ref);

+ 0 - 38
src/MoonSharp.Interpreter/Tree/Expressions/TableConstructor.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -92,43 +91,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-		public TableConstructor(LuaParser.TableconstructorContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			var fieldlist = context.fieldlist();
-
-			if (fieldlist != null)
-			{
-				foreach (var field in fieldlist.field())
-				{
-					var keyval = field.keyexp;
-					var name = field.NAME();
-
-					if (keyval != null)
-					{
-						Expression exp = NodeFactory.CreateExpression(keyval, lcontext);
-
-						m_CtorArgs.Add(new KeyValuePair<Expression,Expression>(
-							exp,
-							NodeFactory.CreateExpression(field.keyedexp, lcontext)));
-					}
-					else if (name != null)
-					{
-						m_CtorArgs.Add(new KeyValuePair<Expression, Expression>(
-							new ANTLR_LiteralExpression(field, lcontext, DynValue.NewString(name.GetText())),
-							NodeFactory.CreateExpression(field.namedexp, lcontext)));
-					}
-					else 
-					{
-						m_PositionalValues.Add(NodeFactory.CreateExpression(field.positionalexp, lcontext));
-					}
-				}
-
-			}
-		}
-
-
-
 		public override void Compile(Execution.VM.ByteCode bc)
 		{
 			bc.Emit_NewTable();

+ 0 - 13
src/MoonSharp.Interpreter/Tree/Expressions/UnaryOperatorExpression.cs

@@ -2,10 +2,8 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Expressions
 {
@@ -23,17 +21,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 
 
 
-		public UnaryOperatorExpression(IParseTree tree, ScriptLoadingContext lcontext)
-			: base(tree, lcontext)
-		{
-			var child0 = tree.GetChild(0);
-
-			m_OpText = child0.GetText();
-
-			m_Exp = NodeFactory.CreateExpression(tree.GetChild(1), lcontext);
-		}
-
-
 		public override void Compile(ByteCode bc)
 		{
 			m_Exp.Compile(bc);

+ 21 - 25
src/MoonSharp.Interpreter/Tree/NodeBase.cs

@@ -2,8 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
@@ -12,18 +10,16 @@ namespace MoonSharp.Interpreter.Tree
 {
 	abstract class NodeBase
 	{
-		protected internal IParseTree TreeNode { get; private set; }
-		protected ScriptLoadingContext LoadingContext { get; private set; }
-
-		protected NodeBase(IParseTree treeNode, ScriptLoadingContext loadingContext)
-		{
-			TreeNode = treeNode;
-			LoadingContext = loadingContext;
+		public NodeBase(ScriptLoadingContext lcontext)
+		{ 
+		
 		}
 
+		protected ScriptLoadingContext LoadingContext { get; private set; }
+
 		public Exception SyntaxError(string format, params object[] args)
 		{
-			return new SyntaxErrorException(TreeNode, format, args);
+			return new SyntaxErrorException(format, args);
 		}
 
 		public void SyntaxAssert(bool condition, string format, params object[] args)
@@ -34,21 +30,21 @@ namespace MoonSharp.Interpreter.Tree
 
 		public abstract void Compile(ByteCode bc);
 
-		protected SourceRef BuildSourceRef(IToken token, ITerminalNode terminalNode)
-		{
-			return RegisterSourceRef(new SourceRef(LoadingContext.Source.SourceID, token.Column, token.Column + terminalNode.GetText().Length, token.Line, token.Line, true));
-		}
-
-		protected SourceRef BuildSourceRef(IToken token1, IToken token2 = null)
-		{
-			token2 = token2 ?? token1;
-			return RegisterSourceRef(new SourceRef(LoadingContext.Source.SourceID, token1.Column, token2.Column + token2.Text.Length, token1.Line, token2.Line, true));
-		}
-
-		protected SourceRef BuildSourceRef(ITerminalNode terminalNode)
-		{
-			return BuildSourceRef(terminalNode.Symbol, terminalNode);
-		}
+		//protected SourceRef BuildSourceRef(IToken token, ITerminalNode terminalNode)
+		//{
+		//	return RegisterSourceRef(new SourceRef(LoadingContext.Source.SourceID, token.Column, token.Column + terminalNode.GetText().Length, token.Line, token.Line, true));
+		//}
+
+		//protected SourceRef BuildSourceRef(IToken token1, IToken token2 = null)
+		//{
+		//	token2 = token2 ?? token1;
+		//	return RegisterSourceRef(new SourceRef(LoadingContext.Source.SourceID, token1.Column, token2.Column + token2.Text.Length, token1.Line, token2.Line, true));
+		//}
+
+		//protected SourceRef BuildSourceRef(ITerminalNode terminalNode)
+		//{
+		//	return BuildSourceRef(terminalNode.Symbol, terminalNode);
+		//}
 
 		private SourceRef RegisterSourceRef(SourceRef sourceRef)
 		{

+ 0 - 283
src/MoonSharp.Interpreter/Tree/NodeFactory.cs

@@ -1,283 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Antlr4.Runtime.Tree;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
-using MoonSharp.Interpreter.Tree.Expressions;
-using MoonSharp.Interpreter.Tree.Statements;
-
-namespace MoonSharp.Interpreter.Tree
-{
-	static class NodeFactory
-	{
-
-		public static Statement CreateStatement(IParseTree tree, ScriptLoadingContext lcontext)
-		{
-			if (tree is Antlr4.Runtime.Tree.TerminalNodeImpl)
-			{ }
-
-			if (tree is LuaParser.BlockContext)
-				return new CompositeStatement((LuaParser.BlockContext)tree, lcontext);
-
-			//if (tree is LuaParser.ChunkContext)
-			//	return new ChunkStatement((LuaParser.ChunkContext)tree, lcontext, null);
-
-			if (tree is LuaParser.Stat_funcdefContext)
-				return new ANTLR_FunctionDefinitionStatement((LuaParser.Stat_funcdefContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_localfuncdefContext)
-				return new ANTLR_FunctionDefinitionStatement((LuaParser.Stat_localfuncdefContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_functioncallContext)
-				return new ANTLR_FunctionCallStatement((LuaParser.Stat_functioncallContext)tree, lcontext);
-
-			if (tree is LuaParser.RetstatContext)
-				return new ReturnStatement((LuaParser.RetstatContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_ifblockContext)
-				return new IfStatement((LuaParser.Stat_ifblockContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_nulstatementContext)
-				return new NullStatement((LuaParser.Stat_nulstatementContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_assignmentContext)
-				return new AssignmentStatement((LuaParser.Stat_assignmentContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_labelContext)
-				return new LabelStatement((LuaParser.Stat_labelContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_localassignmentContext)
-				return new AssignmentStatement((LuaParser.Stat_localassignmentContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_breakContext)
-				return new BreakStatement((LuaParser.Stat_breakContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_forloopContext)
-				return new ForLoopStatement((LuaParser.Stat_forloopContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_foreachloopContext)
-				return new ForEachLoopStatement((LuaParser.Stat_foreachloopContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_whiledoloopContext)
-				return new WhileStatement((LuaParser.Stat_whiledoloopContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_repeatuntilloopContext)
-				return new RepeatStatement((LuaParser.Stat_repeatuntilloopContext)tree, lcontext);
-
-			if (tree is LuaParser.Stat_doblockContext)
-				return new ScopeBlockStatement((LuaParser.Stat_doblockContext)tree, lcontext);
-
-			throw new SyntaxErrorException(tree, "Unexpected statement type: {0}", tree.GetType());
-		}
-
-
-
-
-		public static Expression CreateExpression(IParseTree tree, ScriptLoadingContext lcontext)
-		{
-			IParseTree originalTree = tree;
-
-			// prune dummy tree nodes 
-			while (true)
-			{
-				//if (tree is LuaParser.Exp_logicOrfallbackContext) tree = ((LuaParser.Exp_logicOrfallbackContext)tree).logicAndExp();
-				//else if (tree is LuaParser.Exp_logicAndfallbackContext) tree = ((LuaParser.Exp_logicAndfallbackContext)tree).compareExp();
-				//else if (tree is LuaParser.Exp_comparefallbackContext) tree = ((LuaParser.Exp_comparefallbackContext)tree).strcatExp();
-				//else if (tree is LuaParser.Exp_strcastfallbackContext) tree = ((LuaParser.Exp_strcastfallbackContext)tree).addsubExp();
-				//else if (tree is LuaParser.Exp_addsubfallbackContext) tree = ((LuaParser.Exp_addsubfallbackContext)tree).muldivExp();
-				//else if (tree is LuaParser.Exp_muldivfallbackContext) tree = ((LuaParser.Exp_muldivfallbackContext)tree).unaryExp();
-				//else if (tree is LuaParser.Exp_unaryfallbackContext) tree = ((LuaParser.Exp_unaryfallbackContext)tree).powerExp();
-				//else if (tree is LuaParser.Exp_powerfallbackContext) tree = ((LuaParser.Exp_powerfallbackContext)tree).expterm();
-				//else if (tree is LuaParser.ExptermContext) tree = tree.GetChild(0);
-				//else 
-				if (tree is LuaParser.VarOrExpContext)
-				{
-					// this whole rubbish just to detect adjustments to 1 arg of tuples
-					if ((tree.ChildCount > 0))
-					{
-						Antlr4.Runtime.Tree.TerminalNodeImpl token = tree.GetChild(0) as Antlr4.Runtime.Tree.TerminalNodeImpl;
-
-						if (token != null && token.GetText() == "(")
-						{
-							var subTree = tree.EnumChilds().Single(t => !(t is Antlr4.Runtime.Tree.TerminalNodeImpl));
-							return new AdjustmentExpression(tree, lcontext, subTree);
-						}
-					}
-
-					tree = tree.EnumChilds().Single(t => !(t is Antlr4.Runtime.Tree.TerminalNodeImpl));
-				}
-				else break;
-			}
-
-			//if (tree is LuaParser.ParenthesizedExpressionContext)
-			//{
-			//	return new AdjustmentExpression(tree, lcontext, ((LuaParser.ParenthesizedExpressionContext)tree).exp());
-			//}
-
-			//if (tree is LuaParser.Exp_addsubContext ||
-			//	tree is LuaParser.Exp_compareContext ||
-			//	tree is LuaParser.Exp_logicAndContext ||
-			//	tree is LuaParser.Exp_logicOrContext ||
-			//	tree is LuaParser.Exp_muldivContext ||
-			//	tree is LuaParser.Exp_powerContext ||
-			//	tree is LuaParser.Exp_strcatContext ||
-			//	tree is LuaParser.Exp_unaryContext)
-			//{
-			//	return new OperatorExpression(tree, lcontext);
-			//}
-
-			if (tree is LuaParser.Exp_nilContext) return new ANTLR_LiteralExpression(tree, lcontext, DynValue.Nil);
-			if (tree is LuaParser.Exp_trueContext) return new ANTLR_LiteralExpression(tree, lcontext, DynValue.True);
-			if (tree is LuaParser.Exp_falseContext) return new ANTLR_LiteralExpression(tree, lcontext, DynValue.False);
-
-			if (tree is LuaParser.Exp_numberContext) tree = ((LuaParser.Exp_numberContext)tree).number();
-			if (tree is LuaParser.Exp_stringContext) tree = ((LuaParser.Exp_stringContext)tree).@string();
-			if (tree is LuaParser.Exp_varargsContext) tree = ((LuaParser.Exp_varargsContext)tree).vararg();
-
-			if (tree is LuaParser.Exp_anonfuncContext) return new ANTLR_FunctionDefinitionExpression(((LuaParser.Exp_anonfuncContext)tree), lcontext);
-			if (tree is LuaParser.Exp_prefixexpContext) tree = ((LuaParser.Exp_prefixexpContext)tree).prefixexp();
-			if (tree is LuaParser.Exp_tabctorContext) tree = ((LuaParser.Exp_tabctorContext)tree).tableconstructor();
-			if (tree is LuaParser.Exp_powerContext) return new ANTLR_PowerOperatorExpression(tree, lcontext);
-			if (tree is LuaParser.Exp_unaryContext) return new UnaryOperatorExpression(tree, lcontext);
-			if (tree is LuaParser.Exp_binaryContext) return ANTLR_BinaryOperatorExpression.CreateSubTree(tree, lcontext);
-
-			if (tree is Antlr4.Runtime.Tree.TerminalNodeImpl)
-			{
-				string txt = tree.GetText();
-				if (txt == null) return null;
-				//else if (txt == "nil") return new LiteralExpression(tree, lcontext, DynValue.Nil);
-				//else if (txt == "false") return new LiteralExpression(tree, lcontext, DynValue.False);
-				//else if (txt == "true") return new LiteralExpression(tree, lcontext, DynValue.True);
-				else return null;
-			}
-
-			if (tree is LuaParser.PrefixexpContext)
-			{
-				var prefix = (LuaParser.PrefixexpContext)tree;
-				if (tree.EnumChilds().OfType<LuaParser.NameAndArgsContext>().Any())
-					return new ANTLR_FunctionCallChainExpression(prefix, lcontext);
-				else
-					return CreateExpression(prefix.varOrExp(), lcontext);
-			}
-
-			if (tree is LuaParser.VarContext)
-				return CreateVariableExpression((LuaParser.VarContext)tree, lcontext);
-
-			if (tree is LuaParser.ExplistContext)
-				return new ExprListExpression((LuaParser.ExplistContext)tree, lcontext);
-
-			if (tree is LuaParser.AnonfunctiondefContext)
-				return new ANTLR_FunctionDefinitionExpression((LuaParser.AnonfunctiondefContext)tree, lcontext);
-
-			if (tree is LuaParser.StringContext)
-				return new ANTLR_LiteralExpression((LuaParser.StringContext)tree, lcontext);
-
-			if (tree is LuaParser.NumberContext)
-				return new ANTLR_LiteralExpression((LuaParser.NumberContext)tree, lcontext);
-
-			if (tree is LuaParser.TableconstructorContext)
-				return new TableConstructor((LuaParser.TableconstructorContext)tree, lcontext);
-
-			if (tree is LuaParser.VarargContext)
-				return new SymbolRefExpression((LuaParser.VarargContext)tree, lcontext);
-
-			throw new SyntaxErrorException(tree, "Unexpected expression type: {0}", tree.GetType());
-		}
-
-		public static Expression CreateVariableExpression(LuaParser.VarContext varContext, ScriptLoadingContext lcontext)
-		{
-			Expression varExp;
-			var NAME = varContext.NAME();
-
-			if (NAME != null)
-			{
-				varExp = new SymbolRefExpression(NAME, lcontext);
-			}
-			else
-			{
-				varExp = CreateExpression(varContext.exp(), lcontext);
-			}
-
-			foreach (var suffix in varContext.varSuffix())
-			{
-				var nameAndArgs = suffix.nameAndArgs();
-				var exp = suffix.exp();
-				var suff_NAME = suffix.NAME();
-				Expression indexExp;
-				if (exp != null)
-					indexExp = CreateExpression(exp, lcontext);
-				else
-					indexExp = new ANTLR_LiteralExpression(suff_NAME, lcontext, DynValue.NewString(suff_NAME.GetText()));
-
-				if (nameAndArgs != null && nameAndArgs.Length > 0)
-				{
-					varExp = new ANTLR_FunctionCallChainExpression(suffix, lcontext, varExp, nameAndArgs);
-				}
-
-				varExp = new IndexExpression(suffix, lcontext, varExp, indexExp);
-			}
-
-			return varExp;
-		}
-
-
-
-		public static Expression[] CreateExpressions(IParseTree tree, ScriptLoadingContext lcontext)
-		{
-			if (tree is LuaParser.ExplistContext)
-				return new ExprListExpression((LuaParser.ExplistContext)tree, lcontext).GetExpressions();
-
-			return new Expression[] { CreateExpression(tree, lcontext) };
-		}
-
-		public static Expression[] CreateExpessionArray(IList<IParseTree> expressionNodes, ScriptLoadingContext lcontext)
-		{
-			List<Expression> exps = new List<Expression>();
-
-			foreach (var c in expressionNodes)
-			{
-				var e = NodeFactory.CreateExpression(c, lcontext);
-
-				if (e != null)
-					exps.Add(e);
-			}
-
-			return exps.ToArray();
-		}
-
-		public static IVariable[] CreateVariablesArray(IList<LuaParser.VarContext> expressionNodes, ScriptLoadingContext lcontext)
-		{
-			List<IVariable> exps = new List<IVariable>();
-
-			foreach (var c in expressionNodes)
-			{
-				var e = NodeFactory.CreateVariableExpression(c, lcontext) as IVariable;
-
-				if (e != null)
-					exps.Add(e);
-			}
-
-			return exps.ToArray();
-		}
-
-
-		internal static IVariable[] CreateLocalVariablesArray(IParseTree context, ITerminalNode[] terminalNodes, ScriptLoadingContext lcontext)
-		{
-			List<IVariable> exps = new List<IVariable>();
-
-			foreach (var n in terminalNodes)
-			{
-				string name = n.GetText();
-				var localVar = lcontext.Scope.TryDefineLocal(name);
-				var symbol = new SymbolRefExpression(context, lcontext, localVar) as IVariable;
-
-				if (symbol != null)
-					exps.Add(symbol);
-			}
-
-			return exps.ToArray();
-		}
-	}
-}

+ 1 - 8
src/MoonSharp.Interpreter/Tree/Statement.cs

@@ -3,25 +3,18 @@ using System.Collections.Generic;
 using MoonSharp.Interpreter.Diagnostics;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
 using MoonSharp.Interpreter.Tree.Statements;
 using MoonSharp.Interpreter.Debugging;
-using Antlr4.Runtime;
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree
 {
 	abstract class Statement : NodeBase
 	{
-		public Statement(IParseTree tree, ScriptLoadingContext lcontext)
-			: base(tree, lcontext)
-		{ }
-
 		public Statement(ScriptLoadingContext lcontext)
-			: base(null, lcontext)
+			: base(lcontext)
 		{ }
 
 

+ 1 - 30
src/MoonSharp.Interpreter/Tree/Statements/AssignmentStatement.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree.Statements
@@ -67,35 +67,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public AssignmentStatement(LuaParser.Stat_assignmentContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_LValues = NodeFactory.CreateVariablesArray(context.varlist().var(), lcontext).ToList();
-			m_RValues = NodeFactory.CreateExpessionArray(context.explist().exp(), lcontext).ToList();
-
-			m_Ref = BuildSourceRef(context.Start, context.Stop);
-		}
-
-		public AssignmentStatement(LuaParser.Stat_localassignmentContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			var explist = context.explist();
-
-			if (explist != null)
-			{
-				m_RValues = NodeFactory.CreateExpessionArray(explist.exp(), lcontext).ToList();
-			}
-			else
-			{
-				m_RValues = new Expression[0].ToList();
-			}
-
-			m_LValues = NodeFactory.CreateLocalVariablesArray(context, context.namelist().NAME(), lcontext).ToList();
-
-			m_Ref = BuildSourceRef(context.Start, context.Stop);
-		}
-
-
 		public override void Compile(Execution.VM.ByteCode bc)
 		{
 			using (bc.EnterSource(m_Ref))

+ 1 - 9
src/MoonSharp.Interpreter/Tree/Statements/BreakStatement.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace MoonSharp.Interpreter.Tree.Statements
 {
@@ -21,14 +21,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 
 
 
-		public BreakStatement(LuaParser.Stat_breakContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_Ref = BuildSourceRef(context.Start, context.Stop);
-		}
-
-
-
 		public override void Compile(ByteCode bc)
 		{
 			using (bc.EnterSource(m_Ref))

+ 0 - 15
src/MoonSharp.Interpreter/Tree/Statements/ChunkStatement.cs

@@ -3,12 +3,10 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Diagnostics;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
 using MoonSharp.Interpreter.Tree.Statements;
 
 namespace MoonSharp.Interpreter.Tree.Statements
@@ -39,19 +37,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public ChunkStatement(LuaParser.ChunkContext context, ScriptLoadingContext lcontext, Table globalEnv)
-			: base(context, lcontext)
-		{
-			lcontext.Scope.PushFunction(this, true);
-			m_Env = lcontext.Scope.DefineLocal(WellKnownSymbols.ENV);
-			m_VarArgs = lcontext.Scope.DefineLocal(WellKnownSymbols.VARARGS);
-			
-			m_GlobalEnv = globalEnv;
-
-			m_Block = NodeFactory.CreateStatement(context.block(), lcontext);
-			m_StackFrame = lcontext.Scope.PopFunction();
-		}
-
 		public override void Compile(Execution.VM.ByteCode bc)
 		{
 			Instruction meta = bc.Emit_FuncMeta("<chunk-root>");

+ 2 - 30
src/MoonSharp.Interpreter/Tree/Statements/CompositeStatement.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace MoonSharp.Interpreter.Tree.Statements
 {
@@ -12,30 +12,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 	{
 		List<Statement> m_Statements = new List<Statement>();
 
-		public CompositeStatement(LuaParser.StatContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			if (context.ChildCount > 0)
-			{
-				m_Statements = context.children
-					.Select(t => NodeFactory.CreateStatement(t, lcontext))
-					.Where(s => s != null)
-					.ToList();
-			}
-		}
-
-		public CompositeStatement(LuaParser.BlockContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			if (context.ChildCount > 0)
-			{
-				m_Statements = context.children
-					.Select(t => NodeFactory.CreateStatement(t, lcontext))
-					.Where(s => s != null)
-					.ToList();
-			}
-		}
-
 		public CompositeStatement(ScriptLoadingContext lcontext)
 			: base(lcontext)
 		{
@@ -64,11 +40,7 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			{
 				foreach (Statement s in m_Statements)
 				{
-					if (!(s is NullStatement))
-					{
-						bc.Emit_Debug(s.TreeNode.GetText());
-						s.Compile(bc);
-					}
+					s.Compile(bc);
 				}
 			}
 		}

+ 1 - 31
src/MoonSharp.Interpreter/Tree/Statements/ForEachLoopStatement.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree.Statements
@@ -63,36 +63,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			//m_RefEnd = BuildSourceRef(context.Stop, context.END());
 		}
 
-		public ForEachLoopStatement(LuaParser.Stat_foreachloopContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			context.explist();
-
-			var explist = context.explist();
-
-			m_RValues = NodeFactory.CreateExpression(explist, lcontext);
-
-			lcontext.Scope.PushBlock();
-
-			m_Names = context.namelist().NAME()
-				.Select(n => n.GetText())
-				.Select(n => lcontext.Scope.DefineLocal(n))
-				.ToArray();
-
-			m_NameExps = m_Names
-				.Select(s => new SymbolRefExpression(context, lcontext, s))
-				.Cast<IVariable>()
-				.ToArray();
-
-			
-			m_Block = NodeFactory.CreateStatement(context.block(), lcontext);
-
-			m_StackFrame = lcontext.Scope.PopBlock();
-			m_DebugText = context.GetText();
-
-			m_RefFor = BuildSourceRef(context.Start, context.FOR());
-			m_RefEnd = BuildSourceRef(context.Stop, context.END());
-		}
 
 		public override void Compile(ByteCode bc)
 		{

+ 1 - 23
src/MoonSharp.Interpreter/Tree/Statements/ForLoopStatement.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree.Statements
@@ -53,28 +53,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}		
 
 
-		public ForLoopStatement(LuaParser.Stat_forloopContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			var exps = context.exp();
-
-			m_Start = NodeFactory.CreateExpression(exps[0], lcontext);
-			m_End = NodeFactory.CreateExpression(exps[1], lcontext);
-
-			if (exps.Length > 2)
-				m_Step = NodeFactory.CreateExpression(exps[2], lcontext);
-			else
-				m_Step = new ANTLR_LiteralExpression(context, lcontext, DynValue.NewNumber(1));
-
-			lcontext.Scope.PushBlock();
-			m_VarName = lcontext.Scope.DefineLocal(context.NAME().GetText());
-			m_InnerBlock = NodeFactory.CreateStatement(context.block(), lcontext);
-			m_StackFrame = lcontext.Scope.PopBlock();
-
-			m_RefFor = BuildSourceRef(context.Start, context.FOR());
-			m_RefEnd = BuildSourceRef(context.Stop, context.END());
-		}
-
 		public override void Compile(ByteCode bc)
 		{
 			bc.PushSourceRef(m_RefFor);

+ 1 - 1
src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree.Statements

+ 1 - 39
src/MoonSharp.Interpreter/Tree/Statements/IfStatement.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree.Statements
@@ -68,44 +68,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			return ifblock;
 		}
 
-		public IfStatement(LuaParser.Stat_ifblockContext context, ScriptLoadingContext lcontext)
-			: base(context,lcontext)
-		{
-			int ecount = context.exp().Length;
-			int bcount = context.block().Length;
-
-			for(int i = 0; i < ecount; i++)
-			{
-				var exp = context.exp()[i];
-				var blk = context.block()[i];
-
-				lcontext.Scope.PushBlock();
-				var ifblock = new IfBlock() 
-				{ 
-					Exp = NodeFactory.CreateExpression(exp, lcontext), 
-					Block = NodeFactory.CreateStatement(blk, lcontext),
-					Source = BuildSourceRef(
-						i == 0 ? context.IF().Symbol : context.ELSEIF()[i - 1].Symbol 
-						, exp.Stop)
-				};
-				ifblock.StackFrame = lcontext.Scope.PopBlock();
-
-				m_Ifs.Add(ifblock);
-			}
-
-			if (bcount > ecount)
-			{
-				lcontext.Scope.PushBlock();
-				m_Else = new IfBlock();
-
-				m_Else.Block = NodeFactory.CreateStatement(context.block()[bcount - 1], lcontext);
-				m_Else.StackFrame = lcontext.Scope.PopBlock();
-				m_Else.Source = BuildSourceRef(context.ELSE()); 
-			}
-
-			m_End = BuildSourceRef(context.Stop, context.END());
-		}
-
 
 		public override void Compile(Execution.VM.ByteCode bc)
 		{

+ 5 - 7
src/MoonSharp.Interpreter/Tree/Statements/LabelStatement.cs

@@ -1,9 +1,9 @@
-using System;
+#if false
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Statements
 {
@@ -11,11 +11,7 @@ namespace MoonSharp.Interpreter.Tree.Statements
 	{
 		public string Label { get; private set; }
 
-		public LabelStatement(LuaParser.Stat_labelContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			Label = context.label().NAME().GetText();
-		}
+
 
 		public override void Compile(Execution.VM.ByteCode bc)
 		{
@@ -23,3 +19,5 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 	}
 }
+
+#endif

+ 0 - 21
src/MoonSharp.Interpreter/Tree/Statements/NullStatement.cs

@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Statements
-{
-	class NullStatement : Statement
-	{
-		public NullStatement(LuaParser.Stat_nulstatementContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{ }
-
-
-		public override void Compile(Execution.VM.ByteCode bc)
-		{
-		}
-	}
-}

+ 1 - 15
src/MoonSharp.Interpreter/Tree/Statements/RepeatStatement.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace MoonSharp.Interpreter.Tree.Statements
 {
@@ -34,20 +34,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			//m_Until = BuildSourceRef(exp.Start, exp.Stop);
 		}
 
-		public RepeatStatement(LuaParser.Stat_repeatuntilloopContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			lcontext.Scope.PushBlock();
-			var exp = context.exp();
-
-			m_Block = NodeFactory.CreateStatement(context.block(), lcontext);
-			m_Condition = NodeFactory.CreateExpression(exp, lcontext);
-			m_StackFrame = lcontext.Scope.PopBlock();
-
-			m_Repeat = BuildSourceRef(context.Start, context.REPEAT());
-			m_Until = BuildSourceRef(exp.Start, exp.Stop);
-		}
-
 		public override void Compile(ByteCode bc)
 		{
 			Loop L = new Loop()

+ 1 - 18
src/MoonSharp.Interpreter/Tree/Statements/ReturnStatement.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
+
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree.Statements
@@ -32,23 +32,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public ReturnStatement(LuaParser.RetstatContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			LuaParser.ExplistContext expr = context.children.FirstOrDefault(t => t is LuaParser.ExplistContext) as LuaParser.ExplistContext;
-
-			if (expr != null)
-			{
-				m_Expression = NodeFactory.CreateExpression(expr, lcontext);
-				m_Ref = BuildSourceRef(context.Start, expr.Stop);
-			}
-			else
-			{
-				m_Ref = BuildSourceRef(context.Start, context.RETURN());
-			}
-		}
-
-
 
 		public override void Compile(Execution.VM.ByteCode bc)
 		{

+ 0 - 12
src/MoonSharp.Interpreter/Tree/Statements/ScopeBlockStatement.cs

@@ -4,7 +4,6 @@ using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 
 namespace MoonSharp.Interpreter.Tree.Statements
 {
@@ -28,17 +27,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_StackFrame = lcontext.Scope.PopBlock();
 		}
 
-		public ScopeBlockStatement(LuaParser.Stat_doblockContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			lcontext.Scope.PushBlock();
-			m_Block = NodeFactory.CreateStatement(context.block(), lcontext);
-
-			m_Do = BuildSourceRef(context.Start, context.DO());
-			m_End = BuildSourceRef(context.Stop, context.END());
-
-			m_StackFrame = lcontext.Scope.PopBlock();
-		}
 
 
 		public override void Compile(Execution.VM.ByteCode bc)

+ 1 - 15
src/MoonSharp.Interpreter/Tree/Statements/WhileStatement.cs

@@ -5,7 +5,7 @@ using System.Text;
 using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution;
 using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace MoonSharp.Interpreter.Tree.Statements
 {
@@ -33,20 +33,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_StackFrame = lcontext.Scope.PopBlock();
 		}
 
-		public WhileStatement(LuaParser.Stat_whiledoloopContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			var exp = context.exp();
-			m_Condition = NodeFactory.CreateExpression(exp, lcontext);
-
-			m_Start = BuildSourceRef(context.Start, exp.Stop);
-			m_End = BuildSourceRef(context.Stop, context.END());
-
-			lcontext.Scope.PushBlock();
-			m_Block = NodeFactory.CreateStatement(context.block(), lcontext);
-			m_StackFrame = lcontext.Scope.PopBlock();
-		}
-
 
 		public override void Compile(ByteCode bc)
 		{

+ 1 - 7
src/MoonSharp.Interpreter/Tree/__Expression.cs

@@ -2,21 +2,15 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Antlr4.Runtime.Tree;
 using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Grammar;
 using MoonSharp.Interpreter.Tree.Expressions;
 
 namespace MoonSharp.Interpreter.Tree
 {
 	abstract class Expression : NodeBase
 	{
-		protected Expression(IParseTree node, ScriptLoadingContext lcontext)
-			: base(node, lcontext)
-		{ }
-
 		public Expression(ScriptLoadingContext lcontext)
-			: base(null, lcontext)
+			: base(lcontext)
 		{ }
 
 		public virtual string GetFriendlyDebugName()

+ 0 - 5
src/MoonSharp.Interpreter/packages.config

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="Antlr4" version="4.3.0" targetFramework="net35-Client" />
-  <package id="Antlr4.Runtime" version="4.3.0" targetFramework="net35-Client" />
-</packages>

+ 1 - 1
src/PerformanceComparison/HugeFile.cs

@@ -4,7 +4,7 @@ using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter;
-using MoonSharp.Interpreter.Grammar;
+
 
 namespace PerformanceComparison
 {

BIN
src/packages/Antlr4.4.3.0/Antlr4.4.3.0.nupkg


BIN
src/packages/Antlr4.4.3.0/tools/antlr4-csharp-4.3-complete.jar


+ 0 - 1
src/packages/repositories.config

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <repositories>
   <repository path="..\MoonSharp.Interpreter.Tests\packages.config" />
-  <repository path="..\MoonSharp.Interpreter\packages.config" />
   <repository path="..\MoonSharpTests\packages.config" />
 </repositories>