File: grammar.y

package info (click to toggle)
c2man 2.41-11
  • links: PTS
  • area: main
  • in suites: potato
  • size: 800 kB
  • ctags: 863
  • sloc: ansic: 6,559; sh: 5,236; yacc: 839; lex: 621; makefile: 229; perl: 81
file content (947 lines) | stat: -rw-r--r-- 19,440 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
/* $Id: grammar.y,v 2.0.1.18 1996/03/21 08:49:02 greyham Exp $
 *
 * yacc grammar for C manual page generator
 * This was derived from the grammar given in Appendix A of
 * "The C Programming Language" by Kernighan and Ritchie.
 */

/* identifiers that are not reserved words */
%token T_IDENTIFIER T_TYPEDEF_NAME

/* storage class */
%token T_AUTO T_EXTERN T_REGISTER T_STATIC T_TYPEDEF
/* This keyword included for compatibility with C++. */
%token T_INLINE

/* type specifiers */
%token T_CHAR T_DOUBLE T_FLOAT T_INT T_VOID
%token T_LONG T_SHORT T_SIGNED T_UNSIGNED
%token T_ENUM T_STRUCT T_UNION

/* type qualifiers */
%token T_CONST T_VOLATILE
/* These keywords included for compatibility with MSDOS C compilers. */
%token T_CDECL T_FAR T_HUGE T_INTERRUPT T_NEAR T_PASCAL

/* paired braces and everything between them: { ... } */
%token T_BRACES

/* paired square brackets and everything between them: [ ... ] */
%token T_BRACKETS

/* three periods */
%token T_ELLIPSIS

/* equal sign followed by constant expression or stuff between braces */
%token T_INITIALIZER

/* string literal */
%token T_STRING_LITERAL

/* text inside a regular comment, and one at the end of a non-empty line */
%token T_COMMENT T_EOLCOMMENT

%type <declaration> declaration
%type <parameter> function_definition
%type <decl_spec> declaration_specifiers declaration_specifier
%type <decl_spec> storage_class type_specifier type_qualifier
%type <decl_spec> struct_or_union_specifier enum_specifier
%type <decl_list> declarator_list init_declarator_list
%type <declarator> init_declarator declarator direct_declarator
%type <declarator> parameter_declarator abstract_parameter_declarator
%type <declarator> abstract_declarator direct_abstract_declarator
%type <param_list> parameter_type_list parameter_list
%type <parameter> parameter_declaration
%type <param_list> opt_identifier_list identifier_list
%type <enumerator> enumerator
%type <enum_list> enumerator_list
%type <identifier> identifier
%type <text> struct_or_union
%type <text> pointer type_qualifier_list
%type <text> opt_comment opt_eolcomment
%type <text> any_id T_IDENTIFIER T_TYPEDEF_NAME
%type <text> T_BRACKETS
%type <text> T_COMMENT T_EOLCOMMENT T_STRING_LITERAL

%{
#include "c2man.h"
#include "semantic.h"
#include "strconcat.h"
#include "strappend.h"
#include "manpage.h"
#include "enum.h"

#ifdef I_STDARG
#include <stdarg.h>
#endif
#ifdef I_VARARGS
#include <varargs.h>
#endif

int yylex();

#define YYMAXDEPTH 150

/* where are we up to scanning through an enum? */
static enum { NOENUM, KEYWORD, BRACES } enum_state = NOENUM;

/* Pointer to parameter list for the current function definition. */
static ParameterList *func_params;

/* Table of typedef names */
SymbolTable *typedef_names;

boolean first_comment;	/* are we still looking for the first comment? */
static char *body_comment = NULL;/* last comment found at start of func body */
%}
%%

program
	: /* empty */
	| translation_unit
	;

translation_unit
	: external_declaration
	| translation_unit external_declaration
	;

