-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompiler.h
109 lines (97 loc) · 2.06 KB
/
compiler.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
#ifndef COMPILER_H
#define COMPILER_H
#define BUFFER_SIZE 256
#define NOT_FOUND -1
#define CHAR 'c'
#define INT 'i'
#define FLOAT 'f'
#define DOUBLE 'd'
#define STRING 's'
#define CHAR_SZ 1
#define INT_SZ 4
#define FLOAT_SZ 4
#define DOUBLE_SZ 8
#define ASM 10
#define BINARY 11
int type_out;
enum TOKENS {
CHAR_TYPE, // 0
INT_TYPE, // 1
FLOAT_TYPE, // 2
DOUBLE_TYPE, // 3
STRING_TYPE, // 4
IF, // 5
ELSE, // 6
FOR, // 7
WHILE, // 8
PRINT, // 9
READ, //10
LEFT_PAREN, // 11
RIGHT_PAREN, // 12
ADD, // 13
SUB, // 14
MUL, // 15
DIV, // 16
LESS, // 17
LESS_EQUAL, // 18
GREATER, // 19
GREATER_EQUAL,// 20
EQUAL, // 21
NOT_EQUAL, // 22
LEFT_BRACE, // 23
RIGHT_BRACE, // 24
LEFT_BRACKET, // 25
RIGHT_BRACKET,// 26
ASSIGN, // 27
SEMI_COLON, // 28
ENDLINE, // 29
COMMA, // 30
AND, // 30
OR, // 31
NOT, // 32
QUOTE, // 33
NAME, // 34
SYMBOL, // 35
NUMBER, // 36
DECIMAL // 37
};
extern char* str_tokens[];
extern int tokens_size;
void EmitLn(char * str);
void getChar();
int findAddress();
void next();
void nextString();
void init();
void scan();
void matchString();
int isSpecificString(char *s);
void matchString2();
void error(char *s);
void expected(char* s);
int findVariableAddress(char* s);
void insertSymbol(char type, int type_sz, char* name);
int findLabelAddress(char* label);
void insertPendingLabel();
int isAlphaNum(char c);
int isDeclaration(enum TOKENS TOKEN);
int isAssignment(enum TOKENS TOKEN);
int isRelop(enum TOKENS TOKEN);
int getStringSize();
enum TOKENS TOKEN;
char look;
char VALUE[BUFFER_SIZE];
char tmp[BUFFER_SIZE];
char outBuffer[1000];
struct label_row {
char name[BUFFER_SIZE];
int address;
};
extern int DS; // symbol_def
extern int PC;
struct label_row label_table[100];
struct label_row pending_label_table[100];
extern int st_end;
extern int lt_end;
extern int pending_end;
#endif