1 /* A Bison parser, made by GNU Bison 1.875a. */
2
3 /* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
25
26 /* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
28
29 /* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
35
36 /* Identify Bison output. */
37 #define YYBISON 1
38
39 /* Skeleton name. */
40 #define YYSKELETON_NAME "yacc.c"
41
42 /* Pure parsers. */
43 #define YYPURE 0
44
45 /* Using locations. */
46 #define YYLSP_NEEDED 1
47
48
49
50 /* Tokens. */
51 #ifndef YYTOKENTYPE
52 # define YYTOKENTYPE
53 /* Put the tokens into the symbol table, so that GDB and other debuggers
54 know about them. */
55 enum yytokentype {
56 IDENTIFIER = 258,
57 ACTION = 259,
58 TERMINATE = 260,
59 CSOURCE = 261,
60 CPART = 262,
61 TYPE = 263,
62 STRING = 264,
63 UNDERSCORE_STRINGS = 265,
64 INIT = 266,
65 DEFITEM = 267,
66 OPTION = 268,
67 REST = 269,
68 HELPNODE = 270,
69 OBLIGATORY = 271,
70 INCOMPATIBLE = 272,
71 DATA = 273,
72 AS = 274,
73 OPTIONAL = 275
74 };
75 #endif
76 #define IDENTIFIER 258
77 #define ACTION 259
78 #define TERMINATE 260
79 #define CSOURCE 261
80 #define CPART 262
81 #define TYPE 263
82 #define STRING 264
83 #define UNDERSCORE_STRINGS 265
84 #define INIT 266
85 #define DEFITEM 267
86 #define OPTION 268
87 #define REST 269
88 #define HELPNODE 270
89 #define OBLIGATORY 271
90 #define INCOMPATIBLE 272
91 #define DATA 273
92 #define AS 274
93 #define OPTIONAL 275
94
95
96
97
98 /* Copy the first part of user declarations. */
99 #line 1 "gaa_parser.y"
100
101 /*
102 * Copyright (C) 1998,1999 Joran Maille
103 * Portions Copyright (C) 2002 Nikos Mavroyanopoulos
104 *
105 * This file is part of GAA-ng.
106 *
107 * GAA-ng is free software; you can redistribute it and/or modify
108 * it under the terms of the GNU General Public License as published by
109 * the Free Software Foundation; either version 2 of the License, or
110 * (at your option) any later version.
111 *
112 * GAA-ng is distributed in the hope that it will be useful,
113 * but WITHOUT ANY WARRANTY; without even the implied warranty of
114 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
115 * GNU General Public License for more details.
116 *
117 * You should have received a copy of the GNU General Public License
118 * along with this program; if not, write to the Free Software
119 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
120 */
121
122 /* needed in newer bisons for yytoknum.
123 */
124 #define YYPRINT
125 #define YYERROR_VERBOSE
126
127 #include <stdio.h>
128 #include <stdlib.h>
129 #include <string.h>
130 #include <ctype.h>
131 #include "../config.h"
132
133 #include "gaaout.h"
134
135 #define NEW(x,first, tmp) \
136 tmp = (x*) malloc(sizeof(x)); \
137 tmp->next = first; \
138 first = tmp;
139
140 #define GAA_NOREST -1
141
142 #define GAA_SINGLE 0
143 #define GAA_LIST 1
144
145 #define GAA_OBLIGAT 1
146 #define GAA_INCOMP 2
147 #define GAAMAX_ARGLIST_COUNT 30
148
149
150 #define LOOKUP(first, tmp, id, key, _line) \
151 for(tmp = first; tmp != NULL; tmp = tmp->next) \
152 { \
153 if(tmp->id == key) \
154 { \
155 fprintf(stderr, "%s:%d: identifier '%s' redefined\n", st_in, _line, num2str(key)); \
156 fprintf(stderr, "%s:%d: this is the location of the previous definition\n", st_in, tmp->line); \
157 error_flag = 1; \
158 } \
159 }
160
161 #define SUPERLOOKUP(id, key, line) \
162 LOOKUP(first_option, option_tmp, id, key, line);
163
164 FILE* glb_fd, *glb_skel;
165 FILE* glb_out;
166 FILE* glb_sfd; /* emulates stdin */
167
168 int glb_underscore_strings = 0;
169
170 int yyerror( char* s); /* Called by yyparse on error */
171 int yylex();
172
173 int type = 0;
174 extern int num_lines; /* current line */
175 char* st_in; /* hold input_filename */
176
177 struct _option;
178 struct _option_argless;
179 struct _arg;
180 struct _type;
181 struct _help;
182 struct _struct_elt;
183
184 typedef struct _option option;
185 typedef struct _arg arg;
186 typedef struct _atype atype;
187 typedef struct _struct_elt struct_elt;
188 typedef struct _help help;
189 typedef struct _condition condition;
190
191
192 int k_needed = 0, init_loc = -1, rest_nb_arg = 0;
193 int error_flag = 0;
194
195 int rest_type = GAA_NOREST, rest_action = 0;
196 int c_code = 0;
197 int nb_option = 0, nb_option_argless = 0, nb_atype = 0, nb_struct_elt = 0, nb_help = 0;
198 option *option_tmp, *first_option = NULL;
199 atype *atype_tmp, *first_atype = NULL;
200 struct_elt *struct_elt_tmp, *first_struct_elt = NULL;
201 help *help_tmp, *first_help = NULL;
202 arg *arg_tmp, *first_rest_arg = NULL;
203 condition *condition_tmp, *first_condition = NULL;
204
205 char* num2str(int n);
206 int get_id_line(int n);
207
208 struct _help
209 {
210 int str;
211 int line;
212 help *next;
213 };
214
get_help(int num)215 help* get_help(int num)
216 {
217 int i;
218 help *tmp;
219 tmp = first_help;
220 for(i = 0; (i < num) && (tmp !=NULL); i++)
221 tmp = tmp->next;
222 if(tmp == NULL)
223 {
224 fprintf(stderr, "%s: '%d' out of range\n", st_in, num);
225 exit(1);
226 }
227 return tmp;
228 }
229
230 struct _option
231 {
232 int id1, id2;
233 int action;
234 int help;
235 int nb_arg;
236 arg *fa;
237 int line;
238 option *next;
239 };
240
get_option(int num)241 option* get_option(int num)
242 {
243 int i;
244 option *tmp;
245 tmp = first_option;
246 for(i = 0; (i < num) && (tmp !=NULL); i++)
247 tmp = tmp->next;
248 if(tmp == NULL)
249 {
250 fprintf(stderr, "%s: '%d' out of range\n", st_in, num);
251 exit(1);
252 }
253 return tmp;
254 }
255
256 struct _condition
257 {
258 int type;
259 int options;
260 condition *next;
261 };
262
263
264 struct _arg
265 {
266 int type;
267 int help;
268 int id;
269 arg *next;
270 };
271
get_arg(int numOpt,int num)272 arg* get_arg(int numOpt, int num)
273 {
274 int i;
275 arg *tmp;
276 tmp = (get_option(numOpt))->fa;
277 for(i = 0; (i < num) && (tmp !=NULL); i++)
278 tmp = tmp->next;
279 if(tmp == NULL)
280 {
281 fprintf(stderr, "%s: '%d' out of range\n", st_in, num);
282 exit(1);
283 }
284 return tmp;
285 }
286
287
288
289 struct _atype
290 {
291 int id;
292 int fnName;
293 int argtype;
294 int line;
295 char* type_str;
296 atype *next;
297 };
298
get_atype(int num)299 atype* get_atype(int num)
300 {
301 int i;
302 atype *tmp;
303 tmp = first_atype;
304 for(i = 0; (i < num) && (tmp !=NULL); i++)
305 tmp = tmp->next;
306 if(tmp == NULL)
307 {
308 fprintf(stderr, "%s: '%d' out of range\n", st_in, num);
309 exit(1);
310 }
311 return tmp;
312 }
get_atype_from_id(int num)313 atype* get_atype_from_id(int num)
314 {
315 int i;
316 atype *tmp;
317 tmp = first_atype;
318 for(i = 0; (tmp!=NULL) && (tmp->id != num); i++) {
319 tmp = tmp->next;
320 }
321 if(tmp == NULL)
322 {
323 fprintf(stderr, "%s:%d: identifier '%s' out of range\n", st_in,
324 get_id_line(num), num2str(num));
325 exit(1);
326 }
327 return tmp;
328 }
329
get_type(arg * in)330 atype* get_type(arg *in)
331 {
332 int i;
333 atype *tmp = first_atype;
334 for(i = 0; i < nb_atype; i++)
335 {
336 if(in->id == tmp->id)
337 return tmp;
338 tmp = tmp->next;
339 }
340 fprintf(stderr, "%s:%d: Unknown type '%s'.\n", st_in, num_lines - 1, num2str(in->id));
341 exit(1);
342 }
343
344
345 struct _struct_elt
346 {
347 int data; /* 0 for '#' statement, 1 for 'DATA' 'AS' statement */
348 int type; /* only if data == 1 GAA_LIST / GAA_SINGLE */
349 int id; /* only if data == 1 */
350 int arg_type; /* only if data == 1 */
351 int location; /* only if data == 0 */
352 struct_elt *next;
353 };
354
get_struct_elt(int num)355 struct_elt* get_struct_elt(int num)
356 {
357 int i;
358 struct_elt *tmp;
359 tmp = first_struct_elt;
360 for(i = 0; (i < num) && (tmp !=NULL); i++)
361 tmp = tmp->next;
362 if(tmp == NULL)
363 {
364 printf("Out of range\n");
365 exit(1);
366 }
367 return tmp;
368 };
369
read_str(FILE * fd,int offset,char ** target,char separator)370 void read_str(FILE* fd, int offset, char **target, char separator)
371 {
372 int i, size = -1;
373 int a;
374 fseek(fd, offset, SEEK_SET);
375 do
376 {
377 if( (a=fgetc( fd)) == EOF)
378 {
379 printf("Read error\n");
380 exit(1);
381 }
382 size++;
383 }
384 while(a != separator);
385 *target = malloc(size+1);
386 fseek(fd, offset, SEEK_SET);
387 for(i = 0; i < size; i++)
388 {
389 if( (a=fgetc(fd)) == EOF)
390 {
391 printf("Read error\n");
392 exit(1);
393 }
394 (*target)[i] = a;
395 }
396 (*target)[size] = 0;
397 }
398
399 /* append is appended to the string output */
copy_str(FILE * fd,int offset,FILE * out,const char * append)400 void copy_str(FILE* fd, int offset, FILE* out, const char* append)
401 {
402 int a = '"', b, last = ' ';
403 int flag;
404
405 fseek(fd, offset-1, SEEK_SET);
406 if( (a=fgetc(fd)) == EOF)
407 {
408 printf("Read error\n");
409 exit(1);
410 }
411 while(a == '"' || a == '%')
412 {
413 b = a;
414 if(a == '"') {
415 if (glb_underscore_strings!=0) fputs("_(", out);
416 fprintf(out,"%c", '"');
417 }
418 flag = 1;
419 do
420 {
421 if( (a=fgetc(fd)) == EOF)
422 {
423 printf("Read error\n");
424 exit(1);
425 }
426 if((a == b) && (last != '\\'))
427 {
428 if(flag == 1)
429 flag = 0;
430 else
431 flag = 1;
432 }
433 if((flag == 1) || (a == b && b != '%'))
434 {
435 if (a=='"' && append!=NULL) fputs( append, out);
436 fprintf(out, "%c", a);
437 if (a=='"' && glb_underscore_strings!=0) fputs(")", out);
438 }
439 last = a;
440 }
441 while(flag == 1);
442 do
443 {
444 if( (a=fgetc(fd)) == EOF)
445 {
446 return;
447 }
448 }
449 while ((a == ' ' || a == '\r' || a == '\t' || a == '\n'));
450 }
451 }
452
453
454
455 /* Enabling traces. */
456 #ifndef YYDEBUG
457 # define YYDEBUG 0
458 #endif
459
460 /* Enabling verbose error messages. */
461 #ifdef YYERROR_VERBOSE
462 # undef YYERROR_VERBOSE
463 # define YYERROR_VERBOSE 1
464 #else
465 # define YYERROR_VERBOSE 0
466 #endif
467
468 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
469 typedef int YYSTYPE;
470 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
471 # define YYSTYPE_IS_DECLARED 1
472 # define YYSTYPE_IS_TRIVIAL 1
473 #endif
474
475 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
476 typedef struct YYLTYPE
477 {
478 int first_line;
479 int first_column;
480 int last_line;
481 int last_column;
482 } YYLTYPE;
483 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
484 # define YYLTYPE_IS_DECLARED 1
485 # define YYLTYPE_IS_TRIVIAL 1
486 #endif
487
488
489 /* Copy the second part of user declarations. */
490
491
492 /* Line 214 of yacc.c. */
493 #line 494 "gaa_parser.c"
494
495 #if ! defined (yyoverflow) || YYERROR_VERBOSE
496
497 /* The parser invokes alloca or malloc; define the necessary symbols. */
498
499 # if YYSTACK_USE_ALLOCA
500 # define YYSTACK_ALLOC alloca
501 # else
502 # ifndef YYSTACK_USE_ALLOCA
503 # if defined (alloca) || defined (_ALLOCA_H)
504 # define YYSTACK_ALLOC alloca
505 # else
506 # ifdef __GNUC__
507 # define YYSTACK_ALLOC __builtin_alloca
508 # endif
509 # endif
510 # endif
511 # endif
512
513 # ifdef YYSTACK_ALLOC
514 /* Pacify GCC's `empty if-body' warning. */
515 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
516 # else
517 # if defined (__STDC__) || defined (__cplusplus)
518 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
519 # define YYSIZE_T size_t
520 # endif
521 # define YYSTACK_ALLOC malloc
522 # define YYSTACK_FREE free
523 # endif
524 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
525
526
527 #if (! defined (yyoverflow) \
528 && (! defined (__cplusplus) \
529 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
530
531 /* A type that is properly aligned for any stack member. */
532 union yyalloc
533 {
534 short yyss;
535 YYSTYPE yyvs;
536 YYLTYPE yyls;
537 };
538
539 /* The size of the maximum gap between one aligned stack and the next. */
540 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
541
542 /* The size of an array large to enough to hold all stacks, each with
543 N elements. */
544 # define YYSTACK_BYTES(N) \
545 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
546 + 2 * YYSTACK_GAP_MAXIMUM)
547
548 /* Copy COUNT objects from FROM to TO. The source and destination do
549 not overlap. */
550 # ifndef YYCOPY
551 # if 1 < __GNUC__
552 # define YYCOPY(To, From, Count) \
553 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
554 # else
555 # define YYCOPY(To, From, Count) \
556 do \
557 { \
558 register YYSIZE_T yyi; \
559 for (yyi = 0; yyi < (Count); yyi++) \
560 (To)[yyi] = (From)[yyi]; \
561 } \
562 while (0)
563 # endif
564 # endif
565
566 /* Relocate STACK from its old location to the new one. The
567 local variables YYSIZE and YYSTACKSIZE give the old and new number of
568 elements in the stack, and YYPTR gives the new location of the
569 stack. Advance YYPTR to a properly aligned location for the next
570 stack. */
571 # define YYSTACK_RELOCATE(Stack) \
572 do \
573 { \
574 YYSIZE_T yynewbytes; \
575 YYCOPY (&yyptr->Stack, Stack, yysize); \
576 Stack = &yyptr->Stack; \
577 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
578 yyptr += yynewbytes / sizeof (*yyptr); \
579 } \
580 while (0)
581
582 #endif
583
584 #if defined (__STDC__) || defined (__cplusplus)
585 typedef signed char yysigned_char;
586 #else
587 typedef short yysigned_char;
588 #endif
589
590 /* YYFINAL -- State number of the termination state. */
591 #define YYFINAL 30
592 /* YYLAST -- Last index in YYTABLE. */
593 #define YYLAST 73
594
595 /* YYNTOKENS -- Number of terminals. */
596 #define YYNTOKENS 25
597 /* YYNNTS -- Number of nonterminals. */
598 #define YYNNTS 8
599 /* YYNRULES -- Number of rules. */
600 #define YYNRULES 28
601 /* YYNRULES -- Number of states. */
602 #define YYNSTATES 55
603
604 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
605 #define YYUNDEFTOK 2
606 #define YYMAXUTOK 275
607
608 #define YYTRANSLATE(YYX) \
609 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
610
611 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
612 static const unsigned char yytranslate[] =
613 {
614 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
615 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
616 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
617 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
618 22, 23, 21, 2, 24, 2, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
621 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
623 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
625 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
626 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
627 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
628 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
629 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
630 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
631 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
632 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
633 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
634 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
635 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
636 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
637 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
638 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
639 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
640 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
641 15, 16, 17, 18, 19, 20
642 };
643
644 #if YYDEBUG
645 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
646 YYRHS. */
647 static const unsigned char yyprhs[] =
648 {
649 0, 0, 3, 6, 8, 11, 13, 16, 18, 21,
650 22, 24, 27, 30, 34, 36, 39, 41, 44, 46,
651 51, 54, 57, 62, 70, 80, 84, 87, 90
652 };
653
654 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
655 static const yysigned_char yyrhs[] =
656 {
657 26, 0, -1, 27, 5, -1, 27, -1, 6, 27,
658 -1, 32, -1, 27, 32, -1, 3, -1, 21, 3,
659 -1, -1, 30, -1, 20, 30, -1, 28, 9, -1,
660 28, 9, 30, -1, 28, -1, 28, 30, -1, 9,
661 -1, 31, 9, -1, 7, -1, 18, 3, 19, 28,
662 -1, 15, 31, -1, 11, 4, -1, 12, 3, 3,
663 7, -1, 13, 22, 3, 23, 29, 4, 31, -1,
664 13, 22, 3, 24, 3, 23, 29, 4, 31, -1,
665 14, 29, 4, -1, 16, 3, -1, 17, 3, -1,
666 10, -1
667 };
668
669 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
670 static const unsigned short yyrline[] =
671 {
672 0, 381, 381, 382, 383, 387, 388, 391, 395, 401,
673 405, 411, 418, 425, 432, 439, 448, 451, 456, 463,
674 480, 491, 492, 501, 544, 593, 617, 624, 631
675 };
676 #endif
677
678 #if YYDEBUG || YYERROR_VERBOSE
679 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
680 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
681 static const char *const yytname[] =
682 {
683 "$end", "error", "$undefined", "IDENTIFIER", "ACTION", "TERMINATE",
684 "CSOURCE", "CPART", "TYPE", "STRING", "UNDERSCORE_STRINGS", "\"init\"",
685 "\"defitem\"", "\"option\"", "\"rest\"", "\"helpnode\"", "\"obligat\"",
686 "\"incomp\"", "\"data\"", "\"as\"", "\"optional\"", "'*'", "'('", "')'",
687 "','", "$accept", "input", "source", "arg", "arg_list", "arg_real_list",
688 "many_strings", "line", 0
689 };
690 #endif
691
692 # ifdef YYPRINT
693 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
694 token YYLEX-NUM. */
695 static const unsigned short yytoknum[] =
696 {
697 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
698 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
699 275, 42, 40, 41, 44
700 };
701 # endif
702
703 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
704 static const unsigned char yyr1[] =
705 {
706 0, 25, 26, 26, 26, 27, 27, 28, 28, 29,
707 29, 30, 30, 30, 30, 30, 31, 31, 32, 32,
708 32, 32, 32, 32, 32, 32, 32, 32, 32
709 };
710
711 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
712 static const unsigned char yyr2[] =
713 {
714 0, 2, 2, 1, 2, 1, 2, 1, 2, 0,
715 1, 2, 2, 3, 1, 2, 1, 2, 1, 4,
716 2, 2, 4, 7, 9, 3, 2, 2, 1
717 };
718
719 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
720 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
721 means the default is an error. */
722 static const unsigned char yydefact[] =
723 {
724 0, 0, 18, 28, 0, 0, 0, 9, 0, 0,
725 0, 0, 0, 3, 5, 4, 21, 0, 0, 7,
726 0, 0, 14, 0, 10, 16, 20, 26, 27, 0,
727 1, 2, 6, 0, 0, 11, 8, 12, 15, 25,
728 17, 0, 22, 9, 0, 13, 19, 0, 0, 0,
729 9, 23, 0, 0, 24
730 };
731
732 /* YYDEFGOTO[NTERM-NUM]. */
733 static const yysigned_char yydefgoto[] =
734 {
735 -1, 12, 13, 22, 23, 24, 26, 14
736 };
737
738 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
739 STATE-NUM. */
740 #define YYPACT_NINF -43
741 static const yysigned_char yypact[] =
742 {
743 31, 43, -43, -43, 8, 12, -18, -1, 15, 23,
744 24, 36, 40, 18, -43, 43, -43, 48, 49, -43,
745 -1, 59, -3, 60, -43, -43, 54, -43, -43, 46,
746 -43, -43, -43, 61, -13, -43, -43, -1, -43, -43,
747 -43, 0, -43, -1, 63, -43, -43, 65, 44, 15,
748 -1, 54, 66, 15, 54
749 };
750
751 /* YYPGOTO[NTERM-NUM]. */
752 static const yysigned_char yypgoto[] =
753 {
754 -43, -43, 70, 32, -42, -15, -40, 1
755 };
756
757 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
758 positive, shift that token. If negative, reduce the rule which
759 number is the opposite. If zero, do what YYDEFACT says.
760 If YYTABLE_NINF, syntax error. */
761 #define YYTABLE_NINF -1
762 static const unsigned char yytable[] =
763 {
764 19, 47, 19, 19, 18, 35, 37, 38, 52, 51,
765 43, 44, 16, 54, 32, 17, 32, 20, 21, 20,
766 21, 21, 45, 31, 25, 2, 27, 28, 3, 4,
767 5, 6, 7, 8, 9, 10, 11, 1, 2, 29,
768 30, 3, 4, 5, 6, 7, 8, 9, 10, 11,
769 2, 33, 34, 3, 4, 5, 6, 7, 8, 9,
770 10, 11, 36, 40, 39, 41, 48, 50, 42, 49,
771 53, 15, 0, 46
772 };
773
774 static const yysigned_char yycheck[] =
775 {
776 3, 43, 3, 3, 22, 20, 9, 22, 50, 49,
777 23, 24, 4, 53, 13, 3, 15, 20, 21, 20,
778 21, 21, 37, 5, 9, 7, 3, 3, 10, 11,
779 12, 13, 14, 15, 16, 17, 18, 6, 7, 3,
780 0, 10, 11, 12, 13, 14, 15, 16, 17, 18,
781 7, 3, 3, 10, 11, 12, 13, 14, 15, 16,
782 17, 18, 3, 9, 4, 19, 3, 23, 7, 4,
783 4, 1, -1, 41
784 };
785
786 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
787 symbol of state STATE-NUM. */
788 static const unsigned char yystos[] =
789 {
790 0, 6, 7, 10, 11, 12, 13, 14, 15, 16,
791 17, 18, 26, 27, 32, 27, 4, 3, 22, 3,
792 20, 21, 28, 29, 30, 9, 31, 3, 3, 3,
793 0, 5, 32, 3, 3, 30, 3, 9, 30, 4,
794 9, 19, 7, 23, 24, 30, 28, 29, 3, 4,
795 23, 31, 29, 4, 31
796 };
797
798 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
799 # define YYSIZE_T __SIZE_TYPE__
800 #endif
801 #if ! defined (YYSIZE_T) && defined (size_t)
802 # define YYSIZE_T size_t
803 #endif
804 #if ! defined (YYSIZE_T)
805 # if defined (__STDC__) || defined (__cplusplus)
806 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
807 # define YYSIZE_T size_t
808 # endif
809 #endif
810 #if ! defined (YYSIZE_T)
811 # define YYSIZE_T unsigned int
812 #endif
813
814 #define yyerrok (yyerrstatus = 0)
815 #define yyclearin (yychar = YYEMPTY)
816 #define YYEMPTY (-2)
817 #define YYEOF 0
818
819 #define YYACCEPT goto yyacceptlab
820 #define YYABORT goto yyabortlab
821 #define YYERROR do \
822 { \
823 yylerrsp = yylsp; \
824 *++yylerrsp = yyloc; \
825 goto yyerrlab1; \
826 } \
827 while (0)
828
829
830 /* Like YYERROR except do call yyerror. This remains here temporarily
831 to ease the transition to the new meaning of YYERROR, for GCC.
832 Once GCC version 2 has supplanted version 1, this can go. */
833
834 #define YYFAIL goto yyerrlab
835
836 #define YYRECOVERING() (!!yyerrstatus)
837
838 #define YYBACKUP(Token, Value) \
839 do \
840 if (yychar == YYEMPTY && yylen == 1) \
841 { \
842 yychar = (Token); \
843 yylval = (Value); \
844 yytoken = YYTRANSLATE (yychar); \
845 YYPOPSTACK; \
846 goto yybackup; \
847 } \
848 else \
849 { \
850 yyerror ("syntax error: cannot back up");\
851 YYERROR; \
852 } \
853 while (0)
854
855 #define YYTERROR 1
856 #define YYERRCODE 256
857
858 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
859 are run). */
860
861 #ifndef YYLLOC_DEFAULT
862 # define YYLLOC_DEFAULT(Current, Rhs, N) \
863 Current.first_line = Rhs[1].first_line; \
864 Current.first_column = Rhs[1].first_column; \
865 Current.last_line = Rhs[N].last_line; \
866 Current.last_column = Rhs[N].last_column;
867 #endif
868
869 /* YYLEX -- calling `yylex' with the right arguments. */
870
871 #ifdef YYLEX_PARAM
872 # define YYLEX yylex (YYLEX_PARAM)
873 #else
874 # define YYLEX yylex ()
875 #endif
876
877 /* Enable debugging if requested. */
878 #if YYDEBUG
879
880 # ifndef YYFPRINTF
881 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
882 # define YYFPRINTF fprintf
883 # endif
884
885 # define YYDPRINTF(Args) \
886 do { \
887 if (yydebug) \
888 YYFPRINTF Args; \
889 } while (0)
890
891 # define YYDSYMPRINT(Args) \
892 do { \
893 if (yydebug) \
894 yysymprint Args; \
895 } while (0)
896
897 # define YYDSYMPRINTF(Title, Token, Value, Location) \
898 do { \
899 if (yydebug) \
900 { \
901 YYFPRINTF (stderr, "%s ", Title); \
902 yysymprint (stderr, \
903 Token, Value, Location); \
904 YYFPRINTF (stderr, "\n"); \
905 } \
906 } while (0)
907
908 /*------------------------------------------------------------------.
909 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
910 | TOP (cinluded). |
911 `------------------------------------------------------------------*/
912
913 #if defined (__STDC__) || defined (__cplusplus)
914 static void
yy_stack_print(short * bottom,short * top)915 yy_stack_print (short *bottom, short *top)
916 #else
917 static void
918 yy_stack_print (bottom, top)
919 short *bottom;
920 short *top;
921 #endif
922 {
923 YYFPRINTF (stderr, "Stack now");
924 for (/* Nothing. */; bottom <= top; ++bottom)
925 YYFPRINTF (stderr, " %d", *bottom);
926 YYFPRINTF (stderr, "\n");
927 }
928
929 # define YY_STACK_PRINT(Bottom, Top) \
930 do { \
931 if (yydebug) \
932 yy_stack_print ((Bottom), (Top)); \
933 } while (0)
934
935
936 /*------------------------------------------------.
937 | Report that the YYRULE is going to be reduced. |
938 `------------------------------------------------*/
939
940 #if defined (__STDC__) || defined (__cplusplus)
941 static void
yy_reduce_print(int yyrule)942 yy_reduce_print (int yyrule)
943 #else
944 static void
945 yy_reduce_print (yyrule)
946 int yyrule;
947 #endif
948 {
949 int yyi;
950 unsigned int yylineno = yyrline[yyrule];
951 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
952 yyrule - 1, yylineno);
953 /* Print the symbols being reduced, and their result. */
954 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
955 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
956 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
957 }
958
959 # define YY_REDUCE_PRINT(Rule) \
960 do { \
961 if (yydebug) \
962 yy_reduce_print (Rule); \
963 } while (0)
964
965 /* Nonzero means print parse trace. It is left uninitialized so that
966 multiple parsers can coexist. */
967 int yydebug;
968 #else /* !YYDEBUG */
969 # define YYDPRINTF(Args)
970 # define YYDSYMPRINT(Args)
971 # define YYDSYMPRINTF(Title, Token, Value, Location)
972 # define YY_STACK_PRINT(Bottom, Top)
973 # define YY_REDUCE_PRINT(Rule)
974 #endif /* !YYDEBUG */
975
976
977 /* YYINITDEPTH -- initial size of the parser's stacks. */
978 #ifndef YYINITDEPTH
979 # define YYINITDEPTH 200
980 #endif
981
982 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
983 if the built-in stack extension method is used).
984
985 Do not make this value too large; the results are undefined if
986 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
987 evaluated with infinite-precision integer arithmetic. */
988
989 #if YYMAXDEPTH == 0
990 # undef YYMAXDEPTH
991 #endif
992
993 #ifndef YYMAXDEPTH
994 # define YYMAXDEPTH 10000
995 #endif
996
997
998
999 #if YYERROR_VERBOSE
1000
1001 # ifndef yystrlen
1002 # if defined (__GLIBC__) && defined (_STRING_H)
1003 # define yystrlen strlen
1004 # else
1005 /* Return the length of YYSTR. */
1006 static YYSIZE_T
1007 # if defined (__STDC__) || defined (__cplusplus)
yystrlen(const char * yystr)1008 yystrlen (const char *yystr)
1009 # else
1010 yystrlen (yystr)
1011 const char *yystr;
1012 # endif
1013 {
1014 register const char *yys = yystr;
1015
1016 while (*yys++ != '\0')
1017 continue;
1018
1019 return yys - yystr - 1;
1020 }
1021 # endif
1022 # endif
1023
1024 # ifndef yystpcpy
1025 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
1026 # define yystpcpy stpcpy
1027 # else
1028 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1029 YYDEST. */
1030 static char *
1031 # if defined (__STDC__) || defined (__cplusplus)
yystpcpy(char * yydest,const char * yysrc)1032 yystpcpy (char *yydest, const char *yysrc)
1033 # else
1034 yystpcpy (yydest, yysrc)
1035 char *yydest;
1036 const char *yysrc;
1037 # endif
1038 {
1039 register char *yyd = yydest;
1040 register const char *yys = yysrc;
1041
1042 while ((*yyd++ = *yys++) != '\0')
1043 continue;
1044
1045 return yyd - 1;
1046 }
1047 # endif
1048 # endif
1049
1050 #endif /* !YYERROR_VERBOSE */
1051
1052
1053
1054 #if YYDEBUG
1055 /*--------------------------------.
1056 | Print this symbol on YYOUTPUT. |
1057 `--------------------------------*/
1058
1059 #if defined (__STDC__) || defined (__cplusplus)
1060 static void
yysymprint(FILE * yyoutput,int yytype,YYSTYPE * yyvaluep,YYLTYPE * yylocationp)1061 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1062 #else
1063 static void
1064 yysymprint (yyoutput, yytype, yyvaluep, yylocationp)
1065 FILE *yyoutput;
1066 int yytype;
1067 YYSTYPE *yyvaluep;
1068 YYLTYPE *yylocationp;
1069 #endif
1070 {
1071 /* Pacify ``unused variable'' warnings. */
1072 (void) yyvaluep;
1073 (void) yylocationp;
1074
1075 if (yytype < YYNTOKENS)
1076 {
1077 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1078 # ifdef YYPRINT
1079 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1080 # endif
1081 }
1082 else
1083 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1084
1085 switch (yytype)
1086 {
1087 default:
1088 break;
1089 }
1090 YYFPRINTF (yyoutput, ")");
1091 }
1092
1093 #endif /* ! YYDEBUG */
1094 /*-----------------------------------------------.
1095 | Release the memory associated to this symbol. |
1096 `-----------------------------------------------*/
1097
1098 #if defined (__STDC__) || defined (__cplusplus)
1099 static void
yydestruct(int yytype,YYSTYPE * yyvaluep,YYLTYPE * yylocationp)1100 yydestruct (int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1101 #else
1102 static void
1103 yydestruct (yytype, yyvaluep, yylocationp)
1104 int yytype;
1105 YYSTYPE *yyvaluep;
1106 YYLTYPE *yylocationp;
1107 #endif
1108 {
1109 /* Pacify ``unused variable'' warnings. */
1110 (void) yyvaluep;
1111 (void) yylocationp;
1112
1113 switch (yytype)
1114 {
1115
1116 default:
1117 break;
1118 }
1119 }
1120
1121
1122 /* Prevent warnings from -Wmissing-prototypes. */
1123
1124 #ifdef YYPARSE_PARAM
1125 # if defined (__STDC__) || defined (__cplusplus)
1126 int yyparse (void *YYPARSE_PARAM);
1127 # else
1128 int yyparse ();
1129 # endif
1130 #else /* ! YYPARSE_PARAM */
1131 #if defined (__STDC__) || defined (__cplusplus)
1132 int yyparse (void);
1133 #else
1134 int yyparse ();
1135 #endif
1136 #endif /* ! YYPARSE_PARAM */
1137
1138
1139
1140 /* The lookahead symbol. */
1141 int yychar;
1142
1143 /* The semantic value of the lookahead symbol. */
1144 YYSTYPE yylval;
1145
1146 /* Number of syntax errors so far. */
1147 int yynerrs;
1148 /* Location data for the lookahead symbol. */
1149 YYLTYPE yylloc;
1150
1151
1152
1153 /*----------.
1154 | yyparse. |
1155 `----------*/
1156
1157 #ifdef YYPARSE_PARAM
1158 # if defined (__STDC__) || defined (__cplusplus)
yyparse(void * YYPARSE_PARAM)1159 int yyparse (void *YYPARSE_PARAM)
1160 # else
1161 int yyparse (YYPARSE_PARAM)
1162 void *YYPARSE_PARAM;
1163 # endif
1164 #else /* ! YYPARSE_PARAM */
1165 #if defined (__STDC__) || defined (__cplusplus)
1166 int
1167 yyparse (void)
1168 #else
1169 int
1170 yyparse ()
1171
1172 #endif
1173 #endif
1174 {
1175
1176 register int yystate;
1177 register int yyn;
1178 int yyresult;
1179 /* Number of tokens to shift before error messages enabled. */
1180 int yyerrstatus;
1181 /* Lookahead token as an internal (translated) token number. */
1182 int yytoken = 0;
1183
1184 /* Three stacks and their tools:
1185 `yyss': related to states,
1186 `yyvs': related to semantic values,
1187 `yyls': related to locations.
1188
1189 Refer to the stacks thru separate pointers, to allow yyoverflow
1190 to reallocate them elsewhere. */
1191
1192 /* The state stack. */
1193 short yyssa[YYINITDEPTH];
1194 short *yyss = yyssa;
1195 register short *yyssp;
1196
1197 /* The semantic value stack. */
1198 YYSTYPE yyvsa[YYINITDEPTH];
1199 YYSTYPE *yyvs = yyvsa;
1200 register YYSTYPE *yyvsp;
1201
1202 /* The location stack. */
1203 YYLTYPE yylsa[YYINITDEPTH];
1204 YYLTYPE *yyls = yylsa;
1205 YYLTYPE *yylsp;
1206 YYLTYPE *yylerrsp;
1207
1208 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
1209
1210 YYSIZE_T yystacksize = YYINITDEPTH;
1211
1212 /* The variables used to return semantic value and location from the
1213 action routines. */
1214 YYSTYPE yyval;
1215 YYLTYPE yyloc;
1216
1217 /* When reducing, the number of symbols on the RHS of the reduced
1218 rule. */
1219 int yylen;
1220
1221 YYDPRINTF ((stderr, "Starting parse\n"));
1222
1223 yystate = 0;
1224 yyerrstatus = 0;
1225 yynerrs = 0;
1226 yychar = YYEMPTY; /* Cause a token to be read. */
1227
1228 /* Initialize stack pointers.
1229 Waste one element of value and location stack
1230 so that they stay on the same level as the state stack.
1231 The wasted elements are never initialized. */
1232
1233 yyssp = yyss;
1234 yyvsp = yyvs;
1235 yylsp = yyls;
1236 goto yysetstate;
1237
1238 /*------------------------------------------------------------.
1239 | yynewstate -- Push a new state, which is found in yystate. |
1240 `------------------------------------------------------------*/
1241 yynewstate:
1242 /* In all cases, when you get here, the value and location stacks
1243 have just been pushed. so pushing a state here evens the stacks.
1244 */
1245 yyssp++;
1246
1247 yysetstate:
1248 *yyssp = yystate;
1249
1250 if (yyss + yystacksize - 1 <= yyssp)
1251 {
1252 /* Get the current used size of the three stacks, in elements. */
1253 YYSIZE_T yysize = yyssp - yyss + 1;
1254
1255 #ifdef yyoverflow
1256 {
1257 /* Give user a chance to reallocate the stack. Use copies of
1258 these so that the &'s don't force the real ones into
1259 memory. */
1260 YYSTYPE *yyvs1 = yyvs;
1261 short *yyss1 = yyss;
1262 YYLTYPE *yyls1 = yyls;
1263
1264 /* Each stack pointer address is followed by the size of the
1265 data in use in that stack, in bytes. This used to be a
1266 conditional around just the two extra args, but that might
1267 be undefined if yyoverflow is a macro. */
1268 yyoverflow ("parser stack overflow",
1269 &yyss1, yysize * sizeof (*yyssp),
1270 &yyvs1, yysize * sizeof (*yyvsp),
1271 &yyls1, yysize * sizeof (*yylsp),
1272 &yystacksize);
1273 yyls = yyls1;
1274 yyss = yyss1;
1275 yyvs = yyvs1;
1276 }
1277 #else /* no yyoverflow */
1278 # ifndef YYSTACK_RELOCATE
1279 goto yyoverflowlab;
1280 # else
1281 /* Extend the stack our own way. */
1282 if (YYMAXDEPTH <= yystacksize)
1283 goto yyoverflowlab;
1284 yystacksize *= 2;
1285 if (YYMAXDEPTH < yystacksize)
1286 yystacksize = YYMAXDEPTH;
1287
1288 {
1289 short *yyss1 = yyss;
1290 union yyalloc *yyptr =
1291 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1292 if (! yyptr)
1293 goto yyoverflowlab;
1294 YYSTACK_RELOCATE (yyss);
1295 YYSTACK_RELOCATE (yyvs);
1296 YYSTACK_RELOCATE (yyls);
1297 # undef YYSTACK_RELOCATE
1298 if (yyss1 != yyssa)
1299 YYSTACK_FREE (yyss1);
1300 }
1301 # endif
1302 #endif /* no yyoverflow */
1303
1304 yyssp = yyss + yysize - 1;
1305 yyvsp = yyvs + yysize - 1;
1306 yylsp = yyls + yysize - 1;
1307
1308 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1309 (unsigned long int) yystacksize));
1310
1311 if (yyss + yystacksize - 1 <= yyssp)
1312 YYABORT;
1313 }
1314
1315 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1316
1317 goto yybackup;
1318
1319 /*-----------.
1320 | yybackup. |
1321 `-----------*/
1322 yybackup:
1323
1324 /* Do appropriate processing given the current state. */
1325 /* Read a lookahead token if we need one and don't already have one. */
1326 /* yyresume: */
1327
1328 /* First try to decide what to do without reference to lookahead token. */
1329
1330 yyn = yypact[yystate];
1331 if (yyn == YYPACT_NINF)
1332 goto yydefault;
1333
1334 /* Not known => get a lookahead token if don't already have one. */
1335
1336 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1337 if (yychar == YYEMPTY)
1338 {
1339 YYDPRINTF ((stderr, "Reading a token: "));
1340 yychar = YYLEX;
1341 }
1342
1343 if (yychar <= YYEOF)
1344 {
1345 yychar = yytoken = YYEOF;
1346 YYDPRINTF ((stderr, "Now at end of input.\n"));
1347 }
1348 else
1349 {
1350 yytoken = YYTRANSLATE (yychar);
1351 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
1352 }
1353
1354 /* If the proper action on seeing token YYTOKEN is to reduce or to
1355 detect an error, take that action. */
1356 yyn += yytoken;
1357 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1358 goto yydefault;
1359 yyn = yytable[yyn];
1360 if (yyn <= 0)
1361 {
1362 if (yyn == 0 || yyn == YYTABLE_NINF)
1363 goto yyerrlab;
1364 yyn = -yyn;
1365 goto yyreduce;
1366 }
1367
1368 if (yyn == YYFINAL)
1369 YYACCEPT;
1370
1371 /* Shift the lookahead token. */
1372 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
1373
1374 /* Discard the token being shifted unless it is eof. */
1375 if (yychar != YYEOF)
1376 yychar = YYEMPTY;
1377
1378 *++yyvsp = yylval;
1379 *++yylsp = yylloc;
1380
1381 /* Count tokens shifted since error; after three, turn off error
1382 status. */
1383 if (yyerrstatus)
1384 yyerrstatus--;
1385
1386 yystate = yyn;
1387 goto yynewstate;
1388
1389
1390 /*-----------------------------------------------------------.
1391 | yydefault -- do the default action for the current state. |
1392 `-----------------------------------------------------------*/
1393 yydefault:
1394 yyn = yydefact[yystate];
1395 if (yyn == 0)
1396 goto yyerrlab;
1397 goto yyreduce;
1398
1399
1400 /*-----------------------------.
1401 | yyreduce -- Do a reduction. |
1402 `-----------------------------*/
1403 yyreduce:
1404 /* yyn is the number of a rule to reduce with. */
1405 yylen = yyr2[yyn];
1406
1407 /* If YYLEN is nonzero, implement the default value of the action:
1408 `$$ = $1'.
1409
1410 Otherwise, the following line sets YYVAL to garbage.
1411 This behavior is undocumented and Bison
1412 users should not rely upon it. Assigning to YYVAL
1413 unconditionally makes the parser a bit smaller, and it avoids a
1414 GCC warning that YYVAL may be used uninitialized. */
1415 yyval = yyvsp[1-yylen];
1416
1417 /* Default location. */
1418 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1419 YY_REDUCE_PRINT (yyn);
1420 switch (yyn)
1421 {
1422 case 2:
1423 #line 381 "gaa_parser.y"
1424 { c_code = yyvsp[0]; }
1425 break;
1426
1427 case 3:
1428 #line 382 "gaa_parser.y"
1429 { c_code = -1; }
1430 break;
1431
1432 case 4:
1433 #line 383 "gaa_parser.y"
1434 { c_code = yyvsp[-1]; }
1435 break;
1436
1437 case 7:
1438 #line 392 "gaa_parser.y"
1439 {
1440 yyval = yyvsp[0];
1441 }
1442 break;
1443
1444 case 8:
1445 #line 396 "gaa_parser.y"
1446 {
1447 yyval = -yyvsp[0];
1448 }
1449 break;
1450
1451 case 9:
1452 #line 401 "gaa_parser.y"
1453 {
1454 yyval = (int)malloc(sizeof(int));
1455 ((int*)yyval)[0] = 0;
1456 }
1457 break;
1458
1459 case 10:
1460 #line 406 "gaa_parser.y"
1461 {
1462 yyval = yyvsp[0];
1463 }
1464 break;
1465
1466 case 11:
1467 #line 412 "gaa_parser.y"
1468 {
1469 yyval = yyvsp[0];
1470 ((int*)yyval)[0]++;
1471 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 1] = 0;
1472 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 2] = -1;
1473 }
1474 break;
1475
1476 case 12:
1477 #line 419 "gaa_parser.y"
1478 {
1479 yyval = (int)malloc((2 * GAAMAX_ARGLIST_COUNT + 1)* sizeof(int));
1480 ((int*)yyval)[0] = 1;
1481 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 1] = yyvsp[-1];
1482 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 2] = yyvsp[0];
1483 }
1484 break;
1485
1486 case 13:
1487 #line 426 "gaa_parser.y"
1488 {
1489 yyval = yyvsp[0];
1490 ((int*)yyval)[0]++;
1491 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 1] = yyvsp[-2];
1492 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 2] = yyvsp[-1];
1493 }
1494 break;
1495
1496 case 14:
1497 #line 433 "gaa_parser.y"
1498 {
1499 yyval = (int)malloc((2 * GAAMAX_ARGLIST_COUNT + 1)* sizeof(int));
1500 ((int*)yyval)[0] = 1;
1501 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 1] = yyvsp[0];
1502 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 2] = -1;
1503 }
1504 break;
1505
1506 case 15:
1507 #line 440 "gaa_parser.y"
1508 {
1509 yyval = yyvsp[0];
1510 ((int*)yyval)[0]++;
1511 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 1] = yyvsp[-1];
1512 ((int*)yyval)[2*(((int*)yyval)[0] - 1) + 2] = -1;
1513 }
1514 break;
1515
1516 case 16:
1517 #line 448 "gaa_parser.y"
1518 {
1519 yyval = yyvsp[0];
1520 }
1521 break;
1522
1523 case 17:
1524 #line 451 "gaa_parser.y"
1525 {
1526 yyval = yyvsp[-1];
1527 }
1528 break;
1529
1530 case 18:
1531 #line 457 "gaa_parser.y"
1532 {
1533 NEW(struct_elt, first_struct_elt, struct_elt_tmp);
1534 struct_elt_tmp->data = 0;
1535 struct_elt_tmp->location = yyvsp[0];
1536 nb_struct_elt++;
1537 }
1538 break;
1539
1540 case 19:
1541 #line 464 "gaa_parser.y"
1542 {
1543 NEW(struct_elt, first_struct_elt, struct_elt_tmp);
1544 struct_elt_tmp->data = 1;
1545 struct_elt_tmp->id = yyvsp[-2];
1546 if(yyvsp[0] < 0)
1547 {
1548 struct_elt_tmp->type = GAA_LIST;
1549 struct_elt_tmp->arg_type = -yyvsp[0];
1550 }
1551 else
1552 {
1553 struct_elt_tmp->type = GAA_SINGLE;
1554 struct_elt_tmp->arg_type = yyvsp[0];
1555 }
1556 nb_struct_elt++;
1557 }
1558 break;
1559
1560 case 20:
1561 #line 481 "gaa_parser.y"
1562 {
1563 NEW(help, first_help, help_tmp);
1564 help_tmp->str = yyvsp[0];
1565 help_tmp->line = yylsp[-1].first_line;
1566 nb_help++;
1567
1568 fprintf(glb_out, "\tprintf(");
1569 copy_str(glb_fd, yyvsp[0], glb_out, "\\n");
1570 fprintf(glb_out, ");\n");
1571 }
1572 break;
1573
1574 case 21:
1575 #line 491 "gaa_parser.y"
1576 { init_loc = yyvsp[0]; }
1577 break;
1578
1579 case 22:
1580 #line 493 "gaa_parser.y"
1581 {
1582 NEW(atype, first_atype, atype_tmp);
1583 atype_tmp->id = yyvsp[-2];
1584 atype_tmp->fnName = yyvsp[-1];
1585 atype_tmp->argtype = yyvsp[0];
1586 nb_atype++;
1587
1588 }
1589 break;
1590
1591 case 23:
1592 #line 502 "gaa_parser.y"
1593 {
1594 int i, *tab, sent=0;
1595 SUPERLOOKUP(id2, yyvsp[-4], yylsp[-6].first_line);
1596 NEW(option, first_option, option_tmp);
1597 option_tmp->fa = NULL;
1598 option_tmp->id1 = 0;
1599 option_tmp->id2 = yyvsp[-4];
1600 option_tmp->action = yyvsp[-1];
1601 option_tmp->line = yylsp[-6].first_line;
1602 option_tmp->help = yyvsp[0];
1603 tab = (int*)yyvsp[-2];
1604 option_tmp->nb_arg = tab[0];
1605 nb_option++;
1606
1607 fprintf(glb_out, "\t__gaa_helpsingle(0, \"%s\", ", num2str(yyvsp[-4]));
1608
1609 for(i = 1; i < option_tmp->nb_arg + 1; i++)
1610 {
1611
1612 NEW(arg, option_tmp->fa, arg_tmp);
1613
1614 arg_tmp->id = tab[2*(i-1) + 1];
1615 if(tab[2*(option_tmp->nb_arg-i) + 2]>0)
1616 {
1617 sent++;
1618 copy_str(glb_fd, tab[2*(option_tmp->nb_arg-i) + 2], glb_out, " ");
1619 }
1620 if(arg_tmp->id < 0)
1621 {
1622 arg_tmp->type = GAA_LIST;
1623 arg_tmp->id *= -1;
1624 }
1625 else
1626 {
1627 arg_tmp->type = GAA_SINGLE;
1628 }
1629 }
1630 if (sent==0) fputs( "\"\"", glb_out);
1631 fprintf(glb_out, ", ");
1632 copy_str(glb_fd, yyvsp[0], glb_out, NULL);
1633 fprintf(glb_out,");\n");
1634 }
1635 break;
1636
1637 case 24:
1638 #line 545 "gaa_parser.y"
1639 {
1640 int i, *tab, sent=0;
1641 SUPERLOOKUP(id2, yyvsp[-4], yylsp[-8].first_line);
1642 SUPERLOOKUP(id1, yyvsp[-6], yylsp[-8].first_line);
1643
1644 if(strlen(num2str(yyvsp[-6])) != 1)
1645 {
1646 fprintf( stderr, "%s:%d: first identifier must be a single character\n", st_in, yylsp[-8].first_line);
1647 error_flag = 1;
1648 }
1649 NEW(option, first_option, option_tmp);
1650 option_tmp->fa = NULL;
1651 option_tmp->id1 = yyvsp[-6];
1652 option_tmp->id2 = yyvsp[-4];
1653 option_tmp->action = yyvsp[-1];
1654 option_tmp->line = yylsp[-8].first_line;
1655 option_tmp->help = yyvsp[0];
1656 tab = (int*)yyvsp[-2];
1657 option_tmp->nb_arg = tab[0];
1658 nb_option++;
1659 fprintf(glb_out, "\t__gaa_helpsingle('%c', \"%s\", ",
1660 num2str(yyvsp[-6])[0], num2str(yyvsp[-4]));
1661 for(i = 1; i < option_tmp->nb_arg + 1; i++)
1662 {
1663
1664 NEW(arg, option_tmp->fa, arg_tmp);
1665
1666 arg_tmp->id = tab[2*(i-1) + 1];
1667 if(tab[2*(option_tmp->nb_arg-i) + 2]>0)
1668 {
1669 sent++;
1670 copy_str(glb_fd, tab[2*(option_tmp->nb_arg-i) + 2], glb_out, " ");
1671 }
1672 if(arg_tmp->id < 0)
1673 {
1674 arg_tmp->type = GAA_LIST;
1675 arg_tmp->id *= -1;
1676 }
1677 else
1678 {
1679 arg_tmp->type = GAA_SINGLE;
1680 }
1681 }
1682 if (sent==0) fputs( "\"\"", glb_out);
1683 fprintf(glb_out, ", ");
1684 copy_str(glb_fd, yyvsp[0], glb_out, NULL);
1685 fprintf(glb_out,");\n");
1686 }
1687 break;
1688
1689 case 25:
1690 #line 594 "gaa_parser.y"
1691 {
1692 int i, *tab;
1693
1694 rest_action = yyvsp[0];
1695 tab = (int*)yyvsp[-1];
1696 rest_nb_arg = tab[0];
1697
1698 for(i = 1; i < rest_nb_arg + 1; i++)
1699 {
1700 NEW(arg, first_rest_arg, arg_tmp);
1701
1702 arg_tmp->id = tab[2*(i-1) + 1];
1703 if(arg_tmp->id < 0)
1704 {
1705 arg_tmp->type = GAA_LIST;
1706 arg_tmp->id *= -1;
1707 }
1708 else
1709 {
1710 arg_tmp->type = GAA_SINGLE;
1711 }
1712 }
1713 }
1714 break;
1715
1716 case 26:
1717 #line 618 "gaa_parser.y"
1718 {
1719 NEW(condition, first_condition, condition_tmp);
1720 condition_tmp->options = yyvsp[0];
1721 condition_tmp->type = GAA_OBLIGAT;
1722 k_needed = 1;
1723 }
1724 break;
1725
1726 case 27:
1727 #line 625 "gaa_parser.y"
1728 {
1729 NEW(condition, first_condition, condition_tmp);
1730 condition_tmp->options = yyvsp[0];
1731 condition_tmp->type = GAA_INCOMP;
1732 k_needed = 1;
1733 }
1734 break;
1735
1736 case 28:
1737 #line 632 "gaa_parser.y"
1738 {
1739 glb_underscore_strings = 1;
1740 }
1741 break;
1742
1743
1744 }
1745
1746 /* Line 999 of yacc.c. */
1747 #line 1748 "gaa_parser.c"
1748
1749 yyvsp -= yylen;
1750 yyssp -= yylen;
1751 yylsp -= yylen;
1752
1753 YY_STACK_PRINT (yyss, yyssp);
1754
1755 *++yyvsp = yyval;
1756 *++yylsp = yyloc;
1757
1758 /* Now `shift' the result of the reduction. Determine what state
1759 that goes to, based on the state we popped back to and the rule
1760 number reduced by. */
1761
1762 yyn = yyr1[yyn];
1763
1764 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1765 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1766 yystate = yytable[yystate];
1767 else
1768 yystate = yydefgoto[yyn - YYNTOKENS];
1769
1770 goto yynewstate;
1771
1772
1773 /*------------------------------------.
1774 | yyerrlab -- here on detecting error |
1775 `------------------------------------*/
1776 yyerrlab:
1777 /* If not already recovering from an error, report this error. */
1778 if (!yyerrstatus)
1779 {
1780 ++yynerrs;
1781 #if YYERROR_VERBOSE
1782 yyn = yypact[yystate];
1783
1784 if (YYPACT_NINF < yyn && yyn < YYLAST)
1785 {
1786 YYSIZE_T yysize = 0;
1787 int yytype = YYTRANSLATE (yychar);
1788 char *yymsg;
1789 int yyx, yycount;
1790
1791 yycount = 0;
1792 /* Start YYX at -YYN if negative to avoid negative indexes in
1793 YYCHECK. */
1794 for (yyx = yyn < 0 ? -yyn : 0;
1795 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1796 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1797 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1798 yysize += yystrlen ("syntax error, unexpected ") + 1;
1799 yysize += yystrlen (yytname[yytype]);
1800 yymsg = (char *) YYSTACK_ALLOC (yysize);
1801 if (yymsg != 0)
1802 {
1803 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
1804 yyp = yystpcpy (yyp, yytname[yytype]);
1805
1806 if (yycount < 5)
1807 {
1808 yycount = 0;
1809 for (yyx = yyn < 0 ? -yyn : 0;
1810 yyx < (int) (sizeof (yytname) / sizeof (char *));
1811 yyx++)
1812 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1813 {
1814 const char *yyq = ! yycount ? ", expecting " : " or ";
1815 yyp = yystpcpy (yyp, yyq);
1816 yyp = yystpcpy (yyp, yytname[yyx]);
1817 yycount++;
1818 }
1819 }
1820 yyerror (yymsg);
1821 YYSTACK_FREE (yymsg);
1822 }
1823 else
1824 yyerror ("syntax error; also virtual memory exhausted");
1825 }
1826 else
1827 #endif /* YYERROR_VERBOSE */
1828 yyerror ("syntax error");
1829 }
1830
1831 yylerrsp = yylsp;
1832
1833 if (yyerrstatus == 3)
1834 {
1835 /* If just tried and failed to reuse lookahead token after an
1836 error, discard it. */
1837
1838 /* Return failure if at end of input. */
1839 if (yychar == YYEOF)
1840 {
1841 /* Pop the error token. */
1842 YYPOPSTACK;
1843 /* Pop the rest of the stack. */
1844 while (yyss < yyssp)
1845 {
1846 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1847 yydestruct (yystos[*yyssp], yyvsp, yylsp);
1848 YYPOPSTACK;
1849 }
1850 YYABORT;
1851 }
1852
1853 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
1854 yydestruct (yytoken, &yylval, &yylloc);
1855 yychar = YYEMPTY;
1856 *++yylerrsp = yylloc;
1857 }
1858
1859 /* Else will try to reuse lookahead token after shifting the error
1860 token. */
1861 goto yyerrlab1;
1862
1863
1864 /*----------------------------------------------------.
1865 | yyerrlab1 -- error raised explicitly by an action. |
1866 `----------------------------------------------------*/
1867 yyerrlab1:
1868 yyerrstatus = 3; /* Each real token shifted decrements this. */
1869
1870 for (;;)
1871 {
1872 yyn = yypact[yystate];
1873 if (yyn != YYPACT_NINF)
1874 {
1875 yyn += YYTERROR;
1876 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1877 {
1878 yyn = yytable[yyn];
1879 if (0 < yyn)
1880 break;
1881 }
1882 }
1883
1884 /* Pop the current state because it cannot handle the error token. */
1885 if (yyssp == yyss)
1886 YYABORT;
1887
1888 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1889 yydestruct (yystos[yystate], yyvsp, yylsp);
1890 yyvsp--;
1891 yystate = *--yyssp;
1892 yylsp--;
1893 YY_STACK_PRINT (yyss, yyssp);
1894 }
1895
1896 if (yyn == YYFINAL)
1897 YYACCEPT;
1898
1899 YYDPRINTF ((stderr, "Shifting error token, "));
1900
1901 *++yyvsp = yylval;
1902 YYLLOC_DEFAULT (yyloc, yylsp, (yylerrsp - yylsp));
1903 *++yylsp = yyloc;
1904
1905 yystate = yyn;
1906 goto yynewstate;
1907
1908
1909 /*-------------------------------------.
1910 | yyacceptlab -- YYACCEPT comes here. |
1911 `-------------------------------------*/
1912 yyacceptlab:
1913 yyresult = 0;
1914 goto yyreturn;
1915
1916 /*-----------------------------------.
1917 | yyabortlab -- YYABORT comes here. |
1918 `-----------------------------------*/
1919 yyabortlab:
1920 yyresult = 1;
1921 goto yyreturn;
1922
1923 #ifndef yyoverflow
1924 /*----------------------------------------------.
1925 | yyoverflowlab -- parser overflow comes here. |
1926 `----------------------------------------------*/
1927 yyoverflowlab:
1928 yyerror ("parser stack overflow");
1929 yyresult = 2;
1930 /* Fall through. */
1931 #endif
1932
1933 yyreturn:
1934 #ifndef yyoverflow
1935 if (yyss != yyssa)
1936 YYSTACK_FREE (yyss);
1937 #endif
1938 return yyresult;
1939 }
1940
1941
1942 #line 637 "gaa_parser.y"
1943
1944
1945 extern int loc_index;
1946
1947 struct _idStruct;
1948 typedef struct _idStruct idStruct;
1949
1950 struct _idStruct
1951 {
1952 char *name;
1953 int line; /* the first line it was encountered */
1954 idStruct *next;
1955 };
1956
1957 idStruct *firstId = NULL;
1958
1959 #define RM(x) remove_illegal_C_char(x)
remove_illegal_C_char(const char * str)1960 static char *remove_illegal_C_char( const char* str)
1961 {
1962 static char ret[512];
1963 int i;
1964 if (strlen(str)+1 > sizeof(ret)) {
1965 fprintf(stderr, "num2str: Too long string\n");
1966 exit(1);
1967 }
1968 memset( ret, 0, sizeof ret);
1969 for (i=0;i<strlen(str);i++) {
1970 ret[i] = str[i];
1971 if (ret[i]=='-') ret[i]='_';
1972 }
1973 ret[i]=0;
1974
1975 return ret;
1976 }
1977
num2str(int n)1978 char* num2str(int n)
1979 {
1980 int i;
1981 idStruct *tmp;
1982 tmp = firstId;
1983 if(n == 0)
1984 return "";
1985 for(i = 0; (i < n - 1) && (tmp != NULL); i++)
1986 {
1987 tmp = tmp->next;
1988 }
1989 if(tmp == NULL)
1990 {
1991 fprintf(stderr, "num2str: Out of range\n");
1992 exit(1);
1993 }
1994 return tmp->name;
1995 }
1996
1997 /* returns the line of the identifier, indexed
1998 * by n;
1999 */
get_id_line(int n)2000 int get_id_line(int n)
2001 {
2002 int i;
2003 idStruct *tmp;
2004 tmp = firstId;
2005 if(n == 0)
2006 return num_lines - 1;
2007 for(i = 0; (i < n - 1) && (tmp != NULL); i++)
2008 {
2009 tmp = tmp->next;
2010 }
2011 if(tmp == NULL)
2012 {
2013 fprintf(stderr, "get_id_line: Out of range\n");
2014 exit(1);
2015 }
2016 return tmp->line;
2017 }
2018
length(char * a)2019 int length(char *a)
2020 {
2021 int i = 0;
2022 while(*(a+i) != 0) i++;
2023 return i;
2024 }
2025
2026
getTokenNum(char * str)2027 int getTokenNum( char* str) {
2028 int i;
2029 for (i = 0; i < YYNTOKENS; i++)
2030 {
2031 if (yytname[i] != 0
2032 && yytname[i][0] == '"'
2033 && strncasecmp (yytname[i] + 1, str, strlen (str)) == 0
2034 && yytname[i][strlen (str) + 1] == '"'
2035 && yytname[i][strlen (str) + 2] == 0)
2036 {
2037 return yytoknum[i];
2038 }
2039 }
2040 return -1;
2041 }
2042
getIdNum(char * name,int line)2043 int getIdNum(char *name, int line)
2044 {
2045 int len, data = 1;
2046 idStruct **pter, *blurp;
2047
2048 pter = &firstId;
2049 while(*pter != NULL)
2050 {
2051 if(strcmp(name, (*pter)->name) == 0)
2052 break;
2053 data++;
2054 pter = &((*pter)->next);
2055 }
2056 if(*pter == NULL)
2057 {
2058 blurp = *pter;
2059 len = length(name);
2060 blurp = malloc(sizeof(idStruct));
2061 *pter = blurp;
2062 blurp->name = malloc((len + 1)* sizeof(char));
2063 strcpy(blurp->name, name);
2064 blurp->next = NULL;
2065 blurp->line = line;
2066 }
2067
2068 return data;
2069 }
2070
2071 #define MAXIDSIZE 300
2072
2073 char *tmpStr;
2074
2075
yyerror(char * s)2076 int yyerror( char* s) /* Called by yyparse on error */
2077 {
2078 fprintf (stderr, "%s:%d: %s\n", st_in, num_lines, s);
2079 exit(1);
2080 }
2081
2082 /* Copies the skel file to target file
2083 * if term!=EOF, then the file is copied until
2084 * the terminator byte.
2085 *
2086 * This function will use the file seek pointers
2087 * to keep a state in copying.
2088 */
copy_file_state(FILE * source,FILE * target,int term)2089 void copy_file_state(FILE* source, FILE* target, int term)
2090 {
2091 int a;
2092 do
2093 {
2094 if( (a=fgetc(source)) == EOF && term!=EOF)
2095 {
2096 fprintf(stderr, "copy_file_state: Source read error\n");
2097 exit(1);
2098 }
2099 if(a != term)
2100 {
2101 if(fputc(a, target) == EOF)
2102 {
2103 fprintf(stderr, "copy_file_state: Output write error\n");
2104 exit(1);
2105 }
2106 }
2107 }
2108 while(a != term);
2109 }
2110
2111 /* Returns the number of the line, that the index-th character
2112 * is placed.
2113 */
getline(FILE * fd,int index)2114 int getline(FILE* fd, int index)
2115 {
2116 int tmp, line = 1, i;
2117 int a = 0;
2118 tmp = fseek(fd, 0, SEEK_CUR);
2119 fseek(fd, 0, SEEK_SET);
2120 for(i = 0; i < index; i++)
2121 {
2122 a=fgetc(fd);
2123 if(a==EOF) {
2124 printf("Read error\n");
2125 exit(1);
2126 }
2127 if(a == '\n')
2128 line++;
2129 }
2130 fseek(fd, tmp, SEEK_SET);
2131 return line;
2132 }
2133
2134 /* term holds the terminator character ';', or '\n'
2135 */
copy_line(FILE * fd,int index,FILE * target,char * file,char term)2136 void copy_line(FILE* fd, int index, FILE* target, char* file, char term)
2137 {
2138 int a;
2139 fprintf(target, "#line %d \"%s\"\n\t", getline(fd, index), file);
2140 fseek(fd, index, SEEK_SET);
2141 do
2142 {
2143 if( (a=fgetc(fd)) == EOF)
2144 {
2145 printf("Read error\n");
2146 exit(1);
2147 }
2148 if(fputc(a, target) == EOF)
2149 {
2150 printf("Output write error\n");
2151 exit(1);
2152 }
2153 }
2154 while(a != term);
2155 }
2156
put_action(FILE * fd,int index,FILE * target,char * opt,int narg,char * file)2157 void put_action( FILE* fd, int index, FILE* target, char *opt, int narg, char* file)
2158 {
2159 int a;
2160 char *str_cmp;
2161 int i, flag = 1;
2162 fprintf(target, "#line %d \"%s\"\n", getline(fd, index), file);
2163 fprintf(target, "{");
2164 fseek(fd, index, SEEK_SET);
2165 if(opt[0] == 0)
2166 str_cmp = "GAAREST_tmp";
2167 else
2168 str_cmp = "GAATMP_";
2169 while(flag != 0)
2170 {
2171 if( (a=fgetc(fd)) == EOF)
2172 {
2173 printf("Read error\n");
2174 exit(1);
2175 }
2176 switch(a)
2177 {
2178 case '{':
2179 flag ++;
2180 break;
2181 case '}':
2182 flag --;
2183 break;
2184 case '@':
2185 i = 0;
2186 a = '0';
2187 flag *= -1;
2188 do
2189 {
2190 i *= 10;
2191 i += (a - '0');
2192 if( (a=fgetc(fd)) == EOF)
2193 {
2194 printf("Read error\n");
2195 exit(1);
2196 }
2197 }
2198 while(isdigit(a) != 0);
2199 fseek(fd, -1, SEEK_CUR);
2200 if(( i > narg ) || (i <= 0))
2201 {
2202 printf("Fatal: Option %s: argument $%d unknown\n", opt, i);
2203 exit(1);
2204 }
2205 fprintf(target, "%s%s.size%d", str_cmp, RM(opt), i);
2206 break;
2207 case '$':
2208 if( (a=fgetc(fd)) == EOF)
2209 {
2210 printf("Read error\n");
2211 exit(1);
2212 }
2213 fseek(fd, -1, SEEK_CUR);
2214 flag *= -1;
2215 if(isdigit(a) == 0)
2216 {
2217 fprintf(target, "gaaval->");
2218 }
2219 else
2220 {
2221 i = 0;
2222 a = '0';
2223 do
2224 {
2225 i *= 10;
2226 i += (a - '0');
2227 if( (a=fgetc(fd)) == EOF)
2228 {
2229 printf("Read error\n");
2230 exit(1);
2231 }
2232 }
2233 while(isdigit(a) != 0);
2234 fseek(fd, -1, SEEK_CUR);
2235 if(( i > narg ) || (i <= 0))
2236 {
2237 printf("Fatal: Option %s: argument $%d unknown\n", opt, i);
2238 exit(1);
2239 }
2240 fprintf(target, "%s%s.arg%d", str_cmp, RM(opt), i);
2241 }
2242 break;
2243 default: break;
2244 }
2245 if(flag > 0)
2246 {
2247 if(fputc( a, target) == EOF)
2248 {
2249 printf("Output write error\n");
2250 exit(1);
2251 }
2252 }
2253 if(flag < 0)
2254 flag *= -1;
2255 }
2256 fprintf(target, ";};\n");
2257 }
2258
2259 /* copies the file until it finds #} */
copy_file(FILE * fd,int index,FILE * target,char * file)2260 void copy_file(FILE* fd, int index, FILE* target, char *file)
2261 {
2262 int a, pa = -1;
2263 fprintf(target, "#line %d \"%s\"\n", getline(fd, index), file);
2264 fseek(fd, index, SEEK_SET);
2265 while( (a=fgetc(fd)) != EOF)
2266 {
2267 if (pa=='#' && a=='}') break;
2268
2269 if (pa!=-1)
2270 if(fputc( pa, target) == EOF)
2271 {
2272 printf("Output write error\n");
2273 exit(1);
2274 }
2275 pa = a;
2276 };
2277
2278 if (a==EOF) {
2279 if(fputc( pa, target) == EOF)
2280 {
2281 printf("Output write error\n");
2282 exit(1);
2283 }
2284 }
2285 }
2286
add_type(char * id,char * fnName,char * type)2287 void add_type(char *id, char *fnName, char *type)
2288 {
2289 NEW(atype, first_atype, atype_tmp);
2290 atype_tmp->id = getIdNum(id, 0);
2291 atype_tmp->fnName = getIdNum(fnName, 0);
2292 atype_tmp->type_str = type;
2293 nb_atype++;
2294 }
2295
2296 #define SHORTNAME num2str(option_tmp_loc->id1)
2297 #define LONGNAME num2str(option_tmp_loc->id2)
2298
2299 char __optional_flag;
2300
write_get_arg(FILE * out,arg * x,char * name,int arg_number)2301 void write_get_arg(FILE *out, arg *x, char *name, int arg_number)
2302 {
2303 char *str_name;
2304 char _name[512];
2305
2306 strcpy( _name, RM(name));
2307
2308 if(x->id == 0)
2309 {
2310 __optional_flag = 1;
2311 return;
2312 }
2313
2314 if(name[0] == 0)
2315 str_name = "GAAREST_tmp";
2316 else
2317 str_name = "GAATMP_";
2318
2319 if(x->type == GAA_SINGLE)
2320 {
2321 if(__optional_flag)
2322 {
2323 fprintf(out, "\t\tGAA_TESTMOREOPTIONALARGS;\n\t\tGAA_FILL(%s%s.arg%d, %s, %s%s.size%d);\n\t\tgaa_index++;\n",
2324 str_name,_name,arg_number,RM(num2str(get_type(x)->fnName)),str_name,_name,arg_number);
2325 }
2326 else
2327 {
2328 fprintf(out, "\t\tGAA_TESTMOREARGS;\n\t\tGAA_FILL(%s%s.arg%d, %s, %s%s.size%d);\n\t\tgaa_index++;\n",
2329 str_name,_name,arg_number,RM(num2str(get_type(x)->fnName)),str_name, _name,arg_number);
2330 }
2331 }
2332 else
2333 {
2334 if(!__optional_flag)
2335 fprintf(out, "\t\tGAA_LIST_FILL(%s%s.arg%d, %s, %s, %s%s.size%d);\n",
2336 str_name,_name,arg_number,
2337 RM(num2str(get_type(x)->fnName)), get_type(x)->type_str,
2338 str_name,_name,arg_number);
2339 else
2340 fprintf(out, "\t\tGAA_OPTIONALLIST_FILL(%s%s.arg%d, %s, %s, %s%s.size%d);\n",
2341 str_name,_name,arg_number,
2342 RM(num2str(get_type(x)->fnName)), get_type(x)->type_str,
2343 str_name,_name,arg_number);
2344 }
2345 }
2346
2347 #define EXT_GAA_H "_gaa.h"
2348 #define EXT_GAA_C "_gaa.c"
2349
main(int argc,char ** argv)2350 int main(int argc, char **argv)
2351 {
2352 option *option_tmp_loc;
2353 atype *atype_tmp_loc;
2354 struct_elt *struct_elt_tmp_loc;
2355 /* help *help_tmp_loc; */
2356 arg *arg_tmp_loc;
2357 FILE* fd,* skel;
2358 FILE *out,*header;
2359 int i, j, k, header_start, header_limit;
2360 int rval;
2361 int a;
2362 char *st_out,*st_header, *ptr;
2363 gaainfo info;
2364
2365 if(gaa(argc, argv, &info) != -1)
2366 {
2367 fprintf(stderr, "Error in the arguments.\n");
2368 fprintf(stderr, "Use the -h or --help parameters for help.\n");
2369 return 0;
2370 }
2371 if(info.skel == NULL)
2372 {
2373 j = 0;
2374 info.skel = malloc(sizeof(char) * (length("gaa.skel") + length(argv[0])));
2375 for(i = 0; i < length(argv[0]); i++)
2376 {
2377 if(argv[0][i] == '\\')
2378 j = i+1;
2379 info.skel[i] = argv[0][i];
2380 }
2381 strcpy(info.skel + j, "gaa.skel");
2382 }
2383 st_in = info.input; st_out = info.output; st_header = info.header;
2384
2385 /* generate file names
2386 */
2387 if (st_header==NULL) {
2388 st_header= malloc( strlen(st_in)+ strlen(EXT_GAA_H));
2389 strcpy(st_header, st_in);
2390 ptr = strstr( st_header, ".gaa");
2391 if (ptr==NULL)
2392 strcat( st_header, EXT_GAA_H);
2393 else
2394 strcpy( ptr, EXT_GAA_H);
2395 }
2396 if (st_out==NULL) {
2397 st_out= malloc( strlen(st_in)+ strlen(EXT_GAA_C));
2398 strcpy(st_out, st_in);
2399 ptr = strstr( st_out, ".gaa");
2400 if (ptr==NULL)
2401 strcat( st_out, EXT_GAA_C);
2402 else
2403 strcpy( ptr, EXT_GAA_C);
2404 }
2405
2406 if((skel = fopen(info.skel, "r")) == NULL)
2407 {
2408 printf("Couldn't open skeleton file: %s\n", info.skel);
2409 exit(1);
2410 }
2411 if((glb_fd = fopen(st_in, "r")) == NULL)
2412 {
2413 printf("Couldn't open gaa file '%s'.\n", st_in);
2414 exit(1);
2415 }
2416 if((out = fopen(st_out, "w+")) == NULL)
2417 {
2418 printf("Couldn't open output file '%s'.\n", st_out);
2419 exit(1);
2420 }
2421 if((glb_out = tmpfile()) == NULL)
2422 {
2423 printf("Couldn't open tmp output file.\n");
2424 exit(1);
2425 }
2426 glb_skel = skel;
2427 tmpStr = malloc((MAXIDSIZE + 1)*sizeof(char));
2428
2429 if(( glb_sfd=fopen(st_in, "r")) == NULL)
2430 {
2431 printf("Couldn't open gaa file\n");
2432 exit(1);
2433 }
2434
2435 fprintf(out, "/* File generated by GAA %s\n */\n", VERSION);
2436
2437
2438 if (info.prefix) {
2439 fprintf(out, "\n#define gaainfo %sgaainfo\n", info.prefix);
2440 fprintf(out, "#define gaa %sgaa\n", info.prefix);
2441 fprintf(out, "#define gaa_help %sgaa_help\n", info.prefix);
2442 fprintf(out, "#define gaa_file %sgaa_file\n", info.prefix);
2443 }
2444
2445 /* write the WIN32 headers */
2446 if(info.win32 == 1)
2447 fprintf(out, "#define GAA_WIN32\n");
2448 else
2449 fprintf(out, "#define GAA_NO_WIN32\n");
2450
2451 /* Parse the input file */
2452 rval = yyparse();
2453 fclose( glb_sfd);
2454 free(tmpStr);
2455
2456 fd = glb_fd;
2457
2458 /* Write the C declarations */
2459 if(c_code != -1)
2460 copy_file(fd, c_code, out, st_in);
2461
2462 /* Write the skel file */
2463 copy_file_state(skel,out, '@');
2464
2465 fseek( glb_out, 0, SEEK_SET);
2466 copy_file_state(glb_out, out, EOF);
2467 fclose(glb_out); /* close tmp file */
2468
2469 copy_file_state(skel,out, '@');
2470
2471 header_start = ftell(out);
2472 if((rval != 0) || (error_flag == 1))
2473 return 1;
2474
2475 for(i = 0; i < nb_atype; i++)
2476 {
2477 atype_tmp_loc = get_atype(i);
2478 read_str(fd, atype_tmp_loc->argtype, &(atype_tmp_loc->type_str), ';');
2479 }
2480 add_type("STR", "gaa_getstr", "char*");
2481 add_type("INT", "gaa_getint", "int");
2482 add_type("CHAR", "gaa_getchar", "char");
2483 add_type("FLOAT", "gaa_getfloat", "float");
2484
2485 copy_file_state(skel,out, '@');
2486 for(i = 0; i < nb_struct_elt; i++)
2487 {
2488 struct_elt_tmp_loc = get_struct_elt(i);
2489 if(struct_elt_tmp_loc->data == 0)
2490 copy_line(fd, struct_elt_tmp_loc->location, out, st_in, ';');
2491 else
2492 {
2493 if(struct_elt_tmp_loc->type == GAA_SINGLE)
2494 fprintf(out, "\t%s %s;",
2495 get_atype_from_id(struct_elt_tmp_loc->arg_type)->type_str,
2496 num2str(struct_elt_tmp_loc->id));
2497 else
2498 fprintf(out, "\t%s *%s;",
2499 get_atype_from_id(struct_elt_tmp_loc->arg_type)->type_str,
2500 num2str(struct_elt_tmp_loc->id));
2501 }
2502 fprintf(out, "\n");
2503 }
2504 copy_file_state(skel,out, '@');
2505 header_limit = ftell(out);
2506 copy_file_state(skel,out, '@');
2507
2508 fprintf(out, "%d\n", nb_option + nb_option_argless);
2509
2510 for(j = 0; j < nb_option; j++)
2511 {
2512 option_tmp_loc = get_option(j);
2513
2514 fprintf(out,"#define GAAOPTID_%s\t%d\n", RM(num2str( option_tmp_loc->id2)),
2515 j + 1 );
2516 }
2517
2518 copy_file_state(skel,out, '@');
2519 for(i = 0; i < nb_option; i++)
2520 {
2521 k = 0;
2522 option_tmp_loc = get_option(i);
2523 if(option_tmp_loc->nb_arg > 0)
2524 {
2525 fprintf(out, "\nstruct GAAOPTION_%s \n{\n", RM(num2str(option_tmp_loc->id2)));
2526 for(j = 0; j < option_tmp_loc->nb_arg; j++)
2527 {
2528 arg_tmp_loc = get_arg(i,j);
2529 if(arg_tmp_loc->id != 0)
2530 {
2531 k++;
2532 atype_tmp_loc = get_type(arg_tmp_loc);
2533 fprintf(out, "\t%s", atype_tmp_loc->type_str);
2534 if(arg_tmp_loc->type == GAA_LIST)
2535 fprintf(out, "*");
2536 fprintf(out, " arg%d;\n", k);
2537 /* if(arg_tmp_loc->type == GAA_LIST) */
2538 fprintf(out, "\tint size%d;\n", k);
2539 }
2540 }
2541 fprintf(out, "};\n");
2542 }
2543 }
2544 if(rest_nb_arg != 0)
2545 {
2546 fprintf(out, "#define GAA_REST_EXISTS\n");
2547 fprintf(out, "\nstruct GAAREST\n{\n");
2548 j = 0;
2549 for(arg_tmp_loc = first_rest_arg; arg_tmp_loc != NULL; arg_tmp_loc = arg_tmp_loc->next)
2550 {
2551
2552 if(arg_tmp_loc->id != 0)
2553 {
2554 atype_tmp_loc = get_type(arg_tmp_loc);
2555 fprintf(out, "\t%s", atype_tmp_loc->type_str);
2556 if(arg_tmp_loc->type == GAA_LIST)
2557 fprintf(out, "*");
2558 fprintf(out, " arg%d;\n", j + 1);
2559 /* if(arg_tmp_loc->type == GAA_LIST)*/
2560 fprintf(out, "\tint size%d;\n", j+1);
2561 j++;
2562 }
2563 }
2564 fprintf(out, "};\n");
2565 }
2566 copy_file_state(skel,out, '@');
2567 for(j = 0; j < nb_option; j++)
2568 {
2569 option_tmp_loc = get_option(j);
2570 if(option_tmp_loc->nb_arg != 0)
2571 fprintf(out,"\t\t\tGAA_CHECK1STR(\"%s\", GAAOPTID_%s);\n",
2572 num2str(option_tmp_loc->id1), RM(num2str(option_tmp_loc->id2)));
2573 }
2574 copy_file_state(skel,out,'@');
2575 for(j = 0; j < nb_option; j++)
2576 {
2577 option_tmp_loc = get_option(j);
2578 if(option_tmp_loc->nb_arg == 0)
2579 fprintf(out,"\t\t\tGAA_CHECK1STR(\"%s\", GAAOPTID_%s);\n",
2580 num2str(option_tmp_loc->id1), RM(num2str(option_tmp_loc->id2)));
2581 }
2582 copy_file_state(skel,out, '@');
2583 for(j = 0; j < nb_option; j++)
2584 {
2585 option_tmp_loc = get_option(j);
2586 fprintf(out,"\t\t\tGAA_CHECKSTR(\"%s\", GAAOPTID_%s);\n",
2587 num2str(option_tmp_loc->id2), RM(num2str(option_tmp_loc->id2)));
2588 }
2589 copy_file_state(skel,out, '@');
2590
2591 for(j = 0; j < nb_option; j++)
2592 {
2593 option_tmp_loc = get_option(j);
2594 if(option_tmp_loc->nb_arg > 0)
2595 fprintf(out,"\tstruct GAAOPTION_%s GAATMP_%s;\n",
2596 RM(num2str(option_tmp_loc->id2)), RM(num2str(option_tmp_loc->id2)));
2597 }
2598 copy_file_state(skel,out, '@');
2599 /* for(j = 0; j < nb_option_argless; j++)
2600 {
2601 option_argless_tmp_loc = get_option_argless(j);
2602 fprintf(out,"\tcase GAAOPTID_%s:\n", RM(ALONGNAME));
2603 put_action(fd, option_argless_tmp_loc->action, out, ALONGNAME, 0, st_in);
2604 fprintf(out,"\n\t\treturn GAA_OK;\n\t\tbreak;\n");
2605 } */
2606 for(i = 0; i < nb_option; i++)
2607 {
2608 __optional_flag = 0;
2609 option_tmp_loc = get_option(i);
2610 fprintf(out,"\tcase GAAOPTID_%s:\n\tOK = 0;\n", RM(LONGNAME));
2611 k = 0;
2612 for(j = 0; j < option_tmp_loc->nb_arg; j++)
2613 {
2614 arg_tmp_loc = get_arg(i,j);
2615 if(arg_tmp_loc->id != 0)
2616 k ++;
2617 write_get_arg(out, arg_tmp_loc, LONGNAME, k);
2618 }
2619 put_action(fd, option_tmp_loc->action, out, LONGNAME, option_tmp_loc->nb_arg, st_in);
2620 fprintf(out,"\n\t\treturn GAA_OK;\n\t\tbreak;\n");
2621 }
2622 if(rest_nb_arg != 0)
2623 {
2624 j = 1;
2625 fprintf(out,"\tcase GAA_REST:\n");
2626 for(arg_tmp_loc = first_rest_arg; arg_tmp_loc != NULL; arg_tmp_loc = arg_tmp_loc->next)
2627 {
2628 write_get_arg(out, arg_tmp_loc, "", j);
2629 if(arg_tmp_loc->id != 0)
2630 j++;
2631 }
2632 put_action(fd, rest_action, out, "", rest_nb_arg, st_in);
2633 fprintf(out,"\n\t\treturn GAA_OK;\n\t\tbreak;\n");
2634 }
2635 copy_file_state(skel,out, '@');
2636 if(k_needed)
2637 fprintf(out, ", k");
2638 copy_file_state(skel, out, '@');
2639 if(init_loc >= 0)
2640 put_action(fd, init_loc, out, "init", 0, st_in);
2641 copy_file_state(skel,out, '@');
2642 for(condition_tmp = first_condition; condition_tmp != NULL;
2643 condition_tmp = condition_tmp->next)
2644 {
2645 switch(condition_tmp->type)
2646 {
2647 case GAA_OBLIGAT:
2648 fprintf(out, "\tGAA_OBLIGAT(\"%s\");\n", num2str(condition_tmp->options));
2649 break;
2650 case GAA_INCOMP:
2651 fprintf(out, "\tGAA_INCOMP(\"%s\");\n", num2str(condition_tmp->options));
2652 break;
2653 default: break;
2654 }
2655 }
2656 copy_file_state(skel,out, '@');
2657
2658
2659 if((header = fopen(st_header, "w")) == NULL)
2660 {
2661 printf("Couldn't open header file '%s'.\n", st_header);
2662 exit(1);
2663 }
2664
2665 if (info.prefix) {
2666 fprintf(header, "\n#define gaainfo %sgaainfo\n", info.prefix);
2667 fprintf(header, "#define gaa %sgaa\n", info.prefix);
2668 fprintf(header, "#define gaa_help %sgaa_help\n", info.prefix);
2669 fprintf(header, "#define gaa_file %sgaa_file\n", info.prefix);
2670 }
2671
2672 fseek(out, header_start, SEEK_SET);
2673 for(i = header_start; i < header_limit; i++)
2674 {
2675 if( (a=fgetc(out)) == EOF)
2676 {
2677 printf("Read error\n");
2678 exit(1);
2679 }
2680 if(fputc( a, header) == EOF)
2681 {
2682 printf("Header write error\n");
2683 exit(1);
2684 }
2685 }
2686
2687 if (info.prefix) {
2688 fprintf(header, "\n#undef gaainfo\n");
2689 fprintf(header, "#undef gaa\n");
2690 fprintf(header, "#undef gaa_help\n");
2691 fprintf(header, "#undef gaa_file\n\n");
2692 }
2693
2694 return 0;
2695 }
2696
gaa_version(void)2697 void gaa_version(void) {
2698 printf("Reading skeleton from %s\n", SKEL_DIR);
2699 printf("gaa version %s\n", VERSION);
2700 }
2701
2702