external_declaration
	: declaration opt_eolcomment
	{
	    remember_declarations(NULL, &$1.decl_spec, &$1.decl_list, $2);
	}
	| T_COMMENT declaration opt_eolcomment
	{
	    remember_declarations($1, &$2.decl_spec, &$2.decl_list, $3);
	}
	| function_definition opt_eolcomment
	{
	    if (look_at_body_start && body_comment) {	
				/* Use the body comment */
	      new_manual_page(body_comment,&$1.decl_spec,$1.declarator);
	      body_comment = NULL; /* Prevent it being free'ed */
	    } else {
	      free_declarator($1.declarator);
	      free_decl_spec(&$1.decl_spec);
	    }
	}
	| T_COMMENT function_definition opt_eolcomment
	{
	    if (body_start_only) {
	      if (body_comment) {
		new_manual_page(body_comment,&$2.decl_spec,$2.declarator);
		body_comment = NULL; /* Prevent it being free'ed */
	      } else {
		free_declarator($2.declarator);
		free_decl_spec(&$2.decl_spec);
		safe_free($1);
	      }      
	    } else {
	      new_manual_page($1,&$2.decl_spec,$2.declarator);
	    }
	    safe_free($3);
	}
	| function_definition ';' opt_eolcomment
	{
	    if (look_at_body_start && body_comment) {
	      new_manual_page(body_comment,&$1.decl_spec,$1.declarator);
	      body_comment = NULL; /* Prevent it being free'ed */
	    } else {
	      free_declarator($1.declarator);
	      free_decl_spec(&$1.decl_spec);
	    }
	    safe_free($3);
	}
	| T_COMMENT function_definition ';' opt_eolcomment
	{
	    if (body_start_only) {
	      if (body_comment) {
		new_manual_page(body_comment,&$2.decl_spec,$2.declarator);
		body_comment = NULL; /* Prevent it being free'ed */
	      } else {
		free_declarator($2.declarator);
		free_decl_spec(&$2.decl_spec);
		safe_free($1);
	      }      
	    } else {
	      new_manual_page($1,&$2.decl_spec,$2.declarator);
	    }
	    safe_free($4);
	}
	| linkage_specification
	| T_COMMENT T_EOLCOMMENT
	{
	    free($1);
	    free($2);
	}
	| T_COMMENT
	{
	    if (inbasefile && first_comment)
	    {
		remember_terse($1);
		first_comment = FALSE;
	    }
	    free($1);
	}
	| T_EOLCOMMENT
	{
	    free($1);
	}
	| error ';'
	{
	    yyerrok;
	}
	;

linkage_specification
	: T_EXTERN T_STRING_LITERAL T_BRACES
	{
	    /* Provide an empty action here so bison will not complain about
	     * incompatible types in the default action it normally would
	     * have generated.
	     */
	}
	| T_EXTERN T_STRING_LITERAL declaration
	{
	    /* empty */
	}
	;

function_definition
	: declaration_specifiers declarator opt_eolcomment
	{
	    if ($2->type != DECL_FUNCTION) {
		yyerror("syntax error");
		YYERROR;
	    }
	    func_params = &($2->head->params);
            if ($3)	comment_last_parameter(&$2->head->params, $3);
	}
	  opt_declaration_list T_BRACES
	{
	    func_params = NULL;
	    $2->type = DECL_FUNCDEF;

	    $$.decl_spec = $1;
	    $$.declarator = $2;
	}
	| declarator opt_eolcomment
	{
	    if ($1->type != DECL_FUNCTION) {
		yyerror("syntax error");
		YYERROR;
	    }
	    func_params = &($1->head->params);
            if ($2)	comment_last_parameter(&$1->head->params, $2);
	}
	  opt_declaration_list T_BRACES
	{
	    DeclSpec	decl_spec;

	    func_params = NULL;
	    $1->type = DECL_FUNCDEF;

	    new_decl_spec(&$$.decl_spec, "int", DS_NONE);
	    $$.declarator = $1;
	}
	;

declaration
	: declaration_specifiers ';'
	{
	    $$.decl_spec = $1;
	    $$.decl_list.first = NULL;
	}
	| declaration_specifiers init_declarator_list ';'
	{
	    $$.decl_spec = $1;
	    $$.decl_list = $2;
	}
	| T_TYPEDEF declaration_specifiers declarator_list ';'
	{
	    new_typedef_symbols(&$2,&$3);
	    $$.decl_spec = $2;
	    $$.decl_list = $3;
	}
	;

declarator_list
	: declarator
	{
	    new_decl_list(&$$, $1);
	}
        | declarator_list ',' opt_eolcomment declarator
        {
            if ($3)	comment_last_decl(&$1, $3);
            add_decl_list(&$$, &$1, $4);
        }
        | declarator_list opt_eolcomment
        {
            $$ = $1;
            if ($2)	comment_last_decl(&$1, $2);
        }
	;

