-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTprint.cpp
More file actions
46 lines (41 loc) · 1007 Bytes
/
ASTprint.cpp
File metadata and controls
46 lines (41 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ASTprint.cpp
#pragma warning(disable:4786)
#include "ASTprint.h"
#include "AST.h"
namespace js2cpp {
//
//
void TreePrint(FILE *f, AST *tree, int depth)
{
tail_recursion:
if (!tree) {
fprintf(f, "%*cNULL", depth-1, ' ');
return;
}
TokenType type = Type(tree);
const char *name = Name(type);
if (type >= tIDENT && type <= tREGEX) {
fprintf(f, "%*c%s=%s\n", depth-1, ' ', name, Name(tree));
} else {
fprintf(f, "%*c%s\n", depth-1, ' ', name);
}
if (tree->first) {
TreePrint(f, tree->first, depth+3);
} else if (tree->second || tree->third) {
fprintf(f, "%*cNULL\n", depth+3-1, ' ');
}
if (tree->second) {
TreePrint(f, tree->second, depth+3);
} else if (tree->third) {
fprintf(f, "%*cNULL\n", depth+3-1, ' ');
}
if (tree->third) {
if (Type(tree)==tSTATLIST) {
tree = tree->third;
goto tail_recursion;
} else {
TreePrint(f, tree->third, depth+3);
}
}
} // TreePrint
} // namespace