Add NodeType::Bloc
This commit is contained in:
parent
1e0d372fc6
commit
ec355abb20
@ -78,7 +78,8 @@ enum class NodeType {
|
||||
LDecr, // -> --ParIdentifier
|
||||
RDecr, // -> ParIdentifier--
|
||||
If, // -> If (Expr) Instruction
|
||||
IfElse // -> If (Expr) Instruction Else Instruction
|
||||
IfElse, // -> If (Expr) Instruction Else Instruction
|
||||
Bloc // -> { Prog }
|
||||
};
|
||||
|
||||
struct InnerNode;
|
||||
|
@ -12,7 +12,10 @@ CodePosition null_pos = {
|
||||
};
|
||||
|
||||
|
||||
const char* _node_names[] = {"Prog", "Epsilon", "AssignedDeclaration", "Declaration", "Plus", "Minus", "Mult", "Div", "Mod", "UnaryMinus", "UnaryPlus", "Assignment", "LIncr", "RIncr", "LDecr", "RDecr", "If", "IfElse"};
|
||||
const char* _node_names[] = {
|
||||
"Prog", "Epsilon", "AssignedDeclaration", "Declaration", "Plus", "Minus", "Mult", "Div", "Mod",
|
||||
"UnaryMinus", "UnaryPlus", "Assignment", "LIncr", "RIncr", "LDecr", "RDecr", "If", "IfElse", "Bloc"
|
||||
};
|
||||
void _debug_print_tree(const Node& node, int depth, const string& prefix = "") {
|
||||
if (holds_alternative<InnerNode>(node)) {
|
||||
const InnerNode& innerNode = get<InnerNode>(node);
|
||||
@ -216,6 +219,7 @@ ParseReturn parse_statement(vector<Token> tokens) {
|
||||
};
|
||||
}
|
||||
case TokenType::LCurlyBracket: {
|
||||
CodePosition pos = tokens.back().pos;
|
||||
tokens.pop_back();
|
||||
|
||||
ParseReturn ret = parse_prog(tokens);
|
||||
@ -239,8 +243,13 @@ ParseReturn parse_statement(vector<Token> tokens) {
|
||||
tokens = ret.tokens;
|
||||
tokens.pop_back();
|
||||
|
||||
InnerNode node = {
|
||||
.type=NodeType::Bloc,
|
||||
.children={ret.node},
|
||||
.pos=pos
|
||||
};
|
||||
return {
|
||||
.node=ret.node,
|
||||
.node=node,
|
||||
.tokens=tokens
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user