public override InterpreterResult Interpret(InterpreterEnvironment Env) { InterpreterVariable variable = null; if (Variable.IsLast) { if (Env.CurrentContext.LastVariable == null) { throw new InterpreterException("Invalid use of " + Variable.T.Value, Variable.T); } variable = Env.CurrentContext.LastVariable; } else if (Env.CurrentContext.VariableExists(Variable.Name)) { variable = Env.CurrentContext.GetVariable(Variable.Name); } else { variable = new InterpreterVariable(Variable.Name, InterpreterVariableType.Undefined); Env.CurrentContext.AddVariable(variable); } variable.Type = InterpreterVariableType.String; string value = ""; List <ParseNode> words = Words.GetNodes(); foreach (ParseNode node in words) { WordParseNode word = node as WordParseNode; value += word.Text + " "; } if (value.Length > 0) { value = value.Substring(0, value.Length - 1); } variable.Value = value; return(new InterpreterResult()); }
public override InterpreterResult Interpret(InterpreterEnvironment Env) { InterpreterVariableType typeOfAssignment = InterpreterVariableType.Null; object value = null; if (Value is ParseNodeList) { typeOfAssignment = InterpreterVariableType.Numeric; string strValue = ""; List <ParseNode> wordNodes = (Value as ParseNodeList).GetNodes(); foreach (ParseNode node in wordNodes) { WordParseNode wordNode = node as WordParseNode; if (wordNode.Text == ".") { strValue += "."; continue; } string word = ""; foreach (char c in wordNode.Text) { if (CharactersToIgnore.Contains(c)) { continue; } word += c; } strValue += word.Length % 10; } decimal val = 0; if (!decimal.TryParse(strValue, out val)) { throw new InterpreterException("Invalid poetic number literl", T); } value = val; } else { InterpreterResult rhsResult = Value.Interpret(Env); typeOfAssignment = rhsResult.Type; value = rhsResult.Value; } InterpreterVariable variable = null; if (Variable.IsLast) { if (Env.CurrentContext.LastVariable != null) { variable = Env.CurrentContext.LastVariable; } else { throw new InterpreterException("Invalid use of " + Variable.T.Value, Variable.T); } } else if (Env.CurrentContext.VariableExists(Variable.Name)) { variable = Env.CurrentContext.GetVariable(Variable.Name); } else { variable = new InterpreterVariable(Variable.Name, typeOfAssignment); Env.CurrentContext.AddVariable(variable); } if (variable.Type != typeOfAssignment) { variable.Type = typeOfAssignment; } variable.Value = value; return(new InterpreterResult() { Type = InterpreterVariableType.Null }); }