-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.h
145 lines (116 loc) · 3.6 KB
/
globals.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/****************************************************/
/* File: globals.h */
/* Yacc/Bison Version */
/* Global types and vars for C- compiler */
/* must come before other include files */
/* Max Forasteiro */
/****************************************************/
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
/* Yacc/Bison generates internally its own values
* for the tokens. Other files can access these values
* by including the tab.h file generated using the
* Yacc/Bison option -d ("generate header")
*
* The YYPARSER flag prevents inclusion of the tab.h
* into the Yacc/Bison output itself
*/
#ifndef YYPARSER
/* the name of the following file may change */
#include "cminus.tab.h"
/* ENDFILE is implicitly defined by Yacc/Bison,
* and not included in the tab.h file
*/
#define ENDFILE 0
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* MAXRESERVED = the number of reserved words */
/* See helper file to explain the change between tiny and c- */
#define MAXRESERVED 6
/* Yacc/Bison generates its own integer values
* for tokens
*/
typedef int TokenType;
extern FILE* source; /* source code text file */
extern FILE* listing; /* listing output text file */
extern FILE* code; /* code text file for TM simulator */
extern int lineno; /* source line number for listing */
/**************************************************/
/*********** Syntax tree for parsing ************/
/**************************************************/
typedef enum { StmtK, ExpK, DeclK, ParamK, TypeK } NodeKind;
typedef enum { CompK, IfK, WhileK, ReturnK } StmtKind;
typedef enum { AssignK, OpK, ConstK, IdK, VectorIdK, CallK } ExpKind;
typedef enum { FuncK, VarK, VectorVarK } DeclKind;
typedef enum { VectorParamK, NonVectorParamK } ParamKind;
typedef enum { TypeNameK } TypeKind;
/* ExpType is used for type checking */
typedef enum { Void, Integer, Boolean, IntegerArray } ExpType;
/* Vector attribute structure */
typedef struct vectorAttr {
TokenType type;
char *name;
int size;
} VectorAttr;
#define MAXCHILDREN 3
struct ScopeRec;
typedef struct treeNode {
struct treeNode *child[MAXCHILDREN];
struct treeNode *sibling;
int lineno;
NodeKind nodekind;
union {
StmtKind stmt;
ExpKind exp;
DeclKind decl;
ParamKind param;
TypeKind type;
} kind;
union {
TokenType op;
TokenType type;
int val;
char *name;
VectorAttr vector;
struct ScopeRec *scope;
} attr;
ExpType type; /* for type checking of exps */
} TreeNode;
/**************************************************/
/*********** Flags for tracing ************/
/**************************************************/
/* EchoSource = TRUE causes the source program to
* be echoed to the listing file with line numbers
* during parsing
*/
extern int EchoSource;
/* TraceScan = TRUE causes token information to be
* printed to the listing file as each token is
* recognized by the scanner
*/
extern int TraceScan;
/* TraceParse = TRUE causes the syntax tree to be
* printed to the listing file in linearized form
* (using indents for children)
*/
extern int TraceParse;
/* TraceAnalyze = TRUE causes symbol table inserts
* and lookups to be reported to the listing file
*/
extern int TraceAnalyze;
/* TraceCode = TRUE causes comments to be written
* to the TM code file as code is generated
*/
extern int TraceCode;
/* Error = TRUE prevents further passes if an error occurs */
extern int Error;
#endif