mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-14 16:45:07 +01:00
add stmt to ast
This commit is contained in:
parent
30da01fc05
commit
fb1ce74e08
2 changed files with 39 additions and 7 deletions
|
|
@ -5,13 +5,15 @@ use dbg_pls::DebugPls;
|
|||
|
||||
use crate::Spanned;
|
||||
|
||||
pub type Ident = Spanned<String>;
|
||||
|
||||
//
|
||||
// --- 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<Spanned<Stmt>>),
|
||||
Compound(Vec<Spanned<Stmt>>),
|
||||
If {
|
||||
cond: Expr,
|
||||
then: Vec<Spanned<Stmt>>,
|
||||
otherwise: Option<Vec<Spanned<Stmt>>>,
|
||||
},
|
||||
Switch,
|
||||
While {
|
||||
cond: Expr,
|
||||
body: Vec<Spanned<Stmt>>,
|
||||
},
|
||||
For {
|
||||
init_decl: Option<Spanned<Decl>>,
|
||||
init_expr: Option<Spanned<Expr>>,
|
||||
cond: Option<Spanned<Expr>>,
|
||||
post: Option<Spanned<Expr>>,
|
||||
body: Vec<Spanned<Stmt>>,
|
||||
},
|
||||
Goto(Ident),
|
||||
Continue,
|
||||
Break,
|
||||
Return(Option<Spanned<Expr>>),
|
||||
Expr(Expr),
|
||||
}
|
||||
|
||||
//
|
||||
// --- Types and decls and garbage whatever
|
||||
//
|
||||
|
|
@ -107,8 +141,6 @@ pub enum TypeSpecifier {
|
|||
// typedef-name
|
||||
}
|
||||
|
||||
pub type Ident = Spanned<String>;
|
||||
|
||||
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<Stmt>,
|
||||
}
|
||||
|
||||
#[derive(Debug, DebugPls)]
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue