-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiny.cpp
More file actions
48 lines (43 loc) · 1.16 KB
/
tiny.cpp
File metadata and controls
48 lines (43 loc) · 1.16 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
47
/****************************************************/
/* File: main.c */
/* Main program for TINY compiler */
/* Compiler Construction: Principles and Practice */
/* Kenneth C. Louden */
/****************************************************/
#pragma warning(disable:4996)
#include "util.h"
#include "scan.h"
#include "PARSE.H"
#include "globals.h"
#include "tiny.h"
int lineno = 0;
FILE* source;
FILE* listing;
FILE* code;
int EchoSource = FALSE;
int TraceScan = FALSE;
int TraceParse = FALSE;
int TraceAnalyze = FALSE;
int TraceCode = FALSE;
int Error = FALSE;
void tiny(string sourcePath, string treePath)
{
TreeNode* syntaxTree;
char pgm[120]; /* source code file name */
strcpy(pgm, sourcePath.c_str());
if (strchr(pgm, '.') == NULL)
strcat(pgm, ".tny");
source = fopen(pgm, "r");
if (source == NULL)
{
fprintf(stderr, "File %s not found\n", pgm);
exit(1);
}
listing = fopen(treePath.c_str(), "w");
fprintf(listing, "\nTINY COMPILATION: %s\n", pgm);
syntaxTree = parse();
fprintf(listing, "\nSyntax tree:\n");
printTree(syntaxTree);
fclose(source);
fclose(listing);
}