-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdecl.h
279 lines (222 loc) · 6.4 KB
/
cdecl.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include "bif_lex.h"
#ifdef FOR_OS_DOS
# ifndef FILENAME_MAX
# define FILENAME_MAX 256
# endif
# ifndef FOPEN_MAX
# define FOPEN_MAX 32
# endif
#endif
# ifndef LINT_ARGS
# define LINT_ARGS 1
# endif
/*** Include Files. ***/
#ifndef FILES_INCLUDED
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# ifndef IBM370
# include <malloc.h>
# endif
# include <stdlib.h>
# define FILES_INCLUDED 1
#endif
/*** External definitions. ***/
# ifndef EXTERNAL
# ifdef DEFINE_EXTERNALS
# define EXTERNAL
# else
# define EXTERNAL extern
# endif
# endif
/* define macros. */
# define copyst(x) {strcpy(x,str);}
# define pushstk vstack [vsp++] = nlv
# define clrstk {vsp = 0; nlv = 0;}
# define popstk nlv = vstack [--vsp]
# define write_byte(BYTENUM) fputc ((char) (BYTENUM), fdtmpw)
# define write_bytes(PTR, NUMBYTES) \
fwrite ((void *) (PTR), 1, (NUMBYTES), fdtmpw)
# define write_long(LONGNUM) \
{long TMP; TMP = (long)(LONGNUM); fwrite((void *) &TMP,sizeof(long),1,fdtmpw);}
# define read_byte(X) fread((void *) &(X),1,1,fdtmpr)
# define read_long(X) fread((void *) &(X),sizeof(long),1,fdtmpr)
/* defined constants */
# define ASCIIV 257
# define ID 258
# define NUMBER 259
# define EXTRN 260
# define VAR 261
# define MDIGIT 262
# define COMPSYM 263
# define STRING 264
# define LCBRAK 265
# define FDEF 266
# define SENTS 267
# define ST 268
# define RCS1 269
# define RCS2 270
# define RCS3 271
# define RCS4 272
# define LSF 273
# define RSF 274
# define LSF1 275
# define CONST 276
# define PAR 277
# define RSF1 278
# define ENTRY 279
# define RSF1B 280
/* other '# define's. */
/* number of bytes in a block of memory. (for easy memory allocation). */
# define MEM_BLK_SIZE 512
/* maximum number of variables in a sentence. */
# define MAX_TABLE_LENGTH 512
/* maximum number of sentences per function. */
# define MAX_SENTENCES 200
/* maximum integer 2**31 -1 */
# define MAXINT 2147483647L
/* maximum length allowable for an identifier. */
/* maximum unsigned integer */
# define MAX_INT (2 << (8*(sizeof int) - 1) -1)
# define MAX_UNSIGNED_INT (MAXINT + MAXINT + 1)
#define MAXSTR 200
/* name of the null device. */
# define NULL_DEVICE "NUL"
/* maximum size of a compound symbol. */
# ifndef MAXWS
/*# define MAXWS 32*/
# define MAXWS 1024
# endif
/* various types of links in an expression.
also: NULL = empty expression, STRING = string. */
# define E_VAR 1
# define S_VAR 2
# define T_VAR 3
# define CHAR 4
# define ATOM 5
# define DIGIT 6
# define LPAR 7
# define RPAR 8
# define ACT_LEFT 9
# define ACT_RIGHT 10
/* declarations of global structures and variables. */
struct element {
int type; /* e- s- t- variables, or constants: */
union {
char *f; /* a pointer to a function or atom name or string */
unsigned long n; /* an integer. */
char c; /* character */
int i; /* variable: its number; or right par: index to the pair */
} body;
int number; /* projection number. or left par: index to right. */
};
typedef union {
struct element *chunk;
struct node *tree;
struct functab *func;
char *pchar;
int number;
} branch_t;
EXTERNAL branch_t zero;
struct node {
int nt; /* node type */
branch_t a2, a3, a4;
};
EXTERNAL struct node *Error;
/* parameter for RASL instructions. */
union param {
char c;
char *f;
unsigned long n;
struct { /* two parameters. */
int i1;
int i2;
} d;
int i;
};
struct rasl_instruction {
int code;
union param p;
struct rasl_instruction *next;
};
/* pointer to an array of RASL instructions ... */
EXTERNAL struct rasl_instruction *ftransl;
struct HOLES {
int left;
int right;
int lte;
int rte;
struct HOLES *next;
};
/* table of variables and its length */
struct TABLE {
int index;
int te_offset;
};
EXTERNAL struct TABLE table [MAX_TABLE_LENGTH];
EXTERNAL int table_len;
struct functab {
/*char name[MAXWS];*/ /* name */
char * name;
long offset; /* offset or identificator. */
struct functab *next; /* pointer to the next entry */
};
/* the first of the list of defined labels. It contains
* all functions and auxiliary labels as well.
*/
EXTERNAL struct functab *ft;
/* the first of the list of called functions. */
EXTERNAL struct functab *fc;
/* the first of the list of back-up functions. This list contains only those
* labels, which are actually present in the Refal program.
*/
EXTERNAL struct functab *fb;
EXTERNAL struct functab
*fx, /* the first of the list of external fucntions. */
*fe, /* the first of the list of entry functions. */
*cs; /* the first of the list of compound symbols. */
EXTERNAL long
z, /* Current offset in the code file. */
cscount, /* Count of compound symbols. */
xtcount, /* Count of external functions. */
btcount, /* Count of local functions. */
ntcount; /* Count of entry functions. */
/* built in function table. */
struct locvar {
char vt; /* type */
char vindex[MAXWS]; /* index */
};
EXTERNAL struct locvar lv [128]; /* table of local variables. */
/* Other global variables. */
EXTERNAL int line_no; /* number of the current line. */
EXTERNAL char cbuf [MAXSTR+1]; /* input stream buffer. */
/*EXTERNAL char title [MAXWS];*/ /* title of the output. */
EXTERNAL char title [FILENAME_MAX];
EXTERNAL short sc; /* input stream buffer pointer. */
EXTERNAL char
str [MAXWS + 1], /* location for current comp symbol.*/
strings [MAXSTR + 1], /* location for current string. */
last_fn [MAXWS + 1], /* last function name. */
globsav, /* next input character. */
vtype, /* type of the current variable. */
*block, /* pointer for the current block. */
c_flags [30], /* flags: from command line. (30 - arbitrary number) */
*nonret; /* pointer to nonret memory */
EXTERNAL int
blptr, /* pointer to first free memory location in the block. */
nrptr, /* ptr to nonret memory */
length, /* current length.*/
nerrors, /* number of errors counter */
token, /* current token. */
last_label; /* the number of the first available label number. */
EXTERNAL unsigned long v;
EXTERNAL int
nlv, /* number of local variables. */
vsp, /* pointer to top of vstack */
vstack [256]; /* stack of currently visible number of local variables. */
/* Files: */
EXTERNAL FILE *fdref; /* .REF file */
EXTERNAL FILE *fdlis; /* .LIS file */
EXTERNAL FILE *fdtmpw; /* .TMP write file */
EXTERNAL FILE *fdtmpr; /* .TMP read file */
#include "junk.h"