Home | History | Annotate | Line # | Download | only in test
grammar.y revision 1.1.1.7.16.1
      1  1.1.1.7.16.1  christos /*	$NetBSD: grammar.y,v 1.1.1.7.16.1 2019/06/10 21:44:42 christos Exp $	*/
      2       1.1.1.7  christos 
      3  1.1.1.7.16.1  christos /* Id: grammar.y,v 1.6 2018/05/09 00:59:02 tom Exp
      4           1.1  christos  *
      5           1.1  christos  * yacc grammar for C function prototype generator
      6           1.1  christos  * This was derived from the grammar in Appendix A of
      7           1.1  christos  * "The C Programming Language" by Kernighan and Ritchie.
      8           1.1  christos  */
      9       1.1.1.2  christos %expect 1
     10       1.1.1.5  christos %{
     11       1.1.1.5  christos #ifdef YYBISON
     12       1.1.1.5  christos #include <stdlib.h>
     13       1.1.1.5  christos #define YYSTYPE_IS_DECLARED
     14       1.1.1.5  christos #define yyerror yaccError
     15       1.1.1.5  christos #endif
     16       1.1.1.5  christos 
     17       1.1.1.5  christos #if defined(YYBISON) || !defined(YYBYACC)
     18       1.1.1.5  christos static void yyerror(const char *s);
     19       1.1.1.5  christos #endif
     20       1.1.1.5  christos %}
     21       1.1.1.5  christos 
     22           1.1  christos %token <text> '(' '*' '&'
     23           1.1  christos 	/* identifiers that are not reserved words */
     24           1.1  christos 	T_IDENTIFIER T_TYPEDEF_NAME T_DEFINE_NAME
     25           1.1  christos 
     26           1.1  christos 	/* storage class */
     27           1.1  christos 	T_AUTO T_EXTERN T_REGISTER T_STATIC T_TYPEDEF
     28           1.1  christos 	/* This keyword included for compatibility with C++. */
     29           1.1  christos 	T_INLINE
     30           1.1  christos 	/* This keyword included for compatibility with GCC */
     31           1.1  christos 	T_EXTENSION
     32           1.1  christos 
     33           1.1  christos 	/* type specifiers */
     34           1.1  christos 	T_CHAR T_DOUBLE T_FLOAT T_INT T_VOID
     35           1.1  christos 	T_LONG T_SHORT T_SIGNED T_UNSIGNED
     36           1.1  christos 	T_ENUM T_STRUCT T_UNION
     37           1.1  christos 	/* C9X new types */
     38           1.1  christos 	T_Bool T_Complex T_Imaginary
     39           1.1  christos 
     40           1.1  christos 	/* type qualifiers */
     41           1.1  christos 	T_TYPE_QUALIFIER
     42           1.1  christos 
     43           1.1  christos 	/* paired square brackets and everything between them: [ ... ] */
     44           1.1  christos 	T_BRACKETS
     45           1.1  christos 
     46           1.1  christos %token
     47           1.1  christos 	/* left brace */
     48           1.1  christos 	T_LBRACE
     49           1.1  christos 	/* all input to the matching right brace */
     50           1.1  christos 	T_MATCHRBRACE
     51           1.1  christos 
     52           1.1  christos 	/* three periods */
     53           1.1  christos 	T_ELLIPSIS
     54           1.1  christos 
     55           1.1  christos 	/* constant expression or paired braces following an equal sign */
     56           1.1  christos 	T_INITIALIZER
     57           1.1  christos 
     58           1.1  christos 	/* string literal */
     59           1.1  christos 	T_STRING_LITERAL
     60           1.1  christos 
     61           1.1  christos 	/* asm */
     62           1.1  christos 	T_ASM
     63           1.1  christos 	/* ( "string literal" ) following asm keyword */
     64           1.1  christos 	T_ASMARG
     65           1.1  christos 
     66           1.1  christos 	/* va_dcl from <varargs.h> */
     67           1.1  christos 	T_VA_DCL
     68           1.1  christos 
     69           1.1  christos %type <decl_spec> decl_specifiers decl_specifier
     70           1.1  christos %type <decl_spec> storage_class type_specifier type_qualifier
     71           1.1  christos %type <decl_spec> struct_or_union_specifier enum_specifier
     72           1.1  christos %type <decl_list> init_declarator_list
     73           1.1  christos %type <declarator> init_declarator declarator direct_declarator
     74           1.1  christos %type <declarator> abs_declarator direct_abs_declarator
     75           1.1  christos %type <param_list> parameter_type_list parameter_list
     76           1.1  christos %type <parameter> parameter_declaration
     77           1.1  christos %type <param_list> opt_identifier_list identifier_list
     78           1.1  christos %type <text> struct_or_union pointer opt_type_qualifiers type_qualifier_list
     79           1.1  christos 	any_id identifier_or_ref
     80           1.1  christos %type <text> enumeration
     81           1.1  christos 
     82           1.1  christos %{
     83           1.1  christos #include <stdio.h>
     84           1.1  christos #include <ctype.h>
     85       1.1.1.2  christos #include <string.h>
     86       1.1.1.2  christos 
     87       1.1.1.2  christos #define OPT_LINTLIBRARY 1
     88       1.1.1.2  christos 
     89       1.1.1.2  christos #ifndef TRUE
     90       1.1.1.2  christos #define	TRUE	(1)
     91       1.1.1.2  christos #endif
     92       1.1.1.2  christos 
     93       1.1.1.2  christos #ifndef FALSE
     94       1.1.1.2  christos #define	FALSE	(0)
     95       1.1.1.2  christos #endif
     96       1.1.1.2  christos 
     97       1.1.1.2  christos /* #include "cproto.h" */
     98       1.1.1.2  christos #define MAX_TEXT_SIZE 1024
     99  1.1.1.7.16.1  christos #define TEXT_LEN (MAX_TEXT_SIZE / 2 - 3)
    100       1.1.1.2  christos 
    101       1.1.1.2  christos /* Prototype styles */
    102       1.1.1.2  christos #if OPT_LINTLIBRARY
    103       1.1.1.2  christos #define PROTO_ANSI_LLIB		-2	/* form ANSI lint-library source */
    104       1.1.1.2  christos #define PROTO_LINTLIBRARY	-1	/* form lint-library source */
    105       1.1.1.2  christos #endif
    106       1.1.1.2  christos #define PROTO_NONE		0	/* do not output any prototypes */
    107       1.1.1.2  christos #define PROTO_TRADITIONAL	1	/* comment out parameters */
    108       1.1.1.2  christos #define PROTO_ABSTRACT		2	/* comment out parameter names */
    109       1.1.1.2  christos #define PROTO_ANSI		3	/* ANSI C prototype */
    110       1.1.1.2  christos 
    111       1.1.1.2  christos typedef int PrototypeStyle;
    112       1.1.1.2  christos 
    113       1.1.1.2  christos typedef char boolean;
    114       1.1.1.2  christos 
    115       1.1.1.2  christos extern boolean types_out;
    116       1.1.1.2  christos extern PrototypeStyle proto_style;
    117       1.1.1.2  christos 
    118       1.1.1.2  christos #define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB)
    119       1.1.1.2  christos #define knrLintLibrary()  (proto_style == PROTO_LINTLIBRARY)
    120       1.1.1.2  christos #define lintLibrary()     (knrLintLibrary() || ansiLintLibrary())
    121       1.1.1.2  christos 
    122       1.1.1.2  christos #if OPT_LINTLIBRARY
    123       1.1.1.2  christos #define FUNC_UNKNOWN		-1	/* unspecified */
    124       1.1.1.2  christos #else
    125       1.1.1.2  christos #define FUNC_UNKNOWN		0	/* unspecified (same as FUNC_NONE) */
    126       1.1.1.2  christos #endif
    127       1.1.1.2  christos #define FUNC_NONE		0	/* not a function definition */
    128       1.1.1.2  christos #define FUNC_TRADITIONAL	1	/* traditional style */
    129       1.1.1.2  christos #define FUNC_ANSI		2	/* ANSI style */
    130       1.1.1.2  christos #define FUNC_BOTH		3	/* both styles */
    131       1.1.1.2  christos 
    132       1.1.1.2  christos typedef int FuncDefStyle;
    133       1.1.1.2  christos 
    134       1.1.1.2  christos /* Source file text */
    135       1.1.1.2  christos typedef struct text {
    136       1.1.1.2  christos     char text[MAX_TEXT_SIZE];	/* source text */
    137       1.1.1.2  christos     long begin; 		/* offset in temporary file */
    138       1.1.1.2  christos } Text;
    139       1.1.1.2  christos 
    140       1.1.1.2  christos /* Declaration specifier flags */
    141       1.1.1.2  christos #define DS_NONE 	0	/* default */
    142       1.1.1.2  christos #define DS_EXTERN	1	/* contains "extern" specifier */
    143       1.1.1.2  christos #define DS_STATIC	2	/* contains "static" specifier */
    144       1.1.1.2  christos #define DS_CHAR 	4	/* contains "char" type specifier */
    145       1.1.1.2  christos #define DS_SHORT	8	/* contains "short" type specifier */
    146       1.1.1.2  christos #define DS_FLOAT	16	/* contains "float" type specifier */
    147       1.1.1.2  christos #define DS_INLINE	32	/* contains "inline" specifier */
    148       1.1.1.2  christos #define DS_JUNK 	64	/* we're not interested in this declaration */
    149       1.1.1.2  christos 
    150       1.1.1.2  christos /* This structure stores information about a declaration specifier. */
    151       1.1.1.2  christos typedef struct decl_spec {
    152       1.1.1.2  christos     unsigned short flags;	/* flags defined above */
    153       1.1.1.2  christos     char *text; 		/* source text */
    154       1.1.1.2  christos     long begin; 		/* offset in temporary file */
    155       1.1.1.2  christos } DeclSpec;
    156       1.1.1.2  christos 
    157       1.1.1.2  christos /* This is a list of function parameters. */
    158       1.1.1.2  christos typedef struct _ParameterList {
    159       1.1.1.2  christos     struct parameter *first;	/* pointer to first parameter in list */
    160       1.1.1.2  christos     struct parameter *last;	/* pointer to last parameter in list */
    161       1.1.1.2  christos     long begin_comment; 	/* begin offset of comment */
    162       1.1.1.2  christos     long end_comment;		/* end offset of comment */
    163       1.1.1.2  christos     char *comment;		/* comment at start of parameter list */
    164       1.1.1.2  christos } ParameterList;
    165       1.1.1.2  christos 
    166       1.1.1.2  christos /* This structure stores information about a declarator. */
    167       1.1.1.2  christos typedef struct _Declarator {
    168       1.1.1.2  christos     char *name; 			/* name of variable or function */
    169       1.1.1.2  christos     char *text; 			/* source text */
    170       1.1.1.2  christos     long begin; 			/* offset in temporary file */
    171       1.1.1.2  christos     long begin_comment; 		/* begin offset of comment */
    172       1.1.1.2  christos     long end_comment;			/* end offset of comment */
    173       1.1.1.2  christos     FuncDefStyle func_def;		/* style of function definition */
    174       1.1.1.2  christos     ParameterList params;		/* function parameters */
    175       1.1.1.2  christos     boolean pointer;			/* TRUE if it declares a pointer */
    176       1.1.1.2  christos     struct _Declarator *head;		/* head function declarator */
    177       1.1.1.2  christos     struct _Declarator *func_stack;	/* stack of function declarators */
    178       1.1.1.2  christos     struct _Declarator *next;		/* next declarator in list */
    179       1.1.1.2  christos } Declarator;
    180       1.1.1.2  christos 
    181       1.1.1.2  christos /* This structure stores information about a function parameter. */
    182       1.1.1.2  christos typedef struct parameter {
    183       1.1.1.2  christos     struct parameter *next;	/* next parameter in list */
    184       1.1.1.2  christos     DeclSpec decl_spec;
    185       1.1.1.2  christos     Declarator *declarator;
    186       1.1.1.2  christos     char *comment;		/* comment following the parameter */
    187       1.1.1.2  christos } Parameter;
    188       1.1.1.2  christos 
    189       1.1.1.2  christos /* This is a list of declarators. */
    190       1.1.1.2  christos typedef struct declarator_list {
    191       1.1.1.2  christos     Declarator *first;		/* pointer to first declarator in list */
    192       1.1.1.2  christos     Declarator *last;		/* pointer to last declarator in list */
    193       1.1.1.2  christos } DeclaratorList;
    194       1.1.1.2  christos 
    195       1.1.1.2  christos /* #include "symbol.h" */
    196       1.1.1.2  christos typedef struct symbol {
    197       1.1.1.2  christos     struct symbol *next;	/* next symbol in list */
    198       1.1.1.2  christos     char *name; 		/* name of symbol */
    199       1.1.1.2  christos     char *value;		/* value of symbol (for defines) */
    200       1.1.1.2  christos     short flags;		/* symbol attributes */
    201       1.1.1.2  christos } Symbol;
    202       1.1.1.2  christos 
    203       1.1.1.2  christos /* parser stack entry type */
    204       1.1.1.2  christos typedef union {
    205       1.1.1.2  christos     Text text;
    206       1.1.1.2  christos     DeclSpec decl_spec;
    207       1.1.1.2  christos     Parameter *parameter;
    208       1.1.1.2  christos     ParameterList param_list;
    209       1.1.1.2  christos     Declarator *declarator;
    210       1.1.1.2  christos     DeclaratorList decl_list;
    211       1.1.1.2  christos } YYSTYPE;
    212       1.1.1.2  christos 
    213       1.1.1.2  christos /* The hash table length should be a prime number. */
    214       1.1.1.2  christos #define SYM_MAX_HASH 251
    215       1.1.1.2  christos 
    216       1.1.1.2  christos typedef struct symbol_table {
    217       1.1.1.2  christos     Symbol *bucket[SYM_MAX_HASH];	/* hash buckets */
    218       1.1.1.2  christos } SymbolTable;
    219       1.1.1.2  christos 
    220       1.1.1.2  christos extern SymbolTable *new_symbol_table	/* Create symbol table */
    221       1.1.1.2  christos 	(void);
    222       1.1.1.2  christos extern void free_symbol_table		/* Destroy symbol table */
    223       1.1.1.2  christos 	(SymbolTable *s);
    224       1.1.1.2  christos extern Symbol *find_symbol		/* Lookup symbol name */
    225       1.1.1.2  christos 	(SymbolTable *s, const char *n);
    226       1.1.1.2  christos extern Symbol *new_symbol		/* Define new symbol */
    227       1.1.1.2  christos 	(SymbolTable *s, const char *n, const char *v, int f);
    228       1.1.1.2  christos 
    229       1.1.1.2  christos /* #include "semantic.h" */
    230       1.1.1.2  christos extern void new_decl_spec (DeclSpec *, const char *, long, int);
    231       1.1.1.2  christos extern void free_decl_spec (DeclSpec *);
    232       1.1.1.2  christos extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *);
    233       1.1.1.2  christos extern void check_untagged (DeclSpec *);
    234       1.1.1.2  christos extern Declarator *new_declarator (const char *, const char *, long);
    235       1.1.1.2  christos extern void free_declarator (Declarator *);
    236       1.1.1.2  christos extern void new_decl_list (DeclaratorList *, Declarator *);
    237       1.1.1.2  christos extern void free_decl_list (DeclaratorList *);
    238       1.1.1.2  christos extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *);
    239       1.1.1.2  christos extern Parameter *new_parameter (DeclSpec *, Declarator *);
    240       1.1.1.2  christos extern void free_parameter (Parameter *);
    241       1.1.1.2  christos extern void new_param_list (ParameterList *, Parameter *);
    242       1.1.1.2  christos extern void free_param_list (ParameterList *);
    243       1.1.1.2  christos extern void add_param_list (ParameterList *, ParameterList *, Parameter *);
    244       1.1.1.2  christos extern void new_ident_list (ParameterList *);
    245       1.1.1.2  christos extern void add_ident_list (ParameterList *, ParameterList *, const char *);
    246       1.1.1.2  christos extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *);
    247       1.1.1.2  christos extern void gen_declarations (DeclSpec *, DeclaratorList *);
    248       1.1.1.2  christos extern void gen_prototype (DeclSpec *, Declarator *);
    249       1.1.1.2  christos extern void gen_func_declarator (Declarator *);
    250       1.1.1.2  christos extern void gen_func_definition (DeclSpec *, Declarator *);
    251       1.1.1.2  christos 
    252       1.1.1.2  christos extern void init_parser     (void);
    253       1.1.1.2  christos extern void process_file    (FILE *infile, char *name);
    254       1.1.1.2  christos extern char *cur_text       (void);
    255       1.1.1.2  christos extern char *cur_file_name  (void);
    256       1.1.1.2  christos extern char *implied_typedef (void);
    257       1.1.1.2  christos extern void include_file    (char *name, int convert);
    258       1.1.1.2  christos extern char *supply_parm    (int count);
    259       1.1.1.2  christos extern char *xstrdup        (const char *);
    260       1.1.1.2  christos extern int already_declared (char *name);
    261       1.1.1.2  christos extern int is_actual_func   (Declarator *d);
    262       1.1.1.2  christos extern int lint_ellipsis    (Parameter *p);
    263       1.1.1.2  christos extern int want_typedef     (void);
    264       1.1.1.2  christos extern void begin_tracking  (void);
    265       1.1.1.2  christos extern void begin_typedef   (void);
    266       1.1.1.2  christos extern void copy_typedef    (char *s);
    267       1.1.1.2  christos extern void ellipsis_varargs (Declarator *d);
    268       1.1.1.2  christos extern void end_typedef     (void);
    269       1.1.1.2  christos extern void flush_varargs   (void);
    270       1.1.1.2  christos extern void fmt_library     (int code);
    271       1.1.1.2  christos extern void imply_typedef   (const char *s);
    272       1.1.1.2  christos extern void indent          (FILE *outf);
    273       1.1.1.2  christos extern void put_blankline   (FILE *outf);
    274       1.1.1.2  christos extern void put_body        (FILE *outf, DeclSpec *decl_spec, Declarator *declarator);
    275       1.1.1.2  christos extern void put_char        (FILE *outf, int c);
    276       1.1.1.2  christos extern void put_error       (void);
    277       1.1.1.2  christos extern void put_newline     (FILE *outf);
    278       1.1.1.2  christos extern void put_padded      (FILE *outf, const char *s);
    279       1.1.1.2  christos extern void put_string      (FILE *outf, const char *s);
    280       1.1.1.2  christos extern void track_in        (void);
    281       1.1.1.2  christos 
    282       1.1.1.2  christos extern boolean file_comments;
    283       1.1.1.2  christos extern FuncDefStyle func_style;
    284       1.1.1.2  christos extern char base_file[];
    285           1.1  christos 
    286           1.1  christos extern	int	yylex (void);
    287           1.1  christos 
    288           1.1  christos /* declaration specifier attributes for the typedef statement currently being
    289           1.1  christos  * scanned
    290           1.1  christos  */
    291           1.1  christos static int cur_decl_spec_flags;
    292           1.1  christos 
    293           1.1  christos /* pointer to parameter list for the current function definition */
    294           1.1  christos static ParameterList *func_params;
    295           1.1  christos 
    296           1.1  christos /* A parser semantic action sets this pointer to the current declarator in
    297           1.1  christos  * a function parameter declaration in order to catch any comments following
    298           1.1  christos  * the parameter declaration on the same line.  If the lexer scans a comment
    299           1.1  christos  * and <cur_declarator> is not NULL, then the comment is attached to the
    300           1.1  christos  * declarator.  To ignore subsequent comments, the lexer sets this to NULL
    301           1.1  christos  * after scanning a comment or end of line.
    302           1.1  christos  */
    303           1.1  christos static Declarator *cur_declarator;
    304           1.1  christos 
    305           1.1  christos /* temporary string buffer */
    306           1.1  christos static char buf[MAX_TEXT_SIZE];
    307           1.1  christos 
    308           1.1  christos /* table of typedef names */
    309           1.1  christos static SymbolTable *typedef_names;
    310           1.1  christos 
    311           1.1  christos /* table of define names */
    312           1.1  christos static SymbolTable *define_names;
    313           1.1  christos 
    314           1.1  christos /* table of type qualifiers */
    315           1.1  christos static SymbolTable *type_qualifiers;
    316           1.1  christos 
    317           1.1  christos /* information about the current input file */
    318           1.1  christos typedef struct {
    319           1.1  christos     char *base_name;		/* base input file name */
    320           1.1  christos     char *file_name;		/* current file name */
    321           1.1  christos     FILE *file; 		/* input file */
    322           1.1  christos     unsigned line_num;		/* current line number in input file */
    323           1.1  christos     FILE *tmp_file;		/* temporary file */
    324           1.1  christos     long begin_comment; 	/* tmp file offset after last written ) or ; */
    325           1.1  christos     long end_comment;		/* tmp file offset after last comment */
    326           1.1  christos     boolean convert;		/* if TRUE, convert function definitions */
    327           1.1  christos     boolean changed;		/* TRUE if conversion done in this file */
    328           1.1  christos } IncludeStack;
    329           1.1  christos 
    330           1.1  christos static IncludeStack *cur_file;	/* current input file */
    331           1.1  christos 
    332       1.1.1.2  christos /* #include "yyerror.c" */
    333           1.1  christos 
    334           1.1  christos static int haveAnsiParam (void);
    335           1.1  christos 
    336           1.1  christos 
    337           1.1  christos /* Flags to enable us to find if a procedure returns a value.
    338           1.1  christos  */
    339       1.1.1.2  christos static int return_val;	/* nonzero on BRACES iff return-expression found */
    340           1.1  christos 
    341       1.1.1.2  christos static const char *
    342           1.1  christos dft_decl_spec (void)
    343           1.1  christos {
    344           1.1  christos     return (lintLibrary() && !return_val) ? "void" : "int";
    345           1.1  christos }
    346           1.1  christos 
    347           1.1  christos static int
    348           1.1  christos haveAnsiParam (void)
    349           1.1  christos {
    350           1.1  christos     Parameter *p;
    351           1.1  christos     if (func_params != 0) {
    352           1.1  christos 	for (p = func_params->first; p != 0; p = p->next) {
    353           1.1  christos 	    if (p->declarator->func_def == FUNC_ANSI) {
    354           1.1  christos 		return TRUE;
    355           1.1  christos 	    }
    356           1.1  christos 	}
    357           1.1  christos     }
    358           1.1  christos     return FALSE;
    359           1.1  christos }
    360           1.1  christos %}
    361           1.1  christos %%
    362           1.1  christos 
    363           1.1  christos program
    364           1.1  christos 	: /* empty */
    365           1.1  christos 	| translation_unit
    366           1.1  christos 	;
    367           1.1  christos 
    368           1.1  christos translation_unit
    369           1.1  christos 	: external_declaration
    370           1.1  christos 	| translation_unit external_declaration
    371           1.1  christos 	;
    372           1.1  christos 
    373           1.1  christos external_declaration
    374           1.1  christos 	: declaration
    375           1.1  christos 	| function_definition
    376           1.1  christos 	| ';'
    377           1.1  christos 	| linkage_specification
    378           1.1  christos 	| T_ASM T_ASMARG ';'
    379           1.1  christos 	| error T_MATCHRBRACE
    380           1.1  christos 	{
    381           1.1  christos 	    yyerrok;
    382           1.1  christos 	}
    383           1.1  christos 	| error ';'
    384           1.1  christos 	{
    385           1.1  christos 	    yyerrok;
    386           1.1  christos 	}
    387           1.1  christos 	;
    388           1.1  christos 
    389           1.1  christos braces
    390           1.1  christos 	: T_LBRACE T_MATCHRBRACE
    391           1.1  christos 	;
    392           1.1  christos 
    393           1.1  christos linkage_specification
    394           1.1  christos 	: T_EXTERN T_STRING_LITERAL braces
    395           1.1  christos 	{
    396           1.1  christos 	    /* Provide an empty action here so bison will not complain about
    397           1.1  christos 	     * incompatible types in the default action it normally would
    398           1.1  christos 	     * have generated.
    399           1.1  christos 	     */
    400           1.1  christos 	}
    401           1.1  christos 	| T_EXTERN T_STRING_LITERAL declaration
    402           1.1  christos 	{
    403           1.1  christos 	    /* empty */
    404           1.1  christos 	}
    405           1.1  christos 	;
    406           1.1  christos 
    407           1.1  christos declaration
    408           1.1  christos 	: decl_specifiers ';'
    409           1.1  christos 	{
    410           1.1  christos #if OPT_LINTLIBRARY
    411           1.1  christos 	    if (types_out && want_typedef()) {
    412           1.1  christos 		gen_declarations(&$1, (DeclaratorList *)0);
    413           1.1  christos 		flush_varargs();
    414           1.1  christos 	    }
    415           1.1  christos #endif
    416           1.1  christos 	    free_decl_spec(&$1);
    417           1.1  christos 	    end_typedef();
    418           1.1  christos 	}
    419           1.1  christos 	| decl_specifiers init_declarator_list ';'
    420           1.1  christos 	{
    421           1.1  christos 	    if (func_params != NULL) {
    422           1.1  christos 		set_param_types(func_params, &$1, &$2);
    423           1.1  christos 	    } else {
    424           1.1  christos 		gen_declarations(&$1, &$2);
    425           1.1  christos #if OPT_LINTLIBRARY
    426           1.1  christos 		flush_varargs();
    427           1.1  christos #endif
    428           1.1  christos 		free_decl_list(&$2);
    429           1.1  christos 	    }
    430           1.1  christos 	    free_decl_spec(&$1);
    431           1.1  christos 	    end_typedef();
    432           1.1  christos 	}
    433           1.1  christos 	| any_typedef decl_specifiers
    434           1.1  christos 	{
    435           1.1  christos 	    cur_decl_spec_flags = $2.flags;
    436           1.1  christos 	    free_decl_spec(&$2);
    437           1.1  christos 	}
    438           1.1  christos 	  opt_declarator_list ';'
    439           1.1  christos 	{
    440           1.1  christos 	    end_typedef();
    441           1.1  christos 	}
    442           1.1  christos 	;
    443           1.1  christos 
    444           1.1  christos any_typedef
    445           1.1  christos 	: T_EXTENSION T_TYPEDEF
    446           1.1  christos 	{
    447           1.1  christos 	    begin_typedef();
    448           1.1  christos 	}
    449           1.1  christos 	| T_TYPEDEF
    450           1.1  christos 	{
    451           1.1  christos 	    begin_typedef();
    452           1.1  christos 	}
    453           1.1  christos 	;
    454           1.1  christos 
    455           1.1  christos opt_declarator_list
    456           1.1  christos 	: /* empty */
    457           1.1  christos 	| declarator_list
    458           1.1  christos 	;
    459           1.1  christos 
    460           1.1  christos declarator_list
    461           1.1  christos 	: declarator
    462           1.1  christos 	{
    463           1.1  christos 	    int flags = cur_decl_spec_flags;
    464           1.1  christos 
    465           1.1  christos 	    /* If the typedef is a pointer type, then reset the short type
    466           1.1  christos 	     * flags so it does not get promoted.
    467           1.1  christos 	     */
    468           1.1  christos 	    if (strcmp($1->text, $1->name) != 0)
    469           1.1  christos 		flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT);
    470           1.1  christos 	    new_symbol(typedef_names, $1->name, NULL, flags);
    471           1.1  christos 	    free_declarator($1);
    472           1.1  christos 	}
    473           1.1  christos 	| declarator_list ',' declarator
    474           1.1  christos 	{
    475           1.1  christos 	    int flags = cur_decl_spec_flags;
    476           1.1  christos 
    477           1.1  christos 	    if (strcmp($3->text, $3->name) != 0)
    478           1.1  christos 		flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT);
    479           1.1  christos 	    new_symbol(typedef_names, $3->name, NULL, flags);
    480           1.1  christos 	    free_declarator($3);
    481           1.1  christos 	}
    482           1.1  christos 	;
    483           1.1  christos 
    484           1.1  christos function_definition
    485           1.1  christos 	: decl_specifiers declarator
    486           1.1  christos 	{
    487           1.1  christos 	    check_untagged(&$1);
    488           1.1  christos 	    if ($2->func_def == FUNC_NONE) {
    489           1.1  christos 		yyerror("syntax error");
    490           1.1  christos 		YYERROR;
    491           1.1  christos 	    }
    492           1.1  christos 	    func_params = &($2->head->params);
    493           1.1  christos 	    func_params->begin_comment = cur_file->begin_comment;
    494           1.1  christos 	    func_params->end_comment = cur_file->end_comment;
    495           1.1  christos 	}
    496           1.1  christos 	  opt_declaration_list T_LBRACE
    497           1.1  christos 	{
    498           1.1  christos 	    /* If we're converting to K&R and we've got a nominally K&R
    499           1.1  christos 	     * function which has a parameter which is ANSI (i.e., a prototyped
    500           1.1  christos 	     * function pointer), then we must override the deciphered value of
    501           1.1  christos 	     * 'func_def' so that the parameter will be converted.
    502           1.1  christos 	     */
    503           1.1  christos 	    if (func_style == FUNC_TRADITIONAL
    504           1.1  christos 	     && haveAnsiParam()
    505           1.1  christos 	     && $2->head->func_def == func_style) {
    506           1.1  christos 		$2->head->func_def = FUNC_BOTH;
    507           1.1  christos 	    }
    508           1.1  christos 
    509           1.1  christos 	    func_params = NULL;
    510           1.1  christos 
    511           1.1  christos 	    if (cur_file->convert)
    512           1.1  christos 		gen_func_definition(&$1, $2);
    513           1.1  christos 	    gen_prototype(&$1, $2);
    514           1.1  christos #if OPT_LINTLIBRARY
    515           1.1  christos 	    flush_varargs();
    516           1.1  christos #endif
    517           1.1  christos 	    free_decl_spec(&$1);
    518           1.1  christos 	    free_declarator($2);
    519           1.1  christos 	}
    520           1.1  christos 	  T_MATCHRBRACE
    521           1.1  christos 	| declarator
    522           1.1  christos 	{
    523           1.1  christos 	    if ($1->func_def == FUNC_NONE) {
    524           1.1  christos 		yyerror("syntax error");
    525           1.1  christos 		YYERROR;
    526           1.1  christos 	    }
    527           1.1  christos 	    func_params = &($1->head->params);
    528           1.1  christos 	    func_params->begin_comment = cur_file->begin_comment;
    529           1.1  christos 	    func_params->end_comment = cur_file->end_comment;
    530           1.1  christos 	}
    531           1.1  christos 	  opt_declaration_list T_LBRACE T_MATCHRBRACE
    532           1.1  christos 	{
    533           1.1  christos 	    DeclSpec decl_spec;
    534           1.1  christos 
    535           1.1  christos 	    func_params = NULL;
    536           1.1  christos 
    537           1.1  christos 	    new_decl_spec(&decl_spec, dft_decl_spec(), $1->begin, DS_NONE);
    538           1.1  christos 	    if (cur_file->convert)
    539           1.1  christos 		gen_func_definition(&decl_spec, $1);
    540           1.1  christos 	    gen_prototype(&decl_spec, $1);
    541           1.1  christos #if OPT_LINTLIBRARY
    542           1.1  christos 	    flush_varargs();
    543           1.1  christos #endif
    544           1.1  christos 	    free_decl_spec(&decl_spec);
    545           1.1  christos 	    free_declarator($1);
    546           1.1  christos 	}
    547           1.1  christos 	;
    548           1.1  christos 
    549           1.1  christos opt_declaration_list
    550           1.1  christos 	: /* empty */
    551           1.1  christos 	| T_VA_DCL
    552           1.1  christos 	| declaration_list
    553           1.1  christos 	;
    554           1.1  christos 
    555           1.1  christos declaration_list
    556           1.1  christos 	: declaration
    557           1.1  christos 	| declaration_list declaration
    558           1.1  christos 	;
    559           1.1  christos 
    560           1.1  christos decl_specifiers
    561           1.1  christos 	: decl_specifier
    562           1.1  christos 	| decl_specifiers decl_specifier
    563           1.1  christos 	{
    564           1.1  christos 	    join_decl_specs(&$$, &$1, &$2);
    565           1.1  christos 	    free($1.text);
    566           1.1  christos 	    free($2.text);
    567           1.1  christos 	}
    568           1.1  christos 	;
    569           1.1  christos 
    570           1.1  christos decl_specifier
    571           1.1  christos 	: storage_class
    572           1.1  christos 	| type_specifier
    573           1.1  christos 	| type_qualifier
    574           1.1  christos 	;
    575           1.1  christos 
    576           1.1  christos storage_class
    577           1.1  christos 	: T_AUTO
    578           1.1  christos 	{
    579           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    580           1.1  christos 	}
    581           1.1  christos 	| T_EXTERN
    582           1.1  christos 	{
    583           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
    584           1.1  christos 	}
    585           1.1  christos 	| T_REGISTER
    586           1.1  christos 	{
    587           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    588           1.1  christos 	}
    589           1.1  christos 	| T_STATIC
    590           1.1  christos 	{
    591           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_STATIC);
    592           1.1  christos 	}
    593           1.1  christos 	| T_INLINE
    594           1.1  christos 	{
    595           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_INLINE);
    596           1.1  christos 	}
    597           1.1  christos 	| T_EXTENSION
    598           1.1  christos 	{
    599           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_JUNK);
    600           1.1  christos 	}
    601           1.1  christos 	;
    602           1.1  christos 
    603           1.1  christos type_specifier
    604           1.1  christos 	: T_CHAR
    605           1.1  christos 	{
    606           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_CHAR);
    607           1.1  christos 	}
    608           1.1  christos 	| T_DOUBLE
    609           1.1  christos 	{
    610           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    611           1.1  christos 	}
    612           1.1  christos 	| T_FLOAT
    613           1.1  christos 	{
    614           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_FLOAT);
    615           1.1  christos 	}
    616           1.1  christos 	| T_INT
    617           1.1  christos 	{
    618           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    619           1.1  christos 	}
    620           1.1  christos 	| T_LONG
    621           1.1  christos 	{
    622           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    623           1.1  christos 	}
    624           1.1  christos 	| T_SHORT
    625           1.1  christos 	{
    626           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_SHORT);
    627           1.1  christos 	}
    628           1.1  christos 	| T_SIGNED
    629           1.1  christos 	{
    630           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    631           1.1  christos 	}
    632           1.1  christos 	| T_UNSIGNED
    633           1.1  christos 	{
    634           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    635           1.1  christos 	}
    636           1.1  christos 	| T_VOID
    637           1.1  christos 	{
    638           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    639           1.1  christos 	}
    640           1.1  christos 	| T_Bool
    641           1.1  christos 	{
    642           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_CHAR);
    643           1.1  christos 	}
    644           1.1  christos 	| T_Complex
    645           1.1  christos 	{
    646           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    647           1.1  christos 	}
    648           1.1  christos 	| T_Imaginary
    649           1.1  christos 	{
    650           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    651           1.1  christos 	}
    652           1.1  christos 	| T_TYPEDEF_NAME
    653           1.1  christos 	{
    654           1.1  christos 	    Symbol *s;
    655           1.1  christos 	    s = find_symbol(typedef_names, $1.text);
    656           1.1  christos 	    if (s != NULL)
    657           1.1  christos 		new_decl_spec(&$$, $1.text, $1.begin, s->flags);
    658           1.1  christos 	}
    659           1.1  christos 	| struct_or_union_specifier
    660           1.1  christos 	| enum_specifier
    661           1.1  christos 	;
    662           1.1  christos 
    663           1.1  christos type_qualifier
    664           1.1  christos 	: T_TYPE_QUALIFIER
    665           1.1  christos 	{
    666           1.1  christos 	    new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
    667           1.1  christos 	}
    668           1.1  christos 	| T_DEFINE_NAME
    669           1.1  christos 	{
    670           1.1  christos 	    /* This rule allows the <pointer> nonterminal to scan #define
    671           1.1  christos 	     * names as if they were type modifiers.
    672           1.1  christos 	     */
    673           1.1  christos 	    Symbol *s;
    674           1.1  christos 	    s = find_symbol(define_names, $1.text);
    675           1.1  christos 	    if (s != NULL)
    676           1.1  christos 		new_decl_spec(&$$, $1.text, $1.begin, s->flags);
    677           1.1  christos 	}
    678           1.1  christos 	;
    679           1.1  christos 
    680           1.1  christos struct_or_union_specifier
    681           1.1  christos 	: struct_or_union any_id braces
    682           1.1  christos 	{
    683           1.1  christos 	    char *s;
    684           1.1  christos 	    if ((s = implied_typedef()) == 0)
    685  1.1.1.7.16.1  christos 	        (void)sprintf(s = buf, "%.*s %.*s", TEXT_LEN, $1.text, TEXT_LEN, $2.text);
    686           1.1  christos 	    new_decl_spec(&$$, s, $1.begin, DS_NONE);
    687           1.1  christos 	}
    688           1.1  christos 	| struct_or_union braces
    689           1.1  christos 	{
    690           1.1  christos 	    char *s;
    691           1.1  christos 	    if ((s = implied_typedef()) == 0)
    692  1.1.1.7.16.1  christos 		(void)sprintf(s = buf, "%.*s {}", TEXT_LEN, $1.text);
    693           1.1  christos 	    new_decl_spec(&$$, s, $1.begin, DS_NONE);
    694           1.1  christos 	}
    695           1.1  christos 	| struct_or_union any_id
    696           1.1  christos 	{
    697  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "%.*s %.*s", TEXT_LEN, $1.text, TEXT_LEN, $2.text);
    698           1.1  christos 	    new_decl_spec(&$$, buf, $1.begin, DS_NONE);
    699           1.1  christos 	}
    700           1.1  christos 	;
    701           1.1  christos 
    702           1.1  christos struct_or_union
    703           1.1  christos 	: T_STRUCT
    704           1.1  christos 	{
    705           1.1  christos 	    imply_typedef($$.text);
    706           1.1  christos 	}
    707           1.1  christos 	| T_UNION
    708           1.1  christos 	{
    709           1.1  christos 	    imply_typedef($$.text);
    710           1.1  christos 	}
    711           1.1  christos 	;
    712           1.1  christos 
    713           1.1  christos init_declarator_list
    714           1.1  christos 	: init_declarator
    715           1.1  christos 	{
    716           1.1  christos 	    new_decl_list(&$$, $1);
    717           1.1  christos 	}
    718           1.1  christos 	| init_declarator_list ',' init_declarator
    719           1.1  christos 	{
    720           1.1  christos 	    add_decl_list(&$$, &$1, $3);
    721           1.1  christos 	}
    722           1.1  christos 	;
    723           1.1  christos 
    724           1.1  christos init_declarator
    725           1.1  christos 	: declarator
    726           1.1  christos 	{
    727           1.1  christos 	    if ($1->func_def != FUNC_NONE && func_params == NULL &&
    728           1.1  christos 		func_style == FUNC_TRADITIONAL && cur_file->convert) {
    729           1.1  christos 		gen_func_declarator($1);
    730           1.1  christos 		fputs(cur_text(), cur_file->tmp_file);
    731           1.1  christos 	    }
    732           1.1  christos 	    cur_declarator = $$;
    733           1.1  christos 	}
    734           1.1  christos 	| declarator '='
    735           1.1  christos 	{
    736           1.1  christos 	    if ($1->func_def != FUNC_NONE && func_params == NULL &&
    737           1.1  christos 		func_style == FUNC_TRADITIONAL && cur_file->convert) {
    738           1.1  christos 		gen_func_declarator($1);
    739           1.1  christos 		fputs(" =", cur_file->tmp_file);
    740           1.1  christos 	    }
    741           1.1  christos 	}
    742           1.1  christos 	  T_INITIALIZER
    743           1.1  christos 	;
    744           1.1  christos 
    745           1.1  christos enum_specifier
    746           1.1  christos 	: enumeration any_id braces
    747           1.1  christos 	{
    748           1.1  christos 	    char *s;
    749           1.1  christos 	    if ((s = implied_typedef()) == 0)
    750  1.1.1.7.16.1  christos 		(void)sprintf(s = buf, "enum %.*s", TEXT_LEN, $2.text);
    751           1.1  christos 	    new_decl_spec(&$$, s, $1.begin, DS_NONE);
    752           1.1  christos 	}
    753           1.1  christos 	| enumeration braces
    754           1.1  christos 	{
    755           1.1  christos 	    char *s;
    756           1.1  christos 	    if ((s = implied_typedef()) == 0)
    757  1.1.1.7.16.1  christos 		(void)sprintf(s = buf, "%.*s {}", TEXT_LEN, $1.text);
    758           1.1  christos 	    new_decl_spec(&$$, s, $1.begin, DS_NONE);
    759           1.1  christos 	}
    760           1.1  christos 	| enumeration any_id
    761           1.1  christos 	{
    762  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "enum %.*s", TEXT_LEN, $2.text);
    763           1.1  christos 	    new_decl_spec(&$$, buf, $1.begin, DS_NONE);
    764           1.1  christos 	}
    765           1.1  christos 	;
    766           1.1  christos 
    767           1.1  christos enumeration
    768           1.1  christos 	: T_ENUM
    769           1.1  christos 	{
    770           1.1  christos 	    imply_typedef("enum");
    771           1.1  christos 	    $$ = $1;
    772           1.1  christos 	}
    773           1.1  christos 	;
    774           1.1  christos 
    775           1.1  christos any_id
    776           1.1  christos 	: T_IDENTIFIER
    777           1.1  christos 	| T_TYPEDEF_NAME
    778           1.1  christos 	;
    779           1.1  christos 
    780           1.1  christos declarator
    781           1.1  christos 	: pointer direct_declarator
    782           1.1  christos 	{
    783           1.1  christos 	    $$ = $2;
    784  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $1.text, TEXT_LEN, $$->text);
    785           1.1  christos 	    free($$->text);
    786           1.1  christos 	    $$->text = xstrdup(buf);
    787           1.1  christos 	    $$->begin = $1.begin;
    788           1.1  christos 	    $$->pointer = TRUE;
    789           1.1  christos 	}
    790           1.1  christos 	| direct_declarator
    791           1.1  christos 	;
    792           1.1  christos 
    793           1.1  christos direct_declarator
    794           1.1  christos 	: identifier_or_ref
    795           1.1  christos 	{
    796           1.1  christos 	    $$ = new_declarator($1.text, $1.text, $1.begin);
    797           1.1  christos 	}
    798           1.1  christos 	| '(' declarator ')'
    799           1.1  christos 	{
    800           1.1  christos 	    $$ = $2;
    801  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "(%.*s)", TEXT_LEN, $$->text);
    802           1.1  christos 	    free($$->text);
    803           1.1  christos 	    $$->text = xstrdup(buf);
    804           1.1  christos 	    $$->begin = $1.begin;
    805           1.1  christos 	}
    806           1.1  christos 	| direct_declarator T_BRACKETS
    807           1.1  christos 	{
    808           1.1  christos 	    $$ = $1;
    809  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $$->text, TEXT_LEN, $2.text);
    810           1.1  christos 	    free($$->text);
    811           1.1  christos 	    $$->text = xstrdup(buf);
    812           1.1  christos 	}
    813           1.1  christos 	| direct_declarator '(' parameter_type_list ')'
    814           1.1  christos 	{
    815           1.1  christos 	    $$ = new_declarator("%s()", $1->name, $1->begin);
    816           1.1  christos 	    $$->params = $3;
    817           1.1  christos 	    $$->func_stack = $1;
    818           1.1  christos 	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
    819           1.1  christos 	    $$->func_def = FUNC_ANSI;
    820           1.1  christos 	}
    821           1.1  christos 	| direct_declarator '(' opt_identifier_list ')'
    822           1.1  christos 	{
    823           1.1  christos 	    $$ = new_declarator("%s()", $1->name, $1->begin);
    824           1.1  christos 	    $$->params = $3;
    825           1.1  christos 	    $$->func_stack = $1;
    826           1.1  christos 	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
    827           1.1  christos 	    $$->func_def = FUNC_TRADITIONAL;
    828           1.1  christos 	}
    829           1.1  christos 	;
    830           1.1  christos 
    831           1.1  christos pointer
    832           1.1  christos 	: '*' opt_type_qualifiers
    833           1.1  christos 	{
    834  1.1.1.7.16.1  christos 	    (void)sprintf($$.text, "*%.*s", TEXT_LEN, $2.text);
    835           1.1  christos 	    $$.begin = $1.begin;
    836           1.1  christos 	}
    837           1.1  christos 	| '*' opt_type_qualifiers pointer
    838           1.1  christos 	{
    839  1.1.1.7.16.1  christos 	    (void)sprintf($$.text, "*%.*s%.*s", TEXT_LEN, $2.text, TEXT_LEN, $3.text);
    840           1.1  christos 	    $$.begin = $1.begin;
    841           1.1  christos 	}
    842           1.1  christos 	;
    843           1.1  christos 
    844           1.1  christos opt_type_qualifiers
    845           1.1  christos 	: /* empty */
    846           1.1  christos 	{
    847           1.1  christos 	    strcpy($$.text, "");
    848           1.1  christos 	    $$.begin = 0L;
    849           1.1  christos 	}
    850           1.1  christos 	| type_qualifier_list
    851           1.1  christos 	;
    852           1.1  christos 
    853           1.1  christos type_qualifier_list
    854           1.1  christos 	: type_qualifier
    855           1.1  christos 	{
    856           1.1  christos 	    (void)sprintf($$.text, "%s ", $1.text);
    857           1.1  christos 	    $$.begin = $1.begin;
    858           1.1  christos 	    free($1.text);
    859           1.1  christos 	}
    860           1.1  christos 	| type_qualifier_list type_qualifier
    861           1.1  christos 	{
    862  1.1.1.7.16.1  christos 	    (void)sprintf($$.text, "%.*s%.*s ", TEXT_LEN, $1.text, TEXT_LEN, $2.text);
    863           1.1  christos 	    $$.begin = $1.begin;
    864           1.1  christos 	    free($2.text);
    865           1.1  christos 	}
    866           1.1  christos 	;
    867           1.1  christos 
    868           1.1  christos parameter_type_list
    869           1.1  christos 	: parameter_list
    870           1.1  christos 	| parameter_list ',' T_ELLIPSIS
    871           1.1  christos 	{
    872           1.1  christos 	    add_ident_list(&$$, &$1, "...");
    873           1.1  christos 	}
    874           1.1  christos 	;
    875           1.1  christos 
    876           1.1  christos parameter_list
    877           1.1  christos 	: parameter_declaration
    878           1.1  christos 	{
    879           1.1  christos 	    new_param_list(&$$, $1);
    880           1.1  christos 	}
    881           1.1  christos 	| parameter_list ',' parameter_declaration
    882           1.1  christos 	{
    883           1.1  christos 	    add_param_list(&$$, &$1, $3);
    884           1.1  christos 	}
    885           1.1  christos 	;
    886           1.1  christos 
    887           1.1  christos parameter_declaration
    888           1.1  christos 	: decl_specifiers declarator
    889           1.1  christos 	{
    890           1.1  christos 	    check_untagged(&$1);
    891           1.1  christos 	    $$ = new_parameter(&$1, $2);
    892           1.1  christos 	}
    893           1.1  christos 	| decl_specifiers abs_declarator
    894           1.1  christos 	{
    895           1.1  christos 	    check_untagged(&$1);
    896           1.1  christos 	    $$ = new_parameter(&$1, $2);
    897           1.1  christos 	}
    898           1.1  christos 	| decl_specifiers
    899           1.1  christos 	{
    900           1.1  christos 	    check_untagged(&$1);
    901           1.1  christos 	    $$ = new_parameter(&$1, (Declarator *)0);
    902           1.1  christos 	}
    903           1.1  christos 	;
    904           1.1  christos 
    905           1.1  christos opt_identifier_list
    906           1.1  christos 	: /* empty */
    907           1.1  christos 	{
    908           1.1  christos 	    new_ident_list(&$$);
    909           1.1  christos 	}
    910           1.1  christos 	| identifier_list
    911           1.1  christos 	;
    912           1.1  christos 
    913           1.1  christos identifier_list
    914           1.1  christos 	: any_id
    915           1.1  christos 	{
    916           1.1  christos 	    new_ident_list(&$$);
    917           1.1  christos 	    add_ident_list(&$$, &$$, $1.text);
    918           1.1  christos 	}
    919           1.1  christos 	| identifier_list ',' any_id
    920           1.1  christos 	{
    921           1.1  christos 	    add_ident_list(&$$, &$1, $3.text);
    922           1.1  christos 	}
    923           1.1  christos 	;
    924           1.1  christos 
    925           1.1  christos identifier_or_ref
    926           1.1  christos 	: any_id
    927           1.1  christos 	{
    928           1.1  christos 	    $$ = $1;
    929           1.1  christos 	}
    930           1.1  christos 	| '&' any_id
    931           1.1  christos 	{
    932           1.1  christos #if OPT_LINTLIBRARY
    933           1.1  christos 	    if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */
    934           1.1  christos 		$$ = $2;
    935           1.1  christos 	    } else
    936           1.1  christos #endif
    937  1.1.1.7.16.1  christos 		(void)sprintf($$.text, "&%.*s", TEXT_LEN, $2.text);
    938           1.1  christos 	    $$.begin = $1.begin;
    939           1.1  christos 	}
    940           1.1  christos 	;
    941           1.1  christos 
    942           1.1  christos abs_declarator
    943           1.1  christos 	: pointer
    944           1.1  christos 	{
    945           1.1  christos 	    $$ = new_declarator($1.text, "", $1.begin);
    946           1.1  christos 	}
    947           1.1  christos 	| pointer direct_abs_declarator
    948           1.1  christos 	{
    949           1.1  christos 	    $$ = $2;
    950  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $1.text, TEXT_LEN, $$->text);
    951           1.1  christos 	    free($$->text);
    952           1.1  christos 	    $$->text = xstrdup(buf);
    953           1.1  christos 	    $$->begin = $1.begin;
    954           1.1  christos 	}
    955           1.1  christos 	| direct_abs_declarator
    956           1.1  christos 	;
    957           1.1  christos 
    958           1.1  christos direct_abs_declarator
    959           1.1  christos 	: '(' abs_declarator ')'
    960           1.1  christos 	{
    961           1.1  christos 	    $$ = $2;
    962  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "(%.*s)", TEXT_LEN, $$->text);
    963           1.1  christos 	    free($$->text);
    964           1.1  christos 	    $$->text = xstrdup(buf);
    965           1.1  christos 	    $$->begin = $1.begin;
    966           1.1  christos 	}
    967           1.1  christos 	| direct_abs_declarator T_BRACKETS
    968           1.1  christos 	{
    969           1.1  christos 	    $$ = $1;
    970  1.1.1.7.16.1  christos 	    (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $$->text, TEXT_LEN, $2.text);
    971           1.1  christos 	    free($$->text);
    972           1.1  christos 	    $$->text = xstrdup(buf);
    973           1.1  christos 	}
    974           1.1  christos 	| T_BRACKETS
    975           1.1  christos 	{
    976           1.1  christos 	    $$ = new_declarator($1.text, "", $1.begin);
    977           1.1  christos 	}
    978           1.1  christos 	| direct_abs_declarator '(' parameter_type_list ')'
    979           1.1  christos 	{
    980           1.1  christos 	    $$ = new_declarator("%s()", "", $1->begin);
    981           1.1  christos 	    $$->params = $3;
    982           1.1  christos 	    $$->func_stack = $1;
    983           1.1  christos 	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
    984           1.1  christos 	    $$->func_def = FUNC_ANSI;
    985           1.1  christos 	}
    986           1.1  christos 	| direct_abs_declarator '(' ')'
    987           1.1  christos 	{
    988           1.1  christos 	    $$ = new_declarator("%s()", "", $1->begin);
    989           1.1  christos 	    $$->func_stack = $1;
    990           1.1  christos 	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
    991           1.1  christos 	    $$->func_def = FUNC_ANSI;
    992           1.1  christos 	}
    993           1.1  christos 	| '(' parameter_type_list ')'
    994           1.1  christos 	{
    995           1.1  christos 	    Declarator *d;
    996           1.1  christos 
    997           1.1  christos 	    d = new_declarator("", "", $1.begin);
    998           1.1  christos 	    $$ = new_declarator("%s()", "", $1.begin);
    999           1.1  christos 	    $$->params = $2;
   1000           1.1  christos 	    $$->func_stack = d;
   1001           1.1  christos 	    $$->head = $$;
   1002           1.1  christos 	    $$->func_def = FUNC_ANSI;
   1003           1.1  christos 	}
   1004           1.1  christos 	| '(' ')'
   1005           1.1  christos 	{
   1006           1.1  christos 	    Declarator *d;
   1007           1.1  christos 
   1008           1.1  christos 	    d = new_declarator("", "", $1.begin);
   1009           1.1  christos 	    $$ = new_declarator("%s()", "", $1.begin);
   1010           1.1  christos 	    $$->func_stack = d;
   1011           1.1  christos 	    $$->head = $$;
   1012           1.1  christos 	    $$->func_def = FUNC_ANSI;
   1013           1.1  christos 	}
   1014           1.1  christos 	;
   1015           1.1  christos 
   1016           1.1  christos %%
   1017           1.1  christos 
   1018       1.1.1.2  christos /* lex.yy.c */
   1019       1.1.1.2  christos #define BEGIN yy_start = 1 + 2 *
   1020       1.1.1.2  christos 
   1021       1.1.1.2  christos #define CPP1 1
   1022       1.1.1.2  christos #define INIT1 2
   1023       1.1.1.2  christos #define INIT2 3
   1024       1.1.1.2  christos #define CURLY 4
   1025       1.1.1.2  christos #define LEXYACC 5
   1026       1.1.1.2  christos #define ASM 6
   1027       1.1.1.2  christos #define CPP_INLINE 7
   1028       1.1.1.2  christos 
   1029       1.1.1.2  christos extern char *yytext;
   1030       1.1.1.2  christos extern FILE *yyin, *yyout;
   1031       1.1.1.2  christos 
   1032       1.1.1.2  christos static int curly;			/* number of curly brace nesting levels */
   1033       1.1.1.2  christos static int ly_count;			/* number of occurances of %% */
   1034       1.1.1.2  christos static int inc_depth;			/* include nesting level */
   1035       1.1.1.2  christos static SymbolTable *included_files;	/* files already included */
   1036       1.1.1.2  christos static int yy_start = 0;		/* start state number */
   1037       1.1.1.2  christos 
   1038       1.1.1.2  christos #define grammar_error(s) yaccError(s)
   1039           1.1  christos 
   1040           1.1  christos static void
   1041       1.1.1.2  christos yaccError (const char *msg)
   1042           1.1  christos {
   1043           1.1  christos     func_params = NULL;
   1044           1.1  christos     put_error();		/* tell what line we're on, and what file */
   1045           1.1  christos     fprintf(stderr, "%s at token '%s'\n", msg, yytext);
   1046           1.1  christos }
   1047           1.1  christos 
   1048           1.1  christos /* Initialize the table of type qualifier keywords recognized by the lexical
   1049           1.1  christos  * analyzer.
   1050           1.1  christos  */
   1051           1.1  christos void
   1052           1.1  christos init_parser (void)
   1053           1.1  christos {
   1054       1.1.1.2  christos     static const char *keywords[] = {
   1055           1.1  christos 	"const",
   1056           1.1  christos 	"restrict",
   1057           1.1  christos 	"volatile",
   1058           1.1  christos 	"interrupt",
   1059           1.1  christos #ifdef vms
   1060           1.1  christos 	"noshare",
   1061           1.1  christos 	"readonly",
   1062           1.1  christos #endif
   1063           1.1  christos #if defined(MSDOS) || defined(OS2)
   1064           1.1  christos 	"__cdecl",
   1065           1.1  christos 	"__export",
   1066           1.1  christos 	"__far",
   1067           1.1  christos 	"__fastcall",
   1068           1.1  christos 	"__fortran",
   1069           1.1  christos 	"__huge",
   1070           1.1  christos 	"__inline",
   1071           1.1  christos 	"__interrupt",
   1072           1.1  christos 	"__loadds",
   1073           1.1  christos 	"__near",
   1074           1.1  christos 	"__pascal",
   1075           1.1  christos 	"__saveregs",
   1076           1.1  christos 	"__segment",
   1077           1.1  christos 	"__stdcall",
   1078           1.1  christos 	"__syscall",
   1079           1.1  christos 	"_cdecl",
   1080           1.1  christos 	"_cs",
   1081           1.1  christos 	"_ds",
   1082           1.1  christos 	"_es",
   1083           1.1  christos 	"_export",
   1084           1.1  christos 	"_far",
   1085           1.1  christos 	"_fastcall",
   1086           1.1  christos 	"_fortran",
   1087           1.1  christos 	"_huge",
   1088           1.1  christos 	"_interrupt",
   1089           1.1  christos 	"_loadds",
   1090           1.1  christos 	"_near",
   1091           1.1  christos 	"_pascal",
   1092           1.1  christos 	"_saveregs",
   1093           1.1  christos 	"_seg",
   1094           1.1  christos 	"_segment",
   1095           1.1  christos 	"_ss",
   1096           1.1  christos 	"cdecl",
   1097           1.1  christos 	"far",
   1098           1.1  christos 	"huge",
   1099           1.1  christos 	"near",
   1100           1.1  christos 	"pascal",
   1101           1.1  christos #ifdef OS2
   1102           1.1  christos 	"__far16",
   1103           1.1  christos #endif
   1104           1.1  christos #endif
   1105           1.1  christos #ifdef __GNUC__
   1106           1.1  christos 	/* gcc aliases */
   1107           1.1  christos 	"__builtin_va_arg",
   1108           1.1  christos 	"__builtin_va_list",
   1109           1.1  christos 	"__const",
   1110           1.1  christos 	"__const__",
   1111           1.1  christos 	"__inline",
   1112           1.1  christos 	"__inline__",
   1113           1.1  christos 	"__restrict",
   1114           1.1  christos 	"__restrict__",
   1115           1.1  christos 	"__volatile",
   1116           1.1  christos 	"__volatile__",
   1117           1.1  christos #endif
   1118           1.1  christos     };
   1119           1.1  christos     unsigned i;
   1120           1.1  christos 
   1121           1.1  christos     /* Initialize type qualifier table. */
   1122           1.1  christos     type_qualifiers = new_symbol_table();
   1123           1.1  christos     for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) {
   1124           1.1  christos 	new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE);
   1125           1.1  christos     }
   1126           1.1  christos }
   1127           1.1  christos 
   1128           1.1  christos /* Process the C source file.  Write function prototypes to the standard
   1129           1.1  christos  * output.  Convert function definitions and write the converted source
   1130           1.1  christos  * code to a temporary file.
   1131           1.1  christos  */
   1132           1.1  christos void
   1133           1.1  christos process_file (FILE *infile, char *name)
   1134           1.1  christos {
   1135           1.1  christos     char *s;
   1136           1.1  christos 
   1137           1.1  christos     if (strlen(name) > 2) {
   1138           1.1  christos 	s = name + strlen(name) - 2;
   1139           1.1  christos 	if (*s == '.') {
   1140           1.1  christos 	    ++s;
   1141           1.1  christos 	    if (*s == 'l' || *s == 'y')
   1142           1.1  christos 		BEGIN LEXYACC;
   1143           1.1  christos #if defined(MSDOS) || defined(OS2)
   1144           1.1  christos 	    if (*s == 'L' || *s == 'Y')
   1145           1.1  christos 		BEGIN LEXYACC;
   1146           1.1  christos #endif
   1147           1.1  christos 	}
   1148           1.1  christos     }
   1149           1.1  christos 
   1150           1.1  christos     included_files = new_symbol_table();
   1151           1.1  christos     typedef_names = new_symbol_table();
   1152           1.1  christos     define_names = new_symbol_table();
   1153           1.1  christos     inc_depth = -1;
   1154           1.1  christos     curly = 0;
   1155           1.1  christos     ly_count = 0;
   1156           1.1  christos     func_params = NULL;
   1157           1.1  christos     yyin = infile;
   1158           1.1  christos     include_file(strcpy(base_file, name), func_style != FUNC_NONE);
   1159           1.1  christos     if (file_comments) {
   1160           1.1  christos #if OPT_LINTLIBRARY
   1161           1.1  christos     	if (lintLibrary()) {
   1162           1.1  christos 	    put_blankline(stdout);
   1163           1.1  christos 	    begin_tracking();
   1164           1.1  christos 	}
   1165           1.1  christos #endif
   1166           1.1  christos 	put_string(stdout, "/* ");
   1167           1.1  christos 	put_string(stdout, cur_file_name());
   1168           1.1  christos 	put_string(stdout, " */\n");
   1169           1.1  christos     }
   1170           1.1  christos     yyparse();
   1171           1.1  christos     free_symbol_table(define_names);
   1172           1.1  christos     free_symbol_table(typedef_names);
   1173           1.1  christos     free_symbol_table(included_files);
   1174           1.1  christos }
   1175           1.1  christos 
   1176           1.1  christos #ifdef NO_LEAKS
   1177           1.1  christos void
   1178           1.1  christos free_parser(void)
   1179           1.1  christos {
   1180           1.1  christos     free_symbol_table (type_qualifiers);
   1181           1.1  christos #ifdef FLEX_SCANNER
   1182           1.1  christos     if (yy_current_buffer != 0)
   1183           1.1  christos 	yy_delete_buffer(yy_current_buffer);
   1184           1.1  christos #endif
   1185           1.1  christos }
   1186           1.1  christos #endif
   1187