-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.h
More file actions
89 lines (69 loc) · 1.69 KB
/
globals.h
File metadata and controls
89 lines (69 loc) · 1.69 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
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
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#ifndef YYPARSER
#include "cm.tab.h"
#define ENDFILE 0
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define NO_PARSE FALSE
#define NO_ANALYZE FALSE
#define MAXRESERVED 6
typedef int TokenType;
/*
typedef enum
//book-keeping tokens
{ENDFILE, ERROR, CMERROR,
//reserved words
IF, ELSE, INT, RETURN, VOID, WHILE,
//multicharacter tokens
ID, NUM,
//special symbols
EQ, NE, LE, LT, GE, GT, PLUS, MINUS, TIMES, OVER, ASSIGN, SEMICOLON, COLON,
LPAREN, RPAREN, LSQBRKT, RSQBRKT, LBRACE, RBRACE
} TokenType;
*/
extern FILE *source; //source code text file
extern FILE *listing; //listing output text file(or standard output)
extern int lineno; //source code line number for listing
extern int Error;
//Syntax tree for parsing
typedef struct arrayProp{
char * name;
int size;
} arrayProp;
typedef enum {StmtK,ExpK,DclK,PrmtK,TypeK} NodeKind;
typedef enum {CompK,SelK,IterK,RetK} StmtKind;
typedef enum {AssignK,OpK,ConstK,IdK,ArrIdK,CallK} ExpKind;
typedef enum {FuncK,VarK,ArrK} DclKind;
typedef enum {IntK,VoidK,IntArrK} PrmtKind;
//Used for type checking
typedef enum {Void, Integer, Array} ExpType;
#define MAXCHILDREN 3
typedef struct treeNode{
struct treeNode * child[MAXCHILDREN];
struct treeNode * sibling;
int lineno;
NodeKind nodekind;
union { StmtKind stmt;
ExpKind exp;
DclKind dcl;
PrmtKind prmt;
} kind;
union { TokenType op;
TokenType type;
int val;
char * name;
arrayProp arrProp;
} attr;
ExpType type;
} TreeNode;
#endif