Add NodeType::Bloc
This commit is contained in:
parent
1e0d372fc6
commit
ec355abb20
@ -78,7 +78,8 @@ enum class NodeType {
|
|||||||
LDecr, // -> --ParIdentifier
|
LDecr, // -> --ParIdentifier
|
||||||
RDecr, // -> ParIdentifier--
|
RDecr, // -> ParIdentifier--
|
||||||
If, // -> If (Expr) Instruction
|
If, // -> If (Expr) Instruction
|
||||||
IfElse // -> If (Expr) Instruction Else Instruction
|
IfElse, // -> If (Expr) Instruction Else Instruction
|
||||||
|
Bloc // -> { Prog }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InnerNode;
|
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 = "") {
|
void _debug_print_tree(const Node& node, int depth, const string& prefix = "") {
|
||||||
if (holds_alternative<InnerNode>(node)) {
|
if (holds_alternative<InnerNode>(node)) {
|
||||||
const InnerNode& innerNode = get<InnerNode>(node);
|
const InnerNode& innerNode = get<InnerNode>(node);
|
||||||
@ -216,6 +219,7 @@ ParseReturn parse_statement(vector<Token> tokens) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
case TokenType::LCurlyBracket: {
|
case TokenType::LCurlyBracket: {
|
||||||
|
CodePosition pos = tokens.back().pos;
|
||||||
tokens.pop_back();
|
tokens.pop_back();
|
||||||
|
|
||||||
ParseReturn ret = parse_prog(tokens);
|
ParseReturn ret = parse_prog(tokens);
|
||||||
@ -239,8 +243,13 @@ ParseReturn parse_statement(vector<Token> tokens) {
|
|||||||
tokens = ret.tokens;
|
tokens = ret.tokens;
|
||||||
tokens.pop_back();
|
tokens.pop_back();
|
||||||
|
|
||||||
|
InnerNode node = {
|
||||||
|
.type=NodeType::Bloc,
|
||||||
|
.children={ret.node},
|
||||||
|
.pos=pos
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
.node=ret.node,
|
.node=node,
|
||||||
.tokens=tokens
|
.tokens=tokens
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user