public override void visit(double_question_node dqn) { var st = dqn.Parent; while (!(st is statement)) { st = st.Parent; } var tname = "#temp" + UniqueNumStr(); var tt = new var_statement(new ident(tname), dqn.left); tt.var_def.Parent = tt; var l = new List <statement>(); l.Add(tt); l.Add(st as statement); expression right = dqn.right; var eq = new bin_expr(new ident(tname), new nil_const(), Operators.NotEqual, dqn.left.source_context); var qce = new question_colon_expression(eq, new ident(tname), right, dqn.source_context); ReplaceUsingParent(dqn, qce); visit(qce); ReplaceStatementUsingParent(st as statement, l); visit(tt); }
public static procedure_definition BuildToStringFuncForAutoClass(List <ident> names) { var pal = new procedure_attributes_list(proc_attribute.attr_override); var fp = new formal_parameters(); var ff = new function_header("ToString", "string", fp, pal); var cleft = new char_const('('); var cright = new char_const(')'); var ccomma = new char_const(','); bin_expr ex = new bin_expr(cleft, cright, Operators.Plus); for (var i = 0; i < names.Count; i++) { var dn = new dot_node(names[i], new ident("ToString")); var asnode = new typecast_node(names[i], new named_type_reference("object"), op_typecast.as_op); var eqnode = new bin_expr(asnode, new nil_const(), Operators.Equal); var expr = new question_colon_expression(eqnode, new string_const("nil"), dn); ex.left = new bin_expr(ex.left, expr, Operators.Plus); if (i < names.Count - 1) { ex.left = new bin_expr(ex.left, ccomma, Operators.Plus); } } var ass = new assign("Result", ex); return(BuildShortProcFuncDefinitionNoSC(ff, ass)); }
public statement MyStmt(expression ex, statement st) { // Проверить, что в ex - целый тип // Сделать специальный узел для проверки new semantic_check("Тип проверки",params syntax_node[] ob) // Включать этот узел первым для "сахарных" узлов синтаксического дерева var sc = new semantic_check("ExprIsInteger", ex); var id = new ident("#my"); var idlist = new ident_list(id); var typ = new named_type_reference("integer"); var one = new int32_const(1); var vdef = new var_def_statement(idlist, typ, one, definition_attribute.None, false, null); var vstat = new var_statement(vdef, null); var ass = new assign(new ident("#my"), one, Operators.AssignmentAddition); var stlistwhile = new statement_list(st); stlistwhile.Add(ass); var bin = new bin_expr(id, ex, Operators.LessEqual); var wh = new while_node(bin, stlistwhile, WhileCycleType.While); var stlist = new statement_list(sc); stlist.Add(vstat); stlist.Add(wh); return(stlist); }
public override void visit(bin_expr _bin_expr) { executer.visit(_bin_expr); if (_bin_expr.left != null) this.visit((dynamic)_bin_expr.left); if (_bin_expr.right != null) this.visit((dynamic)_bin_expr.right); if (_bin_expr.attributes != null) this.visit((dynamic)_bin_expr.attributes); }
public override void visit(bin_expr ex) { if (ex.operation_type == Operators.In && ex.right is diapason_expr_new diap && ex.left is addressed_value exl) { var el = new expression_list(); el.Add(exl, exl.source_context); el.Add(diap.left, diap.left.source_context); el.Add(diap.right, diap.right.source_context); var mc = method_call.NewP(new ident("InRangeInternal", exl.source_context), el, exl.source_context); var sug = sugared_addressed_value.NewP(ex, mc, ex.source_context); ReplaceUsingParent(ex, sug); visit(mc); // обойти заменённое на предмет наличия такого же синтаксического сахара }
/*public question_colon_expression ConvertToQCE1(dot_question_node dqn) * { * addressed_value left = dqn.left; * addressed_value right = dqn.right; * * var eq = new bin_expr(left, new nil_const(), Operators.Equal, left.source_context); * * var nr = Into(left, right); * * var q = new question_colon_expression(eq, new nil_const(), nr, dqn.source_context); * nr.Parent = q; * return q; * }*/ public question_colon_expression ConvertToQCE1(dot_question_node dqn, string name) { addressed_value right = dqn.right; var eq = new bin_expr(new ident(name), new nil_const(), Operators.Equal, dqn.left.source_context); var nr = Into(new ident(name), right); var q = new question_colon_expression(eq, new nil_const(), nr, dqn.source_context); nr.Parent = q; return(q); }
public question_colon_expression ConvertToQCE(dot_question_node dqn) { addressed_value left = dqn.left; addressed_value right = dqn.right; var eq = new bin_expr(left, new nil_const(), Operators.Equal, left.source_context); addressed_value dn = null; var dnleft = right; // Левая часть dn addressed_value rdqn = null; addressed_value ldqn = null; // Если right - это dot_question_node, то протащить внутрь него left. В силу ассоциирования слева направо достаточно на первый уровень. if (right.GetType() == typeof(dot_question_node)) { var dqn_int = right as dot_question_node; ldqn = dqn_int.left; dnleft = ldqn; rdqn = dqn_int.right; // необходимо left протащить внутрь в ldqn } // Пока right - это dot_node, то необходимо протаскивать left чтобы присоединить его к первому не dot_node while (dnleft.GetType() == typeof(dot_node)) { dn = dnleft; dnleft = (dnleft as dot_node).left; } // В итоге в dnleft - самый внутренний left, который уже не является dot_node dnleft = new dot_node(left, dnleft, left.source_context); // Прикрепили right к самому внутреннему левому узлу в нотации a.b.c.d if (dn != null) { (dn as dot_node).left = dnleft; } else if (rdqn == null) { right = dnleft; } else { right = new dot_question_node(dnleft, (right as dot_question_node).right, dnleft.source_context); } var q = new question_colon_expression(eq, new nil_const(), right, dqn.source_context); right.Parent = q; return(q); }
private expression CreateConditionFromCaseVariant(expression param, expression_list list) { var res = list.expressions.Aggregate(new bool_const(false) as expression, (acc, expr) => { bin_expr currentExpr = null; diapason_expr diap = expr as diapason_expr; if (diap != null) { currentExpr = new bin_expr(new bin_expr(param, diap.left, Operators.GreaterEqual), new bin_expr(param, diap.right, Operators.LessEqual), Operators.LogicalAND); } else { currentExpr = new bin_expr(param, expr, Operators.Equal); } return(new bin_expr(acc, currentExpr, Operators.LogicalOR)); }); return(res); }
protected bool HasExtendedIs(bin_expr expr) { if (expr.left is bin_expr leftBinExpr && expr.right is bin_expr rightBinExpr) { return(HasExtendedIs(leftBinExpr) || HasExtendedIs(rightBinExpr)); } if (expr.left is is_pattern_expr || expr.right is is_pattern_expr) { return(true); } if (expr.left is bin_expr lBinExpr) { return(HasExtendedIs(lBinExpr)); } if (expr.right is bin_expr rBinExpr) { return(HasExtendedIs(rBinExpr)); } return(false); }
public virtual void visit(bin_expr _bin_expr) { DefaultVisit(_bin_expr); }
public virtual void post_do_visit(bin_expr _bin_expr) { }
public override void visit(bin_expr _bin_expr) { DefaultVisit(_bin_expr); pre_do_visit(_bin_expr); visit(bin_expr.left); visit(bin_expr.right); post_do_visit(_bin_expr); }
public override void Exit(syntax_tree_node st) { bracket_expr bre = st as bracket_expr; if (bre != null) { if (bre.expr is int32_const) { Replace(st, bre.expr); } } bin_expr vs = st as bin_expr; if (vs != null) { if (vs.left is int32_const && vs.right is int32_const) { var a = vs.left as int32_const; var b = vs.right as int32_const; var op = vs.operation_type; syntax_tree_node res; switch (op) { case Operators.Plus: res = new int32_const(a.val + b.val); break; case Operators.Minus: res = new int32_const(a.val - b.val); break; case Operators.Multiplication: res = new int32_const(a.val * b.val); break; case Operators.Division: res = new double_const((double)a.val / b.val); break; case Operators.Greater: res = new bool_const(a.val > b.val); break; case Operators.Less: res = new bool_const(a.val < b.val); break; case Operators.GreaterEqual: res = new bool_const(a.val >= b.val); break; case Operators.LessEqual: res = new bool_const(a.val <= b.val); break; default: res = vs; break; } Replace(vs, res); } if (vs.left is int32_const && vs.right is double_const || vs.right is int32_const && vs.left is double_const || vs.left is double_const && vs.right is double_const) { double x, y; if (vs.left is int32_const) { x = (vs.left as int32_const).val; } else { x = (vs.left as double_const).val; } if (vs.right is int32_const) { y = (vs.right as int32_const).val; } else { y = (vs.right as double_const).val; } var op = vs.operation_type; syntax_tree_node res; switch (op) { case Operators.Plus: res = new double_const(x + y); break; case Operators.Minus: res = new double_const(x - y); break; case Operators.Multiplication: res = new double_const(x * y); break; case Operators.Division: res = new double_const(x / y); break; case Operators.Greater: res = new bool_const(x > y); break; case Operators.Less: res = new bool_const(x < y); break; case Operators.GreaterEqual: res = new bool_const(x >= y); break; case Operators.LessEqual: res = new bool_const(x <= y); break; default: res = vs; break; } Replace(vs, res); } } base.Exit(st); // это обязательно! }
public virtual void visit(bin_expr _bin_expr) { }
public override void visit(bin_expr node) { node.left.visit(this); int left = intStack.Pop(); node.right.visit(this); int right = intStack.Pop(); switch (node.operation_type) { case Operators.Minus: intStack.Push(left - right); break; case Operators.Plus: intStack.Push(left + right); break; case Operators.Multiplication: intStack.Push(left * right); break; case Operators.Division: intStack.Push(left / right); break; case Operators.Greater: intStack.Push(left > right ? 1 : 0); break; case Operators.Less: intStack.Push(left < right ? 1 : 0); break; case Operators.GreaterEqual: intStack.Push(left >= right ? 1 : 0); break; case Operators.LessEqual: intStack.Push(left <= right ? 1 : 0); break; case Operators.Equal: intStack.Push(left == right ? 1 : 0); break; case Operators.NotEqual: intStack.Push(left != right ? 1 : 0); break; case Operators.BitwiseLeftShift: intStack.Push(left << right); break; case Operators.BitwiseRightShift: intStack.Push(left >> right); break; case Operators.BitwiseAND: intStack.Push(left & right); break; case Operators.BitwiseOR: intStack.Push(left | right); break; case Operators.BitwiseXOR: intStack.Push(left ^ right); break; default: throw new InvalidIntegerExpression(); } }
public override void visit(bin_expr _bin_expr) { _bin_expr.left.visit(this); _bin_expr.right.visit(this); }
public override void visit(bin_expr n) { fs.WriteLine(n.GetType().Name + " " + n.operation_type); base.DefaultVisit(n); }
private CollectionDesugaringResult DesugarCollectionPattern(collection_pattern pattern, expression matchingExpression) { Debug.Assert(!pattern.IsRecursive, "All recursive patterns should be desugared into simple patterns at this point"); var desugaringResult = new CollectionDesugaringResult(); var collectionItems = pattern.parameters; var gapItemMet = false; var gapIndex = 0; var exprBeforeGap = new List <pattern_parameter>(); var exprAfterGap = new List <pattern_parameter>(); for (int i = 0; i < collectionItems.Count; ++i) { if (collectionItems[i] is collection_pattern_gap_parameter) { if (gapItemMet) { throw new SyntaxVisitorError("REPEATED_DOTDOT_COLLECTION_PATTERN_EXPR", pattern.source_context); } gapItemMet = true; gapIndex = i; continue; } if (gapItemMet) { exprAfterGap.Insert(0, collectionItems[i]); } else { exprBeforeGap.Add(collectionItems[i]); } } var successMatchingCheck = GetCollectionItemsEqualCheckBeforeGap( matchingExpression as addressed_value, exprBeforeGap, desugaringResult); if (gapItemMet && exprAfterGap.Count != 0) { var afterGapEqual = GetCollectionItemsEqualCheckAfterGap( matchingExpression as addressed_value, exprAfterGap, desugaringResult); if (afterGapEqual != null) { successMatchingCheck = successMatchingCheck == null ? afterGapEqual : bin_expr.LogicalAnd(successMatchingCheck, afterGapEqual); } } // если добавлять в and, то все равно ран тайм эррор, будто вычисляет все, даже если первое = false desugaringResult.CollectionLengthCheck = new bin_expr( new dot_node(matchingExpression as addressed_value, new ident(CountPropertyName), pattern.source_context), new int32_const(exprBeforeGap.Count + exprAfterGap.Count), Operators.GreaterEqual, pattern.source_context ); if (!gapItemMet) { var lengthWithoutGapCheck = new bin_expr( new dot_node(matchingExpression as addressed_value, new ident(CountPropertyName), pattern.source_context), new int32_const(exprBeforeGap.Count), Operators.Equal, pattern.source_context ); successMatchingCheck = successMatchingCheck == null ? lengthWithoutGapCheck : bin_expr.LogicalAnd(lengthWithoutGapCheck, successMatchingCheck); } desugaringResult.SuccessMatchingCheck = successMatchingCheck == null ? new bool_const(true) : successMatchingCheck; return(desugaringResult); }
public override void visit(bin_expr _bin_expr) { text = "operator_type: " + _bin_expr.operation_type.ToString(); }
public override void visit(bin_expr _bin_expr) { prepare_node(_bin_expr.left, "left"); prepare_node(_bin_expr.right, "right"); }