private System.Type TypeOfExpr(expr expr) { if (expr is StringLiteral) { return(typeof(string)); //setting the type of expr to type string } else if (expr is IntLiteral) { return(typeof(int)); //type to int } else if (expr is Variable) { Variable var = (Variable)expr; if (this.symbolTable.ContainsKey(var.Ident)) { Emit.LocalBuilder locb = symbolTable[var.Ident]; //loacal variable assigned the value of symbol table at key var.Ident return(locb.LocalType); } else { throw new System.Exception("undeclared variable '" + var.Ident + "'"); } } else if (expr is BinExpr) { BinExpr var = (BinExpr)expr; return(typeof(int)); } else { throw new System.Exception("don't know how to calculate the type of " + expr.GetType().Name); } }
public override object VisitBetweenExpr([NotNull] SQLiteParser.BetweenExprContext context) { var left = new BinExpr((Expr)Visit(context.arith_expr(0)), (Expr)Visit(context.arith_expr(1)), ">="); var right = new BinExpr((Expr)Visit(context.arith_expr(0)), (Expr)Visit(context.arith_expr(2)), "<="); return(new LogicAndExpr(left, right)); }
// parse private string Parse() { foreach (string token in Tokens) { if (IsNumber(token)) { Stack.Push(new Number(token)); } else if (token == "X") { Stack.Push(new Number(token)); } else if (IsUnary(token)) { Stack.Push(UnaryExpr.Create(Stack, token)); } else { Stack.Push(BinExpr.Create(Stack, token)); } } StringBuilder sb = new StringBuilder(); Stack.Pop().Write(sb); return(sb.ToString()); }
void addExpr(out Expr e) { Operator op; Expr e2; multExpr(out e); if (la.kind == 5 || la.kind == 6) { addExprOp(out op, out e2); e = new BinExpr(e, op, e2); } }
void multExpr(out Expr e) { Operator op; Expr e2; terminalExpr(out e); if (la.kind == 7 || la.kind == 8 || la.kind == 9) { multExprOp(out op, out e2); e = new BinExpr(e, op, e2); } }
private void extraerTokens(BinExpr binExpr) { Tokens.Add(binExpr.Left); Tokens.Add(binExpr.Op); if (binExpr.Right is Variable || binExpr.Right is IntLiteral) Tokens.Add(binExpr.Right); else if(binExpr.Right is BinExpr) extraerTokens((BinExpr)binExpr.Right); }
private ICollection normalize_bin_args(BinExpr e) { var args = new ArrayList(); XPathNode left = (XPathNode)e.left().accept(this); XPathNode right = (XPathNode)e.right().accept(this); args.Add(left); args.Add(right); return(args); }
private void extraerTokens(BinExpr binExpr) { Tokens.Add(binExpr.Left); Tokens.Add(binExpr.Op); if (binExpr.Right is Variable || binExpr.Right is IntLiteral) { Tokens.Add(binExpr.Right); } else if (binExpr.Right is BinExpr) { extraerTokens((BinExpr)binExpr.Right); } }
LogicNode inToMarkJoin(LogicNode planWithSubExpr, InSubqueryExpr inExpr) { LogicNode nodeA = planWithSubExpr; // nodeB contains the join filter var nodeB = inExpr.query_.logicPlan_; var nodeBFilter = nodeB.filter_; nodeB.NullifyFilter(); // nullify nodeA's filter: the rest is push to top filter. However, // if nodeA is a Filter|MarkJoin, keep its mark filter. var markerFilter = new ExprRef(new MarkerExpr(nodeBFilter.tableRefs_, inExpr.subqueryid_), 0); var nodeAFilter = extractCurINExprFromNodeAFilter(nodeA, inExpr, markerFilter); // consider SQL ...a1 in select b1 from... // a1 is outerExpr and b1 is selectExpr Expr outerExpr = inExpr.child_(); Debug.Assert(inExpr.query_.selection_.Count == 1); Expr selectExpr = inExpr.query_.selection_[0]; BinExpr inToEqual = BinExpr.MakeBooleanExpr(outerExpr, selectExpr, "=", true); // make a mark join LogicMarkJoin markjoin; if (inExpr.hasNot_) { markjoin = new LogicMarkAntiSemiJoin(nodeA, nodeB, inExpr.subqueryid_); } else { markjoin = new LogicMarkSemiJoin(nodeA, nodeB, inExpr.subqueryid_); } // make a filter on top of the mark join collecting all filters Expr topfilter = nodeAFilter.SearchAndReplace(inExpr, markerFilter); nodeBFilter.DeParameter(nodeA.InclusiveTableRefs()); topfilter = topfilter.AddAndFilter(nodeBFilter); // TODO mutiple nested insubquery subquery // seperate the overlapping code with existsToSubquery to a new method // when the PR in #support nestted exist subquery pass LogicFilter Filter = new LogicFilter(markjoin, topfilter); Filter = new LogicFilter(Filter, inToEqual); return(Filter); }
// fs:fname( fs:convert-operand( fn:data(ARG1), 1.0E0 ), // fs:convert-operand( fn:data(ARG2), 1.0E0 ) // ) private XPathExpr make_convert_binop(BinExpr e, XPathExpr convarg, QName name) { throw new Exception(); //ICollection args = normalize_bin_args(e); //XPathExpr[] args_arr = new XPathExpr[2]; //int j = 0; //for (IEnumerator i = args.GetEnumerator(); i.MoveNext();) //{ // args_arr[j] = (XPathExpr) i.Current; // j++; //} //var argsfname = new ArrayList(); //for (j = 0; j < 2; j++) //{ // XPathExpr arg = make_convert_operand(args_arr[j], convarg); // argsfname.Add(arg); //} //return make_function(name, argsfname); }
private BinExpr make_logic_expr(BinExpr e) { throw new Exception(); //ICollection normalized = normalize_bin_args(e); //XPathNode[] nor_arr = new XPathNode[2]; //int j = 0; //for (IEnumerator i = normalized.GetEnumerator(); i.MoveNext();) //{ // nor_arr[j] = (XPathNode) i.Current; // j++; //} //var args = new List<XPathNode>(); //args.Add(nor_arr[0]); //e.set_left(make_function(new QName("fn", "boolean", FnFunctionLibrary.XPATH_FUNCTIONS_NS), args)); //args.Clear(); //args.Add(nor_arr[1]); //e.set_right(make_function(new QName("fn", "boolean", FnFunctionLibrary.XPATH_FUNCTIONS_NS), args)); //return e; }
private Expr ParseExpr() { if (this.index == this.tokens.Count) { throw new System.Exception("expected expression, got EOF"); } Expr expr = null; while (this.tokens[this.index] != Scanner.Semi) { if (this.tokens[this.index] is Text.StringBuilder) { string value = ((Text.StringBuilder) this.tokens[this.index++]).ToString(); StringLiteral stringLiteral = new StringLiteral(); stringLiteral.Value = value; return(stringLiteral); } else if (this.tokens[this.index] is AMExpression) { AMExpression amExpression = (AMExpression)this.tokens[this.index++]; BinExpr binExpr = new BinExpr(); binExpr.Op = BinOp.Mul; if (amExpression is ADD) { binExpr.Op = BinOp.Add; } else if (amExpression is SUB) { binExpr.Op = BinOp.Sub; } else if (amExpression is MUL) { binExpr.Op = BinOp.Mul; } else if (amExpression is DIV) { binExpr.Op = BinOp.Div; } binExpr.Left = expr; expr = binExpr; } else if (this.tokens[this.index] is LogicalExpression) { LogicalExpression logicalExpression = (LogicalExpression)this.tokens[this.index++]; BinExpr binExpr = new BinExpr(); if (logicalExpression is EqualTo) { binExpr.Op = BinOp.EqualTo; } else if (logicalExpression is NotEqualTo) { binExpr.Op = BinOp.NotEqualTo; } binExpr.Left = expr; expr = binExpr; } else if (this.tokens[this.index] is int && expr != null) { int intValue = (int)this.tokens[this.index++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; BinExpr binExp = expr as BinExpr; binExp.Right = intLiteral; } else if (this.tokens[this.index] is int && expr == null) { int intValue = (int)this.tokens[this.index++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; expr = intLiteral; } else if (this.tokens[this.index] is string && expr != null) { string ident = (string)this.tokens[this.index++]; Variable var = new Variable(); var.Ident = ident; BinExpr binExp = expr as BinExpr; binExp.Right = var; } else if (this.tokens[this.index] is string && expr == null) { string ident = (string)this.tokens[this.index++]; Variable var = new Variable(); var.Ident = ident; expr = var; } else if (this.tokens[this.index] == Scanner.newobj) { this.index++; expr = ParseMethodCall(true); } else if (this.tokens[this.index++] == Scanner.Call) { expr = ParseMethodCall(false); } else { throw new System.Exception("expected string literal, int literal, or variable"); } } return(expr); }
private void GenExpr(Expr expr, System.Type expectedType) { System.Type deliveredType; if (expr is StringLiteral) { deliveredType = typeof(string); this.il.Emit(Emit.OpCodes.Ldstr, ((StringLiteral)expr).Value); } else if (expr is IntLiteral) { deliveredType = typeof(int); this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)expr).Value); } else if (expr is Variable) { string ident = ((Variable)expr).Ident; deliveredType = this.TypeOfExpr(expr); if (this.symbolTable.ContainsKey(ident)) { this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[ident]); } else if (this.parameterTable.ContainsKey(ident)) { //Only for First paramete...have to change this.il.Emit(Emit.OpCodes.Ldarg_S, Convert.ToByte(0)); } else if (this.typefieldList.ContainsKey(ident)) { if (this.typefieldList[ident].IsStatic) { this.il.Emit(Emit.OpCodes.Ldsfld, this.typefieldList[ident]); } else { //Load current object(this) on stack.. which always first argument.. this.il.Emit(Emit.OpCodes.Ldarg_0); this.il.Emit(Emit.OpCodes.Ldfld, this.typefieldList[ident]); } } else { throw new System.Exception("undeclared variable '" + ident + "'"); } } else if (expr is BinExpr) { BinExpr binExpr = expr as BinExpr; deliveredType = this.TypeOfExpr(expr); if (binExpr.Left is IntLiteral) { this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)binExpr.Left).Value); } if (binExpr.Left is Variable) { this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[((Variable)binExpr.Left).Ident]); } if (binExpr.Right is IntLiteral) { this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)binExpr.Right).Value); } if (binExpr.Right is Variable) { this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[((Variable)binExpr.Right).Ident]); } switch (binExpr.Op) { case BinOp.Add: this.il.Emit(Emit.OpCodes.Add); break; case BinOp.Sub: this.il.Emit(Emit.OpCodes.Sub); break; case BinOp.Mul: this.il.Emit(Emit.OpCodes.Mul); break; case BinOp.Div: this.il.Emit(Emit.OpCodes.Div); break; case BinOp.EqualTo: case BinOp.NotEqualTo: this.il.Emit(Emit.OpCodes.Ceq); break; } } else if (expr is MethodCall) { deliveredType = GenerteMethodCallCode((MethodCall)expr); } else { throw new System.Exception("don't know how to generate " + expr.GetType().Name); } if (deliveredType != expectedType) { if (deliveredType == typeof(int) && expectedType == typeof(string)) { this.il.Emit(Emit.OpCodes.Box, typeof(int)); this.il.Emit(Emit.OpCodes.Callvirt, typeof(object).GetMethod("ToString")); } else { throw new System.Exception("can't coerce a " + deliveredType.Name + " to a " + expectedType.Name); } } }
private expr ParsExpr(string blah) { if (index >= tokens.Count) { adderror("Got EOF, and i expected an expression idiot"); return(null); } else if (tokens[index] is StringBuilder) { string value = ((StringBuilder)tokens[index]).ToString(); index++; linecount(); StringLiteral stringLiteral = new StringLiteral(); stringLiteral.Value = value; return(stringLiteral); } else if (tokens[index] is int) { int intValue = (int)tokens[index]; index++; linecount(); IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; BinOp x = ParseA_op(); //MessageBox.Show(x.ToString()); if (x.Equals(BinOp.empty)) { //MessageBox.Show("ninop"); return(intLiteral); } else { // if (x.Equals(BinOp.add) || x.Equals(BinOp.divide) || x.Equals(BinOp.minus) || x.Equals(BinOp.multiply) || x.Equals(BinOp.parallel) || x.Equals(BinOp.series)) //{ BinExpr thing = new BinExpr(); if (!(x.Equals(BinOp.add) || x.Equals(BinOp.divide) || x.Equals(BinOp.minus) || x.Equals(BinOp.multiply) || x.Equals(BinOp.parallel) || x.Equals(BinOp.series))) { if (blah.Equals("con")) { return(thing); } else { adderror("Expected Operator"); } } thing.Left = (expr)intLiteral; thing.Op = x; index++; linecount(); thing.Right = ParsExpr(blah); //MessageBox.Show(thing.Right.ToString()); if (thing.Right is Variable) { if (!identifier.identity.Contains(tokens[index - 1].ToString())) { adderror(tokens[index - 1].ToString() + ": undeclared identifier"); // index++; } else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false) { adderror(tokens[index - 1].ToString() + " : unassigned"); //index++; } } // return thing; // } /* if (!(x.Equals(BinOp.add) || x.Equals(BinOp.divide) || x.Equals(BinOp.minus) || x.Equals(BinOp.multiply) || x.Equals(BinOp.parallel) || x.Equals(BinOp.series))) * { * adderror("Expected Operator"); * // //MessageBox.Show("hello "); * * ////MessageBox.Show(thing.Left.ToString() + " " + thing.Op.ToString() + " " + thing.Right.ToString()); * return thing; * * }*/ return(thing); } } else if (tokens[index] is string) { string ident = (string)tokens[index]; index++; linecount(); Variable var = new Variable(); var.Ident = ident; BinOp x = ParseA_op(); if (x.Equals(BinOp.empty)) { return(var); } else { BinExpr thing = new BinExpr(); thing.Left = (expr)var; if (!identifier.identity.Contains(var.Ident)) { adderror(tokens[index - 1].ToString() + ": undeclared identifier"); //index++; } thing.Op = x; index++; linecount(); thing.Right = ParsExpr("blah"); if (thing.Right is Variable) { if (!identifier.identity.Contains(tokens[index - 1].ToString())) { adderror(tokens[index - 1].ToString() + ": undeclared identifier"); } else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false) { adderror(tokens[index - 1].ToString() + " : unassigned"); } } //return thing; if (!(x.Equals(BinOp.add) || x.Equals(BinOp.divide) || x.Equals(BinOp.minus) || x.Equals(BinOp.multiply) || x.Equals(BinOp.parallel) || x.Equals(BinOp.series))) { //MessageBox.Show("binop add"); adderror("Expected Operator"); return(thing); // return null; } return(thing); //index--; } } else { //MessageBox.Show("i am in string literal"); //MessageBox.Show(tokens[index].ToString()); adderror("expected string literal, int literal or variable"); return(null); } }
private expr ParseCond() { if (index == tokens.Count) { adderror("Got EOF, and i expected an expression idiot"); } if (tokens[index] is StringBuilder) { adderror("expected intger/variable/condition"); return(null); } else if (tokens[index] is int) { int intValue = (int)tokens[index]; index++; linecount(); IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; BinOp x = ParseA_op(); if (x.Equals(BinOp.empty)) { return(intLiteral); } else { BinExpr thing = new BinExpr(); if (x.Equals(BinOp.add) || x.Equals(BinOp.divide) || x.Equals(BinOp.minus) || x.Equals(BinOp.multiply) || x.Equals(BinOp.parallel) || x.Equals(BinOp.series)) { index--; //MessageBox.Show(tokens[index].ToString()+" "+tokens[index+1].ToString()+" "+tokens[index+2].ToString()); thing.Left = ParsExpr("con"); //MessageBox.Show("back"); //adderror("Expected Conditional Operator"); } x = ParseA_op(); if (x.Equals(BinOp.empty)) { Something blahness = new Something(); blahness.hello = (BinExpr)thing.Left; //MessageBox.Show("i m in there"); return(blahness); } thing.Left = (expr)intLiteral; thing.Op = x; index++; linecount(); thing.Right = ParsExpr("blah"); if (thing.Right is Variable) { if (!identifier.identity.Contains(tokens[index - 1].ToString())) { adderror(tokens[index - 1].ToString() + ": undeclared identifier"); } else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false) { adderror(tokens[index - 1].ToString() + " : unassigned"); } } return(thing); } // return intLiteral; } else if (tokens[index] is string) { string ident = (string)tokens[index]; if (!identifier.identity.Contains(tokens[index].ToString())) { adderror(tokens[index].ToString() + " : undeclared identifier"); } else if (identifier.assignment[identifier.identity.IndexOf(tokens[index].ToString())] == false) { adderror(tokens[index].ToString() + " : unassigned"); } index++; linecount(); Variable var = new Variable(); var.Ident = ident; BinOp x = ParseA_op(); if (x.Equals(BinOp.empty)) { return(var); } else { BinExpr thing = new BinExpr(); thing.Left = (expr)var; if (x.Equals(BinOp.add) || x.Equals(BinOp.divide) || x.Equals(BinOp.minus) || x.Equals(BinOp.multiply) || x.Equals(BinOp.parallel) || x.Equals(BinOp.series)) { index--; thing.Left = ParsExpr("con"); // if (errors[errors.Count - 1].error.ToString().Equals("Expected Operator")) // errors.Remove(errors.Count - 1); //adderror("Expected Conditional Operator"); } if (!identifier.identity.Contains(var.Ident)) { adderror(var.Ident + ": undeclared identifier"); } else if (identifier.assignment[identifier.identity.IndexOf(var.Ident)] == false) { adderror(tokens[index].ToString() + " : unassigned"); } x = ParseA_op(); if (x.Equals(BinOp.empty)) { Something blahness = new Something(); blahness.hello = (BinExpr)thing.Left; return(blahness); } thing.Op = x; index++; linecount(); thing.Right = ParsExpr("blah"); if (thing.Right is Variable) { if (!identifier.identity.Contains(tokens[index - 1].ToString())) { adderror(tokens[index - 1].ToString() + ": undeclared identifier"); } else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false) { adderror(tokens[index - 1].ToString() + " : unassigned"); } //index } return(thing); } } else if (tokens[index] is bool) { bool value = (bool)tokens[index++]; linecount(); booleanL boolean = new booleanL(); boolean.Value = value; return(boolean); } else { adderror("expected string literal, int literal or variable"); return(null); } }
private Expr ParseExpr() { if (this.indice == this.tokens.Count) { throw new System.Exception("Se esperaba una expresion, se llego al final del archivo"); } if (this.tokens[this.indice] is Text.StringBuilder) { string value = ((Text.StringBuilder)this.tokens[this.indice++]).ToString(); StringLiteral stringLiteral = new StringLiteral(); stringLiteral.Value = value; return stringLiteral; } //********* else if (this.tokens[this.indice + 1] == Scanner.Sum || this.tokens[this.indice + 1] == Scanner.Res || this.tokens[this.indice + 1] == Scanner.Mul || this.tokens[this.indice + 1] == Scanner.Div) { BinExpr binExpr = new BinExpr(); Expr left; if (this.tokens[this.indice] is int) { int intValue = (int)this.tokens[this.indice++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; left = intLiteral; } else if (this.tokens[this.indice] is string) { string ident = (string)this.tokens[this.indice++]; Variable var = new Variable(); var.Ident = ident; left = var; } else { throw new System.Exception("Se esperaba un entero o variable para la operacion."); } binExpr.Left = left; object op = this.tokens[this.indice++]; if (op == Scanner.Sum) binExpr.Op = BinOp.Sum; else if (op == Scanner.Res) binExpr.Op = BinOp.Res; else if (op == Scanner.Mul) binExpr.Op = BinOp.Mul; else if (op == Scanner.Div) binExpr.Op = BinOp.Div; binExpr.Right = this.ParseExpr(); return binExpr; } //********* else if (this.tokens[this.indice] is int) { int intValue = (int)this.tokens[this.indice++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; return intLiteral; } else if (this.tokens[this.indice] is string) { string ident = (string)this.tokens[this.indice++]; Variable var = new Variable(); var.Ident = ident; return var; } else { throw new System.Exception("se esperaba una cadena, entero o variable"); } }
public abstract void visit(BinExpr n);
private void GenExpr(expr expr, System.Type expectedType) { System.Type deliveredType; if (expr is StringLiteral) { deliveredType = typeof(string); this.il.Emit(Emit.OpCodes.Ldstr, ((StringLiteral)expr).Value); //pushes the value of passed expression on string type stack // il.EmitWriteLine("hello"); } else if (expr is IntLiteral) { deliveredType = typeof(int); this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)expr).Value); //pushes the value of passed expression on integer type stack } else if (expr is Variable) { string ident = ((Variable)expr).Ident; deliveredType = this.TypeOfExpr(expr); if (!this.symbolTable.ContainsKey(ident)) { throw new System.Exception("undeclared variable '" + ident + "'"); } this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[ident]); } else if (expr is BinExpr) { BinExpr val = new BinExpr(); val = (BinExpr)expr; deliveredType = typeof(int); whole.Add(val.Left); counter++; //MessageBox.Show(whole.Count().ToString()); whole.Add(val.Op); //counters++; //MessageBox.Show(whole.Count().ToString()); if ((TypeOfExpr((expr)val.Right) == typeof(int) && (!(val.Right is BinExpr))) || val.Right is Variable) { whole.Add(val.Right); //MessageBox.Show(whole.Count().ToString()); ADD_EMIT(); } else { this.GenExpr(val.Right, this.TypeOfExpr(val.Right)); } /*if (val.Left is IntLiteral) * * this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)val.Left).Value);//pushes the value of passed expression on integer type stack * else * { * string ident = ((Variable)val.Left).Ident; * Emit.LocalBuilder locb = this.symbolTable[ident]; * this.il.Emit(Emit.OpCodes.Ldloc, locb); * } * * * if ( (TypeOfExpr((expr)val.Right)== typeof(int) && (! (val.Right is BinExpr))) || val.Right is Variable) * { * * * * MessageBox.Show("blah blah"); * * if (val.Right is IntLiteral) * * this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)val.Right).Value);//pushes the value of passed expression on integer type stack * else * { * string ident = ((Variable)val.Right).Ident; * Emit.LocalBuilder locb = this.symbolTable[ident]; * this.il.Emit(Emit.OpCodes.Ldloc, locb); * } * * if ((val.Op).Equals(BinOp.add)) * { * this.il.Emit(Emit.OpCodes.Add); * } * else if ((val.Op).Equals(BinOp.minus)) * { * this.il.Emit(Emit.OpCodes.Sub); * } * else if ((val.Op).Equals(BinOp.multiply)) * { * this.il.Emit(Emit.OpCodes.Mul); * } * else if ((val.Op).Equals(BinOp.divide)) * { * this.il.Emit(Emit.OpCodes.Div); * } * * } * else * { * this.GenExpr(val.Right, this.TypeOfExpr(val.Right)); * }*/ } else { throw new System.Exception("don't know how to generate " + expr.GetType().Name); } if (deliveredType != expectedType) //type cheking { if (deliveredType == typeof(int) && expectedType == typeof(string)) { this.il.Emit(Emit.OpCodes.Box, typeof(int)); this.il.Emit(Emit.OpCodes.Callvirt, typeof(object).GetMethod("ToString")); //parsing integer to string //il.EmitCall(Emit.OpCodes.new } else { throw new System.Exception("can't coerce a " + deliveredType.Name + " to a " + expectedType.Name); } } }
private Expr ParseExpr() { if (this.indice == this.tokens.Count) { throw new System.Exception("Se esperaba una expresion, se llego al final del archivo"); } if (this.tokens[this.indice] is Text.StringBuilder) { string value = ((Text.StringBuilder) this.tokens[this.indice++]).ToString(); StringLiteral stringLiteral = new StringLiteral(); stringLiteral.Value = value; return(stringLiteral); } //********* else if (this.tokens[this.indice + 1] == Scanner.Sum || this.tokens[this.indice + 1] == Scanner.Res || this.tokens[this.indice + 1] == Scanner.Mul || this.tokens[this.indice + 1] == Scanner.Div) { BinExpr binExpr = new BinExpr(); Expr left; if (this.tokens[this.indice] is int) { int intValue = (int)this.tokens[this.indice++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; left = intLiteral; } else if (this.tokens[this.indice] is string) { string ident = (string)this.tokens[this.indice++]; Variable var = new Variable(); var.Ident = ident; left = var; } else { throw new System.Exception("Se esperaba un entero o variable para la operacion."); } binExpr.Left = left; object op = this.tokens[this.indice++]; if (op == Scanner.Sum) { binExpr.Op = BinOp.Sum; } else if (op == Scanner.Res) { binExpr.Op = BinOp.Res; } else if (op == Scanner.Mul) { binExpr.Op = BinOp.Mul; } else if (op == Scanner.Div) { binExpr.Op = BinOp.Div; } binExpr.Right = this.ParseExpr(); return(binExpr); } //********* else if (this.tokens[this.indice] is int) { int intValue = (int)this.tokens[this.indice++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; return(intLiteral); } else if (this.tokens[this.indice] is string) { string ident = (string)this.tokens[this.indice++]; Variable var = new Variable(); var.Ident = ident; return(var); } else { throw new System.Exception("se esperaba una cadena, entero o variable"); } }
private void GenExpr(Expr expr, System.Type expectedType) { System.Type deliveredType; if (expr is StringLiteral) { deliveredType = typeof(string); this.il.Emit(Emit.OpCodes.Ldstr, ((StringLiteral)expr).Value); } else if (expr is IntLiteral) { deliveredType = typeof(int); this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)expr).Value); } else if (expr is Variable) { string ident = ((Variable)expr).Ident; deliveredType = this.TypeOfExpr(expr); if (!this.symbolTable.ContainsKey(ident)) { throw new System.Exception("undeclared variable '" + ident + "'"); } this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[ident]); } else if (expr is BinExpr) { BinExpr binExpr = expr as BinExpr; deliveredType = this.TypeOfExpr(expr); if (binExpr.Left is IntLiteral) { this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)binExpr.Left).Value); } if (binExpr.Left is Variable) { this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[((Variable)binExpr.Left).Ident]); } if (binExpr.Right is IntLiteral) { this.il.Emit(Emit.OpCodes.Ldc_I4, ((IntLiteral)binExpr.Right).Value); } if (binExpr.Right is Variable) { this.il.Emit(Emit.OpCodes.Ldloc, this.symbolTable[((Variable)binExpr.Right).Ident]); } switch (binExpr.Op) { case BinOp.Add: this.il.Emit(Emit.OpCodes.Add); break; case BinOp.Sub: this.il.Emit(Emit.OpCodes.Sub); break; case BinOp.Mul: this.il.Emit(Emit.OpCodes.Mul); break; case BinOp.Div: this.il.Emit(Emit.OpCodes.Div); break; } } else if (expr is MethodCall) { deliveredType = GenerteMethodCallCode((MethodCall)expr); } else { throw new System.Exception("don't know how to generate " + expr.GetType().Name); } if (deliveredType != expectedType) { if (deliveredType == typeof(int) && expectedType == typeof(string)) { this.il.Emit(Emit.OpCodes.Box, typeof(int)); this.il.Emit(Emit.OpCodes.Callvirt, typeof(object).GetMethod("ToString")); } else { throw new System.Exception("can't coerce a " + deliveredType.Name + " to a " + expectedType.Name); } } }
public PolInv(BinExpr binExpr) { extraerTokens(binExpr); }
// fs:fname( fs:convert_operand( fn:data(ARG1), "string"), // fs:convert_operand( fn:data(ARG2), "string") // ) private XPathExpr make_CmpOp(BinExpr e, QName name) { return(make_convert_binop(e, make_string_lit("string"), name)); }
private XPathExpr make_ArithOp(BinExpr e, QName name) { return(make_convert_binop(e, make_double_lit(1.0), name)); }
/// <summary> /// Validate a binary expression by checking its left and right children. /// </summary> /// <param name="name"> /// is the name of the binary expression. </param> /// <param name="e"> /// is the expression itself. </param> public virtual void printBinExpr(string name, BinExpr e) { e.left().accept(this); e.right().accept(this); }