|
using System;
using System.Collections.Generic;
using System.Text;
namespace EvaluationEngine.Parser
{
public class TokenGroup
{
#region Local Variables
private Tokens tokens = null;
private Variables variables = null;
#endregion
#region Constructor
public TokenGroup()
{
tokens = new Tokens(this);
variables = new Variables();
}
#endregion
#region Public Properties
public Tokens Tokens
{
get
{
return tokens;
}
}
public Variables Variables
{
get
{
return variables;
}
}
#endregion
#region Private/Internal Methods
/// <summary>
/// This method is called when we add a token to Group.Tokens.Add(tk). This methods allows us to collect the
/// unique variables.
/// </summary>
/// <param name="tk"></param>
internal void UpdateVariables(Token tk)
{
// loop through the variables in the current token
foreach (Parser.Variable var in tk.Variables)
{
// check if the variable exists it the Group.Variables collection
if (this.variables.VariableExists(var.VariableName) == false)
{
// we found a new variable to add to our Group.Variables collection
this.variables.Add(var.VariableName);
}
}
}
#endregion
#region Public Methods
public bool EvaluateGroup()
{
string value = "";
string ErrorMsg = "";
bool anyFailures = false;
// first, populate the variable values in each of the tokens
foreach (Parser.Token tk in this.tokens)
{
// loop through each tokens variables
foreach (Parser.Variable var in tk.Variables)
{
if (this.variables.VariableExists(var.VariableName) == true)
{
var.VariableValue = this.variables[var.VariableName].VariableValue;
}
}
// see if we have tokens and an RPN queue
if ((tk.TokenItems.Count > 0) && (tk.RPNQueue.Count > 0)) tk.LastErrorMessage = ""; // reset the last error message
// the variables for the token have been populated; evaluate the token
Evaluate.Evaluator eval = new EvaluationEngine.Evaluate.Evaluator(tk);
if (eval.Evaluate(out value, out ErrorMsg) == false)
{
tk.LastErrorMessage = ErrorMsg;
anyFailures = true;
}
}
return anyFailures;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.