#ifndef DEF_PARSER_H #define DEF_PARSER_H #include #include "tokenize.h" using namespace std; /** Grammar: Prog -> Instruction; Prog | \epsilon Instruction -> Statement | ExprStatement | Expr Statement -> // Rien pour l'instant, mais "for", "if" etc ExprStatement -> | Type Identifier = Expr // AssignedDeclaration | Type Identifier // Declaration Expr -> | T | T + Expr | T - Expr T -> | F | F * T | F / T | F % T U -> | F | - U | + U F -> | (Expr) | Identifier | Number | Identifier = Expr // Assignment */ enum class NodeType { Prog, // -> Instruction; Prog AssignedDeclaration, // -> Type Identifier = Expr Declaration, // -> Type Identifier Plus, // -> T + Expr Minus, // -> T - Expr Mult, // -> F * T Div, // -> F / T Mod, // -> F % T UnaryMinus, // -> -F UnaryPlus, // -> +F Parenthesis, // -> (Expr) Assignment // -> Identifier = Expr }; struct InnerNode { NodeType type; vector children; }; // A Leaf is always corresponding to a Token struct Node { bool is_leaf; union { InnerNode node; Token leaf; }; }; #endif