xref: /freebsd/contrib/byacc/defs.h (revision 822ca3276345b4a67ccbc9b54616d8b205fd37f2)
1*822ca327SBaptiste Daroussin /* $Id: defs.h,v 1.74 2023/05/18 21:28:05 tom Exp $ */
298e903e7SBaptiste Daroussin 
398e903e7SBaptiste Daroussin #ifdef HAVE_CONFIG_H
498e903e7SBaptiste Daroussin #include <config.h>
598e903e7SBaptiste Daroussin #endif
698e903e7SBaptiste Daroussin 
70c8de5b0SBaptiste Daroussin #include <limits.h>
898e903e7SBaptiste Daroussin #include <stdlib.h>
998e903e7SBaptiste Daroussin #include <string.h>
1098e903e7SBaptiste Daroussin #include <errno.h>
1198e903e7SBaptiste Daroussin #include <assert.h>
1298e903e7SBaptiste Daroussin #include <ctype.h>
1398e903e7SBaptiste Daroussin #include <stdio.h>
1498e903e7SBaptiste Daroussin 
153e066022SBaptiste Daroussin #if defined(__cplusplus)	/* __cplusplus, etc. */
163e066022SBaptiste Daroussin #define class myClass
173e066022SBaptiste Daroussin #endif
183e066022SBaptiste Daroussin 
198e022d3cSDag-Erling Smørgrav #define YYMAJOR 2
208e022d3cSDag-Erling Smørgrav #define YYMINOR 0
2198e903e7SBaptiste Daroussin 
2298e903e7SBaptiste Daroussin #define CONCAT(first,second)    first #second
2398e903e7SBaptiste Daroussin #define CONCAT1(string,number)  CONCAT(string, number)
2498e903e7SBaptiste Daroussin #define CONCAT2(first,second)   #first "." #second
2598e903e7SBaptiste Daroussin 
2698e903e7SBaptiste Daroussin #ifdef YYPATCH
2798e903e7SBaptiste Daroussin #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
2898e903e7SBaptiste Daroussin #else
2998e903e7SBaptiste Daroussin #define VSTRING(a,b) CONCAT2(a,b)
3098e903e7SBaptiste Daroussin #endif
3198e903e7SBaptiste Daroussin 
3298e903e7SBaptiste Daroussin #define VERSION VSTRING(YYMAJOR, YYMINOR)
3398e903e7SBaptiste Daroussin 
340c8de5b0SBaptiste Daroussin /*  machine-dependent definitions:			*/
3598e903e7SBaptiste Daroussin 
3698e903e7SBaptiste Daroussin /*  MAXCHAR is the largest unsigned character value	*/
3798e903e7SBaptiste Daroussin /*  MAXTABLE is the maximum table size			*/
380c8de5b0SBaptiste Daroussin /*  YYINT is the smallest C integer type that can be	*/
390c8de5b0SBaptiste Daroussin /*	used to address a table of size MAXTABLE	*/
400c8de5b0SBaptiste Daroussin /*  MAXYYINT is the largest value of a YYINT		*/
410c8de5b0SBaptiste Daroussin /*  MINYYINT is the most negative value of a YYINT	*/
4298e903e7SBaptiste Daroussin /*  BITS_PER_WORD is the number of bits in a C unsigned	*/
4398e903e7SBaptiste Daroussin /*  WORDSIZE computes the number of words needed to	*/
4498e903e7SBaptiste Daroussin /*	store n bits					*/
4598e903e7SBaptiste Daroussin /*  BIT returns the value of the n-th bit starting	*/
4698e903e7SBaptiste Daroussin /*	from r (0-indexed)				*/
4798e903e7SBaptiste Daroussin /*  SETBIT sets the n-th bit starting from r		*/
4898e903e7SBaptiste Daroussin 
490c8de5b0SBaptiste Daroussin #define	MAXCHAR		UCHAR_MAX
500c8de5b0SBaptiste Daroussin #ifndef MAXTABLE
518e022d3cSDag-Erling Smørgrav #define MAXTABLE	INT_MAX
520c8de5b0SBaptiste Daroussin #endif
530c8de5b0SBaptiste Daroussin #if MAXTABLE <= SHRT_MAX
540c8de5b0SBaptiste Daroussin #define YYINT		short
550c8de5b0SBaptiste Daroussin #define MAXYYINT	SHRT_MAX
560c8de5b0SBaptiste Daroussin #define MINYYINT	SHRT_MIN
570c8de5b0SBaptiste Daroussin #elif MAXTABLE <= INT_MAX
580c8de5b0SBaptiste Daroussin #define YYINT		int
590c8de5b0SBaptiste Daroussin #define MAXYYINT	INT_MAX
600c8de5b0SBaptiste Daroussin #define MINYYINT	INT_MIN
618e022d3cSDag-Erling Smørgrav #elif MAXTABLE <= LONG_MAX
628e022d3cSDag-Erling Smørgrav #define YYINT		long
638e022d3cSDag-Erling Smørgrav #define MAXYYINT	LONG_MAX
648e022d3cSDag-Erling Smørgrav #define MINYYINT	LONG_MIN
650c8de5b0SBaptiste Daroussin #else
660c8de5b0SBaptiste Daroussin #error "MAXTABLE is too large for this machine architecture!"
670c8de5b0SBaptiste Daroussin #endif
680c8de5b0SBaptiste Daroussin 
690c8de5b0SBaptiste Daroussin #define BITS_PER_WORD	((int) sizeof (unsigned) * CHAR_BIT)
7098e903e7SBaptiste Daroussin #define WORDSIZE(n)	(((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
710c8de5b0SBaptiste Daroussin #define BIT(r, n)	((((r)[(n)/BITS_PER_WORD])>>((n)&(BITS_PER_WORD-1)))&1)
720c8de5b0SBaptiste Daroussin #define SETBIT(r, n)	((r)[(n)/BITS_PER_WORD]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
7398e903e7SBaptiste Daroussin 
7498e903e7SBaptiste Daroussin /*  character names  */
7598e903e7SBaptiste Daroussin 
7698e903e7SBaptiste Daroussin #define	NUL		'\0'	/*  the null character  */
7798e903e7SBaptiste Daroussin #define	NEWLINE		'\n'	/*  line feed  */
7898e903e7SBaptiste Daroussin #define	SP		' '	/*  space  */
7998e903e7SBaptiste Daroussin #define	BS		'\b'	/*  backspace  */
8098e903e7SBaptiste Daroussin #define	HT		'\t'	/*  horizontal tab  */
8198e903e7SBaptiste Daroussin #define	VT		'\013'	/*  vertical tab  */
8298e903e7SBaptiste Daroussin #define	CR		'\r'	/*  carriage return  */
8398e903e7SBaptiste Daroussin #define	FF		'\f'	/*  form feed  */
8498e903e7SBaptiste Daroussin #define	QUOTE		'\''	/*  single quote  */
8598e903e7SBaptiste Daroussin #define	DOUBLE_QUOTE	'\"'	/*  double quote  */
8698e903e7SBaptiste Daroussin #define	BACKSLASH	'\\'	/*  backslash  */
8798e903e7SBaptiste Daroussin 
8898e903e7SBaptiste Daroussin #define UCH(c)          (unsigned char)(c)
8998e903e7SBaptiste Daroussin 
9098e903e7SBaptiste Daroussin /* defines for constructing filenames */
9198e903e7SBaptiste Daroussin 
9298e903e7SBaptiste Daroussin #if defined(VMS)
9398e903e7SBaptiste Daroussin #define CODE_SUFFIX	"_code.c"
9498e903e7SBaptiste Daroussin #define	DEFINES_SUFFIX	"_tab.h"
9598e903e7SBaptiste Daroussin #define	EXTERNS_SUFFIX	"_tab.i"
9698e903e7SBaptiste Daroussin #define	OUTPUT_SUFFIX	"_tab.c"
9798e903e7SBaptiste Daroussin #else
9898e903e7SBaptiste Daroussin #define CODE_SUFFIX	".code.c"
9998e903e7SBaptiste Daroussin #define	DEFINES_SUFFIX	".tab.h"
10098e903e7SBaptiste Daroussin #define	EXTERNS_SUFFIX	".tab.i"
10198e903e7SBaptiste Daroussin #define	OUTPUT_SUFFIX	".tab.c"
10298e903e7SBaptiste Daroussin #endif
10398e903e7SBaptiste Daroussin #define	VERBOSE_SUFFIX	".output"
10498e903e7SBaptiste Daroussin #define GRAPH_SUFFIX    ".dot"
10598e903e7SBaptiste Daroussin 
10698e903e7SBaptiste Daroussin /* keyword codes */
10798e903e7SBaptiste Daroussin 
108b53bb29fSJung-uk Kim typedef enum
109b53bb29fSJung-uk Kim {
110b53bb29fSJung-uk Kim     TOKEN = 0
111b53bb29fSJung-uk Kim     ,LEFT
112b53bb29fSJung-uk Kim     ,RIGHT
113b53bb29fSJung-uk Kim     ,NONASSOC
114b53bb29fSJung-uk Kim     ,MARK
115b53bb29fSJung-uk Kim     ,TEXT
116b53bb29fSJung-uk Kim     ,TYPE
117b53bb29fSJung-uk Kim     ,START
118b53bb29fSJung-uk Kim     ,UNION
119b53bb29fSJung-uk Kim     ,IDENT
1208e022d3cSDag-Erling Smørgrav 
1218e022d3cSDag-Erling Smørgrav     /* trivial bison "extensions" which have POSIX equivalents */
1228e022d3cSDag-Erling Smørgrav     ,NONPOSIX_DEBUG
1238e022d3cSDag-Erling Smørgrav 
1248e022d3cSDag-Erling Smørgrav     /* other bison "extensions", some useful */
125*822ca327SBaptiste Daroussin     ,HACK_DEFINE
1268e022d3cSDag-Erling Smørgrav     ,ERROR_VERBOSE
127b53bb29fSJung-uk Kim     ,EXPECT
128b53bb29fSJung-uk Kim     ,EXPECT_RR
129b53bb29fSJung-uk Kim     ,LEX_PARAM
1308e022d3cSDag-Erling Smørgrav     ,PARSE_PARAM
131b53bb29fSJung-uk Kim     ,POSIX_YACC
1328e022d3cSDag-Erling Smørgrav     ,PURE_PARSER
133b53bb29fSJung-uk Kim     ,TOKEN_TABLE
134b53bb29fSJung-uk Kim     ,XCODE
13598e903e7SBaptiste Daroussin 
1360c8de5b0SBaptiste Daroussin #if defined(YYBTYACC)
137b53bb29fSJung-uk Kim     ,DESTRUCTOR
138b53bb29fSJung-uk Kim     ,INITIAL_ACTION
1398e022d3cSDag-Erling Smørgrav     ,LOCATIONS
1400c8de5b0SBaptiste Daroussin #endif
141b53bb29fSJung-uk Kim }
142b53bb29fSJung-uk Kim KEY_CASES;
1430c8de5b0SBaptiste Daroussin 
14498e903e7SBaptiste Daroussin /*  symbol classes  */
14598e903e7SBaptiste Daroussin 
146b53bb29fSJung-uk Kim typedef enum
147b53bb29fSJung-uk Kim {
148b53bb29fSJung-uk Kim     UNKNOWN = 0
149b53bb29fSJung-uk Kim     ,TERM
150b53bb29fSJung-uk Kim     ,NONTERM
151b53bb29fSJung-uk Kim     ,ACTION
152b53bb29fSJung-uk Kim     ,ARGUMENT
153b53bb29fSJung-uk Kim }
154b53bb29fSJung-uk Kim SYM_CASES;
15598e903e7SBaptiste Daroussin 
15698e903e7SBaptiste Daroussin /*  the undefined value  */
15798e903e7SBaptiste Daroussin 
15898e903e7SBaptiste Daroussin #define UNDEFINED (-1)
15998e903e7SBaptiste Daroussin 
16098e903e7SBaptiste Daroussin /*  action codes  */
16198e903e7SBaptiste Daroussin 
16298e903e7SBaptiste Daroussin #define SHIFT 1
16398e903e7SBaptiste Daroussin #define REDUCE 2
16498e903e7SBaptiste Daroussin 
16598e903e7SBaptiste Daroussin /*  character macros  */
16698e903e7SBaptiste Daroussin 
167b53bb29fSJung-uk Kim #define IS_NAME1(c)	(isalpha(UCH(c)) || (c) == '_' || (c) == '$')
168b53bb29fSJung-uk Kim #define IS_NAME2(c)	(isalnum(UCH(c)) || (c) == '_' || (c) == '$')
169b53bb29fSJung-uk Kim #define IS_IDENT(c)	(isalnum(UCH(c)) || (c) == '_' || (c) == '.' || (c) == '$')
17098e903e7SBaptiste Daroussin #define	IS_OCTAL(c)	((c) >= '0' && (c) <= '7')
17198e903e7SBaptiste Daroussin 
17298e903e7SBaptiste Daroussin /*  symbol macros  */
17398e903e7SBaptiste Daroussin 
17498e903e7SBaptiste Daroussin #define ISTOKEN(s)	((s) < start_symbol)
17598e903e7SBaptiste Daroussin #define ISVAR(s)	((s) >= start_symbol)
17698e903e7SBaptiste Daroussin 
17798e903e7SBaptiste Daroussin /*  storage allocation macros  */
17898e903e7SBaptiste Daroussin 
17998e903e7SBaptiste Daroussin #define CALLOC(k,n)	(calloc((size_t)(k),(size_t)(n)))
18098e903e7SBaptiste Daroussin #define	FREE(x)		(free((char*)(x)))
18198e903e7SBaptiste Daroussin #define MALLOC(n)	(malloc((size_t)(n)))
182ab7bf3d4SCraig Rodrigues #define TCMALLOC(t,n)	((t*) calloc((size_t)(n), sizeof(t)))
1833e066022SBaptiste Daroussin #define TMALLOC(t,n)	((t*) malloc((size_t)(n) * sizeof(t)))
18498e903e7SBaptiste Daroussin #define	NEW(t)		((t*)allocate(sizeof(t)))
18598e903e7SBaptiste Daroussin #define	NEW2(n,t)	((t*)allocate(((size_t)(n)*sizeof(t))))
18698e903e7SBaptiste Daroussin #define REALLOC(p,n)	(realloc((char*)(p),(size_t)(n)))
1873e066022SBaptiste Daroussin #define TREALLOC(t,p,n)	((t*)realloc((char*)(p), (size_t)(n) * sizeof(t)))
18898e903e7SBaptiste Daroussin 
18998e903e7SBaptiste Daroussin #define DO_FREE(x)	if (x) { FREE(x); x = 0; }
19098e903e7SBaptiste Daroussin 
191*822ca327SBaptiste Daroussin #define NO_SPACE(p)	do { if (p == 0) on_error(); assert(p != 0); } while (0)
19298e903e7SBaptiste Daroussin 
19398e903e7SBaptiste Daroussin /* messages */
19498e903e7SBaptiste Daroussin #define PLURAL(n) ((n) > 1 ? "s" : "")
19598e903e7SBaptiste Daroussin 
1960c8de5b0SBaptiste Daroussin /*
1970c8de5b0SBaptiste Daroussin  * Features which depend indirectly on the btyacc configuration, but are not
1980c8de5b0SBaptiste Daroussin  * essential.
1990c8de5b0SBaptiste Daroussin  */
2000c8de5b0SBaptiste Daroussin #if defined(YYBTYACC)
2010c8de5b0SBaptiste Daroussin #define USE_HEADER_GUARDS 1
2020c8de5b0SBaptiste Daroussin #else
2030c8de5b0SBaptiste Daroussin #define USE_HEADER_GUARDS 0
2040c8de5b0SBaptiste Daroussin #endif
2050c8de5b0SBaptiste Daroussin 
20698e903e7SBaptiste Daroussin typedef char Assoc_t;
20798e903e7SBaptiste Daroussin typedef char Class_t;
2080c8de5b0SBaptiste Daroussin typedef YYINT Index_t;
2090c8de5b0SBaptiste Daroussin typedef YYINT Value_t;
21098e903e7SBaptiste Daroussin 
21198e903e7SBaptiste Daroussin /*  the structure of a symbol table entry  */
21298e903e7SBaptiste Daroussin 
21398e903e7SBaptiste Daroussin typedef struct bucket bucket;
21498e903e7SBaptiste Daroussin struct bucket
21598e903e7SBaptiste Daroussin {
21698e903e7SBaptiste Daroussin     struct bucket *link;
21798e903e7SBaptiste Daroussin     struct bucket *next;
21898e903e7SBaptiste Daroussin     char *name;
21998e903e7SBaptiste Daroussin     char *tag;
2200c8de5b0SBaptiste Daroussin #if defined(YYBTYACC)
2210c8de5b0SBaptiste Daroussin     char **argnames;
2220c8de5b0SBaptiste Daroussin     char **argtags;
2230c8de5b0SBaptiste Daroussin     int args;
2240c8de5b0SBaptiste Daroussin     char *destructor;
2250c8de5b0SBaptiste Daroussin #endif
22698e903e7SBaptiste Daroussin     Value_t value;
22798e903e7SBaptiste Daroussin     Index_t index;
22898e903e7SBaptiste Daroussin     Value_t prec;
22998e903e7SBaptiste Daroussin     Class_t class;
23098e903e7SBaptiste Daroussin     Assoc_t assoc;
23198e903e7SBaptiste Daroussin };
23298e903e7SBaptiste Daroussin 
23398e903e7SBaptiste Daroussin /*  the structure of the LR(0) state machine  */
23498e903e7SBaptiste Daroussin 
23598e903e7SBaptiste Daroussin typedef struct core core;
23698e903e7SBaptiste Daroussin struct core
23798e903e7SBaptiste Daroussin {
23898e903e7SBaptiste Daroussin     struct core *next;
23998e903e7SBaptiste Daroussin     struct core *link;
24098e903e7SBaptiste Daroussin     Value_t number;
24198e903e7SBaptiste Daroussin     Value_t accessing_symbol;
24298e903e7SBaptiste Daroussin     Value_t nitems;
24398e903e7SBaptiste Daroussin     Value_t items[1];
24498e903e7SBaptiste Daroussin };
24598e903e7SBaptiste Daroussin 
24698e903e7SBaptiste Daroussin /*  the structure used to record shifts  */
24798e903e7SBaptiste Daroussin 
24898e903e7SBaptiste Daroussin typedef struct shifts shifts;
24998e903e7SBaptiste Daroussin struct shifts
25098e903e7SBaptiste Daroussin {
25198e903e7SBaptiste Daroussin     struct shifts *next;
25298e903e7SBaptiste Daroussin     Value_t number;
25398e903e7SBaptiste Daroussin     Value_t nshifts;
25498e903e7SBaptiste Daroussin     Value_t shift[1];
25598e903e7SBaptiste Daroussin };
25698e903e7SBaptiste Daroussin 
25798e903e7SBaptiste Daroussin /*  the structure used to store reductions  */
25898e903e7SBaptiste Daroussin 
25998e903e7SBaptiste Daroussin typedef struct reductions reductions;
26098e903e7SBaptiste Daroussin struct reductions
26198e903e7SBaptiste Daroussin {
26298e903e7SBaptiste Daroussin     struct reductions *next;
26398e903e7SBaptiste Daroussin     Value_t number;
26498e903e7SBaptiste Daroussin     Value_t nreds;
26598e903e7SBaptiste Daroussin     Value_t rules[1];
26698e903e7SBaptiste Daroussin };
26798e903e7SBaptiste Daroussin 
26898e903e7SBaptiste Daroussin /*  the structure used to represent parser actions  */
26998e903e7SBaptiste Daroussin 
27098e903e7SBaptiste Daroussin typedef struct action action;
27198e903e7SBaptiste Daroussin struct action
27298e903e7SBaptiste Daroussin {
27398e903e7SBaptiste Daroussin     struct action *next;
27498e903e7SBaptiste Daroussin     Value_t symbol;
27598e903e7SBaptiste Daroussin     Value_t number;
27698e903e7SBaptiste Daroussin     Value_t prec;
27798e903e7SBaptiste Daroussin     char action_code;
27898e903e7SBaptiste Daroussin     Assoc_t assoc;
27998e903e7SBaptiste Daroussin     char suppressed;
28098e903e7SBaptiste Daroussin };
28198e903e7SBaptiste Daroussin 
28298e903e7SBaptiste Daroussin /*  the structure used to store parse/lex parameters  */
28398e903e7SBaptiste Daroussin typedef struct param param;
28498e903e7SBaptiste Daroussin struct param
28598e903e7SBaptiste Daroussin {
28698e903e7SBaptiste Daroussin     struct param *next;
28798e903e7SBaptiste Daroussin     char *name;		/* parameter name */
28898e903e7SBaptiste Daroussin     char *type;		/* everything before parameter name */
28998e903e7SBaptiste Daroussin     char *type2;	/* everything after parameter name */
29098e903e7SBaptiste Daroussin };
29198e903e7SBaptiste Daroussin 
29298e903e7SBaptiste Daroussin /* global variables */
29398e903e7SBaptiste Daroussin 
294b53bb29fSJung-uk Kim extern char dflag2;
29598e903e7SBaptiste Daroussin extern char dflag;
29698e903e7SBaptiste Daroussin extern char gflag;
29798e903e7SBaptiste Daroussin extern char iflag;
29898e903e7SBaptiste Daroussin extern char lflag;
29998e903e7SBaptiste Daroussin extern char rflag;
30098e903e7SBaptiste Daroussin extern char sflag;
30198e903e7SBaptiste Daroussin extern char tflag;
30298e903e7SBaptiste Daroussin extern char vflag;
30398e903e7SBaptiste Daroussin extern const char *symbol_prefix;
30498e903e7SBaptiste Daroussin 
30598e903e7SBaptiste Daroussin extern const char *myname;
30698e903e7SBaptiste Daroussin extern char *cptr;
30798e903e7SBaptiste Daroussin extern char *line;
30898e903e7SBaptiste Daroussin extern int lineno;
30998e903e7SBaptiste Daroussin extern int outline;
31098e903e7SBaptiste Daroussin extern int exit_code;
3113e066022SBaptiste Daroussin extern int pure_parser;
3124b4a8fcaSBaptiste Daroussin extern int token_table;
3132aca18c7SJung-uk Kim extern int error_verbose;
3140c8de5b0SBaptiste Daroussin #if defined(YYBTYACC)
3150c8de5b0SBaptiste Daroussin extern int locations;
3160c8de5b0SBaptiste Daroussin extern int backtrack;
3170c8de5b0SBaptiste Daroussin extern int destructor;
3182aca18c7SJung-uk Kim extern char *initial_action;
3190c8de5b0SBaptiste Daroussin #endif
32098e903e7SBaptiste Daroussin 
32198e903e7SBaptiste Daroussin extern const char *const banner[];
32298e903e7SBaptiste Daroussin extern const char *const xdecls[];
32398e903e7SBaptiste Daroussin extern const char *const tables[];
32498e903e7SBaptiste Daroussin extern const char *const global_vars[];
32598e903e7SBaptiste Daroussin extern const char *const impure_vars[];
32698e903e7SBaptiste Daroussin extern const char *const hdr_defs[];
32798e903e7SBaptiste Daroussin extern const char *const hdr_vars[];
32898e903e7SBaptiste Daroussin extern const char *const body_1[];
32998e903e7SBaptiste Daroussin extern const char *const body_vars[];
3306166fdceSJung-uk Kim extern const char *const init_vars[];
33198e903e7SBaptiste Daroussin extern const char *const body_2[];
3322aca18c7SJung-uk Kim extern const char *const body_3[];
33398e903e7SBaptiste Daroussin extern const char *const trailer[];
33498e903e7SBaptiste Daroussin 
33598e903e7SBaptiste Daroussin extern char *code_file_name;
33698e903e7SBaptiste Daroussin extern char *input_file_name;
3373e794565SJung-uk Kim extern size_t input_file_name_len;
33898e903e7SBaptiste Daroussin extern char *defines_file_name;
33998e903e7SBaptiste Daroussin extern char *externs_file_name;
34098e903e7SBaptiste Daroussin 
34198e903e7SBaptiste Daroussin extern FILE *action_file;
34298e903e7SBaptiste Daroussin extern FILE *code_file;
34398e903e7SBaptiste Daroussin extern FILE *defines_file;
34498e903e7SBaptiste Daroussin extern FILE *externs_file;
34598e903e7SBaptiste Daroussin extern FILE *input_file;
34698e903e7SBaptiste Daroussin extern FILE *output_file;
34798e903e7SBaptiste Daroussin extern FILE *text_file;
34898e903e7SBaptiste Daroussin extern FILE *union_file;
34998e903e7SBaptiste Daroussin extern FILE *verbose_file;
35098e903e7SBaptiste Daroussin extern FILE *graph_file;
35198e903e7SBaptiste Daroussin 
3520c8de5b0SBaptiste Daroussin extern Value_t nitems;
3530c8de5b0SBaptiste Daroussin extern Value_t nrules;
3540c8de5b0SBaptiste Daroussin extern Value_t nsyms;
3550c8de5b0SBaptiste Daroussin extern Value_t ntokens;
3560c8de5b0SBaptiste Daroussin extern Value_t nvars;
35798e903e7SBaptiste Daroussin extern int ntags;
35898e903e7SBaptiste Daroussin 
35998e903e7SBaptiste Daroussin extern char unionized;
36098e903e7SBaptiste Daroussin extern char line_format[];
36198e903e7SBaptiste Daroussin 
3628e022d3cSDag-Erling Smørgrav #define fprintf_lineno(f, n, s) \
3638e022d3cSDag-Erling Smørgrav 	    if (!lflag) \
3648e022d3cSDag-Erling Smørgrav 		fprintf(f, line_format, (n), (s) ? (s) : "(null)")
3658e022d3cSDag-Erling Smørgrav 
36698e903e7SBaptiste Daroussin extern Value_t start_symbol;
36798e903e7SBaptiste Daroussin extern char **symbol_name;
36898e903e7SBaptiste Daroussin extern char **symbol_pname;
36998e903e7SBaptiste Daroussin extern Value_t *symbol_value;
37098e903e7SBaptiste Daroussin extern Value_t *symbol_prec;
37198e903e7SBaptiste Daroussin extern char *symbol_assoc;
37298e903e7SBaptiste Daroussin 
3730c8de5b0SBaptiste Daroussin #if defined(YYBTYACC)
3740c8de5b0SBaptiste Daroussin extern Value_t *symbol_pval;
3750c8de5b0SBaptiste Daroussin extern char **symbol_destructor;
3760c8de5b0SBaptiste Daroussin extern char **symbol_type_tag;
3770c8de5b0SBaptiste Daroussin #endif
3780c8de5b0SBaptiste Daroussin 
37998e903e7SBaptiste Daroussin extern Value_t *ritem;
38098e903e7SBaptiste Daroussin extern Value_t *rlhs;
38198e903e7SBaptiste Daroussin extern Value_t *rrhs;
38298e903e7SBaptiste Daroussin extern Value_t *rprec;
38398e903e7SBaptiste Daroussin extern Assoc_t *rassoc;
38498e903e7SBaptiste Daroussin 
38598e903e7SBaptiste Daroussin extern Value_t **derives;
38698e903e7SBaptiste Daroussin extern char *nullable;
38798e903e7SBaptiste Daroussin 
38898e903e7SBaptiste Daroussin extern bucket *first_symbol;
38998e903e7SBaptiste Daroussin extern bucket *last_symbol;
39098e903e7SBaptiste Daroussin 
3918e022d3cSDag-Erling Smørgrav extern Value_t nstates;
39298e903e7SBaptiste Daroussin extern core *first_state;
39398e903e7SBaptiste Daroussin extern shifts *first_shift;
39498e903e7SBaptiste Daroussin extern reductions *first_reduction;
39598e903e7SBaptiste Daroussin extern Value_t *accessing_symbol;
39698e903e7SBaptiste Daroussin extern core **state_table;
39798e903e7SBaptiste Daroussin extern shifts **shift_table;
39898e903e7SBaptiste Daroussin extern reductions **reduction_table;
39998e903e7SBaptiste Daroussin extern unsigned *LA;
40098e903e7SBaptiste Daroussin extern Value_t *LAruleno;
40198e903e7SBaptiste Daroussin extern Value_t *lookaheads;
40211fce282SBaptiste Daroussin extern Value_t *goto_base;
40398e903e7SBaptiste Daroussin extern Value_t *goto_map;
40498e903e7SBaptiste Daroussin extern Value_t *from_state;
40598e903e7SBaptiste Daroussin extern Value_t *to_state;
40698e903e7SBaptiste Daroussin 
40798e903e7SBaptiste Daroussin extern action **parser;
40898e903e7SBaptiste Daroussin extern int SRexpect;
40998e903e7SBaptiste Daroussin extern int RRexpect;
41098e903e7SBaptiste Daroussin extern int SRtotal;
41198e903e7SBaptiste Daroussin extern int RRtotal;
41298e903e7SBaptiste Daroussin extern Value_t *SRconflicts;
41398e903e7SBaptiste Daroussin extern Value_t *RRconflicts;
41498e903e7SBaptiste Daroussin extern Value_t *defred;
41598e903e7SBaptiste Daroussin extern Value_t *rules_used;
41698e903e7SBaptiste Daroussin extern Value_t nunused;
41798e903e7SBaptiste Daroussin extern Value_t final_state;
41898e903e7SBaptiste Daroussin 
41998e903e7SBaptiste Daroussin extern Value_t *itemset;
42098e903e7SBaptiste Daroussin extern Value_t *itemsetend;
42198e903e7SBaptiste Daroussin extern unsigned *ruleset;
42298e903e7SBaptiste Daroussin 
42398e903e7SBaptiste Daroussin extern param *lex_param;
42498e903e7SBaptiste Daroussin extern param *parse_param;
42598e903e7SBaptiste Daroussin 
42698e903e7SBaptiste Daroussin /* global functions */
42798e903e7SBaptiste Daroussin 
4288e022d3cSDag-Erling Smørgrav #ifdef HAVE_STDNORETURN_H
4298e022d3cSDag-Erling Smørgrav #undef GCC_NORETURN
4308e022d3cSDag-Erling Smørgrav #include <stdnoreturn.h>
4318e022d3cSDag-Erling Smørgrav #define GCC_NORETURN _Noreturn
4328e022d3cSDag-Erling Smørgrav #endif
4338e022d3cSDag-Erling Smørgrav 
43498e903e7SBaptiste Daroussin #ifndef GCC_NORETURN
4358e022d3cSDag-Erling Smørgrav #if defined(_MSC_VER)
4368e022d3cSDag-Erling Smørgrav #define GCC_NORETURN		__declspec(noreturn)
4373e066022SBaptiste Daroussin #else
43898e903e7SBaptiste Daroussin #define GCC_NORETURN		/* nothing */
43998e903e7SBaptiste Daroussin #endif
4403e066022SBaptiste Daroussin #endif
44198e903e7SBaptiste Daroussin 
442b53bb29fSJung-uk Kim #if defined(NDEBUG) && defined(_MSC_VER)
443b53bb29fSJung-uk Kim #define NODEFAULT   __assume(0);
444b53bb29fSJung-uk Kim #else
445b53bb29fSJung-uk Kim #define NODEFAULT
446b53bb29fSJung-uk Kim #endif
447b53bb29fSJung-uk Kim #define NOTREACHED	NODEFAULT
448b53bb29fSJung-uk Kim 
44998e903e7SBaptiste Daroussin #ifndef GCC_UNUSED
4503e066022SBaptiste Daroussin #if defined(__unused)
4513e066022SBaptiste Daroussin #define GCC_UNUSED		__unused
4523e066022SBaptiste Daroussin #else
45398e903e7SBaptiste Daroussin #define GCC_UNUSED		/* nothing */
45498e903e7SBaptiste Daroussin #endif
4553e066022SBaptiste Daroussin #endif
45698e903e7SBaptiste Daroussin 
457497dcf4cSBaptiste Daroussin #ifndef GCC_PRINTFLIKE
458497dcf4cSBaptiste Daroussin #define GCC_PRINTFLIKE(fmt,var)	/*nothing */
459497dcf4cSBaptiste Daroussin #endif
460497dcf4cSBaptiste Daroussin 
46198e903e7SBaptiste Daroussin /* closure.c */
46298e903e7SBaptiste Daroussin extern void closure(Value_t *nucleus, int n);
46398e903e7SBaptiste Daroussin extern void finalize_closure(void);
46498e903e7SBaptiste Daroussin extern void set_first_derives(void);
46598e903e7SBaptiste Daroussin 
46698e903e7SBaptiste Daroussin /* error.c */
4672aca18c7SJung-uk Kim struct ainfo
4682aca18c7SJung-uk Kim {
4692aca18c7SJung-uk Kim     int a_lineno;
4702aca18c7SJung-uk Kim     char *a_line;
4712aca18c7SJung-uk Kim     char *a_cptr;
4722aca18c7SJung-uk Kim };
4732aca18c7SJung-uk Kim 
474*822ca327SBaptiste Daroussin extern void arg_number_disagree_warning(int a_lineno, const char *a_name);
475*822ca327SBaptiste Daroussin extern void arg_type_disagree_warning(int a_lineno, int i, const char *a_name);
476*822ca327SBaptiste Daroussin extern GCC_NORETURN void at_error(int a_lineno, const char *a_line, const char *a_cptr);
4770c8de5b0SBaptiste Daroussin extern void at_warning(int a_lineno, int i);
4788e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void bad_formals(void);
479*822ca327SBaptiste Daroussin extern void default_action_warning(const char *s);
4802aca18c7SJung-uk Kim extern void destructor_redeclared_warning(const struct ainfo *);
481*822ca327SBaptiste Daroussin extern void dislocations_warning(void);
482*822ca327SBaptiste Daroussin extern GCC_NORETURN void dollar_error(int a_lineno, const char *a_line, const char *a_cptr);
48398e903e7SBaptiste Daroussin extern void dollar_warning(int a_lineno, int i);
4848e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void fatal(const char *msg);
485*822ca327SBaptiste Daroussin extern GCC_NORETURN void illegal_character(const char *c_cptr);
486*822ca327SBaptiste Daroussin extern GCC_NORETURN void illegal_tag(int t_lineno, const char *t_line, const char *t_cptr);
4878e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void missing_brace(void);
4888e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void no_grammar(void);
489*822ca327SBaptiste Daroussin extern GCC_NORETURN void on_error(void);
4908e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void open_error(const char *filename);
491*822ca327SBaptiste Daroussin extern GCC_NORETURN void over_unionized(const char *u_cptr);
49298e903e7SBaptiste Daroussin extern void prec_redeclared(void);
493*822ca327SBaptiste Daroussin extern void reprec_warning(const char *s);
49498e903e7SBaptiste Daroussin extern void restarted_warning(void);
495*822ca327SBaptiste Daroussin extern void retyped_warning(const char *s);
496*822ca327SBaptiste Daroussin extern void revalued_warning(const char *s);
497*822ca327SBaptiste Daroussin extern void start_requires_args(const char *a_name);
498*822ca327SBaptiste Daroussin extern GCC_NORETURN void syntax_error(int st_lineno, const char *st_line, const char *st_cptr);
4998e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void terminal_lhs(int s_lineno);
500*822ca327SBaptiste Daroussin extern GCC_NORETURN void terminal_start(const char *s);
501*822ca327SBaptiste Daroussin extern GCC_NORETURN void tokenized_start(const char *s);
502*822ca327SBaptiste Daroussin extern GCC_NORETURN void undefined_goal(const char *s);
503*822ca327SBaptiste Daroussin extern void undefined_symbol_warning(const char *s);
5048e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unexpected_EOF(void);
505*822ca327SBaptiste Daroussin extern void unknown_arg_warning(int d_lineno,
506*822ca327SBaptiste Daroussin 				const char *dlr_opt,
507*822ca327SBaptiste Daroussin 				const char *d_arg,
508*822ca327SBaptiste Daroussin 				const char *d_line,
509b53bb29fSJung-uk Kim 				const char *d_cptr);
5108e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unknown_rhs(int i);
5110c8de5b0SBaptiste Daroussin extern void unsupported_flag_warning(const char *flag, const char *details);
512*822ca327SBaptiste Daroussin extern GCC_NORETURN void unexpected_value(const struct ainfo *);
5138e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unterminated_action(const struct ainfo *);
5148e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unterminated_comment(const struct ainfo *);
5158e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unterminated_string(const struct ainfo *);
5168e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unterminated_text(const struct ainfo *);
5178e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unterminated_union(const struct ainfo *);
5180c8de5b0SBaptiste Daroussin extern void untyped_arg_warning(int a_lineno, const char *dlr_opt, const char *a_name);
5198e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void untyped_lhs(void);
520*822ca327SBaptiste Daroussin extern GCC_NORETURN void untyped_rhs(int i, const char *s);
521*822ca327SBaptiste Daroussin extern GCC_NORETURN void used_reserved(const char *s);
5228e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void unterminated_arglist(const struct ainfo *);
5230c8de5b0SBaptiste Daroussin extern void wrong_number_args_warning(const char *which, const char *a_name);
524*822ca327SBaptiste Daroussin extern void wrong_type_for_arg_warning(int i, const char *a_name);
52598e903e7SBaptiste Daroussin 
52698e903e7SBaptiste Daroussin /* graph.c */
52798e903e7SBaptiste Daroussin extern void graph(void);
52898e903e7SBaptiste Daroussin 
52998e903e7SBaptiste Daroussin /* lalr.c */
53098e903e7SBaptiste Daroussin extern void lalr(void);
53198e903e7SBaptiste Daroussin 
53298e903e7SBaptiste Daroussin /* lr0.c */
53398e903e7SBaptiste Daroussin extern void lr0(void);
53498e903e7SBaptiste Daroussin extern void show_cores(void);
53598e903e7SBaptiste Daroussin extern void show_ritems(void);
53698e903e7SBaptiste Daroussin extern void show_rrhs(void);
53798e903e7SBaptiste Daroussin extern void show_shifts(void);
53898e903e7SBaptiste Daroussin 
53998e903e7SBaptiste Daroussin /* main.c */
54098e903e7SBaptiste Daroussin extern void *allocate(size_t n);
5418e022d3cSDag-Erling Smørgrav extern GCC_NORETURN void done(int k);
54298e903e7SBaptiste Daroussin 
54398e903e7SBaptiste Daroussin /* mkpar.c */
54498e903e7SBaptiste Daroussin extern void free_parser(void);
54598e903e7SBaptiste Daroussin extern void make_parser(void);
54698e903e7SBaptiste Daroussin 
5470c8de5b0SBaptiste Daroussin /* mstring.c */
5480c8de5b0SBaptiste Daroussin struct mstring
5490c8de5b0SBaptiste Daroussin {
5500c8de5b0SBaptiste Daroussin     char *base, *ptr, *end;
5510c8de5b0SBaptiste Daroussin };
5520c8de5b0SBaptiste Daroussin 
553497dcf4cSBaptiste Daroussin extern void msprintf(struct mstring *, const char *, ...) GCC_PRINTFLIKE(2,3);
5540c8de5b0SBaptiste Daroussin extern int mputchar(struct mstring *, int);
5550c8de5b0SBaptiste Daroussin extern struct mstring *msnew(void);
556b53bb29fSJung-uk Kim extern struct mstring *msrenew(char *);
5570c8de5b0SBaptiste Daroussin extern char *msdone(struct mstring *);
5580c8de5b0SBaptiste Daroussin extern int strnscmp(const char *, const char *);
5590c8de5b0SBaptiste Daroussin extern unsigned int strnshash(const char *);
5600c8de5b0SBaptiste Daroussin 
5610c8de5b0SBaptiste Daroussin #define mputc(m, ch)	(((m)->ptr == (m)->end) \
5620c8de5b0SBaptiste Daroussin 			 ? mputchar(m,ch) \
5630c8de5b0SBaptiste Daroussin 			 : (*(m)->ptr++ = (char) (ch)))
5640c8de5b0SBaptiste Daroussin 
56598e903e7SBaptiste Daroussin /* output.c */
56698e903e7SBaptiste Daroussin extern void output(void);
56798e903e7SBaptiste Daroussin 
56898e903e7SBaptiste Daroussin /* reader.c */
56998e903e7SBaptiste Daroussin extern void reader(void);
57098e903e7SBaptiste Daroussin 
571b53bb29fSJung-uk Kim typedef enum
572b53bb29fSJung-uk Kim {
573b53bb29fSJung-uk Kim     CODE_HEADER = 0
574b53bb29fSJung-uk Kim     ,CODE_REQUIRES
575b53bb29fSJung-uk Kim     ,CODE_PROVIDES
576b53bb29fSJung-uk Kim     ,CODE_TOP
577b53bb29fSJung-uk Kim     ,CODE_IMPORTS
578b53bb29fSJung-uk Kim     ,CODE_MAX		/* this must be last */
579b53bb29fSJung-uk Kim }
580b53bb29fSJung-uk Kim CODE_CASES;
581b53bb29fSJung-uk Kim extern struct code_lines
582b53bb29fSJung-uk Kim {
583b53bb29fSJung-uk Kim     const char *name;
584b53bb29fSJung-uk Kim     char *lines;
585b53bb29fSJung-uk Kim     size_t num;
586b53bb29fSJung-uk Kim }
587b53bb29fSJung-uk Kim code_lines[CODE_MAX];
588b53bb29fSJung-uk Kim 
5890c8de5b0SBaptiste Daroussin /* skeleton.c (generated by skel2c) */
59098e903e7SBaptiste Daroussin extern void write_section(FILE * fp, const char *const section[]);
59198e903e7SBaptiste Daroussin 
5920c8de5b0SBaptiste Daroussin /* symtab.c */
5930c8de5b0SBaptiste Daroussin extern bucket *make_bucket(const char *);
5940c8de5b0SBaptiste Daroussin extern bucket *lookup(const char *);
5950c8de5b0SBaptiste Daroussin extern void create_symbol_table(void);
5960c8de5b0SBaptiste Daroussin extern void free_symbol_table(void);
5970c8de5b0SBaptiste Daroussin extern void free_symbols(void);
5980c8de5b0SBaptiste Daroussin 
59998e903e7SBaptiste Daroussin /* verbose.c */
60098e903e7SBaptiste Daroussin extern void verbose(void);
60198e903e7SBaptiste Daroussin 
60298e903e7SBaptiste Daroussin /* warshall.c */
60398e903e7SBaptiste Daroussin extern void reflexive_transitive_closure(unsigned *R, int n);
60498e903e7SBaptiste Daroussin 
6050c8de5b0SBaptiste Daroussin #ifdef DEBUG
6060c8de5b0SBaptiste Daroussin     /* closure.c */
6070c8de5b0SBaptiste Daroussin extern void print_closure(int n);
6080c8de5b0SBaptiste Daroussin extern void print_EFF(void);
6090c8de5b0SBaptiste Daroussin extern void print_first_derives(void);
6100c8de5b0SBaptiste Daroussin     /* lr0.c */
6110c8de5b0SBaptiste Daroussin extern void print_derives(void);
6120c8de5b0SBaptiste Daroussin #endif
6130c8de5b0SBaptiste Daroussin 
61498e903e7SBaptiste Daroussin #ifdef NO_LEAKS
61598e903e7SBaptiste Daroussin extern void lr0_leaks(void);
61698e903e7SBaptiste Daroussin extern void lalr_leaks(void);
61798e903e7SBaptiste Daroussin extern void mkpar_leaks(void);
61898e903e7SBaptiste Daroussin extern void output_leaks(void);
619497dcf4cSBaptiste Daroussin extern void mstring_leaks(void);
62098e903e7SBaptiste Daroussin extern void reader_leaks(void);
62198e903e7SBaptiste Daroussin #endif
622