Example #1
0
        private Expr multiplication()
        {
            Expr expr = unary();

            while (match(TokenType.SLASH, TokenType.STAR))
            {
                Token operator_ = previous();
                Expr  right     = unary();
                expr = new Expr.Binary(expr, operator_, right);
            }

            return(expr);
        }
Example #2
0
        private Expr addition()
        {
            Expr expr = multiplication();

            while (match(TokenType.MINUS, TokenType.PLUS))
            {
                Token operator_ = previous();
                Expr  right     = multiplication();
                expr = new Expr.Binary(expr, operator_, right);
            }

            return(expr);
        }
Example #3
0
        private Expr comparison()
        {
            Expr expr = addition();

            while (match(TokenType.GREATER, TokenType.GREATER_EQUAL, TokenType.LESS, TokenType.LESS_EQUAL))
            {
                Token operator_ = previous();
                Expr  right     = addition();
                expr = new Expr.Binary(expr, operator_, right);
            }

            return(expr);
        }
Example #4
0
        private Expr equality()
        {
            Expr expr = comparison();

            while (match(TokenType.BANG_EQUAL, TokenType.EQUAL_EQUAL))
            {
                Token operator_ = previous();
                Expr  right     = comparison();
                expr = new Expr.Binary(expr, operator_, right);
            }

            return(expr);
        }
Example #5
0
 public string visitBinaryExpr(Expr.Binary expr)
 {
     return(parenthesize(expr.operator_.lexeme, expr.left, expr.right));
 }
Example #6
0
 public object visitBinaryExpr(Expr.Binary expr)
 {
     resolve(expr.left);
     resolve(expr.right);
     return(null);
 }