void facteur(ref Expression ex) { if (la.kind == 1) { Get(); if (StartOf(8)) { ex = new VariableExpression { Name = t.val, Location = new Location(t.line, t.col, t.charPos) }; } else if (la.kind == 22) { ex = new MethodInvocationExpression { Name = t.val, Location = new Location(t.line, t.col, t.charPos) }; List <Expression> el = null; Get(); expr_list(ref el); (ex as MethodInvocationExpression).Arguments = el; Expect(23); } else { SynErr(61); } } else if (la.kind == 2) { Get(); ex = new IntegralExpression { Value = int.Parse(t.val), Location = new Location(t.line, t.col, t.charPos) }; } else if (la.kind == 22) { Expression target = null; Get(); ex = new ParenthesisExpression { Location = new Location(t.line, t.col, t.charPos) }; expr(ref target); (ex as ParenthesisExpression).Target = target; Expect(23); } else if (la.kind == 17) { Expression e = null; Get(); ex = new UnaryOperationExpression { Location = new Location(t.line, t.col, t.charPos), Operator = Operators.LogicalNot }; facteur(ref e); (ex as UnaryOperationExpression).Expression = e; } else { SynErr(62); } }
protected IExpression MayNegate(IExpression expression) { if (negate) { if (expression is BinaryOperationExpression) { expression = new ParenthesisExpression(null, expression); } expression = new UnaryOperationExpression(null, UnaryOperator.Not, expression); } return(expression); }
public void UnaryOperationExpressionHasProperties() { var a = JS.Id("a"); var expression = new UnaryOperationExpression(a, UnaryOperator.Number); Assert.AreEqual("+a;", expression.ToString()); expression.Operator = UnaryOperator.New; Assert.AreEqual(UnaryOperator.New, expression.Operator); Assert.AreEqual("new a;", expression.ToString()); expression.Operand = JS.ParseId("Sys.UI.Component"); Assert.AreEqual("Sys.UI.Component;", expression.Operand.ToString()); Assert.AreEqual("new Sys.UI.Component;", expression.ToString()); }
void simple_expr(ref Expression expr) { if (la.kind == 27 || la.kind == 28) { Expression e = null; Operators op = Operators.Add; signe(ref op); terme(ref e); expr = new UnaryOperationExpression { Operator = op, Location = e.Location, Expression = e }; } else if (StartOf(4)) { Expression e = null; Operators op = Operators.Add; terme(ref expr); if (StartOf(5)) { } else if (la.kind == 27 || la.kind == 28) { signe(ref op); simple_expr(ref e); expr = new BinaryOperationExpression { Left = expr, Right = e, Operator = op, Location = expr.Location }; } else if (la.kind == 16) { Get(); simple_expr(ref e); expr = new BinaryOperationExpression { Left = expr, Right = e, Operator = Operators.Or, Location = expr.Location }; } else { SynErr(56); } } else { SynErr(57); } }
public void UnaryOperationExpressionDetectsUnknownEnumeration() { var expression = new UnaryOperationExpression(1, (UnaryOperator)int.MaxValue); Expect.Throw <InvalidOperationException>(() => expression.ToString()); }
public void UnaryOperationExpressionDetectsUnknownEnumeration() { var expression = new UnaryOperationExpression(1, (UnaryOperator) int.MaxValue); Expect.Throw<InvalidOperationException>(() => expression.ToString()); }