public FunctionDefinition(Type returnType, string name, Type argumentType, string argumentName, Expression body) { _argument = Tuple.Create(argumentName, argumentType); _body = body; _returnType = returnType; _name = name; }
public SqlQuery QueryRecords(DatasetInfo dataset, Expression expression) { var builder = new SqlBuilder(adapter) .Select(dataset.Members) .From(dataset.Name) .Where(expression); return new SqlQuery(builder.ToString(), builder.Parameters); }
public SubtractExpression(Expression operand1, Expression operand2) : base(operand1, operand2) { base.symbol = '-'; }
public BinaryOperation(Operator op, Expression e1, Expression e2) { _op = op; _e1 = e1; _e2 = e2; }
void SimExpr(out Expression e) { Expression e1, e2; Operator op; Term(out e1); e = e1; while (la.kind == 17 || la.kind == 18) { AddOp(out op); Term(out e2); e = new BinaryOperation(op, e, e2); } }
void Factor(out Expression e) { string name; Expression e1; e = null; if (la.kind == 1) { Ident(out name); e = new Variable(name); if (la.kind == 3) { Get(); Expr(out e1); Expect(4); e = new FunctionCall(name, e1); } } else if (la.kind == 2) { Get(); e = new Constant(int.Parse(t.val), Type.IntegerType); } else if (la.kind == 18) { Get(); Factor(out e1); e = new UnaryOperation(Operator.Neg, e1); } else if (la.kind == 3) { Get(); Expr(out e1); Expect(4); e = e1; } else SynErr(25); }
void BoolTerm(out Expression e) { Expression e1, e2; Operator op; e = null; SimBoolExpr(out e1); e = e1; while (la.kind == 10) { OrOp(out op); SimBoolExpr(out e2); e = new BinaryOperation(op, e, e2); } }
public Program(IDictionary<string, FunctionDefinition> functions, Expression expression) { _functionEnvironment = new FunctionEnvironment(functions); _expression = expression; }
public AddExpression(Expression operand1, Expression operand2) : base(operand1, operand2) { base.symbol = '+'; }
public Expression GetKeyFilter(DatasetInfo schema) { var conditions = new Expression[schema.PrimaryKey.Size]; for (var i = 0; i < conditions.Length; i++) { var key = schema.PrimaryKey[i]; conditions[i] = Expression.Eq(key.Name, new Symbol("@" + key.PropertyName)); } return Expression.Conjunction(conditions); }
private Expression Expand(Expression expression, DatasetInfo baseTable) { if (expression is Symbol) { var symbol = (Symbol)expression; var member = baseTable[symbol.Name]; var prefix = member.IsKey || member.IsMutable || member.IsVersion ? "v" : "a"; return new Symbol(prefix, member.Name); } else if (expression is BinaryExpression) { var binary = (BinaryExpression)expression; var lhs = Expand(binary.Left, baseTable); var rhs = Expand(binary.Right, baseTable); return new BinaryExpression(lhs, binary.Op, rhs); } return expression; }
public SqlQuery QueryVersions(DatasetInfo baseTable, DatasetInfo versionedTable, Expression expression) { var sql = new SqlBuilder(adapter); var v = new SchemaObject(versionedTable.Name, "v"); var a = new SchemaObject(baseTable.Name, "a"); sql.Append("SELECT "); sql.WriteColumns(versionedTable.Members, prefix: "v"); // mutable values, primary keys, ... sql.Append(", "); sql.WriteColumns(baseTable.Members.Where(m => !m.IsVersion && !m.IsKey && !m.IsMutable), prefix: "a"); // immutable values from base table sql.From(v); // SELECT from v var keyName = baseTable.PrimaryKey[0].Name; // join the base (immutable) values with the versioned values sql.InnerJoin( baseTable : v, // versioned values joinedTable : a, // base values baseColumn : keyName, joinedColumn : keyName ); sql.Where(Expand(expression, baseTable)); return new SqlQuery(sql.ToString(), sql.Parameters); }
public FunctionCall(string name, Expression arg) { _name = name; _arg = arg; }
protected UnaryExpression(Expression operand1) { this.operand1 = operand1; }
public SqlQuery QueryFirst(DatasetInfo dataset, Expression expression) { var sql = new SqlBuilder(adapter) .Select(dataset.Members) .From(dataset.Name) .Where(expression) .Limit(1); return new SqlQuery(sql.ToString(), sql.Parameters); }
protected BinaryExpression(Expression operand1, Expression operand2) { this.operand1 = operand1; this.operand2 = operand2; }
public object ProcessPart(object val) { if (DEBUG) Console.WriteLine("Process part"); if (val != null) { if (expr[_offset] != '.') throw new FormatException("Invalid symbol: " + expr[_offset]); _offset++; } var c = expr[_offset]; if (DEBUG) Console.WriteLine(_offset + ": " + c); if (c == '\'' || c == '"') // String expression { return ReadString(); } if (Char.IsDigit(c)) { return ReadDigit(); } if (Char.IsLetter(c)) // Variable { string word = ReadWord(); if (DEBUG) Console.WriteLine("Word: " + word); if (Search('(')) // Method calling { if (DEBUG) Console.WriteLine("Method: " + val + "." + word); string argStr = ReadBracers().Trim(); if (argStr.Length > 0) { string[] argParts = argStr.Split(','); object[] args = new object[argParts.Length]; for (int i = 0; i < argParts.Length; i++) { object arg = new Expression(argParts[i], _scopes).Process(); args[i] = arg; } if (DEBUG) Console.WriteLine("Call: " + word + "(" + String.Join(", ", args) + ")"); return Call(val, word, args); } else { if (DEBUG) Console.WriteLine("Call: " + word + "()"); return Call(val, word); } } else // Variable or property { if (val == null) // TODO Check on first word, because it can be property or method result { if (DEBUG) Console.WriteLine("Variable: " + word); return GetVariable(word); } else { if (DEBUG) Console.WriteLine("Property: " + word + " of " + val); return GetProperty(val, word); } } } if (c == '(') { string argStr = ReadBracers(); object arg = new Expression(argStr, _scopes).Process(); return arg; } throw new FormatException(String.Format("Wrong symbol '{0}' at {1}", c, _offset)); }
public DivideExpression(Expression operand1, Expression operand2) : base(operand1, operand2) { base.symbol = '/'; }
public ModulusExpression(Expression operand1, Expression operand2) : base(operand1, operand2) { base.symbol = '%'; }
public UnaryOperation(Operator op, Expression expression) { _op = op; _expression = expression; }
public MultiplyExpression(Expression operand1, Expression operand2) : base(operand1, operand2) { base.symbol = '*'; }
void Expr(out Expression e) { Expression e1, e2; Operator op; e = null; BoolTerm(out e1); e = e1; while (la.kind == 9) { AndOp(out op); BoolTerm(out e2); e = new BinaryOperation(op, e, e2); } }
public NegateExpression(Expression operand1) : base(operand1) { base.symbol = '!'; }
void SimBoolExpr(out Expression e) { Expression e1, e2; Operator op; e = null; SimExpr(out e1); e = e1; if (StartOf(1)) { RelOp(out op); SimExpr(out e2); e = new BinaryOperation(op, e, e2); } }
public PowerExpression(Expression operand1, Expression operand2) : base(operand1, operand2) { base.symbol = '^'; }
void Term(out Expression e) { Operator op; Expression e1, e2; Factor(out e1); e = e1; while (la.kind == 19 || la.kind == 20) { MulOp(out op); Factor(out e2); e = new BinaryOperation(op, e, e2); } }
// BinaryOperationRHS ::= ('+' primary)* private Expression ParseBinaryOperationRHS(Lexer lexer, int previousPrecedence, Expression LHS) { while (true) { // get current token and find its precedence var currentToken = lexer.Next(); int currentPrecedence = GetTokenPrecedence(currentToken); // if the current precedence is less that the previous, return LHS as it is if (currentPrecedence < previousPrecedence) { lexer.UnGet(currentToken); return LHS; } var operation = (currentToken as BinaryOperatorLexToken).Value(); // otherwise, parse out the RHS var RHS = ParsePrimary(lexer); if (RHS == null) { return null; } // If BinOp binds less tightly with RHS than the operator after RHS, let // the pending operator take RHS as its LHS. var tokenAfterRHS = lexer.Next(); lexer.UnGet(tokenAfterRHS); var afterRHSPrecendence = GetTokenPrecedence(tokenAfterRHS); if (currentPrecedence < afterRHSPrecendence) { RHS = ParseBinaryOperationRHS(lexer, currentPrecedence + 1, RHS); } // merge LHS and RHS LHS = new BinaryOperatorExpression(operation, LHS, RHS); } }