2
typedef unsigned char byte;
6
#define repeat while(true)
7
#define unless(C) if(!(C))
8
#define until(C) while(!(C))
10
#define MALLOC check_malloc
11
#define FREE check_free
13
#define NEW(type, p) struct type * p = (struct type *) MALLOC(sizeof(struct type))
14
#define NEWVEC(type, p, n) struct type * p = (struct type *) MALLOC(sizeof(struct type) * n)
17
#define SIZE(p) ((int *)(p))[-1]
18
#define CAPACITY(p) ((int *)(p))[-2]
20
extern byte * create_b(int n);
21
extern void report_b(FILE * out, byte * p);
22
extern void lose_b(byte * p);
23
extern byte * increase_capacity(byte * p, int n);
24
extern byte * move_to_b(byte * p, int n, byte * q);
25
extern byte * add_to_b(byte * p, int n, byte * q);
26
extern byte * copy_b(byte * p);
28
extern void sort(void * p, void * p_end, int unit, int (*f)());
57
struct m_pair * m_pairs;
68
extern byte * get_input(byte * p);
69
extern struct tokeniser * create_tokeniser(byte * b);
70
extern int read_token(struct tokeniser * t);
71
extern byte * name_of_token(int code);
72
extern void close_tokeniser(struct tokeniser * t);
88
extern int space_count;
89
extern void * check_malloc(int n);
90
extern void check_free(void * p);
98
int type; /* t_string etc */
99
int mode; /* )_ for routines, externals */
100
struct node * definition; /* ) */
101
int count; /* 0, 1, 2 for each type */
102
struct grouping * grouping; /* for grouping names */
108
struct literalstring {
110
struct literalstring * next;
117
byte * b; /* the string giving the case */
118
int size; /* - and its size */
119
struct node * p; /* the corresponding command */
120
int i; /* the amongvec index of the longest substring of b */
121
int result; /* the numeric result for the case */
128
struct amongvec * b; /* pointer to the amongvec */
129
int number; /* amongs are numbered 0, 1, 2 ... */
130
int literalstring_count; /* in this among */
131
int command_count; /* in this among */
132
struct node * starter; /* i.e. among( (starter) 'string' ... ) */
133
struct node * substring; /* i.e. substring ... among ( ... ) */
138
struct grouping * next;
139
int number; /* groupings are numbered 0, 1, 2 ... */
140
byte * b; /* the characters of this group */
141
int largest_ch; /* character with max code */
142
int smallest_ch; /* character with min code */
143
byte no_gaps; /* no gaps between min and max codes */
144
struct name * name; /* so g->name->grouping == g */
151
struct node * aux; /* used in setlimit */
152
struct among * among; /* used in among */
158
byte * literalstring;
168
t_string = 0, t_boolean = 1, t_integer = 2, t_routine = 3, t_external = 4,
171
/* If this list is extended, adjust wvn in generator.c */
174
/* In name_count[i] below, remember that
187
struct tokeniser * tokeniser;
190
struct literalstring * literalstrings;
192
byte modifyable; /* false inside reverse(...) */
193
struct node * program;
194
struct node * program_end;
195
int name_count[t_size]; /* name_count[i] counts the number of names of type i */
196
struct among * amongs;
197
struct among * amongs_end;
199
struct grouping * groupings;
200
struct grouping * groupings_end;
201
struct node * substring; /* pending 'substring' in current routine definition */
205
enum analyser_modes {
207
m_forward = 0, m_backward /*, m_integer */
211
extern void print_program(struct analyser * a);
212
extern struct analyser * create_analyser(struct tokeniser * t);
213
extern void close_analyser(struct analyser * a);
215
extern void read_program(struct analyser * a);
219
struct analyser * analyser;
220
struct options * options;
224
char * failure_string;
228
char * S[10]; /* strings */
229
int I[10]; /* integers */
230
struct name * V[5]; /* variables */
231
byte * L[5]; /* literals, used in formatted write */
237
/* for the command line: */
243
char * externals_prefix;
244
char * variables_prefix;
248
extern struct generator * create_generator(struct analyser * a, struct options * o);
249
extern void close_generator(struct generator * g);
251
extern void generate_program(struct generator * g);