This is Unofficial EPICS BASE Doxygen Site
defs.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 #include <assert.h>
10 #include <ctype.h>
11 #include <stdio.h>
12 
13 
14 /* machine-dependent definitions */
15 /* the following definitions are for the Tahoe */
16 /* they might have to be changed for other machines */
17 
18 /* MAXCHAR is the largest unsigned character value */
19 /* MAXSHORT is the largest value of a C short */
20 /* MINSHORT is the most negative value of a C short */
21 /* MAXTABLE is the maximum table size */
22 /* BITS_PER_WORD is the number of bits in a C unsigned */
23 /* WORDSIZE computes the number of words needed to */
24 /* store n bits */
25 /* BIT returns the value of the n-th bit starting */
26 /* from r (0-indexed) */
27 /* SETBIT sets the n-th bit starting from r */
28 
29 #define MAXCHAR 255
30 #define MAXSHORT 32767
31 #define MINSHORT -32768
32 #define MAXTABLE 32500
33 #define BITS_PER_WORD 32
34 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
35 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
36 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
37 
38 
39 /* character names */
40 
41 #define NUL '\0' /* the null character */
42 #define NEWLINE '\n' /* line feed */
43 #define SP ' ' /* space */
44 #define BS '\b' /* backspace */
45 #define HT '\t' /* horizontal tab */
46 #define VT '\013' /* vertical tab */
47 #define CR '\r' /* carriage return */
48 #define FF '\f' /* form feed */
49 #define QUOTE '\'' /* single quote */
50 #define DOUBLE_QUOTE '\"' /* double quote */
51 #define BACKSLASH '\\' /* backslash */
52 
53 
54 /* defines for constructing filenames */
55 
56 #define CODE_SUFFIX ".code.c"
57 #define DEFINES_SUFFIX ".tab.h"
58 #define OUTPUT_SUFFIX ".tab.c"
59 #define VERBOSE_SUFFIX ".output"
60 
61 
62 /* keyword codes */
63 
64 #define TOKEN 0
65 #define LEFT 1
66 #define RIGHT 2
67 #define NONASSOC 3
68 #define MARK 4
69 #define TEXT 5
70 #define TYPE 6
71 #define START 7
72 #define UNION 8
73 #define IDENT 9
74 
75 
76 /* symbol classes */
77 
78 #define UNKNOWN 0
79 #define TERM 1
80 #define NONTERM 2
81 
82 
83 /* the undefined value */
84 
85 #define UNDEFINED (-1)
86 
87 
88 /* action codes */
89 
90 #define SHIFT 1
91 #define REDUCE 2
92 
93 
94 /* character macros */
95 
96 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
97 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
98 #define NUMERIC_VALUE(c) ((c) - '0')
99 
100 
101 /* symbol macros */
102 
103 #define ISTOKEN(s) ((s) < start_symbol)
104 #define ISVAR(s) ((s) >= start_symbol)
105 
106 
107 /* storage allocation macros */
108 
109 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
110 #define FREE(x) (free((char*)(x)))
111 #define MALLOC(n) (malloc((unsigned)(n)))
112 #define NEW(t) ((t*)allocate(sizeof(t)))
113 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
114 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
115 
116 
117 /* the structure of a symbol table entry */
118 
119 typedef struct bucket bucket;
120 struct bucket
121 {
122  struct bucket *link;
123  struct bucket *next;
124  char *name;
125  char *tag;
126  short value;
127  short index;
128  short prec;
129  char class;
130  char assoc;
131 };
132 
133 
134 /* the structure of the LR(0) state machine */
135 
136 typedef struct core core;
137 struct core
138 {
139  struct core *next;
140  struct core *link;
141  short number;
143  short nitems;
144  short items[1];
145 };
146 
147 
148 /* the structure used to record shifts */
149 
150 typedef struct shifts shifts;
151 struct shifts
152 {
153  struct shifts *next;
154  short number;
155  short nshifts;
156  short shift[1];
157 };
158 
159 
160 /* the structure used to store reductions */
161 
162 typedef struct reductions reductions;
164 {
165  struct reductions *next;
166  short number;
167  short nreds;
168  short rules[1];
169 };
170 
171 
172 /* the structure used to represent parser actions */
173 
174 typedef struct action action;
175 struct action
176 {
177  struct action *next;
178  short symbol;
179  short number;
180  short prec;
182  char assoc;
184 };
185 
186 
187 /* global variables */
188 
189 extern char dflag;
190 extern char lflag;
191 extern char rflag;
192 extern char tflag;
193 extern char vflag;
194 extern char *symbol_prefix;
195 
196 extern char *myname;
197 extern char *cptr;
198 extern char *line;
199 extern int lineno;
200 extern int outline;
201 
202 extern char *banner[];
203 extern char *tables[];
204 extern char *header[];
205 extern char *body[];
206 extern char *trailer[];
207 
208 extern char *code_file_name;
209 extern char *defines_file_name;
210 extern char *input_file_name;
211 extern char *output_file_name;
212 extern char *verbose_file_name;
213 
214 extern FILE *action_file;
215 extern FILE *code_file;
216 extern FILE *defines_file;
217 extern FILE *input_file;
218 extern FILE *output_file;
219 extern FILE *text_file;
220 extern FILE *union_file;
221 extern FILE *verbose_file;
222 
223 extern int nitems;
224 extern int nrules;
225 extern int nsyms;
226 extern int ntokens;
227 extern int nvars;
228 extern int ntags;
229 
230 extern char unionized;
231 extern char line_format[];
232 
233 extern int start_symbol;
234 extern char **symbol_name;
235 extern short *symbol_value;
236 extern short *symbol_prec;
237 extern char *symbol_assoc;
238 
239 extern short *ritem;
240 extern short *rlhs;
241 extern short *rrhs;
242 extern short *rprec;
243 extern char *rassoc;
244 
245 extern short **derives;
246 extern char *nullable;
247 
248 extern bucket *first_symbol;
249 extern bucket *last_symbol;
250 
251 extern int nstates;
252 extern core *first_state;
253 extern shifts *first_shift;
255 extern short *accessing_symbol;
256 extern core **state_table;
257 extern shifts **shift_table;
258 extern reductions **reduction_table;
259 extern unsigned *LA;
260 extern short *LAruleno;
261 extern short *lookaheads;
262 extern short *goto_map;
263 extern short *from_state;
264 extern short *to_state;
265 
266 extern action **parser;
267 extern int SRtotal;
268 extern int RRtotal;
269 extern short *SRconflicts;
270 extern short *RRconflicts;
271 extern short *defred;
272 extern short *rules_used;
273 extern short nunused;
274 extern short final_state;
275 
276 /*
277  * global functions
278  */
279 
280 #ifdef __GNUC__
281 #define NORETURN __attribute__((noreturn))
282 #else
283 #define NORETURN
284 #endif
285 
286 /* main.c */
287 extern void done(int k) NORETURN;
288 extern char *allocate(unsigned int n);
289 
290 /* error.c */
291 extern void no_space(void) NORETURN;
292 extern void fatal(char *msg) NORETURN;
293 extern void open_error(char *filename) NORETURN;
294 extern void unexpected_EOF(void) NORETURN;
295 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) NORETURN;
296 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) NORETURN;
297 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr) NORETURN;
298 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr) NORETURN;
299 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr) NORETURN;
300 extern void over_unionized(char *u_cptr) NORETURN;
301 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr) NORETURN;
302 extern void illegal_character(char *c_cptr) NORETURN;
303 extern void used_reserved(char *s) NORETURN;
304 extern void tokenized_start(char *s) NORETURN;
305 extern void retyped_warning(char *s);
306 extern void reprec_warning(char *s);
307 extern void revalued_warning(char *s);
308 extern void terminal_start(char *s);
309 extern void restarted_warning(void);
310 extern void no_grammar(void) NORETURN;
311 extern void terminal_lhs(int s_lineno) NORETURN;
312 extern void prec_redeclared(void);
313 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr) NORETURN;
314 extern void dollar_warning(int a_lineno, int i);
315 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr) NORETURN;
316 extern void untyped_lhs(void) NORETURN;
317 extern void untyped_rhs(int i, char *s) NORETURN;
318 extern void unknown_rhs(int i) NORETURN;
319 extern void default_action_warning(void);
320 extern void undefined_goal(char *s) NORETURN;
321 extern void undefined_symbol_warning(char *s);
322 
323 /* symtab.c */
324 extern bucket *make_bucket(char *name);
325 extern bucket *lookup(char *name);
326 extern void create_symbol_table(void);
327 extern void free_symbol_table(void);
328 extern void free_symbols(void);
329 
330 /* closure.c */
331 extern void set_first_derives(void);
332 extern void closure(short int *nucleus, int n);
333 extern void finalize_closure(void);
334 
335 /* reader.c */
336 extern void reader(void);
337 
338 /* lr0.c */
339 extern void lr0(void);
340 
341 /* lalr.c */
342 extern void lalr(void);
343 
344 /* mkpar.c */
345 extern void make_parser(void);
346 extern void free_parser(void);
347 
348 /* warshall.c */
349 extern void reflexive_transitive_closure(unsigned int *R, int n);
350 
351 /* output.c */
352 extern void output(void);
353 extern int default_goto(int symbol);
354 extern int matching_vector(int vector);
355 extern int pack_vector(int vector);
356 
357 /* skeleton.c */
358 extern void write_section(char *section[]);
359 
360 /* verbose.c */
361 extern void verbose(void);
362 
363 /* system includes */
364 
365 #include <stdlib.h>
366 #include <string.h>
367 #include <errno.h>
void retyped_warning(char *s)
Definition: error.c:173
FILE * text_file
Definition: antelope.c:48
void free_parser(void)
Definition: mkpar.c:363
bucket * last_symbol
Definition: symtab.c:20
void fatal(char *msg) NORETURN
Definition: error.c:15
void output(void)
Definition: output.c:51
void unexpected_EOF(void) NORETURN
Definition: error.c:39
char * tag
Definition: defs.h:125
char rflag
Definition: antelope.c:24
short nunused
Definition: mkpar.c:19
short number
Definition: defs.h:179
void illegal_tag(int t_lineno, char *t_line, char *t_cptr) NORETURN
Definition: error.c:135
char * symbol_prefix
Definition: antelope.c:28
char * body[]
Definition: skeleton.c:81
short final_state
Definition: mkpar.c:20
void used_reserved(char *s) NORETURN
Definition: error.c:155
struct reductions * next
Definition: defs.h:165
short * LAruleno
Definition: lalr.c:21
short shift[1]
Definition: defs.h:156
char * verbose_file_name
Definition: antelope.c:40
char dflag
Definition: antelope.c:22
short rules[1]
Definition: defs.h:168
unsigned * LA
Definition: lalr.c:22
void set_first_derives(void)
Definition: closure.c:64
void unknown_rhs(int i) NORETURN
Definition: error.c:286
int i
Definition: scan.c:967
void open_error(char *filename) NORETURN
Definition: error.c:31
char unionized
Definition: reader.c:24
char * input_file_name
Definition: antelope.c:38
Definition: defs.h:175
void lr0(void)
Definition: lr0.c:608
short * accessing_symbol
Definition: lalr.c:23
void over_unionized(char *u_cptr) NORETURN
Definition: error.c:125
void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) NORETURN
Definition: error.c:85
bucket * make_bucket(char *name)
Definition: symtab.c:40
struct core * next
Definition: defs.h:139
Definition: defs.h:151
void no_grammar(void) NORETURN
Definition: error.c:214
short * rlhs
Definition: antelope.c:68
void unterminated_action(int a_lineno, char *a_line, char *a_cptr) NORETURN
Definition: error.c:240
short * lookaheads
Definition: lalr.c:20
char * name
Definition: defs.h:124
void restarted_warning(void)
Definition: error.c:206
void tokenized_start(char *s) NORETURN
Definition: error.c:164
core * first_state
Definition: lr0.c:17
int ntokens
Definition: antelope.c:58
FILE * output_file
Definition: antelope.c:47
char * banner[]
Definition: skeleton.c:19
FILE * defines_file
Definition: antelope.c:45
int pack_vector(int vector)
Definition: output.c:575
int nitems
Definition: antelope.c:55
char vflag
Definition: antelope.c:26
int lineno
Definition: antelope.c:33
char * rassoc
Definition: antelope.c:71
bucket * lookup(char *name)
Definition: symtab.c:66
#define NORETURN
Definition: defs.h:283
char * code_file_name
Definition: antelope.c:36
void undefined_goal(char *s) NORETURN
Definition: error.c:303
int nstates
Definition: lr0.c:16
void illegal_character(char *c_cptr) NORETURN
Definition: error.c:145
short * rules_used
Definition: mkpar.c:18
char tflag
Definition: antelope.c:25
short * SRconflicts
Definition: mkpar.c:15
char * defines_file_name
Definition: antelope.c:37
shifts ** shift_table
Definition: lalr.c:25
void untyped_lhs(void) NORETURN
Definition: error.c:268
short * goto_map
Definition: lalr.c:27
FILE * action_file
Definition: antelope.c:42
char * allocate(unsigned int n)
Definition: antelope.c:230
short * to_state
Definition: lalr.c:29
void write_section(char *section[])
Definition: skeleton.c:284
action ** parser
Definition: mkpar.c:12
short prec
Definition: defs.h:128
void revalued_warning(char *s)
Definition: error.c:189
short * from_state
Definition: lalr.c:28
char * tables[]
Definition: skeleton.c:32
char * cptr
Definition: reader.c:25
char * trailer[]
Definition: skeleton.c:221
void reflexive_transitive_closure(unsigned int *R, int n)
Definition: warshall.c:63
struct shifts * next
Definition: defs.h:153
char action_code
Definition: defs.h:181
bucket * first_symbol
Definition: symtab.c:19
shifts * first_shift
Definition: lr0.c:18
char * header[]
Definition: skeleton.c:51
int RRtotal
Definition: mkpar.c:14
struct bucket * link
Definition: defs.h:122
void prec_redeclared(void)
Definition: error.c:232
short number
Definition: defs.h:166
void terminal_lhs(int s_lineno) NORETURN
Definition: error.c:223
void dollar_error(int a_lineno, char *a_line, char *a_cptr) NORETURN
Definition: error.c:258
int nrules
Definition: antelope.c:56
short * rprec
Definition: antelope.c:70
void closure(short int *nucleus, int n)
Definition: closure.c:120
char * line
Definition: reader.c:25
reductions * first_reduction
Definition: lr0.c:19
short items[1]
Definition: defs.h:144
void free_symbols(void)
Definition: symtab.c:117
short * symbol_prec
Definition: antelope.c:64
short nshifts
Definition: defs.h:155
void done(int k) NORETURN
Definition: antelope.c:77
char * nullable
Definition: antelope.c:73
void finalize_closure(void)
Definition: closure.c:189
struct action * next
Definition: defs.h:177
Definition: defs.h:137
int nvars
Definition: antelope.c:59
short * defred
Definition: mkpar.c:17
short * RRconflicts
Definition: mkpar.c:16
char lflag
Definition: antelope.c:23
short symbol
Definition: defs.h:178
core ** state_table
Definition: lalr.c:24
FILE * verbose_file
Definition: antelope.c:53
void default_action_warning(void)
Definition: error.c:295
void untyped_rhs(int i, char *s) NORETURN
Definition: error.c:277
void make_parser(void)
Definition: mkpar.c:37
int nsyms
Definition: antelope.c:57
short * rrhs
Definition: antelope.c:69
struct core * link
Definition: defs.h:140
short index
Definition: defs.h:127
char * myname
Definition: antelope.c:30
short * ritem
Definition: antelope.c:67
short ** derives
Definition: antelope.c:72
void create_symbol_table(void)
Definition: symtab.c:88
char * symbol_assoc
Definition: antelope.c:65
void reader(void)
Definition: reader.c:1791
char assoc
Definition: defs.h:182
int ntags
Definition: reader.c:21
short nitems
Definition: defs.h:143
struct bucket * next
Definition: defs.h:123
void dollar_warning(int a_lineno, int i)
Definition: error.c:250
void reprec_warning(char *s)
Definition: error.c:181
void verbose(void)
Definition: verbose.c:27
int start_symbol
Definition: antelope.c:61
short nreds
Definition: defs.h:167
void unterminated_string(int s_lineno, char *s_line, char *s_cptr) NORETURN
Definition: error.c:95
short value
Definition: defs.h:126
int default_goto(int symbol)
Definition: output.c:358
FILE * input_file
Definition: antelope.c:46
char line_format[]
Definition: reader.c:42
char ** symbol_name
Definition: antelope.c:62
short prec
Definition: defs.h:180
void free_symbol_table(void)
Definition: symtab.c:109
short accessing_symbol
Definition: defs.h:142
short * symbol_value
Definition: antelope.c:63
FILE * union_file
Definition: antelope.c:50
void no_space(void) NORETURN
Definition: error.c:23
reductions ** reduction_table
Definition: lalr.c:26
void unterminated_union(int u_lineno, char *u_line, char *u_cptr) NORETURN
Definition: error.c:115
int matching_vector(int vector)
Definition: output.c:535
char assoc
Definition: defs.h:130
char * output_file_name
Definition: antelope.c:39
void terminal_start(char *s)
Definition: error.c:197
void undefined_symbol_warning(char *s)
Definition: error.c:311
void syntax_error(int st_lineno, char *st_line, char *st_cptr) NORETURN
Definition: error.c:75
FILE * code_file
Definition: antelope.c:44
void lalr(void)
Definition: lalr.c:60
short number
Definition: defs.h:154
Internal: Hash table structure.
Definition: bucketLib.h:48
void unterminated_text(int t_lineno, char *t_line, char *t_cptr) NORETURN
Definition: error.c:105
int SRtotal
Definition: mkpar.c:13
int outline
Definition: antelope.c:34
short number
Definition: defs.h:141
char suppressed
Definition: defs.h:183