parser: Add debug function instead of array
This commit is contained in:
parent
c4b39ecc6e
commit
2f1d9ab183
@ -15,17 +15,54 @@ CodePosition null_pos = {
|
||||
};
|
||||
|
||||
|
||||
const char* _debug_ast_node_names[] = {
|
||||
"Prog", "Epsilon", "AssignedDeclaration", "Declaration", "Plus", "Minus", "Mult", "Div", "Mod",
|
||||
"UnaryMinus", "UnaryPlus", "Neg", "Assignment", "LIncr", "RIncr", "LDecr", "RDecr", "If", "IfElse",
|
||||
"For", "While", "Bloc", "Lt", "Gt", "Leq", "Geq", "Eq", "Neq", "Land", "Lor", "Comma",
|
||||
"FunctionPrototype", "FunctionDeclaration", "FunctionCall", "FunctionArgs", "FunctionArgsValues", "Return"
|
||||
};
|
||||
string _debug_get_ast_node_name(NodeType type) {
|
||||
switch (type) {
|
||||
case NodeType::Prog: return "Prog";
|
||||
case NodeType::Epsilon: return "Epsilon";
|
||||
case NodeType::AssignedDeclaration: return "AssignedDeclaration";
|
||||
case NodeType::Declaration: return "Declaration";
|
||||
case NodeType::Plus: return "Plus";
|
||||
case NodeType::Minus: return "Minus";
|
||||
case NodeType::Mult: return "Mult";
|
||||
case NodeType::Div: return "Div";
|
||||
case NodeType::Mod: return "Mod";
|
||||
case NodeType::UnaryMinus: return "UnaryMinus";
|
||||
case NodeType::UnaryPlus: return "UnaryPlus";
|
||||
case NodeType::Neg: return "Neg";
|
||||
case NodeType::Assignment: return "Assignment";
|
||||
case NodeType::LIncr: return "LIncr";
|
||||
case NodeType::RIncr: return "RIncr";
|
||||
case NodeType::LDecr: return "LDecr";
|
||||
case NodeType::RDecr: return "RDecr";
|
||||
case NodeType::If: return "If";
|
||||
case NodeType::IfElse: return "IfElse";
|
||||
case NodeType::For: return "For";
|
||||
case NodeType::While: return "While";
|
||||
case NodeType::Bloc: return "Bloc";
|
||||
case NodeType::Lt: return "Lt";
|
||||
case NodeType::Gt: return "Gt";
|
||||
case NodeType::Leq: return "Leq";
|
||||
case NodeType::Geq: return "Geq";
|
||||
case NodeType::Eq: return "Eq";
|
||||
case NodeType::Neq: return "Neq";
|
||||
case NodeType::Land: return "Land";
|
||||
case NodeType::Lor: return "Lor";
|
||||
case NodeType::Comma: return "Comma";
|
||||
case NodeType::FunctionPrototype: return "FunctionPrototype";
|
||||
case NodeType::FunctionDeclaration: return "FunctionDeclaration";
|
||||
case NodeType::FunctionCall: return "FunctionCall";
|
||||
case NodeType::FunctionArgs: return "FunctionArgs";
|
||||
case NodeType::FunctionArgsValues: return "FunctionArgsValues";
|
||||
case NodeType::Return: return "Return";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void _debug_print_tree(const Node& node, int depth, const string& prefix) {
|
||||
if (holds_alternative<InnerNode>(node)) {
|
||||
const InnerNode& inner_node = get<InnerNode>(node);
|
||||
|
||||
cout << prefix << _debug_ast_node_names[int(inner_node.type)] << "\n";
|
||||
cout << prefix << _debug_get_ast_node_name(inner_node.type) << "\n";
|
||||
|
||||
string new_prefix = prefix;
|
||||
size_t pos = new_prefix.find("└──");
|
||||
|
Loading…
Reference in New Issue
Block a user