public void TestUnary() { var mult = new Arith(new Token('*'), new Constant(42), new Constant(3)); var u = new Unary(new Token('-'), mult); Assert.AreEqual("- 42 * 3", u.ToString()); Assert.IsTrue(u.Gen() is Expr); }
public void TestArith() { var add = new Arith(new Token('+'), new Constant(42), new Constant(99)); Assert.AreEqual("42 + 99", add.ToString()); Assert.IsTrue(add.Reduce() is Sara.Temp); var mult = new Arith(new Token('*'), new Constant(142), new Constant(0)); var poly = new Arith(new Token('-'), add, mult); Assert.AreEqual("42 + 99 - 142 * 0", poly.ToString()); }
public Expr Term() { Expr expr = this.Unary(); while (_look.TagValue == '*' || _look.TagValue == '/') { Token tok = _look; this.Move(); expr = new Arith(tok, expr, this.Unary()); } return(expr); }
public Expr Expr() { Expr expr = this.Term(); while (_look.TagValue == '+' || _look.TagValue == '-') { Token tok = _look; this.Move(); expr = new Arith(tok, expr, this.Term()); } return(expr); }
public Access Offset(Id a) { Expr i, w, t1, t2, loc; Type type = a.Type; this.Match('['); i = this.Bool(); this.Match(']'); type = (type as Array).Of; w = new Constant(type.Width); t1 = new Arith(new Token('*'), i, w); loc = t1; while(_look.TagValue == '[') { this.Match('['); i = this.Bool(); this.Match(']'); type = (type as Array).Of; w = new Constant(type.Width); t1 = new Arith(new Token('*'), i, w); t2 = new Arith(new Token('+'), loc, t1); loc = t2; } return new Access(a, loc, type); }
public Expr Term() { Expr expr = this.Unary(); while(_look.TagValue == '*' || _look.TagValue == '/') { Token tok = _look; this.Move(); expr = new Arith(tok, expr, this.Unary()); } return expr; }
public Expr Expr() { Expr expr = this.Term(); while(_look.TagValue == '+' || _look.TagValue == '-') { Token tok = _look; this.Move(); expr = new Arith(tok, expr, this.Term()); } return expr; }