public BinaryExpresssion(BinaryExpressionType type, LogicalExpression leftExpression, LogicalExpression rightExpression) { this.type = type; this.leftExpression = leftExpression; this.rightExpression = rightExpression; }
public static LogicalExpression Create(CommonTree ast) { if (ast == null) { throw new ArgumentNullException("tree"); } switch (ast.Type) { case ECalcParser.STRING: return(new Value(extractString(ast.Text), ValueType.String)); case ECalcParser.INTEGER: return(new Value(ast.Text, ValueType.Integer)); case ECalcParser.BOOLEAN: return(new Value(ast.Text, ValueType.Boolean)); case ECalcParser.DATETIME: return(new Value(ast.Text, ValueType.DateTime)); case ECalcParser.FLOAT: return(new Value(ast.Text, ValueType.Float)); case ECalcParser.NOT: return(new UnaryExpression(UnaryExpressionType.Not, Create((CommonTree)ast.GetChild(0)))); case ECalcParser.NEGATE: return(new UnaryExpression(UnaryExpressionType.Negate, Create((CommonTree)ast.GetChild(0)))); case ECalcParser.MULT: return(new BinaryExpresssion(BinaryExpressionType.Times, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.POW: return(new BinaryExpresssion(BinaryExpressionType.Pow, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.DIV: return(new BinaryExpresssion(BinaryExpressionType.Div, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.MOD: return(new BinaryExpresssion(BinaryExpressionType.Modulo, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.PLUS: return(new BinaryExpresssion(BinaryExpressionType.Plus, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.MINUS: return(new BinaryExpresssion(BinaryExpressionType.Minus, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.LT: return(new BinaryExpresssion(BinaryExpressionType.Lesser, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.LTEQ: return(new BinaryExpresssion(BinaryExpressionType.LesserOrEqual, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.GT: return(new BinaryExpresssion(BinaryExpressionType.Greater, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.GTEQ: return(new BinaryExpresssion(BinaryExpressionType.GreaterOrEqual, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.EQUALS: return(new BinaryExpresssion(BinaryExpressionType.Equal, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.NOTEQUALS: return(new BinaryExpresssion(BinaryExpressionType.NotEqual, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.AND: return(new BinaryExpresssion(BinaryExpressionType.And, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcParser.OR: return(new BinaryExpresssion(BinaryExpressionType.Or, Create((CommonTree)ast.GetChild(0)), Create((CommonTree)ast.GetChild(1)))); case ECalcLexer.IDENT: LogicalExpression[] expressions = new LogicalExpression[ast.ChildCount]; for (int i = 0; i < ast.ChildCount; i++) { expressions[i] = LogicalExpression.Create((CommonTree)ast.GetChild(i)); } return(new Function(ast.Text, expressions)); case ECalcLexer.PARAM: return(new Parameter(((CommonTree)ast.GetChild(0)).Text)); default: return(null); } }
private object Evaluate(LogicalExpression expression) { expression.Accept(this); return(result); }
public override void Visit(LogicalExpression expression) { throw new Exception("The method or operation is not implemented."); }
public UnaryExpression(UnaryExpressionType type, LogicalExpression expression) { this.type = type; this.expression = expression; }