Update grammar definition
This commit is contained in:
parent
7b86fecc6f
commit
807482583a
@ -47,10 +47,14 @@ pub enum Ast {
|
|||||||
/*
|
/*
|
||||||
## Grammar
|
## Grammar
|
||||||
### Expressions
|
### Expressions
|
||||||
`expr_primary = LITERAL` \
|
expr_primary = LITERAL
|
||||||
`expr_mul = expr_primary (("*" | "/") expr_primary)*` \
|
expr_mul = expr_primary (("*" | "/" | "%") expr_primary)*
|
||||||
`expr_add = expr_mul (("+" | "-") expr_mul)*` \
|
expr_add = expr_mul (("+" | "-") expr_mul)*
|
||||||
`expr = expr_add` \
|
expr_shift = expr_add ((">>" | "<<") expr_add)*
|
||||||
|
expr_band = expr_shift ("&" expr_shift)*
|
||||||
|
expr_bxor = expr_band ("^") expr_band)*
|
||||||
|
expr_bor = expr_bxor ("|" expr_bxor)*
|
||||||
|
expr = expr_bor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct Parser<T: Iterator<Item = Token>> {
|
struct Parser<T: Iterator<Item = Token>> {
|
||||||
@ -129,6 +133,10 @@ pub fn parse<T: Iterator<Item = Token>, A: IntoIterator<IntoIter = T>>(tokens: A
|
|||||||
impl BinOpType {
|
impl BinOpType {
|
||||||
/// Get the precedence for a binary operator. Higher value means the OP is stronger binding.
|
/// Get the precedence for a binary operator. Higher value means the OP is stronger binding.
|
||||||
/// For example Multiplication is stronger than addition, so Mul has higher precedence than Add.
|
/// For example Multiplication is stronger than addition, so Mul has higher precedence than Add.
|
||||||
|
///
|
||||||
|
/// The operator precedences are derived from the C language operator precedences. While not all
|
||||||
|
/// C operators are included or the exact same, the precedence oder is the same.
|
||||||
|
/// See: https://en.cppreference.com/w/c/language/operator_precedence
|
||||||
fn precedence(&self) -> u8 {
|
fn precedence(&self) -> u8 {
|
||||||
match self {
|
match self {
|
||||||
BinOpType::BOr => 0,
|
BinOpType::BOr => 0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user