public If(Expression e, Statement s, int l, int c) : base(l, c) { Expression = e; Body = s; Else = Statement.Nop; }
public If(Expression e, Statement t, Statement f, int l, int c) : base(l, c) { Expression = e; Body = t; Else = f; }
public For(Statement init, Expression test, Statement iterator, Statement body, int l, int c) : base(l, c) { Initializer = init; Iterator = iterator; Body = body; Test = test; }
public override Expression Reduce() { var e = new Expression[Expressions.Length]; for (int i = 0; i < e.Length; i++) e[i] = Expressions[i].Reduce(); return new Call(Function, Expressions, Line, Column); }
protected Expression Fold(Expression expr, Func<double, double> reducer) { var e = expr.Reduce(); if (e.Kind == ExpressionKind.Constant) { var v = ((Constant)e).Value; if (v.IsReal) return new Constant(reducer(v.Real), Line, Column); } return this; }
public void VisitExpression(Expression e) { switch (e.Kind) { case ExpressionKind.Addition: case ExpressionKind.BitwiseAnd: case ExpressionKind.BitwiseOr: case ExpressionKind.BitwiseXor: case ExpressionKind.Div: case ExpressionKind.Divide: case ExpressionKind.Equality: case ExpressionKind.GreaterThan: case ExpressionKind.GreaterThanOrEqual: case ExpressionKind.LessThan: case ExpressionKind.LessThanOrEqual: case ExpressionKind.LogicalAnd: case ExpressionKind.LogicalOr: case ExpressionKind.LogicalXor: case ExpressionKind.Mod: case ExpressionKind.Multiply: case ExpressionKind.NotEqual: case ExpressionKind.ShiftLeft: case ExpressionKind.ShiftRight: case ExpressionKind.Subtraction: VisitBinaryExpression(e as BinaryExpression); break; case ExpressionKind.Complement: case ExpressionKind.Minus: case ExpressionKind.Not: case ExpressionKind.Plus: VisitUnary(e as UnaryExpression); break; case ExpressionKind.Access: VisitAccess(e as Access); break; case ExpressionKind.Call: VisitCall(e as Call); break; case ExpressionKind.Constant: VisitConstant(e as Constant); break; case ExpressionKind.Grouping: VisitGrouping(e as Grouping); break; case ExpressionKind.None: case ExpressionKind.Id: throw new InvalidOperationException(); } }
protected Expression Fold(Expression expr1, Expression expr2, Func<double, double, double> reducer) { var e1 = expr1.Reduce(); var e2 = expr2.Reduce(); if (e1.Kind == ExpressionKind.Constant && e2.Kind == ExpressionKind.Constant) { var v1 = ((Constant)e1).Value; var v2 = ((Constant)e2).Value; if (v1.IsReal && v2.IsReal) return new Constant(reducer(v1.Real, v2.Real), Line, Column); } return this; }
public NotEqual(Expression e1, Expression e2, int line, int col) : base(e1, e2, line, col) { }
public Not(Expression operand, int line, int col) : base(operand, line, col) { }
public CallStatement(IFunction func, Expression[] expressions, int l, int c) : base(l, c) { this.Call = new Call(func, expressions, l, c); }
public Addition(Expression left, Expression right, int line, int col) : base(left, right, line, col) { }
public LogicalXor(Expression e1, Expression e2, int line, int col) : base(e1, e2, line, col) { }
public Subtraction(Expression left, Expression right, int line, int col) : base(left, right, line, col) { }
public Equality(Expression e1, Expression e2, int line, int col) : base(e1, e2, line, col) { }
public Divide(Expression left, Expression right, int line, int col) : base(left, right, line, col) { }
public BitwiseOr(Expression left, Expression right, int line, int col) : base(left, right, line, col) { }
public Case(Expression x, int l, int c) : base(l, c) { Expression = x; }
public ShiftLeft(Expression left, Expression right, int line, int col) : base(left, right, line, col) { }
public Assignment(Access acc, Expression e, int l, int c) : base(l, c) { Lefthand = acc; Expression = e; }
public Multiply(Expression left, Expression right, int line, int col) : base(left, right, line, col) { }
protected Expression Fold(Expression expr1, Expression expr2, Func<double, double, bool> reducer) { return Fold(expr1, expr2, (v1, v2) => reducer(v1, v2) ? 1.0 : 0.0); }
public Grouping(Expression e, int line, int col) : base(line, col) { InnerExpression = e; }
public Switch(Expression x, IEnumerable<Statement> y, int line, int col) : base(line, col) { Expression = x; Statements = y; }
public Return(Expression e, int line, int col) : base(line, col) { Expression = e; }
public Complement(Expression operand, int line, int col) : base(operand, line, col) { }
public With(Expression e, Statement s, int l, int c) : base(l, c) { Instance = e; Body = s; }
public While(Expression e, Statement s, int line, int col) : base(line,col) { Expression = e; Body = s; }
public Call(IFunction func, Expression[] expressions, int line, int col) : base(line, col) { Function = func; Expressions = expressions; }
public DivideAssignment(Access a, Expression e, int l, int c) : base(a, e, l, c) { }
public GreaterThanOrEqual(Expression e1, Expression e2, int line, int col) : base(e1, e2, line, col) { }