opt_declaration_list
	: /* empty */
	| declaration_list
	| declaration_list T_ELLIPSIS
	;

declaration_list
	: opt_comment declaration opt_eolcomment
	{
	    set_param_types(func_params, &$2.decl_spec, &$2.decl_list, $1, $3);
	}
	| declaration_list opt_comment declaration opt_eolcomment
	{
	    set_param_types(func_params, &$3.decl_spec, &$3.decl_list, $2, $4);
	}
	;

declaration_specifiers
	: declaration_specifier
	| declaration_specifiers declaration_specifier
	{
	    join_decl_specs(&$$, &$1, &$2);
	}
	;

declaration_specifier
	: storage_class
	| type_specifier
	| type_qualifier
	;

storage_class
	: T_AUTO
	{
	    new_decl_spec(&$$, "auto", DS_NONE);
	}
	| T_EXTERN
	{
	    new_decl_spec(&$$, "extern", DS_EXTERN);
	}
	| T_REGISTER
	{
	    new_decl_spec(&$$, "register", DS_NONE);
	}
	| T_STATIC
	{
	    new_decl_spec(&$$, "static", DS_STATIC);
	}
	| T_INLINE
	{
	    new_decl_spec(&$$, "inline", DS_INLINE);
	}
	;

type_specifier
	: T_CHAR
	{
	    new_decl_spec(&$$, "char", DS_CHAR);
	}
	| T_DOUBLE
	{
	    new_decl_spec(&$$, "double", DS_NONE);
	}
	| T_FLOAT
	{
	    new_decl_spec(&$$, "float", DS_FLOAT);
	}
	| T_INT
	{
	    new_decl_spec(&$$, "int", DS_NONE);
	}
	| T_LONG
	{
	    new_decl_spec(&$$, "long", DS_NONE);
	}
	| T_SHORT
	{
	    new_decl_spec(&$$, "short", DS_SHORT);
	}
	| T_SIGNED
	{
	    new_decl_spec(&$$, "signed", DS_NONE);
	}
	| T_UNSIGNED
	{
	    new_decl_spec(&$$, "unsigned", DS_NONE);
	}
	| T_VOID
	{
	    new_decl_spec(&$$, "void", DS_NONE);
	}
	| struct_or_union_specifier
	| enum_specifier
	| T_TYPEDEF_NAME
	{
	    Symbol *s = find_symbol(typedef_names, $1);
	   
	    new_enum_decl_spec(&$$, $1, s->flags,
		s->valtype == SYMVAL_ENUM ? s->value.enum_list
					  : (EnumeratorList *)NULL);
	}
	;

type_qualifier
	: T_CONST
	{
	    new_decl_spec(&$$, "const", DS_NONE);
	}
	| T_VOLATILE
	{
	    new_decl_spec(&$$, "volatile", DS_NONE);
	}
	| T_CDECL
	{
	    new_decl_spec(&$$, "cdecl", DS_NONE);
	}
	| T_INTERRUPT
	{
	    new_decl_spec(&$$, "interrupt", DS_NONE);
	}
	| T_FAR
	{
	    new_decl_spec(&$$, "far", DS_NONE);
	}
	| T_HUGE
	{
	    new_decl_spec(&$$, "huge", DS_NONE);
	}
	| T_NEAR
	{
	    new_decl_spec(&$$, "near", DS_NONE);
	}
	| T_PASCAL
	{
	    new_decl_spec(&$$, "pascal", DS_NONE);
	}
	;

struct_or_union_specifier
	: struct_or_union any_id T_BRACES
	{
	    dyn_decl_spec(&$$, strconcat($1, " ",$2," {}",NULLCP), DS_NONE);
	    free($2);
	}
	| struct_or_union T_BRACES
	{
	    dyn_decl_spec(&$$, strconcat($1," {}",NULLCP), DS_NONE);
	}
	| struct_or_union any_id
	{
	    dyn_decl_spec(&$$, strconcat($1, " ",$2,NULLCP), DS_NONE);
	    free($2);
	}
	;

struct_or_union
	: T_STRUCT
	{
	    $$ = "struct";
	}
	| T_UNION
	{
	    $$ = "union";
	}
	;

