private ExpressionNode ParseRelationalExpression() { var left = ParseAdditiveExpression(); while (IsOperator('<') || IsOperator('>') || IsOperator('L') || IsOperator('G')) { var o = (Operator)Token; NextToken(); switch (o.Value) { case '<': left = new LessThan(left, ParseAdditiveExpression()); break; case '>': left = new GreaterThan(left, ParseAdditiveExpression()); break; case 'L': left = new LessEqual(left, ParseAdditiveExpression()); break; case 'G': left = new GreaterEqual(left, ParseAdditiveExpression()); break; } } return(left); }
public override ASTNode VisitComparisson([NotNull] CoolParser.ComparissonContext context) { ComparisonOperation operators; switch (context.op.Text) { case "<=": operators = new LessEqual(context); break; case "<": operators = new Less(context); break; case "=": operators = new EqualNode(context); break; default: throw new NotSupportedException(); } operators.LeftOperand = Visit(context.expression(0)) as ExpressionNode; // LEFT EXPRESSION operators.RightOperand = Visit(context.expression(1)) as ExpressionNode; //RIGHT EXPRESSION return(operators); }
public void Visit(LessEqual n) { Helpers.Write("("); n.LeftExpression.Accept(this); Helpers.Write(" <= "); n.RightExpression.Accept(this); Helpers.Write(")"); }
public void Visit(LessEqual leq) { leq.Left.Accept(this); leq.Right.Accept(this); _instructions.Add(Instruction.Create(OpCodes.Cgt)); _instructions.Add(Instruction.Create(OpCodes.Ldc_I4_0)); _instructions.Add(Instruction.Create(OpCodes.Ceq)); }
public string Visit(LessEqual node) { var result = ""; result += "\t\tldc.i4 42\n"; result += Visit((dynamic)node[0]); result += Visit((dynamic)node[1]); var labelSuccess = GenerateLabel(); result += "\t\tble " + labelSuccess + "\n"; result += "\t\tpop\n"; result += "\t\tldc.i4 0\n"; result += "\t\t" + labelSuccess + ":\n"; return(result); }
public void Visit(LessEqual n) { Helpers.WriteLine($"{_tab}{n.Text} [{n.Location.StartLine}, {n.Location.StartColumn}]"); Tab(); Helpers.WriteLine($"{_tab}Left"); Tab(); n.LeftExpression.Accept(this); Untab(); Helpers.WriteLine($"{_tab}Right"); Tab(); n.RightExpression.Accept(this); Untab(); Untab(); }
public void Visit(LessEqual n) { Globals.Builder.Start($"less equal (<=) [{n.Location.StartLine}, {n.Location.StartColumn}]"); WriteBinaryExpression("cmp", n.LeftExpression, n.RightExpression); var labelFalse = $"lessEqualFalse{Globals.Builder.Count()}"; var labelEnd = $"lessEqualEnd{Globals.Builder.Count()}"; Globals.Builder.WriteUnaryOp("jnle", labelFalse); Globals.Builder.WriteBinaryOp("mov", "rax", 1.ToString()); Globals.Builder.WriteUnaryOp("jmp", labelEnd); Globals.Builder.WriteLabel(labelFalse); Globals.Builder.WriteBinaryOp("mov", "rax", 0.ToString()); Globals.Builder.WriteLabel(labelEnd); Globals.Builder.End($"less equal (<=) [{n.Location.EndLine}, {n.Location.EndColumn}]"); }
public void Visit(LessEqual leq) { // Nothing to do here... }
public void Visit(LessEqual leq) { // Nothing to do here... }
public void Visit(LessEqual leq) { ResultIsBoolAndBothOperandsMustBeInt(leq); }
protected static int GetPrior(string arg) { if (IsSkoba(arg) != 0) { return(0); } if (arg == "!" || arg == ":" || arg == ";") { return(1); } if (arg == ">" || arg == "<" || arg == "=" || arg == MoreEqual.ToString() || arg == LessEqual.ToString()) { return(2); } if (arg == "+" || arg == "-") { return(3); } if (arg == "*" || arg == "/") { return(4); } if (arg == "^") { return(5); } if (arg == "N") { return(6); } return(-1); }
private static Operator GetOperator(char[] sql, int beginIndex, int endIndex) { char c; Operator op1 = null; Operator op2 = null; for (int i = beginIndex; i < endIndex;) { c = sql[i]; if (c == '+') { op2 = new Add(sql, i, i); i++; } else if (c == '-') { op2 = new Sub(sql, i, i); i++; } else if (c == '*') { op2 = new Multi(sql, i, i); i++; } else if (c == '/') { op2 = new Div(sql, i, i); i++; } else if ( (i + 2 <= endIndex) && (c == 'a' && sql[i + 1] == 'n' && sql[i + 2] == 'd') && (i == beginIndex || StrUtil.IsOneOf(sql[i - 1], Parser._whiteSpaces)) && (i + 2 == endIndex || i + 3 <= endIndex && StrUtil.IsOneOf(sql[i + 3], Parser._whiteSpaces)) ) { op2 = new And(sql, i, i + 2); i = i + 3; } else if ( (i + 1 <= endIndex) && (c == 'o' && sql[i + 1] == 'r') && (i == beginIndex || StrUtil.IsOneOf(sql[i - 1], Parser._whiteSpaces)) && (i + 1 == endIndex || i + 2 <= endIndex && StrUtil.IsOneOf(sql[i + 2], Parser._whiteSpaces)) ) { op2 = new Or(sql, i, i + 1); i = i + 2; } else if ( (i + 2 <= endIndex) && (c == 'n' && sql[i + 1] == 'o' && sql[i + 2] == 't') && (i == beginIndex || StrUtil.IsOneOf(sql[i - 1], Parser._whiteSpaces)) && (i + 2 == endIndex || i + 3 <= endIndex && StrUtil.IsOneOf(sql[i + 3], Parser._whiteSpaces)) ) { op2 = new Not(sql, i, i + 2); i = i + 3; } else if ( (i + 1 <= endIndex) && (c == '>' && sql[i + 1] == '=') ) { op2 = new GreaterEqual(sql, i, i + 1); i = i + 2; } else if ( (i + 1 <= endIndex) && (c == '<' && sql[i + 1] == '=') ) { op2 = new LessEqual(sql, i, i + 1); i = i + 2; } else if ( (i + 1 <= endIndex) && (c == '!' && sql[i + 1] == '=') ) { op2 = new NotEqual(sql, i, i + 1); i = i + 2; } else if (c == '=') { op2 = new Equal(sql, i, i); i++; } else if (c == '>') { op2 = new Greater(sql, i, i); i++; } else if (c == '<') { op2 = new Less(sql, i, i); i++; } else { i++; } if (op1 == null) { if (op2 != null) { op1 = op2; } } // 对于 Priority(优先级) 相同 的 运算符,取 最左边 的 , 这是 为了 适应 Not(非) 运算符 的 特性 // Not 运算符 是 一元运算符 。 其它 运算符 都是 二元运算符 , 从左往右 结合 和 从右往左 结合 都一样 // 但 Not 运算符 只能 从左往右 结合, 因为 从右往左 结合 会 找不到 操作数 // 从 编程 的 角度 来 看, 从左往右 的 思路 也 比较 顺 // 但 等价性 上来看, 我们 人类 的 计算习惯 是 从左到右, 而 这个 计算顺序 对应在 计算机 里 是 从右往左 结合运算符 // 计算机 从右往左 结合运算符 之后 执行计算 的 顺序 就是 从左到右 // 而 从左往右 结合运算符 的 执行计算顺序 是 从右到左 // 但 不管 计算顺序 是 从左到右 还是 从右到左, 结果 都一样 // 综上, 从 编程 的 角度 考虑, 我们选择 了 从左到右 结合 运算符, 执行计算 的 顺序 就是 从右到左 else if (op2 != null && op2.Priority < op1.Priority) { op1 = op2; } //if (c == '+') // return new Add(sql, i, i); //else if (c == '-') // return new Sub(sql, i, i); //else if (c == '*') // return new Multi(sql, i, i); //else if (c == '/') // return new Div(sql, i, i); //else if (c == 'a' && sql[i + 1] == 'n' && sql[i + 2] == 'd') // return new And(sql, i, i + 2); //else if (c == 'o' && sql[i + 1] == 'r') // return new Or(sql, i, i + 1); //else if (c == 'n' && sql[i + 1] == 'o' && sql[i + 1] == 't') // return new Not(sql, i, i + 2); //else if (c == '=') // return new Equal(sql, i, i + 1); //else if (c == '>') // return new Greater(sql, i, i); //else if (c == '<') // return new Less(sql, i, i); //else if (c == '>' && sql[i + 1] == '=') // return new GreaterEqual(sql, i, i + 1); //else if (c == '<' && sql[i + 1] == '=') // return new LessEqual(sql, i, i + 1); //else if (c == '!' && sql[i + 1] == '=') // return new NotEqual(sql, i, i + 1); } return(op1); //return null; }
public void Visit(LessEqual node) { Visit((dynamic)node[0]); Visit((dynamic)node[1]); }
public void Visit(LessEqual leq) { leq.Left.Accept(this); leq.Right.Accept(this); _instructions.Add(Instruction.Create(OpCodes.Cgt)); _instructions.Add(Instruction.Create(OpCodes.Ldc_I4_0)); _instructions.Add(Instruction.Create(OpCodes.Ceq)); }
public SemanticAtom Visit(LessEqual n) { n.RealizedType = BinaryExpressionHelper(n, Primitive.Int, "<=", Primitive.Boolean); return(n.RealizedType); }
public static Delegate CompileFunc(string input) { input = input.Replace(">=", MoreEqual.ToString()).Replace("<=", LessEqual.ToString()); return(GetLambda(input).Compile()); }
public void Visit(LessEqual leq) { leq.Left.Accept(this); _sb.Append(" <= "); leq.Right.Accept(this); }
public SemanticAtom Visit(LessEqual n) { n.LeftExpression.Accept(this); n.RightExpression.Accept(this); return(null); }
public string Visit(LessEqual node) { return(Visit((dynamic)node[0]) + Visit((dynamic)node[1]) + $" i32.le_s\n"); }
public void Visit(LessEqual leq) { leq.Left.Accept(this); _sb.Append(" <= "); leq.Right.Accept(this); }
public void Visit(LessEqual leq) { ResultIsBoolAndBothOperandsMustBeInt(leq); }
public void Visit(LessEqual node) { VisitChildren(node); }