ygen - Learn

Learning ygen


Welcome to the ygen-book! Here you will learn how to build a simple compiler with ygen. I won't cover how to implement the parser, lexer, semnatic analayis here but you can refere to our examples.

Our ast (Abstract Syntax Tree)


Every language has a ast which represents the expressions and statements. For our language we will have following statements:

Rust

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Statement {  
    FnStmt{
        name: String,
        extern: bool,
        import: bool,

        args: Vec<Expr>,
        body: Vec<Statement>,
    },

    RetStmt{
        to_return: Expr,
    },

    ConstStmt{
        name: String,
        extern: bool,
        import: bool,
        data: Vec<Expr>,
    },
}