init_declarator_list
	: init_declarator
	{
	    new_decl_list(&$$, $1);
	}
        | init_declarator_list ',' opt_eolcomment init_declarator
        {
            if ($3)	comment_last_decl(&$1, $3);
            add_decl_list(&$$, &$1, $4);
        }
        | init_declarator_list opt_eolcomment
        {
            $$ = $1;
            if ($2)	comment_last_decl(&$1, $2);
        }
	;

init_declarator
	: declarator
	| declarator T_INITIALIZER
	;

enum_specifier
	: T_ENUM any_id '{' opt_eolcomment enumerator_list '}'
	{
	    add_enum_symbol($2, $5);
	    new_enum_decl_spec(&$$, strconcat("enum ",$2," {}",NULLCP),
		   DS_NONE, $5);
	    free($2);
	    safe_free($4);
	    enum_state = NOENUM;
	}
	| T_ENUM '{' opt_eolcomment enumerator_list '}'
	{
	    new_enum_decl_spec(&$$, strduplicate("enum {}"), DS_NONE, $4);
	    safe_free($3);
	    enum_state = NOENUM;
	}
	| T_ENUM any_id
	{
	    new_enum_decl_spec(&$$, strconcat("enum ",$2,NULLCP), DS_NONE,
	    	find_enum_symbol($2));
	    free($2);
	    enum_state = NOENUM;
	}
	;

enumerator_list
	: enumerator
	{
	    $$ = new_enumerator_list(&$1);
	}
	| enumerator_list ',' opt_eolcomment enumerator
	{
	    $$ = $1;
	    if ($3)	comment_last_enumerator($$, $3);
	    add_enumerator_list($$, &$4);
	}
	| enumerator_list opt_eolcomment
	{
	    $$ = $1;
	    if ($2)	comment_last_enumerator($$, $2);
	}
	| enumerator_list ',' opt_eolcomment
	{
	    $$ = $1;
	    if ($3)     comment_last_enumerator($$, $3);
	}
	;
	
enumerator
	: identifier
	{
	    new_enumerator(&$$,$1.name,$1.comment_before,$1.comment_after);
	}
	;
	
any_id
	: T_IDENTIFIER
	| T_TYPEDEF_NAME
	| any_id T_COMMENT
	{
	    $$ = $1;
	    free($2);
	}
	| any_id T_EOLCOMMENT
	{
	    $$ = $1;
	    free($2);
	}
	;

declarator
	: pointer T_EOLCOMMENT direct_declarator
	{
	    char *newtext = strappend($1,$3->text,NULLCP);
	    free($3->text);
	    $$ = $3;
	    $$->text = newtext;
	    if ($$->type == DECL_SIMPLE)
		$$->type = DECL_COMPOUND;
	    $$->retcomment = $2;
	}
	| pointer direct_declarator
	{
	    char *newtext = strappend($1,$2->text,NULLCP);
	    free($2->text);
	    $$ = $2;
	    $$->text = newtext;
	    if ($$->type == DECL_SIMPLE)
		$$->type = DECL_COMPOUND;
	}
	| T_EOLCOMMENT direct_declarator
	{
	    $$ = $2;
	    $$->retcomment = $1;
	}
	| direct_declarator
	{
	    $$ = $1;
	}
	;

parameter_declarator
	: pointer direct_declarator
	{
	    char *newtext = strappend($1,$2->text,NULLCP);
	    free($2->text);
	    $$ = $2;
	    $$->text = newtext;
	    if ($$->type == DECL_SIMPLE)
		$$->type = DECL_COMPOUND;
	}
	| direct_declarator
	{
	    $$ = $1;
	}
	;

direct_declarator
	: T_IDENTIFIER
	{
	    $$ = new_declarator($1, strduplicate($1));
	}
	| '(' declarator ')'
	{
	    char *newtext = strconcat("(",$2->text,")",NULLCP);
	    free($2->text);
	    $$ = $2;
	    $$->text = newtext;
	}
	| direct_declarator T_BRACKETS
	{
	    $$ = $1;
	    $$->text = strappend($1->text,$2,NULLCP);
	    free($2);
	}
	| direct_declarator '(' parameter_type_list ')'
	{
	    $$ = new_declarator(strduplicate("%s()"), strduplicate($1->name));
	    $$->params = $3;
	    $$->func_stack = $1;
	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
	    $$->type = ($1->type == DECL_SIMPLE) ? DECL_FUNCTION : $1->type;
	}
	| direct_declarator '(' opt_identifier_list ')'
	{
	    $$ = new_declarator(strduplicate("%s()"), strduplicate($1->name));
	    $$->params = $3;
	    $$->func_stack = $1;
	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
	    $$->type = ($1->type == DECL_SIMPLE) ? DECL_FUNCTION : $1->type;
	}
	;

