mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-14 08:35:08 +01:00
more power ⚡
This commit is contained in:
parent
c4f3e3dc93
commit
30da01fc05
1 changed files with 50 additions and 5 deletions
|
|
@ -170,18 +170,63 @@ fn binary_op_from_token(tok: &Tok<'_>) -> Option<BinaryOp> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod powers {
|
||||||
|
pub const COMMA: (u8, u8) = (1, 2);
|
||||||
|
pub const ASSIGN: (u8, u8) = (3, 4);
|
||||||
|
pub const TERNARY: (u8, u8) = (5, 6);
|
||||||
|
pub const LOGICAL_OR: (u8, u8) = (7, 8);
|
||||||
|
pub const LOGICAL_AND: (u8, u8) = (9, 10);
|
||||||
|
pub const BIT_OR: (u8, u8) = (11, 12);
|
||||||
|
pub const BIT_XOR: (u8, u8) = (13, 14);
|
||||||
|
pub const BIT_AND: (u8, u8) = (15, 16);
|
||||||
|
pub const EQ_NEQ: (u8, u8) = (17, 18);
|
||||||
|
pub const CMP: (u8, u8) = (19, 20);
|
||||||
|
pub const SHIFT: (u8, u8) = (21, 22);
|
||||||
|
pub const ADD_SUB: (u8, u8) = (23, 24);
|
||||||
|
pub const MUL_DIV_MOD: (u8, u8) = (25, 26);
|
||||||
|
pub const CAST: (u8, u8) = (27, 28);
|
||||||
|
pub const UNARY_OPERATOR: u8 = 29;
|
||||||
|
pub const POSTFIX: u8 = 30;
|
||||||
|
}
|
||||||
|
|
||||||
fn prefix_binding_power(tok: &Tok<'_>) -> u8 {
|
fn prefix_binding_power(tok: &Tok<'_>) -> u8 {
|
||||||
match tok {
|
match tok {
|
||||||
Tok::Punct(P::Ampersand | P::Asterisk | P::Plus | P::Minus | P::Tilde | P::Bang) => 255,
|
Tok::Punct(P::Ampersand | P::Asterisk | P::Plus | P::Minus | P::Tilde | P::Bang) => {
|
||||||
|
powers::UNARY_OPERATOR
|
||||||
|
}
|
||||||
_ => panic!("invalid token in expression! {tok:?}"),
|
_ => panic!("invalid token in expression! {tok:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infix_binding_power(tok: &Tok<'_>) -> (u8, u8) {
|
fn infix_binding_power(tok: &Tok<'_>) -> (u8, u8) {
|
||||||
match tok {
|
let Tok::Punct(puct) = tok else {
|
||||||
Tok::Punct(P::Comma) => (1, 2),
|
panic!("invalid token in expression! {tok:?}")
|
||||||
Tok::Punct(P::Plus | P::Minus) => (3, 4),
|
};
|
||||||
Tok::Punct(P::Asterisk | P::Slash) => (5, 6),
|
|
||||||
|
match puct {
|
||||||
|
P::Comma => powers::COMMA,
|
||||||
|
P::Eq
|
||||||
|
| P::PlusEq
|
||||||
|
| P::MinusEq
|
||||||
|
| P::AsteriskEq
|
||||||
|
| P::SlashEq
|
||||||
|
| P::PercentEq
|
||||||
|
| P::LeftLeftChevronEq
|
||||||
|
| P::RightRightChevronEq
|
||||||
|
| P::AmpersandEq
|
||||||
|
| P::CaretEq
|
||||||
|
| P::PipeEq => powers::ASSIGN,
|
||||||
|
// then, ternary here
|
||||||
|
P::PipePipe => powers::LOGICAL_OR,
|
||||||
|
P::AmpersandAmpersand => powers::LOGICAL_AND,
|
||||||
|
P::Pipe => powers::BIT_OR,
|
||||||
|
P::Caret => powers::BIT_XOR,
|
||||||
|
P::Ampersand => powers::BIT_AND,
|
||||||
|
P::EqEq | P::BangEq => powers::EQ_NEQ,
|
||||||
|
P::LeftChevron | P::RightChevron | P::LeftChevronEq | P::RightChevronEq => powers::CMP,
|
||||||
|
P::LeftLeftChevron | P::RightRightChevron => powers::SHIFT,
|
||||||
|
P::Plus | P::Minus => powers::ADD_SUB,
|
||||||
|
P::Asterisk | P::Slash | P::Percent => powers::MUL_DIV_MOD,
|
||||||
_ => panic!("invalid token in expression! {tok:?}"),
|
_ => panic!("invalid token in expression! {tok:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue