static void Main(string[] args) { Context ctx = new Context(); ctx.SetValue( "x", true ); ctx.SetValue( "y", false ); AbstractExpression left = new UnaryExpression(new ConstExpression(new ConstToken(false)), new Negation()); AbstractExpression right_x = new ConstExpression(new VariableToken("x")); AbstractExpression right_y = new ConstExpression(new VariableToken("y")); AbstractExpression expr = new BinaryExpression( left, right_x, new Conjunction() ); AbstractExpression expr2 = new BinaryExpression( left, right_y, new Conjunction() ); AbstractExpression expr3 = new BinaryExpression( left, right_y, new Alternative() ); Console.WriteLine(expr.Interpret(ctx)); Console.WriteLine(expr2.Interpret(ctx)); Console.WriteLine(expr3.Interpret(ctx)); Console.ReadKey(); }
public abstract bool Interpret(Context context);
public override bool Interpret(Context context) { return token.Interpret(context); }
public override bool Interpret(Context context, AbstractExpression left, AbstractExpression right) { return left.Interpret(context) && right.Interpret(context); }
public override bool Interpret(Context context) { return binaryOperator.Interpret( context, leftExpression, rightExpression ); }
public override bool Interpret(Context context) { return unaryOperator.Interpret( context, expression ); }
public abstract bool Interpret(Context context, AbstractExpression expression);
public abstract bool Interpret(Context context, AbstractExpression left, AbstractExpression right);
public override bool Interpret(Context context) { return value; }
public override bool Interpret(Context context, AbstractExpression expression) { return !expression.Interpret( context ); }
public override bool Interpret(Context context) { return context.GetValue( variableName ); }