~snowball-yiddish-dev/snowball-yiddish/trunk

« back to all changes in this revision

Viewing changes to website/p/header.h

  • Committer: martinporter
  • Date: 2001-10-19 11:36:36 UTC
  • Revision ID: svn-v4:633ccae0-01f4-0310-8c99-d3591da6f01f:trunk:60
initialĀ upload

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
typedef unsigned char byte;
 
3
 
 
4
#define true 1
 
5
#define false 0
 
6
#define repeat while(true)
 
7
#define unless(C) if(!(C))
 
8
#define until(C) while(!(C))
 
9
 
 
10
#define MALLOC check_malloc
 
11
#define FREE check_free
 
12
 
 
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)
 
15
 
 
16
#define STARTSIZE   10
 
17
#define SIZE(p)     ((int *)(p))[-1]
 
18
#define CAPACITY(p) ((int *)(p))[-2]
 
19
 
 
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);
 
27
 
 
28
extern void sort(void * p, void * p_end, int unit, int (*f)());
 
29
 
 
30
struct m_pair {
 
31
 
 
32
    struct m_pair * next;
 
33
    byte * name;
 
34
    byte * value;
 
35
 
 
36
};
 
37
 
 
38
struct input {
 
39
 
 
40
    struct input * next;
 
41
    byte * p;
 
42
    int c;
 
43
 
 
44
};
 
45
 
 
46
struct tokeniser {
 
47
 
 
48
    struct input * next;
 
49
    byte * p;
 
50
    int c;
 
51
    int line_number;
 
52
    byte * b;
 
53
    byte * b2;
 
54
    int number;
 
55
    int m_start;
 
56
    int m_end;
 
57
    struct m_pair * m_pairs;
 
58
    int get_depth;
 
59
    int error_count;
 
60
    int token;
 
61
    int previous_token;
 
62
    byte token_held;
 
63
 
 
64
    int omission;
 
65
 
 
66
};
 
67
 
 
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);
 
73
 
 
74
enum token_codes {
 
75
 
 
76
#include "syswords2"
 
77
 
 
78
    c_mathassign,
 
79
    c_name,
 
80
    c_number,
 
81
    c_literalstring,
 
82
    c_neg,
 
83
    c_call,
 
84
    c_grouping,
 
85
    c_booltest
 
86
};
 
87
 
 
88
extern int space_count;
 
89
extern void * check_malloc(int n);
 
90
extern void check_free(void * p);
 
91
 
 
92
struct node;
 
93
 
 
94
struct name {
 
95
 
 
96
    struct name * next;
 
97
    byte * b;
 
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 */
 
103
    byte referenced;
 
104
    byte used;
 
105
 
 
106
};
 
107
 
 
108
struct literalstring {
 
109
 
 
110
    struct literalstring * next;
 
111
    byte * b;
 
112
 
 
113
};
 
114
 
 
115
struct amongvec {
 
116
 
 
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 */
 
122
 
 
123
};
 
124
 
 
125
struct among {
 
126
 
 
127
    struct among * next;
 
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 ( ... ) */
 
134
};
 
135
 
 
136
struct grouping {
 
137
 
 
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 */
 
145
};
 
146
 
 
147
struct node {
 
148
 
 
149
    struct node * next;
 
150
    struct node * left;
 
151
    struct node * aux;     /* used in setlimit */
 
152
    struct among * among;  /* used in among */
 
153
    struct node * right;
 
154
    int type;
 
155
    int mode;
 
156
    struct node * AE;
 
157
    struct name * name;
 
158
    byte * literalstring;
 
159
    int number;
 
160
    int line_number;
 
161
 
 
162
};
 
163
 
 
164
enum name_types {
 
165
 
 
166
    t_size = 6,
 
167
 
 
168
    t_string = 0, t_boolean = 1, t_integer = 2, t_routine = 3, t_external = 4,
 
169
    t_grouping = 5
 
170
 
 
171
/*  If this list is extended, adjust wvn in generator.c  */
 
172
};
 
173
 
 
174
/*  In name_count[i] below, remember that
 
175
    type   is
 
176
    ----+----
 
177
      0 |  string
 
178
      1 |  boolean
 
179
      2 |  integer
 
180
      3 |  routine
 
181
      4 |  external
 
182
      5 |  grouping
 
183
*/
 
184
 
 
185
struct analyser {
 
186
 
 
187
    struct tokeniser * tokeniser;
 
188
    struct node * nodes;
 
189
    struct name * names;
 
190
    struct literalstring * literalstrings;
 
191
    int mode;
 
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;
 
198
    int among_count;
 
199
    struct grouping * groupings;
 
200
    struct grouping * groupings_end;
 
201
    struct node * substring;  /* pending 'substring' in current routine definition */
 
202
 
 
203
};
 
204
 
 
205
enum analyser_modes {
 
206
 
 
207
    m_forward = 0, m_backward /*, m_integer */
 
208
 
 
209
};
 
210
 
 
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);
 
214
 
 
215
extern void read_program(struct analyser * a);
 
216
 
 
217
struct generator {
 
218
 
 
219
    struct analyser * analyser;
 
220
    struct options * options;
 
221
    int next_label;
 
222
    FILE * output;
 
223
    int margin;
 
224
    char * failure_string;
 
225
    int failure_label;
 
226
    int debug_count;
 
227
 
 
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 */
 
232
 
 
233
};
 
234
 
 
235
struct options {
 
236
 
 
237
    /* for the command line: */
 
238
 
 
239
    char * output_file;
 
240
    FILE * output_c;
 
241
    FILE * output_h;
 
242
    byte syntax_tree;
 
243
    char * externals_prefix;
 
244
    char * variables_prefix;
 
245
 
 
246
};
 
247
 
 
248
extern struct generator * create_generator(struct analyser * a, struct options * o);
 
249
extern void close_generator(struct generator * g);
 
250
 
 
251
extern void generate_program(struct generator * g);
 
252