-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.q
More file actions
executable file
·46 lines (36 loc) · 1.09 KB
/
printer.q
File metadata and controls
executable file
·46 lines (36 loc) · 1.09 KB
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
#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-
/********************************************************************
Printer.q
=============================================================
A script printing debug info about AST tree of a target file.
---
Usage: printer.q TARGET_FILE [OUTPUT_FILE]
*******************************************************************/
%new-style
%enable-all-warnings
%require-types
%strict-args
%requires astparser
sub printUsage() {
printf("usage: %s TARGET_FILE [OUTPUT_FILE]\n", get_script_name());
}
if (ARGV.size() < 1) {
stderr.printf("not enough arguments!\n");
printUsage();
exit(1);
}
if (ARGV.size() > 2) {
stderr.printf("too many arguments!\n");
printUsage();
exit(1);
}
string fileToParse = ARGV[0];
string outFile = (ARGV.size() == 2) ? ARGV[1] : "./tree.out.txt";
astparser::AstParser parser();
*astparser::AstTree tree = parser.parseFile(fileToParse);
if (tree)
tree.printTree(outFile);
#printf("tree: %N\n", tree.getNodesInfo());
else
stderr.printf("error occured during parsing!\n");