Exemple #1
0
        private Expr Multiplication()
        {
            Expr expr = Unary();

            while (Match(TokenType.SLASH, TokenType.STAR))
            {
                Token op    = Previous();
                Expr  right = Unary();
                expr = new Expr.Binary(expr, op, right);
            }

            return(expr);
        }
Exemple #2
0
        private Expr Addition()
        {
            Expr expr = Multiplication();

            while (Match(TokenType.MINUS, TokenType.PLUS))
            {
                Token op    = Previous();
                Expr  right = Multiplication();
                expr = new Expr.Binary(expr, op, right);
            }

            return(expr);
        }
Exemple #3
0
        private Expr Comp()
        {
            Expr expr = Addition();

            while (Match(TokenType.GREATER, TokenType.GREATER_EQUAL, TokenType.LESS, TokenType.LESS_EQUAL))
            {
                Token op    = Previous();
                Expr  right = Addition();
                expr = new Expr.Binary(expr, op, right);
            }

            return(expr);
        }
Exemple #4
0
        private Expr Equality()
        {
            // The default returned value if while loop never executes is just the result of comp()
            Expr expr = Comp();

            while (Match(TokenType.BANG_EQUAL, TokenType.EQUAL_EQUAL))
            {
                Token op    = Previous();
                Expr  right = Comp();
                expr = new Expr.Binary(expr, op, right);
            }

            return(expr);
        }
Exemple #5
0
 public string VisitBinaryExpr(Expr.Binary expr)
 {
     return(Parenthesize(expr.op.lexeme, expr.left, expr.right));
 }
 public MyVoid VisitBinaryExpr(Expr.Binary expr)
 {
     resolve(expr.left);
     resolve(expr.right);
     return(null);
 }