Daily Shaarli
May 27, 2024
TIL the faintness sensation come from hyperventilation is a result of respiratory alkalosis, which is caused by reduced CO2 (acidic) level in blood. CO2 is equilibrated with HCO3- (basic) in blood as a pH buffering solution. The lung controls the amount of CO2 whereas the kidney controls the amount of HCO3-. So breathing rate is determined by the level of CO2. Although the CO2 exhaled contributes to the majority of weight loss in human, hyperventilation is not a feasible way to lose weight because the benefit is marginal compared to the downside of respiratory alkalosis. A better way to lose weight is through producing more CO2, which is achieved by increasing metabolism rate.
Pratt parsing is a parsing algorithm that solves the awkward handling of left-recursion in a recursive descent parser. It elegantly handles both operator precedence and associativity using a single "binding power" concept. The core algorithm is as simple as follows:
fn expr(input: &str) -> S {
let mut lexer = Lexer::new(input);
expr_bp(&mut lexer, 0)
}
fn expr_bp(lexer: &mut Lexer, min_bp: u8) -> S {
let mut lhs = match lexer.next() {
Token::Atom(it) => S::Atom(it),
t => panic!("bad token: {:?}", t),
};
loop {
let op = match lexer.peek() {
Token::Eof => break,
Token::Op(op) => op,
t => panic!("bad token: {:?}", t),
};
let (l_bp, r_bp) = infix_binding_power(op);
if l_bp < min_bp {
break;
}
lexer.next();
let rhs = expr_bp(lexer, r_bp);
lhs = S::Cons(op, vec![lhs, rhs]);
}
lhs
}
fn infix_binding_power(op: char) -> (u8, u8) {
match op {
'+' | '-' => (1, 2),
'*' | '/' => (3, 4),
_ => panic!("bad op: {:?}"),
}
}
Like the now shut down RawGit, it's a free CDN for serving raw files from GitHub and other platforms.