public override double Visit(VariableNode node) { if (!this.variables.TryGetValue(node.Name, out var value)) { throw EvaluatingException.VariableDoesNotExist(node.Name); } return(value); }
public override double Visit(ConstantNode node) { var constant = this.configuration.EnumerateConstantes().FirstOrDefault(x => x.Key == node.Name); if (constant.Key == null) { throw EvaluatingException.ConstantDoesNotExist(node.Name); } return(constant.Value); }
public EvaluateAstVisitor(IConfigurationEvaluator configurationEvaluation, IDictionary <string, double> variables = null) { this.variables = new Dictionary <string, double>(variables ?? new Dictionary <string, double>()); this.configuration = configurationEvaluation ?? throw new ArgumentNullException(nameof(configurationEvaluation)); foreach (var constant in configurationEvaluation.EnumerateConstantes()) { if (this.variables.ContainsKey(constant.Key)) { throw EvaluatingException.VariableNameConflictsWithExistingConstantName(constant.Key); } this.variables.Add(constant); } }