#ifndef DEF_PARSER_H #define DEF_PARSER_H #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 + S | T - S T -> | F | F * T | F / T | F % T F -> | U | - F | + F U -> | (Expr) | Identifier | Number | Identifier = Expr // Assignment */ enum class NodeType { Prog, // -> Instruction; Prog AssignedDeclaration, // -> Type Identifier = Expr Declaration, // -> Type Identifier Plus, // -> T + S Minus, // -> T - S Mult, // -> F * T Div, // -> F / T Mod, // -> F % T UnaryMinus, // -> -F UnaryPlus, // -> +F Parenthesis, // -> (Expr) Assignment, // -> Identifier = Expr Leaf }; struct Node { NodeType type; Node* children; }; // A Leaf is always corresponding to a Token enum class TreeType { Leaf, Node }; struct SyntaxTree { TreeType type; union { Node node; Token leaf; }; }; #endif