-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrb_comp.parser.h
More file actions
249 lines (203 loc) · 4.35 KB
/
rb_comp.parser.h
File metadata and controls
249 lines (203 loc) · 4.35 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
Parser header generated by unicc from rb6.par.
DO NOT EDIT THIS FILE MANUALLY, IT WILL GO AWAY!
*/
#ifndef RB_COMP_PARSER_H
#define RB_COMP_PARSER_H
/* Wide character processing enabled? */
#ifndef UNICC_WCHAR
#define UNICC_WCHAR 0
#endif
/* UTF-8 processing enabled? */
#if !UNICC_WCHAR
#ifndef UNICC_UTF8
# define UNICC_UTF8 1
#endif
#else
# ifdef UNICC_UTF8
# undef UNICC_UTF8
# endif
# define UNICC_UTF8 0
#endif
/* UNICC_CHAR is used as character type for internal processing */
#ifndef UNICC_CHAR
#if UNICC_UTF8 || UNICC_WCHAR
# define UNICC_CHAR wchar_t
# define UNICC_CHAR_FORMAT "%S"
#else
# define UNICC_CHAR char
# define UNICC_CHAR_FORMAT "%s"
#endif
#endif /* UNICC_CHAR */
/* UNICC_SCHAR defines the character type for semantic action procession */
#ifndef UNICC_SCHAR
#if UNICC_WCHAR
# define UNICC_SCHAR wchar_t
# define UNICC_SCHAR_FORMAT "%S"
#else
# define UNICC_SCHAR char
# define UNICC_SCHAR_FORMAT "%s"
#endif
#endif /* UNICC_SCHAR */
/* Boolean */
#ifndef UNICC_BOOLEAN
#define UNICC_BOOLEAN short
#endif
/* Debug level */
#ifndef UNICC_DEBUG
#define UNICC_DEBUG 0
#endif
/* Stack debug switch */
#ifndef UNICC_STACKDEBUG
#define UNICC_STACKDEBUG 0
#endif
/* Parse error macro */
#ifndef UNICC_PARSE_ERROR
#define UNICC_PARSE_ERROR( pcb ) \
fprintf( stderr, "line %d, column %d: syntax error on symbol %d, token '" \
UNICC_SCHAR_FORMAT "'\n", \
( pcb )->line, ( pcb )->column, pcb->sym, rb_lexem( pcb ) )
#endif
/* Input buffering clean-up */
#ifndef UNICC_CLEARIN
#define UNICC_CLEARIN( pcb ) rb_clear_input( pcb )
#endif
/*TODO:*/
#ifndef UNICC_NO_INPUT_BUFFER
#define UNICC_NO_INPUT_BUFFER 0
#endif
/* Memory allocation step size for dynamic stack- and buffer allocation */
#ifndef UNICC_MALLOCSTEP
#define UNICC_MALLOCSTEP 128
#endif
/* Call this when running out of memory during memory allocation */
#ifndef UNICC_OUTOFMEM
#define UNICC_OUTOFMEM( pcb ) fprintf( stderr, \
"Fatal error, ran out of memory\n" ), \
exit( 1 )
#endif
/* Static switch */
#ifndef UNICC_STATIC
#define UNICC_STATIC static
#endif
#ifdef UNICC_PARSER
#undef UNICC_PARSER
#endif
#define UNICC_PARSER "rb" "debug"
/* Don't change next three defines below! */
#ifndef UNICC_ERROR
#define UNICC_ERROR 0
#endif
#ifndef UNICC_REDUCE
#define UNICC_REDUCE 1
#endif
#ifndef UNICC_SHIFT
#define UNICC_SHIFT 2
#endif
#ifndef UNICC_SUCCESS
#define UNICC_SUCCESS 4
#endif
/* Error delay after recovery */
#ifndef UNICC_ERROR_DELAY
#define UNICC_ERROR_DELAY 3
#endif
/* Enable/Disable terminal selection in semantic actions */
#ifndef UNICC_SEMANTIC_TERM_SEL
#define UNICC_SEMANTIC_TERM_SEL 0
#endif
/* Value Types */
typedef union rb_VTYPE
{
REGION value_0;
vm_addr value_1;
symbol* value_2;
plist* value_3;
char* value_4;
char value_5;
VAR_INFO value_6;
VAR_INFO_SYM value_7;
PROC_INFO value_8;
struct param value_9;
long value_10;
SCOPE_INFO value_11;
int value_12;
} rb_vtype;
/* Typedef for symbol information table */
typedef struct
{
char* name;
char* emit;
short type;
UNICC_BOOLEAN lexem;
UNICC_BOOLEAN whitespace;
UNICC_BOOLEAN greedy;
} rb_syminfo;
/* Typedef for production information table */
typedef struct
{
char* definition;
char* emit;
int length;
int lhs;
} rb_prodinfo;
/* Abstract Syntax Tree */
typedef struct rb_AST rb_ast;
struct rb_AST
{
char* emit;
UNICC_SCHAR* token;
rb_ast* parent;
rb_ast* child;
rb_ast* prev;
rb_ast* next;
};
/* Stack Token */
typedef struct
{
rb_vtype value;
rb_ast* node;
rb_syminfo* symbol;
int state;
unsigned int line;
unsigned int column;
} rb_tok;
/* Parser Control Block */
typedef struct
{
/* Is this PCB allocated by parser? */
char is_internal;
/* Stack */
rb_tok* stack;
rb_tok* tos;
/* Stack size */
unsigned int stacksize;
/* Values */
rb_vtype ret;
rb_vtype test;
/* State */
int act;
int idx;
int lhs;
/* Lookahead */
int sym;
int old_sym;
unsigned int len;
/* Input buffering */
UNICC_SCHAR* lexem;
UNICC_CHAR* buf;
UNICC_CHAR* bufend;
UNICC_CHAR* bufsize;
/* Lexical analysis */
UNICC_CHAR next;
UNICC_CHAR eof;
UNICC_BOOLEAN is_eof;
/* Error handling */
int error_delay;
int error_count;
unsigned int line;
unsigned int column;
/* Abstract Syntax Tree */
rb_ast* ast;
/* User-defined components */
} rb_pcb;
#endif /* RB_COMP_PARSER_H */