-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
52 lines (50 loc) · 1.52 KB
/
main.cpp
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
47
48
49
50
51
52
#include <iostream>
#include "driver.hpp"
#include <fstream>
#include <string>
driver drv;
int main (int argc, char *argv[])
{
bool verbose = false;
bool latex = false;
static std::ofstream outfile;
std::string latex_preamble = R"PREAMBLE(
\documentclass[12pt]{article}
\usepackage{synttree}
\begin{document}
)PREAMBLE";
std::cout << argv[0] << std::endl;
for (int i = 1; i < argc; ++i)
if (argv[i] == std::string ("-p"))
drv.trace_parsing = true;
else if (argv[i] == std::string ("-s"))
drv.trace_scanning = true;
else if (argv[i] == std::string("-v"))
verbose = true;
else if (argv[i] == std::string("-l"))
latex = true;
else if (!drv.parse (argv[i])) {
std::cout << "Parse successful\n";
if (latex) {
drv.toLatex = true;
drv.opening = "[$";
drv.closing = "$]";
outfile.open(argv[i]+std::string(".tex"));
drv.outputTarget = &outfile;
*drv.outputTarget << latex_preamble << std::endl;
*drv.outputTarget << "{\\bf\\LARGE Foresta AST di " << argv[i] << "}\n";
*drv.outputTarget << "\\vspace{1cm}\n\n";
} else if (verbose)
drv.outputTarget = &std::cout;
else break;
for (DefAST* tree: drv.root) {
if (latex) *drv.outputTarget << "\\synttree";
tree->visit();
if (latex) *drv.outputTarget << "\n\\par\\vspace{1cm}\n";
else std::cout << std::endl;
}
if (latex) *drv.outputTarget << "\\end{document}";
outfile.close();
} else return 1;
return 0;
}