fn parse_binary_expr(&mut self, prec: i32, mut left: Expr) -> Result<Expr, &'static str> {
        loop {
            let curr_prec = self.get_tok_precedence();

            if curr_prec < prec || self.at_end() {
                return Ok(left);
            }

            let op = match self.curr() {
                Op(op) => op,
                _ => return Err("Invalid operator."),
            };

            self.advance()?;

            let mut right = self.parse_unary_expr()?;

            let next_prec = self.get_tok_precedence();

            if curr_prec < next_prec {
                right = self.parse_binary_expr(curr_prec + 1, right)?;
            }

            left = Expr::Binary {
                op: op,
                left: Box::new(left),
                right: Box::new(right),
            };
        }
    }
/// Parses a binary expression, given its left-hand expression.
Parses a binary expression, given its left-hand expression.
Parses a binary expression given its left - hand expression .
fn parse_binary_expr(&mut self, prec: i32, mut left: Expr) -> Result<Expr, &'static str> {
        loop {
            let curr_prec = self.get_tok_precedence();
            if curr_prec < prec || self.at_end() {
                return Ok(left);
            }
            let op = match self.curr() {
                Op(op) => op,
                _ => return Err("Invalid operator."),
            };
            self.advance()?;
            let mut right = self.parse_unary_expr()?;
            let next_prec = self.get_tok_precedence();
            if curr_prec < next_prec {
                right = self.parse_binary_expr(curr_prec + 1, right)?;
            }
            left = Expr::Binary {
                op: op,
                left: Box::new(left),
                right: Box::new(right),
            };
        }
    }
fn parse_binary_expr ( & mut self , prec : i32 , mut left : Expr ) -> Result < Expr , & ' static str > { loop { let curr_prec = self . get_tok_precedence ( ) ; if curr_prec < prec || self . at_end ( ) { return Ok ( left ) ; } let op = match self . curr ( ) { Op ( op ) => op , _ => return Err ( " " ) , } ; self . advance ( ) ? ; let mut right = self . parse_unary_expr ( ) ? ; let next_prec = self . get_tok_precedence ( ) ; if curr_prec < next_prec { right = self . parse_binary_expr ( curr_prec + 1 , right ) ? ; } left = Expr :: Binary { op : op , left : Box :: new ( left ) , right : Box :: new ( right ) , } ; } }
Parses a binary expression, given its left-hand expression.
Parses a binary expression given its left - hand expression .
&mut self
prec
i32
left
Expr
&mut self
prec
i32
left
Expr