22 lines
790 B
C#
22 lines
790 B
C#
namespace Bts.ArithmeticExpressions;
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
class ArithmeticProgram : IArithmeticProgram {
|
|
readonly ImmutableList<Assignment>? assignments;
|
|
|
|
public ArithmeticProgram(Assignment assignment) =>
|
|
assignments = ImmutableList<Assignment>.Empty.Add(assignment);
|
|
|
|
public ArithmeticProgram(ImmutableList<Assignment> assignments) =>
|
|
this.assignments = assignments;
|
|
|
|
IEnumerable<string> IArithmeticProgram.OutputIdentifiers =>
|
|
assignments.empty_if_null()
|
|
.Select(a => a.Identifier ?? throw new Exception("Identifier string is null"))
|
|
.Distinct();
|
|
|
|
IDictionary<string, object?> IArithmeticProgram.Evaluate(IDictionary<string, object?> env) =>
|
|
assignments.empty_if_null().Aggregate(env, (e, a) => a.Evaluate(e));
|
|
}
|