pointer
	: '*' type_qualifier_list
	{
	    $$ = strconcat("*",$2, NULLCP);
	    safe_free($2);
	}
	| '*' type_qualifier_list pointer
	{
	    $$ = $2 ? strconcat("*",$2, $3, NULLCP)
		    : strconcat("*", $3, NULLCP);
	    safe_free($2);
	    free($3);
	}
	;

type_qualifier_list
	: /* empty */
	{
	    $$ = NULL;
	}
	| type_qualifier_list type_qualifier
	{
	    $$ = $1 ? strconcat($1," ",$2.text," ",NULLCP)
		    : strconcat($2.text," ",NULLCP);
	    safe_free($1);
	    free_decl_spec(&$2);
	}
	;

parameter_type_list
	: parameter_list opt_eolcomment
	{
	    $$ = $1;
	    if ($2)	comment_last_parameter(&$1, $2);
	}
	| parameter_list ',' opt_eolcomment
		opt_comment T_ELLIPSIS opt_comment opt_eolcomment
	{
	    Identifier ellipsis;

	    if ($3)	comment_last_parameter(&$1, $3);
	    ellipsis.name = strduplicate("...");

	    if ($4 && $6 && $7)
	    {
		yyerror("ellipsis parameter has multiple comments");
		free($7);
		free($6);
		free($4);
		ellipsis.comment_before = ellipsis.comment_after = NULL;
	    }
	    else
	    {
		ellipsis.comment_before = $4;
		ellipsis.comment_after = $6 ? $6 : $7;
	    }

	    add_ident_list(&$$, &$1, &ellipsis);
	}
	;

parameter_list
	: parameter_declaration
	{
	    new_param_list(&$$, &$1);
	}
	| parameter_list ',' opt_eolcomment parameter_declaration
	{
	    if ($3)	comment_last_parameter(&$1, $3);
	    add_param_list(&$$, &$1, &$4);
	}
	;

parameter_declaration
	: opt_comment declaration_specifiers parameter_declarator opt_comment
	{
	    new_parameter(&$$, &$2, $3, $1, $4);
	}
	| opt_comment declaration_specifiers abstract_parameter_declarator opt_comment
	{
	    new_parameter(&$$, &$2, $3, $1, $4);
	}
	| opt_comment declaration_specifiers opt_comment
	{
	    new_parameter(&$$, &$2, (Declarator *)NULL, $1, $3);
	}
	;

opt_identifier_list
	: /* empty */
	{
	    new_ident_list(&$$);
	}
	| identifier_list opt_eolcomment
	{
	    $$ = $1;
	    if ($2)	comment_last_parameter(&$1, $2);
	}
	;

identifier_list
	: identifier
	{
	    new_ident_list(&$$);
	    add_ident_list(&$$, &$$, &$1);
	}
	| identifier_list ',' opt_eolcomment identifier
	{
	    if ($3)	comment_last_parameter(&$1, $3);
	    add_ident_list(&$$, &$1, &$4);
	}
	;

identifier
	: opt_comment T_IDENTIFIER opt_comment
	{
	    $$.comment_before = $1;
	    $$.comment_after = $3;
	    $$.name = $2;
	}
	
abstract_declarator
	: pointer
	{
	    $$ = new_declarator($1, NULLCP);
	}
	| pointer T_EOLCOMMENT direct_abstract_declarator
	{
	    char *newtext = strappend($1,$3->text,NULLCP);
	    free($3->text);
	    $$ = $3;
	    $$->text = newtext;
	    if ($$->type == DECL_SIMPLE)
		$$->type = DECL_COMPOUND;
	    $$->retcomment = $2;
	}
	| pointer direct_abstract_declarator
	{
	    char *newtext = strappend($1,$2->text,NULLCP);
	    free($2->text);
	    $$ = $2;
	    $$->text = newtext;
	    if ($$->type == DECL_SIMPLE)
		$$->type = DECL_COMPOUND;
	}
	| T_EOLCOMMENT direct_abstract_declarator
	{
	    $$ = $2;
	    $$->retcomment = $1;
	}
	| direct_abstract_declarator
	{
	    $$ = $1;
	}
	;

