diff --git a/parser/src/ast.rs b/parser/src/ast.rs index f4f82ad..875e274 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -5,13 +5,15 @@ use dbg_pls::DebugPls; use crate::Spanned; +pub type Ident = Spanned; + // // --- Expr // #[derive(Debug, DebugPls)] pub enum Atom { - Ident(String), + Ident(Ident), Int(i128), Float(f64), String(String), @@ -83,6 +85,38 @@ pub enum Expr { Binary(ExprBinary), } +// +// --- Statements +// + +#[derive(Debug, DebugPls)] +pub enum Stmt { + Labeled(Box>), + Compound(Vec>), + If { + cond: Expr, + then: Vec>, + otherwise: Option>>, + }, + Switch, + While { + cond: Expr, + body: Vec>, + }, + For { + init_decl: Option>, + init_expr: Option>, + cond: Option>, + post: Option>, + body: Vec>, + }, + Goto(Ident), + Continue, + Break, + Return(Option>), + Expr(Expr), +} + // // --- Types and decls and garbage whatever // @@ -107,8 +141,6 @@ pub enum TypeSpecifier { // typedef-name } -pub type Ident = Spanned; - bitflags! { pub struct DeclAttr: u8 { const EXTERN = 0b00000001; @@ -174,7 +206,7 @@ pub struct Declarator { #[derive(Debug, DebugPls)] pub struct FunctionDef { pub decl: Decl, - pub body: Vec<()>, + pub body: Vec, } #[derive(Debug, DebugPls)] diff --git a/parser/src/parser/expr.rs b/parser/src/parser/expr.rs index c988a23..87df712 100644 --- a/parser/src/parser/expr.rs +++ b/parser/src/parser/expr.rs @@ -184,9 +184,9 @@ mod powers { 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; + pub const CAST: u8 = 27; + pub const UNARY_OPERATOR: u8 = 28; + pub const POSTFIX: u8 = 29; } fn prefix_binding_power(tok: &Tok<'_>) -> u8 {