Example #1
0
        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;
        }
Example #2
0
        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;
        }
Example #3
0
        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;
            }
        }
Example #4
0
        public Arg(Expr expr)
            : this(null, expr)
        {

        }
Example #5
0
 public ConditionalExpr(Expr testExpr, Expr trueExpr, Expr falseExpr)
 {
     _testExpr = testExpr;
     _trueExpr = trueExpr;
     _falseExpr = falseExpr;
 }
Example #6
0
 public ParenthesisExpr(Expr expr)
 {
     _expr = expr;
 }
Example #7
0
 public MemberExpr(Expr target, string name)
 {
     _target = target;
     _name = name;
 }
        public ArrayLiteralExpr(Expr[] values)
        {
            ContractUtils.RequiresNotNullItems(values, "values");

            _values = values;
        }
Example #9
0
        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;
        }
Example #10
0
 public Parameter(string name, Expr defaultValue)
 {
     _name = name;
     _defaultValue = defaultValue;
     _kind = ParameterKind.Normal;
 }
Example #11
0
 public ExprStmt(Expr expr)
 {
     _expr = expr;
 }
Example #12
0
 public static bool IsComparison(Expr expression)
 {
     BinaryExpr be = expression as BinaryExpr;
     return be != null && be.IsComparison();
 }
Example #13
0
 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;
 }
Example #14
0
 private Expr ParseMemberExpr(Expr target)
 {
     Eat(TokenType.Dot);
     var ret = new MemberExpr(target, ((NameToken)NextToken()).Name);
     ret.SetLoc(_globalParent, ret.StartIndex, GetEnd());
     return ret;
 }
Example #15
0
 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;
         }
     }
 }
Example #16
0
 public Arg(string name, Expr expr)
 {
     _name = name;
     _expr = expr;
 }
Example #17
0
 public IndexExpr(Expr target, Expr[] indexes)
 {
     _target = target;
     _indexes = indexes;
 }
Example #18
0
 public ReturnStmt(Expr expr)
 {
     _expr = expr;
 }
Example #19
0
 public CallExpr(Expr target, Arg[] args)
 {
     _target = target;
     _args = args;
 }
 public VarInitialization(string name, Expr value)
 {
     _name = name;
     _value = value;
 }