abstract_parameter_declarator
	: pointer
	{
	    $$ = new_declarator($1, NULLCP);
	}
	| pointer direct_abstract_declarator
	{
	    char *newtext = strappend($1,$2->text,NULLCP);
	    free($2->text);
	    $$ = $2;
	    $$->text = newtext;
	    if ($$->type == DECL_SIMPLE)
		$$->type = DECL_COMPOUND;
	}
	| direct_abstract_declarator
	{
	    $$ = $1;
	}
	;

direct_abstract_declarator
	: '(' abstract_declarator ')'
	{
	    char *newtext = strconcat("(",$2->text,")",NULLCP);
	    free($2->text);
	    $$ = $2;
	    $$->text = newtext;
	}
	| direct_abstract_declarator T_BRACKETS
	{
	    $$ = $1;
	    $$->text = strappend($1->text,$2,NULLCP);
	    free($2);
	}
	| T_BRACKETS
	{
	    $$ = new_declarator($1, NULLCP);
	}
	| direct_abstract_declarator '(' parameter_type_list ')'
	{
	    $$ = new_declarator(strduplicate("%s()"), NULLCP);
	    $$->params = $3;
	    $$->func_stack = $1;
	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
	    $$->type = ($1->type == DECL_SIMPLE) ? DECL_FUNCTION : $1->type;
	}
	| direct_abstract_declarator '(' ')'
	{
	    $$ = new_declarator(strduplicate("%s()"), NULLCP);
	    $$->func_stack = $1;
	    $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
	    $$->type = ($1->type == DECL_SIMPLE) ? DECL_FUNCTION : $1->type;
	}
	| '(' parameter_type_list ')'
	{
	    Declarator *d;
	    
	    d = new_declarator(NULL, NULL);
	    $$ = new_declarator(strduplicate("%s()"), NULLCP);
	    $$->params = $2;
	    $$->func_stack = d;
	    $$->head = $$;
	}
	| '(' ')'
	{
	    Declarator *d;
	    
	    d = new_declarator(NULL, NULL);
	    $$ = new_declarator(strduplicate("%s()"), NULLCP);
	    $$->func_stack = d;
	    $$->head = $$;
	}
	;

opt_comment
	: /* empty */
	{
	    $$ = NULL;
	}
	| T_COMMENT
	;

opt_eolcomment
	: /* empty */
	{
	    $$ = NULL;
	}
	| T_EOLCOMMENT
	;

%%
#ifdef MSDOS
#include "lex_yy.c"
#else
#ifdef VMS
#include "lexyy.c"
#else
#include "lex.yy.c"
#endif /* !VMS   */
#endif /* !MSDOS */

#ifdef I_STDARG
void yyerror(const char *format, ...)
#else
void yyerror(va_alist)
    va_dcl
#endif
{
#ifndef I_STDARG
    const char *format;
#endif
    va_list args;

    output_error();

#ifdef I_STDARG
    va_start(args, format);
#else
    va_start(args);
    format = va_arg(args, char *);
#endif

    vfprintf(stderr, format, args);
    va_end(args);
    putc('.',stderr);
    putc('\n',stderr);
}

void
parse_file (start_file)
const char *start_file;
{
    const char *s;
#ifdef FLEX_SCANNER
    static boolean restart = FALSE;
#endif

    cur_file = start_file ? strduplicate(start_file) : NULL;

    if (basefile && strlen(basefile) > 2) {
	s = basefile + strlen(basefile) - 2;
	if (strcmp(s, ".l") == 0 || strcmp(s, ".y") == 0)
	    BEGIN LEXYACC;
    }

    typedef_names = create_symbol_table();
    enum_table = create_symbol_table();

    line_num = 1;
    ly_count = 0;
    first_comment = group_together && !terse_specified;

    /* flex needs a yyrestart before every file but the first */
#ifdef FLEX_SCANNER
    if (restart)	yyrestart(yyin);
    restart = TRUE;
#endif

    yyparse();

    destroy_symbol_table(enum_table);
    destroy_symbol_table(typedef_names);

    safe_free(cur_file);
}