Parsing/Shunting-yard algorithm: Difference between revisions
Content deleted Content added
Line 4,384: | Line 4,384: | ||
return None; |
return None; |
||
} |
} |
||
self. |
self.last().cloned() |
||
} |
} |
||
} |
} |
||
fn lex_token(input: char) -> Result<Token, char> { |
fn lex_token(input: char) -> Result<Token, char> { |
||
match input { |
let ret = match input { |
||
'0'...'9' => |
'0'...'9' => Token::Digit(input.to_digit(10).unwrap() as Number), |
||
'+' => |
'+' => Operator::new_token('+', 1, true, |x, y| x + y), |
||
'-' => |
'-' => Operator::new_token('-', 1, true, |x, y| x - y), |
||
'*' => |
'*' => Operator::new_token('*', 2, true, |x, y| x * y), |
||
'/' => |
'/' => Operator::new_token('/', 2, true, |x, y| x / y), |
||
'^' => |
'^' => Operator::new_token('^', 3, false, |x, y| x.powf(y)), |
||
'(' => |
'(' => Token::LeftParen, |
||
')' => |
')' => Token::RightParen, |
||
_ => Err(input), |
_ => return Err(input), |
||
} |
}; |
||
Ok(ret) |
|||
} |
} |
||