-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.C.bak
52 lines (44 loc) · 1.37 KB
/
Test.C.bak
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
/*** Compiler Front-End Test automatically generated by the BNF Converter ***/
/* */
/* This test will parse a file, print the abstract syntax tree, and then */
/* pretty-print the result. */
/* */
/****************************************************************************/
#include <stdio.h>
#include "Parser.H"
#include "Printer.H"
#include "Absyn.H"
#include "Skeleton.H"
int main(int argc, char ** argv)
{
FILE *input;
if (argc > 1)
{
input = fopen(argv[1], "r");
if (!input)
{
fprintf(stderr, "Error opening input file.\n");
exit(1);
}
}
else input = stdin;
/* The default entry point is used. For other options see Parser.H */
Program *parse_tree = pProgram(input);
if (parse_tree)
{
printf("\nParse Succesful!\n");
printf("\n[Abstract Syntax]\n");
ShowAbsyn *s = new ShowAbsyn();
printf("%s\n\n", s->show(parse_tree));
printf("[Linearized Tree]\n");
PrintAbsyn *p = new PrintAbsyn();
printf("%s\n\n", p->print(parse_tree));
printf("BYTECODE\n");
Skeleton *a = new Skeleton();
a->run(parse_tree);
printf("SAVE BYTECODE\n");
a->writeToFile("VM/saved_data");
return 0;
}
return 1;
}