瀏覽代碼

BEGIN and comment fixes

Bepsi 6 年之前
父節點
當前提交
5d2b59655b

+ 11 - 1
NTERA.Compiler/Compiler.cs

@@ -35,7 +35,10 @@ namespace NTERA.Compiler
 			"IS",
 			"CUP",
 			"CDOWN",
+			"UP",
+			"DOWN",
 			"DOWNBASE",
+			"COUNT",
 			"TCVAR",
 			"CDFLAG",
 			"ITEMPRICE",
@@ -79,6 +82,12 @@ namespace NTERA.Compiler
 			"RELATION",
 			"JUEL",
 			"GOTJUEL",
+			"EJAC",
+			"BOUGHT",
+			"ITEMSALES",
+			"FORWARD", //special casing for SORTCHARA
+			"BACK", //special casing for SORTCHARA
+			"DEBUG_MODE",
 		};
 
 		protected static string[] DefaultGlobalStringVariables =
@@ -172,6 +181,7 @@ namespace NTERA.Compiler
 				new FunctionDefinition("STRLENS", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("CSVBASE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVTALENT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVCSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVEXP", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
@@ -180,7 +190,7 @@ namespace NTERA.Compiler
 				new FunctionDefinition("FINDCHARA", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("LIMIT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("SUBSTRINGU", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GROUPMATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("GROUPMATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0], isArrayParameter: true), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("GETTIME", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("SAVENOS", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("GETCOLOR", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),

+ 8 - 0
NTERA.Interpreter/Compiler/Lexer.cs

@@ -304,6 +304,10 @@ namespace NTERA.Interpreter.Compiler
 				{
 					Value = real;
 					yield return Token.Value;
+
+					if (CurrentChar == '\n')
+						yield return Token.NewLine;
+
 					continue;
 				}
 
@@ -311,6 +315,10 @@ namespace NTERA.Interpreter.Compiler
 				{
 					Value = hexResult;
 					yield return Token.Value;
+
+					if (CurrentChar == '\n')
+						yield return Token.NewLine;
+
 					continue;
 				}
 

+ 47 - 19
NTERA.Interpreter/Compiler/Parser.cs

@@ -199,6 +199,11 @@ namespace NTERA.Interpreter.Compiler
 							Symbol = CurrentPosition
 						};
 
+						if (SelfDefinition.Filename == "EVENT_K15_LIBRARY.ERB" && CurrentPosition.Line == 131)
+						{
+							var f = 3;
+						}
+
 						List<ExecutionNode> subNodes = new List<ExecutionNode>();
 
 						do
@@ -207,22 +212,19 @@ namespace NTERA.Interpreter.Compiler
 							if (error != null)
 								return null;
 
-							if (Enumerator.Current == Token.Identifer)
+							if (Enumerator.Current == Token.To)
 							{
-								if (Lexer.Identifier == "TO")
+								var value2 = Expression(out error);
+								if (error != null)
+									return null;
+
+								subNodes.Add(new ExecutionNode
 								{
-									var value2 = Expression(out error);
-									if (error != null)
-										return null;
-
-									subNodes.Add(new ExecutionNode
-									{
-										Type = "case-to",
-										SubNodes = new[] { value, value2 }
-									});
-
-									continue;
-								}
+									Type = "case-to",
+									SubNodes = new[] { value, value2 }
+								});
+
+								continue;
 							}
 
 							subNodes.Add(new ExecutionNode
@@ -243,7 +245,7 @@ namespace NTERA.Interpreter.Compiler
 						return node;
 					}
 					else if (Lexer.Identifier == "CALL"
-							 || Lexer.Identifier == "BEGIN")
+							 || Lexer.Identifier == "TRYCALL")
 					{
 						Enumerator.MoveNext();
 
@@ -300,7 +302,8 @@ namespace NTERA.Interpreter.Compiler
 						return CallMethod(target, symbolMarker, parameters.ToArray());
 					}
 					else if (Lexer.Identifier == "CALLFORM"
-							 || Lexer.Identifier == "TRYCALLFORM")
+							 || Lexer.Identifier == "TRYCALLFORM"
+							 || Lexer.Identifier == "TRYJUMPFORM")
 					{
 						string statementName = Lexer.Identifier;
 
@@ -384,6 +387,30 @@ namespace NTERA.Interpreter.Compiler
 
 						return node;
 					}
+					else if (Lexer.Identifier == "BEGIN")
+					{
+						var node = new ExecutionNode
+						{
+							Type = "statement",
+							Metadata =
+							{
+								["name"] = "BEGIN"
+							},
+							Symbol = CurrentPosition
+						};
+
+						Enumerator.MoveNext();
+
+						if (Enumerator.Current != Token.Identifer)
+						{
+							error = new ParserError($"Unexpected token: {Enumerator.Current}", CurrentPosition);
+							return null;
+						}
+
+						node.SubNodes = new[] { CreateConstant(Lexer.Identifier) };
+
+						return node;
+					}
 					else //treat as statement
 					{
 						string statementName = Lexer.Identifier;
@@ -702,6 +729,7 @@ namespace NTERA.Interpreter.Compiler
 				   && token != Token.EOF
 				   && token != Token.Comma
 				   && token != Token.Colon
+				   && token != Token.To
 				   && token != Token.CloseBracket
 				   && token != Token.RParen
 				   && token != Token.QuestionMark
@@ -820,7 +848,7 @@ namespace NTERA.Interpreter.Compiler
 		{
 			error = null;
 			ExecutionNode value = null;
-			
+
 			if (Lexer.IsPeeking)
 				Lexer.GetNextChar();
 
@@ -889,7 +917,7 @@ namespace NTERA.Interpreter.Compiler
 					value = value == null
 						? expressionValue
 						: OperateNodes(value, expressionValue, Token.Plus);
-					
+
 					Lexer.GetNextChar();
 					continue;
 				}
@@ -917,7 +945,7 @@ namespace NTERA.Interpreter.Compiler
 				error = new ParserError("Was expecting string to be closed", CurrentPosition);
 				return null;
 			}
-			
+
 			ExecutionNode appendedValue = CreateConstant(currentBlock.ToString());
 
 			value = value == null

+ 3 - 0
NTERA.Interpreter/Compiler/Token.cs

@@ -32,6 +32,9 @@
 		[LexerKeyword("FUNCTIONS")]
 		ReturnFunction,
 
+		[LexerKeyword("TO")]
+		To,
+
 		[LexerCharacter('\n')]
 		NewLine,