summaryrefslogtreecommitdiff
path: root/src/defs.h.in
blob: 9784f955d22dc5a43b3160a2a123821318c23e9b (plain)
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
/***************************************************************
  DEFS.H

     This file containt common declarations for ZUBR .

     PART OF : ZUBR - Parsers generator for multiple syntax
                      language compilers .

     COMPILE : .

     NOTE    : NONE .

     Copyright (C) 1995 - 2026  by Andrey V.Kosteltsev.
     All Rights Reserved.
 ***************************************************************/
/*
  This file contant RUSSIAN letters( code-page: UTF-8 )
 ***************************************************************/

#ifndef   _DEFS_H
#define   _DEFS_H


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_STDLIB_H
#include <stdlib.h>     /* exit()   */
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_SIGNAL_H
#include <signal.h>     /* signal() */
#endif

#if HAVE_LIBMPU && HAVE_LIBMPUIO
#include <libmpuio.h>
#else
#define __NO_COMPILE 1
#endif

#ifndef ZUBR_VERSION
#define ZUBR_VERSION MPU_UCS2( "@ZUBR_VERSION@" )
#endif
#ifndef ZUBR_BITS_PER_INT
#define ZUBR_BITS_PER_INT @ZUBR_BITS_PER_INT@
#endif

#ifndef NUL
#define NUL 0
#endif


