|
@@ -14,23 +14,22 @@ namespace NTERA.Engine.Compiler
|
|
|
protected ICollection<FunctionDefinition> FunctionDefinitions { get; }
|
|
|
protected ICollection<FunctionDefinition> ProcedureDefinitions { get; }
|
|
|
protected ICollection<FunctionVariable> ConstantDefinitions { get; }
|
|
|
+ protected ICollection<FunctionVariable> GlobalVariables { get; }
|
|
|
+ protected ICollection<FunctionVariable> LocalVariables { get; }
|
|
|
+ protected ICollection<Keyword> ExplicitKeywords { get; }
|
|
|
|
|
|
- protected List<ParserError> Errors { get; } = new List<ParserError>();
|
|
|
- protected List<ParserError> Warnings { get; } = new List<ParserError>();
|
|
|
-
|
|
|
- protected VariableDictionary GlobalVariables { get; }
|
|
|
+ protected CSVDefinition CsvDefinition { get; }
|
|
|
|
|
|
- protected VariableDictionary LocalVariables { get; }
|
|
|
|
|
|
- protected ICollection<Keyword> ExplicitKeywords { get; }
|
|
|
+ protected List<ParserError> Errors { get; } = new List<ParserError>();
|
|
|
+ protected List<ParserError> Warnings { get; } = new List<ParserError>();
|
|
|
|
|
|
- protected CSVDefinition CsvDefinition { get; }
|
|
|
|
|
|
protected IEnumerator<Token> Enumerator { get; }
|
|
|
|
|
|
protected bool hasPeeked = false;
|
|
|
protected Token peekedToken = Token.Unknown;
|
|
|
-
|
|
|
+
|
|
|
protected Token GetNextToken(bool peek = false)
|
|
|
{
|
|
|
if (peek && hasPeeked)
|
|
@@ -49,7 +48,7 @@ namespace NTERA.Engine.Compiler
|
|
|
Lexer.TokenMarker.Line + SelfDefinition.Position.Line - 1,
|
|
|
Lexer.TokenMarker.Column);
|
|
|
|
|
|
- public Parser(string input, FunctionDefinition selfDefinition, ICollection<FunctionDefinition> functionDefinitions, ICollection<FunctionDefinition> procedureDefinitions, VariableDictionary globalVariables, VariableDictionary localVariables, ICollection<Keyword> explicitKeywords, CSVDefinition csvDefinition, ICollection<FunctionVariable> constantDefnitions)
|
|
|
+ public Parser(string input, FunctionDefinition selfDefinition, ICollection<FunctionDefinition> functionDefinitions, ICollection<FunctionDefinition> procedureDefinitions, ICollection<FunctionVariable> globalVariables, ICollection<FunctionVariable> localVariables, ICollection<Keyword> explicitKeywords, CSVDefinition csvDefinition, ICollection<FunctionVariable> constantDefinitions)
|
|
|
{
|
|
|
Lexer = new Lexer(input);
|
|
|
Enumerator = Lexer.GetEnumerator();
|
|
@@ -57,7 +56,7 @@ namespace NTERA.Engine.Compiler
|
|
|
SelfDefinition = selfDefinition;
|
|
|
FunctionDefinitions = functionDefinitions;
|
|
|
ProcedureDefinitions = procedureDefinitions;
|
|
|
- ConstantDefinitions = constantDefnitions;
|
|
|
+ ConstantDefinitions = constantDefinitions;
|
|
|
GlobalVariables = globalVariables;
|
|
|
LocalVariables = localVariables;
|
|
|
ExplicitKeywords = explicitKeywords;
|
|
@@ -118,18 +117,16 @@ namespace NTERA.Engine.Compiler
|
|
|
{
|
|
|
case Token.Identifer:
|
|
|
|
|
|
- if (GlobalVariables.ContainsKey(Lexer.Identifier)
|
|
|
- || LocalVariables.ContainsKey(Lexer.Identifier)
|
|
|
- || ConstantDefinitions.Any(x => x.Name.Equals(Lexer.Identifier, StringComparison.OrdinalIgnoreCase)))
|
|
|
+ if (IsVariable(Lexer.Identifier))
|
|
|
{
|
|
|
string variableName = Lexer.Identifier;
|
|
|
|
|
|
- ValueType type = (ValueType)0;
|
|
|
-
|
|
|
- if (GlobalVariables.ContainsKey(variableName))
|
|
|
- type = GlobalVariables[variableName].Type;
|
|
|
- else if (LocalVariables.ContainsKey(variableName))
|
|
|
- type = LocalVariables[variableName].Type;
|
|
|
+ ValueType type = 0;
|
|
|
+
|
|
|
+ if (GlobalVariables.Any(x => x.Name.Equals(variableName, StringComparison.OrdinalIgnoreCase)))
|
|
|
+ type = GlobalVariables.First(x => x.Name.Equals(variableName, StringComparison.OrdinalIgnoreCase)).ValueType;
|
|
|
+ else if (LocalVariables.Any(x => x.Name.Equals(variableName, StringComparison.OrdinalIgnoreCase)))
|
|
|
+ type = LocalVariables.First(x => x.Name.Equals(variableName, StringComparison.OrdinalIgnoreCase)).ValueType;
|
|
|
else if (ConstantDefinitions.Any(x => x.Name.Equals(variableName, StringComparison.OrdinalIgnoreCase)))
|
|
|
type = ConstantDefinitions.First(x => x.Name.Equals(variableName, StringComparison.OrdinalIgnoreCase)).ValueType;
|
|
|
|
|
@@ -514,6 +511,13 @@ namespace NTERA.Engine.Compiler
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ protected bool IsVariable(string identifier)
|
|
|
+ {
|
|
|
+ return GlobalVariables.Any(x => x.Name.Equals(identifier, StringComparison.OrdinalIgnoreCase))
|
|
|
+ || LocalVariables.Any(x => x.Name.Equals(identifier, StringComparison.OrdinalIgnoreCase))
|
|
|
+ || ConstantDefinitions.Any(x => x.Name.Equals(identifier, StringComparison.OrdinalIgnoreCase));
|
|
|
+ }
|
|
|
+
|
|
|
protected ExecutionNode GetVariable(out ParserError error)
|
|
|
{
|
|
|
string variableName = Lexer.Identifier;
|
|
@@ -562,9 +566,7 @@ namespace NTERA.Engine.Compiler
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (GlobalVariables.ContainsKey(Lexer.Identifier)
|
|
|
- || LocalVariables.ContainsKey(Lexer.Identifier)
|
|
|
- || ConstantDefinitions.Any(x => x.Name == Lexer.Identifier))
|
|
|
+ if (IsVariable(Lexer.Identifier))
|
|
|
{
|
|
|
var subNode = new ExecutionNode
|
|
|
{
|
|
@@ -783,9 +785,7 @@ namespace NTERA.Engine.Compiler
|
|
|
}
|
|
|
else if (token == Token.Identifer)
|
|
|
{
|
|
|
- if (GlobalVariables.ContainsKey(Lexer.Identifier)
|
|
|
- || LocalVariables.ContainsKey(Lexer.Identifier)
|
|
|
- || ConstantDefinitions.Any(x => x.Name == Lexer.Identifier))
|
|
|
+ if (IsVariable(Lexer.Identifier))
|
|
|
{
|
|
|
operands.Push(GetVariable(out error));
|
|
|
if (error != null)
|