public BinaryExpr(TotemOperator op, Expr left, Expr right) { ContractUtils.RequiresNotNull(left, "left"); ContractUtils.RequiresNotNull(right, "right"); switch (op) { case TotemOperator.Add: case TotemOperator.Subtract: case TotemOperator.Modulo: case TotemOperator.Multiply: case TotemOperator.Divide: case TotemOperator.LessThan: case TotemOperator.LessThanOrEqual: case TotemOperator.GreaterThan: case TotemOperator.GreaterThanOrEqual: case TotemOperator.Equal: case TotemOperator.NotEqual: case TotemOperator.LogicalAnd: case TotemOperator.LogicalOr: case TotemOperator.Attatch: break; default: throw Assert.Unreachable; } _left = left; _right = right; _op = op; }
public AssignExpr(TokenType type, Expr left, Expr right) { switch (type) { case TokenType.Assign: _op = ExpressionType.Assign; break; case TokenType.AddEqual: _op = ExpressionType.AddAssign; break; case TokenType.SubtractEqual: _op = ExpressionType.SubtractAssign; break; default: throw Assert.Unreachable; } _left = left; _right = right; }
public UnaryExpr(TotemOperator op, Expr expr) { _expr = expr; _op = op; switch (op) { case TotemOperator.Increment: case TotemOperator.Decrement: case TotemOperator.PostIncrement: case TotemOperator.PostDecrement: case TotemOperator.Not: case TotemOperator.Negate: case TotemOperator.Pos: break; default: throw Assert.Unreachable; } }
public Arg(Expr expr) : this(null, expr) { }
public ConditionalExpr(Expr testExpr, Expr trueExpr, Expr falseExpr) { _testExpr = testExpr; _trueExpr = trueExpr; _falseExpr = falseExpr; }
public ParenthesisExpr(Expr expr) { _expr = expr; }
public MemberExpr(Expr target, string name) { _target = target; _name = name; }
public ArrayLiteralExpr(Expr[] values) { ContractUtils.RequiresNotNullItems(values, "values"); _values = values; }
private CallExpr ParseCall(Expr target) { Eat(TokenType.LeftParenthesis); List<Arg> args = new List<Arg>(); if (!MaybeEat(TokenType.RightParenthesis)) { do { args.Add(ParseArg()); } while (MaybeEat(TokenType.Comma)); Eat(TokenType.RightParenthesis); } var ret = new CallExpr(target, args.ToArray()); ret.SetLoc(_globalParent, target.StartIndex, GetEnd()); return ret; }
public Parameter(string name, Expr defaultValue) { _name = name; _defaultValue = defaultValue; _kind = ParameterKind.Normal; }
public ExprStmt(Expr expr) { _expr = expr; }
public static bool IsComparison(Expr expression) { BinaryExpr be = expression as BinaryExpr; return be != null && be.IsComparison(); }
private Expr ParseIndexExpr(Expr target) { Eat(TokenType.LeftBracket); List<Expr> indexes = new List<Expr>(); do { indexes.Add(ParseExpr()); } while (MaybeEat(TokenType.Comma)); var ret = new IndexExpr(target, indexes.ToArray()); ret.SetLoc(_globalParent, ret.StartIndex, GetEnd()); Eat(TokenType.RightBracket); return ret; }
private Expr ParseMemberExpr(Expr target) { Eat(TokenType.Dot); var ret = new MemberExpr(target, ((NameToken)NextToken()).Name); ret.SetLoc(_globalParent, ret.StartIndex, GetEnd()); return ret; }
private Expr ParseCallOrMemberTail(Expr ret) { while (true) { if (PeekToken().Kind == TokenType.LeftParenthesis) { ret = ParseCall(ret); } else if (PeekToken().Kind == TokenType.Dot) { ret = ParseMemberExpr(ret); } else if (PeekToken().Kind == TokenType.LeftBracket) { ret = ParseIndexExpr(ret); } else { return ret; } } }
public Arg(string name, Expr expr) { _name = name; _expr = expr; }
public IndexExpr(Expr target, Expr[] indexes) { _target = target; _indexes = indexes; }
public ReturnStmt(Expr expr) { _expr = expr; }
public CallExpr(Expr target, Arg[] args) { _target = target; _args = args; }
public VarInitialization(string name, Expr value) { _name = name; _value = value; }