#ifdef __cplusplus
extern "C" {
#endif

#ifndef __NO_COMPILE

/***************************************************************
  Определения PATH_SEPARATOR, DIR_SEPARATOR, IS_DIR_SEPARATOR
 ***************************************************************/
#ifndef PATH_SEPARATOR
#define PATH_SEPARATOR           ':'
#endif

#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR           '/'
#endif

#ifndef IS_DIR_SEPARATOR
#define IS_DIR_SEPARATOR(_c_)   ((_c_) == ('/'))
#endif

#define COMMON_DIR_SEPARATOR  ('/')  /* Доступен в UNIX && Windows NT */

#define MAXCHAR    0xffff     /* maximum UCS-2 character value           */
#define MAXWORD    32767      /* 32767 maximum value of a short int      */
#define MINWORD    (-32768)   /* (-32767-1) minimum value of a short int */
#define MAXTABLE   32500      /* от фонаря < SHRT_MAX */


#undef _NOT_BIT_MACRO
#undef _NON_COMPILE
#if ZUBR_BITS_PER_INT == 64
#define RPOW2          6
/*************************************************************************

    ...                              r[0]
   --|------------------------------------------------------------------|
     | 0000000000000000000000000000000000000000000000000000000000000000 |
   --|------------------------------------------------------------------|
   n: 63                                                               0

*************************************************************************/
#else
#if ZUBR_BITS_PER_INT == 32
#define RPOW2          5
/*************************************************************************

  ...             r[1]                               r[0]
 --|----------------------------------|----------------------------------|
   | 00000000000000000000000000000000 | 00000000000000000000000000000000 |
 --|----------------------------------|----------------------------------|
 n: 63                              32 31                              0

 *************************************************************************/
#else
#if ZUBR_BITS_PER_INT == 16
#define RPOW2          4
/*************************************************************************

            ...      r[1]              r[0]
            --|------------------|------------------|
              | 0000000000000000 | 0000000000000000 |
            --|------------------|------------------|
            n: 31              16 15              0

 *************************************************************************/
#else /* not (ZUBR_BITS_PER_INT == 16) */
#define _NOT_BIT_MACRO 1
#define _NON_COMPILE
#endif /* ZUBR_BITS_PER_INT == 16 */
#endif /* ZUBR_BITS_PER_INT == 32 */
#endif /* ZUBR_BITS_PER_INT == 64 */

#if     !defined( _NOT_BIT_MACRO )
#define SIZE_IN_INT(n) (((n)+(ZUBR_BITS_PER_INT-1))/ZUBR_BITS_PER_INT)
#if defined( BIT ) || defined( SETBIT )
#undef BIT
#undef SETBIT
#endif
#define BIT(r,n)    ((((r)[(n)>>RPOW2])>>((n)&(ZUBR_BITS_PER_INT-1)))&1)
#define SETBIT(r,n) ((r)[(n)>>RPOW2]|=((unsigned)1<<((n)&(ZUBR_BITS_PER_INT-1))))
#endif /* _NOT_BIT_MACRO */



/*******  character names  ***********************************************/
/* определены в configx.h
  #define   NUL            '\0'    -  the null character
  #define   NEWLINE        '\n'    -  line feed
  #define   SP             ' '     -  space
  #define   BS             '\b'    -  backspace
  #define   HT             '\t'    -  horizontal tab
  #define   VT             '\013'  -  vertical tab
  #define   CR             '\r'    -  carriage return
  #define   FF             '\f'    -  form feed
  #define   QUOTE          '\''    -  single quote
  #define   DOUBLE_QUOTE   '\"'    -  double quote
  #define   BACKSLASH      '\\'    -  backslash
 */

/*******  defines for constructing filenames  ****************************/

#define PROC_C_SUFFIX     MPU_UCS2( ".c" )
#define PROC_CPP_SUFFIX   MPU_UCS2( ".cpp" )
#define HEADER_SUFFIX     MPU_UCS2( ".h" )
#define CODE_SUFFIX       MPU_UCS2( "_code" )
#define DEFINES_SUFFIX    MPU_UCS2( "_tab.h" )
#define OUTPUT_SUFFIX     MPU_UCS2( "_tab" )
#define VERBOSE_SUFFIX    MPU_UCS2( ".output" )
#define MAX_SUFFIX_LEN    7 /* strlen( VERBOSE_SUFFIX ) */

/*******  keyword codes  *************************************************/

#define TOKEN    0
#define LEFT     1
#define RIGHT    2
#define NONASSOC 3
#define MARK     4
#define TEXT     5
#define TYPE     6
#define START    7
#define UNION    8
#define IDENT    9


/*******  symbol classes  ************************************************/

#define UNKNOWN   0
#define TERM      1
#define NONTERM   2


/*******  the undefined value  *******************************************/

#define UNDEFINED (-1)


/*******  action codes  **************************************************/

#define SHIFT    1
#define REDUCE   2


/*******  character macros  **********************************************/

#define IS_IDENT(c) (zubr_is_alnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
#define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')

#define NUMERIC_VALUE(c)  ((c) - '0')


/*******  symbol macros  *************************************************/

#define ISTOKEN(s)      ((s) < start_symbol)
#define ISVAR(s)        ((s) >= start_symbol)


/*******  the structure of a symbol table entry  *************************/

typedef struct bucket bucket;
struct bucket
{
  struct bucket  *link;
  struct bucket  *next;
  __mpu_char16_t *name;
  __mpu_char16_t *tag;

  int value;   /* old: short */
  int index;   /* old: short */
  int prec;    /* old: short */

  char class;
  char assoc;
};


/*******  the structure of the LR(0) state machine  **********************/

typedef struct core core;
struct core
{
  struct core *next;
  struct core *link;

  int number;
  int accessing_symbol;
  int nitems;
  int items[1];
};


/*******  the structure used to record shifts  ***************************/

typedef struct shifts shifts;
struct shifts
{
  struct shifts *next;

  int number;
  int nshifts;
  int shift[1];
};


/*******  the structure used to store reductions  ************************/

typedef struct reductions reductions;
struct reductions
{
  struct reductions *next;

  int number;
  int nreds;
  int rules[1];
};


/*******  the structure used to represent parser actions  ****************/

typedef struct action action;
struct action
{
  struct action *next;

  int  symbol;
  int  number;
  int  prec;
  char action_code;
  char assoc;
  char suppressed;
};


/*************************************************************************
  global variables
 *************************************************************************/

/*******  lalr.c  ********************************************************/

extern int         *lookaheads;
extern int         *LAruleno;
extern unsigned    *LA;
extern int         *accessing_symbol;
extern core       **state_table;
extern shifts     **shift_table;
extern reductions **reduction_table;
extern int         *goto_map;
extern int         *from_state;
extern int         *to_state;


/*******  lr0.c  *********************************************************/

extern int         nstates;
extern core       *first_state;
extern shifts     *first_shift;
extern reductions *first_reduction;


/*******  main.c  ********************************************************/

extern char bflag;
extern char p_name_flag;
extern char l_name_flag;
extern char iflag;

extern char dflag;
extern char lflag;
extern char pflag;
extern char rflag;
extern char sflag;
extern char tflag;
extern char vflag;



extern __mpu_char16_t *myname;
extern int             lineno;
extern int             outline;

extern __mpu_char16_t *parse_func_name;
extern __mpu_char16_t *lex_func_name;
extern __mpu_char16_t *inc_token_filename;
extern __mpu_char16_t *name_prefix;
extern __mpu_char16_t *name_prefix_upper;

extern __mpu_char16_t *parse_header_file_name;
extern __mpu_char16_t *action_file_name;
extern __mpu_char16_t *text_file_name;
extern __mpu_char16_t *union_file_name;
extern __mpu_char16_t *input_file_name;
extern __mpu_char16_t *output_file_name;
extern __mpu_char16_t *defines_file_name;
extern __mpu_char16_t *code_file_name;
extern __mpu_char16_t *verbose_file_name;


extern mpu_FILE *parse_header_file;
extern mpu_FILE *action_file;
extern mpu_FILE *text_file;
extern mpu_FILE *union_file;
extern mpu_FILE *input_file;
extern mpu_FILE *output_file;
extern mpu_FILE *defines_file;
extern mpu_FILE *code_file;
extern mpu_FILE *verbose_file;

extern int nitems;
extern int nrules;
extern int nsyms;
extern int ntokens;
extern int nvars;

extern int              start_symbol;
extern __mpu_char16_t **symbol_name;
extern int             *symbol_value;
extern int             *symbol_prec;
extern char            *symbol_assoc;

extern int  *ritem;
extern int  *rlhs;
extern int  *rrhs;
extern int  *rprec;
extern char *rassoc;

extern int  **derives;
extern char  *nullable;


/*******  mkpar.c  *******************************************************/

extern action **parser;
extern int      SRtotal;
extern int      RRtotal;
extern int     *SRconflicts;
extern int     *RRconflicts;
extern int     *defred;
extern int     *rules_used;
extern int      nunused;
extern int      final_state;


/*******  reader.c  ******************************************************/

extern __mpu_char16_t *cptr;
extern __mpu_char16_t *line;
extern int             ntags;
extern char            unionized;
extern __mpu_char16_t  line_format[];


/*******  skeleton.c  ****************************************************/


/*******  symtab.c  ******************************************************/

extern bucket *first_symbol;
extern bucket *last_symbol;


/*************************************************************************
  global functions
 *************************************************************************/

/*******  error.c  *******************************************************/

extern void fatal( __mpu_char16_t *message );
extern void fatal_reorder( __mpu_char16_t *fname );
extern void no_space( void );
extern void bad_fileprefix( __mpu_char16_t *s, int l );
extern void bad_filename( __mpu_char16_t *s, int l );
extern void bad_funcname( __mpu_char16_t *s, int l );
extern void open_error( __mpu_char16_t *filename );
extern void input_error( void );
extern void unexpected_EOF( void );
extern void print_pos( __mpu_char16_t *st_line, __mpu_char16_t *st_cptr );
extern void syntax_error( int st_lineno, __mpu_char16_t *st_line, __mpu_char16_t *st_cptr );
extern void unterminated_comment( int c_lineno, __mpu_char16_t *c_line, __mpu_char16_t *c_cptr );
extern void unterminated_string( int s_lineno, __mpu_char16_t *s_line, __mpu_char16_t *s_cptr );
extern void unterminated_text( int t_lineno, __mpu_char16_t *t_line, __mpu_char16_t *t_cptr ) __attribute__((noreturn));
extern void unterminated_union( int u_lineno, __mpu_char16_t *u_line, __mpu_char16_t *u_cptr );
extern void over_unionized( __mpu_char16_t *u_cptr );
extern void illegal_character( __mpu_char16_t *c_cptr );
extern void used_reserved( __mpu_char16_t *s );
extern void illegal_tag( int t_lineno, __mpu_char16_t *t_line, __mpu_char16_t *t_cptr );
extern void tokenized_start( __mpu_char16_t *s );
extern void terminal_start( __mpu_char16_t *s );
extern void no_grammar( void ) __attribute__((noreturn));
extern void terminal_lhs( int s_lineno );
extern void unterminated_action( int a_lineno, __mpu_char16_t *a_line, __mpu_char16_t *a_cptr ) __attribute__((noreturn));
extern void untyped_lhs( void );
extern void untyped_rhs( int i, __mpu_char16_t *s );
extern void unknown_rhs( int i );
extern void undefined_goal( __mpu_char16_t *s );
extern void dollar_error( int a_lineno, __mpu_char16_t *a_line, __mpu_char16_t *a_cptr );

extern void bad_option( __mpu_char16_t *s ) __attribute__((noreturn));
extern void bad_code_page( __mpu_char16_t *s, __mpu_char16_t *p );


/**********  warnings  **********/
extern void dollar_warning( int a_lineno, int i );
extern void retyped_warning( __mpu_char16_t *s );
extern void reprec_warning( __mpu_char16_t *s );
extern void revalued_warning( __mpu_char16_t *s );
extern void restarted_warning( void );
extern void default_action_warning( void );
extern void undefined_symbol_warning( __mpu_char16_t *s );
extern void prec_redeclared( void );

/*******  closure.c  ****************************************************/

extern void set_first_derives( void );         /*  use in LR0.C  */
extern void closure( int *nucleus, int n );    /*  use in LR0.C  */
extern void finalize_closure( void );          /*  use in LR0.C  */

/*******  lalr.c  ********************************************************/

extern void lalr( void );

/*******  lr0.c  *********************************************************/

extern void lr0( void );
extern void free_nullable( void );
extern void free_derives( void );

/*******  main.c  ********************************************************/

extern void  done( int k ) __attribute__((noreturn));
extern void  onintr( int sig_number );
extern void  set_signals( void );
extern void  usage( void );
extern void  getargs( int argc, __mpu_char16_t *argv[] );
extern char *allocate( unsigned n );
extern void  create_file_names( void );
extern void  open_files( void );

/*******  mkpar.c  *******************************************************/

extern void make_parser( void );
extern void free_parser( void );  /*  use in OUTPUT.C  */

/*******  output.c  ******************************************************/

extern void output( void );

/*******  reader.c  ******************************************************/

extern void reader( void );

/*******  skeleton.c  ****************************************************/

extern void write_parse_name_definition( void );
extern void write_parse_name_declaration( void );

extern void write_banner( void );
extern void write_extern_tables( void );
extern void write_header( void );
extern void write_header_definitions( void );
extern void write_begin_body( void );
extern void write_end_body( void );
extern void write_trailer( void );

/*******  symtab.c  ******************************************************/

extern int      hash( __mpu_char16_t *name );
extern bucket * make_bucket( __mpu_char16_t *name );
extern bucket * lookup( __mpu_char16_t *name );     /*  use in READER.C  */
extern void     create_symbol_table( void ); /*  use in READER.C  */
extern void     free_symbol_table( void );   /*  use in READER.C  */
extern void     free_symbols( void );        /*  use in READER.C  */

/*******  verbose.c  *****************************************************/

extern void verbose( void );

/*******  warshall.c  ****************************************************/

extern void reflexive_transitive_closure( unsigned *R, int n );
                                  /*  use in CLOSURE.C  */

/*******  zubr-port.c  ***************************************************/

extern int             zubr_is_alpha( __mpu_char16_t c );
extern int             zubr_is_alnum( __mpu_char16_t c );
extern int             zubr_is_digit( __mpu_char16_t c );
extern int             zubr_is_upper( __mpu_char16_t c );
extern int             zubr_is_print( __mpu_char16_t c );
extern __mpu_char16_t  zubr_to_lower( __mpu_char16_t c );
extern __mpu_char16_t  zubr_to_upper( __mpu_char16_t c );
extern mpu_FILE       *zubr_fopen( const __mpu_char16_t *filename, const char *mode );
extern int             zubr_unlink( const __mpu_char16_t *filename );
extern __mpu_char16_t *zubr_getenv( const char *name );
extern __mpu_char16_t *zubr_utf8_to_ucs2_dup( const char *s );


/*******  storage allocation macros  *************************************/

#define MALLOC(n)    (malloc((size_t)(n)))
#define CALLOC(k,n)  (calloc((size_t)(k),(size_t)(n)))
#define REALLOC(p,n) (realloc((void *)(p),(size_t)(n)))
#define FREE(x)      (free((void *)(x)))
#define NEW(t)       ((t*)allocate(sizeof(t)))
#define NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))


#endif /* __NO_COMPILE */

#ifdef __cplusplus
}
#endif

#endif /* _DEFS_H */

/*************************  END OF FILE DEFS.H  **************************/