internal ExpressionData Dynamic(string expressionText, CompiledScope scope) { var expression = ToExpression(expressionText, scope); return(ExpressionData.CreateDynamic(expression, scope)); }
public IEnumerable <ExpressionToken> ApplySemantics(ScriptVariableTable variableTable, IEnumerable <InputToken> tokenStream) { var tokens = tokenStream.ToList(); PreprocessSemantics(ref tokens); var rv = new List <ExpressionToken>(tokens.Count()); foreach (var token in tokens) { if (token.OperationType == TranspileTest.OperationType.Operator) { var t = OperatorToOpcode(token); rv.Add(t); } else { switch (token.TokenType) { // TODO Add variable lookups for this we might want some kind of index? // To be stored with the expression? case SemanticTokenType.FunctionCall: { var t = new ExpressionToken { TokenType = token.TokenType, OperationType = OperationType.FunctionCall, Precedence = 9 }; var function = m_HostCallTable.GetFunctionByName(token.TokenValue); t.Data.Int = function.Id; rv.Add(t); break; } case SemanticTokenType.FunctionArgumentSeperator: { rv.Add(new ExpressionToken { TokenType = token.TokenType, OperationType = OperationType.Operand }); break; } case SemanticTokenType.Symbol: { var symbol = HostSymbolTable.GetSymbolByName(token.TokenValue); var expressionData = new ExpressionData() { Int = symbol.SymbolId }; rv.Add(new ExpressionToken { TokenType = token.TokenType, OperationType = OperationType.Operator, Data = expressionData, Precedence = 9 }); break; } default: { var t = new ExpressionToken { TokenType = token.TokenType, OperationType = OperationType.Operand }; if (!t.IsBracket()) { if (t.TokenType == SemanticTokenType.VariableName) { t.Data.Guid = variableTable.GetGuid(token.TokenValue); } else { t.Data.Float = float.Parse(token.TokenValue); } } rv.Add(t); break; } } } } return(rv); }