1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
61 /* Substitute the variable and function names. */
62 #define yyparse macroparse
63 #define yylex macrolex
64 #define yyerror macroerror
65 #define yylval macrolval
66 #define yychar macrochar
67 #define yydebug macrodebug
68 #define yynerrs macronerrs
74 /* Put the tokens into the symbol table, so that GDB and other debuggers
95 TK_VAR_EXPANSION
= 276,
96 TK_LABEL_EXPANSION
= 277,
97 TK_UNIQUE_LABEL
= 278,
98 TK_UNIQUE_LOCAL
= 279,
108 #define TK_INCLUDE 261
109 #define TK_MACRO_CONST 262
110 #define TK_MACRO_LOCAL 263
111 #define TK_MACRO_LABEL 264
115 #define TK_STRING 268
120 #define TK_DOT_IDENT 273
121 #define TK_LABEL_ID 274
122 #define TK_LOCAL_ID 275
123 #define TK_VAR_EXPANSION 276
124 #define TK_LABEL_EXPANSION 277
125 #define TK_UNIQUE_LABEL 278
126 #define TK_UNIQUE_LOCAL 279
127 #define TK_STRINGC 280
134 /* Copy the first part of user declarations. */
140 * Copyright (C) 2007, The Perl Foundation.
149 #include "macroparser.h"
153 /* prevent inclusion of <unistd.h> on windows */
154 #define YY_NO_UNISTD_H
156 /* declare yylex prototype BEFORE inclusion of lexer header file. */
157 #define YY_DECL int macrolex(YYSTYPE *yylval, yyscan_t yyscanner)
159 /* inlude flex-generated lexer header file. */
160 #include "macrolexer.h"
165 /* declare yyerror */
166 extern int yyerror(yyscan_t yyscanner
, lexer_state
*lexer
, char *message
);
173 static void process_file(char *filename
, lexer_state
*lexer
);
174 static void process_string(char *buffer
, lexer_state
*lexer
);
175 static void include_file(char *filename
, lexer_state
*lexer
);
176 static void expand(macro_def
*macro
, list
*args
, lexer_state
*lexer
);
177 static void define_constant(constant_table
*table
, char *name
, char *value
);
178 static void define_macro(constant_table
*table
, char *name
, list
*parameters
, char *body
);
179 static void emit(char *str
);
180 static list
*new_list(char *first_item
);
181 static list
*add_item(list
*L
, char *item
);
183 static char *munge_id(char *label_id
, int is_label_declaration
, lexer_state
*lexer
);
184 static constant_table
*new_constant_table(constant_table
*current
, lexer_state
*lexer
);
185 static constant_table
*pop_constant_table(lexer_state
*lexer
);
186 static void delete_constant_table(constant_table
*table
);
187 static void update_unique_id(lexer_state
*lexer
);
189 macro_def
*find_macro(constant_table
*table
, char *name
);
191 extern char *dupstr(char *str
);
193 char *concat(char *str1
, char *str2
, int insert_space
);
198 /* Enabling traces. */
203 /* Enabling verbose error messages. */
204 #ifdef YYERROR_VERBOSE
205 # undef YYERROR_VERBOSE
206 # define YYERROR_VERBOSE 1
208 # define YYERROR_VERBOSE 1
211 /* Enabling the token table. */
212 #ifndef YYTOKEN_TABLE
213 # define YYTOKEN_TABLE 0
216 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
217 typedef union YYSTYPE
222 struct macro_def
*mval
;
225 /* Line 187 of yacc.c. */
226 #line 227 "macroparser.c"
228 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
229 # define YYSTYPE_IS_DECLARED 1
230 # define YYSTYPE_IS_TRIVIAL 1
235 /* Copy the second part of user declarations. */
238 /* Line 216 of yacc.c. */
239 #line 240 "macroparser.c"
246 typedef YYTYPE_UINT8 yytype_uint8
;
248 typedef unsigned char yytype_uint8
;
252 typedef YYTYPE_INT8 yytype_int8
;
253 #elif (defined __STDC__ || defined __C99__FUNC__ \
254 || defined __cplusplus || defined _MSC_VER)
255 typedef signed char yytype_int8
;
257 typedef short int yytype_int8
;
261 typedef YYTYPE_UINT16 yytype_uint16
;
263 typedef unsigned short int yytype_uint16
;
267 typedef YYTYPE_INT16 yytype_int16
;
269 typedef short int yytype_int16
;
273 # ifdef __SIZE_TYPE__
274 # define YYSIZE_T __SIZE_TYPE__
275 # elif defined size_t
276 # define YYSIZE_T size_t
277 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
278 || defined __cplusplus || defined _MSC_VER)
279 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
280 # define YYSIZE_T size_t
282 # define YYSIZE_T unsigned int
286 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
291 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
292 # define YY_(msgid) dgettext ("bison-runtime", msgid)
296 # define YY_(msgid) msgid
300 /* Suppress unused-variable warnings by "using" E. */
301 #if ! defined lint || defined __GNUC__
302 # define YYUSE(e) ((void) (e))
304 # define YYUSE(e) /* empty */
307 /* Identity function, used to suppress warnings about constant conditions. */
311 #if (defined __STDC__ || defined __C99__FUNC__ \
312 || defined __cplusplus || defined _MSC_VER)
325 #if ! defined yyoverflow || YYERROR_VERBOSE
327 /* The parser invokes alloca or malloc; define the necessary symbols. */
329 # ifdef YYSTACK_USE_ALLOCA
330 # if YYSTACK_USE_ALLOCA
332 # define YYSTACK_ALLOC __builtin_alloca
333 # elif defined __BUILTIN_VA_ARG_INCR
334 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
336 # define YYSTACK_ALLOC __alloca
337 # elif defined _MSC_VER
338 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
339 # define alloca _alloca
341 # define YYSTACK_ALLOC alloca
342 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
343 || defined __cplusplus || defined _MSC_VER)
344 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
353 # ifdef YYSTACK_ALLOC
354 /* Pacify GCC's `empty if-body' warning. */
355 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
356 # ifndef YYSTACK_ALLOC_MAXIMUM
357 /* The OS might guarantee only one guard page at the bottom of the stack,
358 and a page size can be as small as 4096 bytes. So we cannot safely
359 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
360 to allow for a few compiler-allocated temporary stack slots. */
361 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
364 # define YYSTACK_ALLOC YYMALLOC
365 # define YYSTACK_FREE YYFREE
366 # ifndef YYSTACK_ALLOC_MAXIMUM
367 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
369 # if (defined __cplusplus && ! defined _STDLIB_H \
370 && ! ((defined YYMALLOC || defined malloc) \
371 && (defined YYFREE || defined free)))
372 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
378 # define YYMALLOC malloc
379 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
380 || defined __cplusplus || defined _MSC_VER)
381 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
386 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
387 || defined __cplusplus || defined _MSC_VER)
388 void free (void *); /* INFRINGES ON USER NAME SPACE */
392 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
395 #if (! defined yyoverflow \
396 && (! defined __cplusplus \
397 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
399 /* A type that is properly aligned for any stack member. */
406 /* The size of the maximum gap between one aligned stack and the next. */
407 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
409 /* The size of an array large to enough to hold all stacks, each with
411 # define YYSTACK_BYTES(N) \
412 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
413 + YYSTACK_GAP_MAXIMUM)
415 /* Copy COUNT objects from FROM to TO. The source and destination do
418 # if defined __GNUC__ && 1 < __GNUC__
419 # define YYCOPY(To, From, Count) \
420 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
422 # define YYCOPY(To, From, Count) \
426 for (yyi = 0; yyi < (Count); yyi++) \
427 (To)[yyi] = (From)[yyi]; \
433 /* Relocate STACK from its old location to the new one. The
434 local variables YYSIZE and YYSTACKSIZE give the old and new number of
435 elements in the stack, and YYPTR gives the new location of the
436 stack. Advance YYPTR to a properly aligned location for the next
438 # define YYSTACK_RELOCATE(Stack) \
441 YYSIZE_T yynewbytes; \
442 YYCOPY (&yyptr->Stack, Stack, yysize); \
443 Stack = &yyptr->Stack; \
444 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
445 yyptr += yynewbytes / sizeof (*yyptr); \
451 /* YYFINAL -- State number of the termination state. */
453 /* YYLAST -- Last index in YYTABLE. */
456 /* YYNTOKENS -- Number of terminals. */
458 /* YYNNTS -- Number of nonterminals. */
460 /* YYNRULES -- Number of rules. */
462 /* YYNRULES -- Number of states. */
465 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
467 #define YYMAXUTOK 282
469 #define YYTRANSLATE(YYX) \
470 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
472 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
473 static const yytype_uint8 yytranslate
[] =
475 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
477 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
478 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
479 29, 30, 2, 2, 28, 2, 2, 2, 2, 2,
480 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
481 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
482 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
483 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
484 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
487 2, 2, 2, 31, 2, 32, 2, 2, 2, 2,
488 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
489 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
490 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
493 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
494 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
496 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
497 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
498 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
499 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
500 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
501 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
502 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
507 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
509 static const yytype_uint8 yyprhs
[] =
511 0, 0, 3, 4, 8, 9, 11, 13, 17, 19,
512 21, 23, 25, 27, 29, 33, 34, 37, 39, 42,
513 44, 47, 49, 51, 53, 55, 58, 62, 69, 70,
514 72, 74, 77, 79, 81, 83, 86, 90, 92, 94,
515 96, 98, 99, 103, 104, 106, 108, 112, 113, 117,
516 118, 120, 122, 126, 128, 130, 134, 135, 138, 140,
520 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
521 static const yytype_int8 yyrhs
[] =
523 34, 0, -1, -1, 35, 36, 35, -1, -1, 4,
524 -1, 38, -1, 36, 37, 38, -1, 4, -1, 45,
525 -1, 43, -1, 44, -1, 39, -1, 41, -1, 10,
526 27, 40, -1, -1, 28, 25, -1, 42, -1, 41,
527 42, -1, 16, -1, 18, 55, -1, 22, -1, 23,
528 -1, 24, -1, 21, -1, 6, 25, -1, 7, 15,
529 61, -1, 3, 15, 52, 4, 46, 5, -1, -1,
530 47, -1, 48, -1, 47, 48, -1, 16, -1, 49,
531 -1, 50, -1, 9, 19, -1, 8, 51, 20, -1,
532 11, -1, 14, -1, 12, -1, 13, -1, -1, 29,
533 53, 30, -1, -1, 54, -1, 15, -1, 54, 28,
534 15, -1, -1, 29, 56, 30, -1, -1, 57, -1,
535 58, -1, 57, 28, 58, -1, 61, -1, 59, -1,
536 31, 60, 32, -1, -1, 60, 16, -1, 15, -1,
537 26, -1, 27, -1, 25, -1
540 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
541 static const yytype_uint16 yyrline
[] =
543 0, 130, 130, 131, 134, 135, 138, 139, 143, 150,
544 151, 152, 153, 154, 157, 163, 164, 172, 173, 176,
545 177, 178, 181, 184, 187, 193, 197, 203, 210, 211,
546 214, 215, 218, 219, 220, 223, 227, 235, 236, 237,
547 238, 241, 242, 245, 246, 249, 250, 253, 254, 257,
548 258, 261, 262, 265, 266, 269, 272, 273, 279, 280,
553 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
554 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
555 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
556 static const char *const yytname
[] =
558 "$end", "error", "$undefined", "\".macro\"", "\"\\n\"", "\".endm\"",
559 "\".include\"", "\".macro_const\"", "\".macro_local\"",
560 "\".macro_label\"", "\".line\"", "\"int\"", "\"num\"", "\"string\"",
561 "\"pmc\"", "\"identifier\"", "\"any token\"", "\"macro body\"",
562 "\".identifier\"", "\"label\"", "\"$identifier\"", "\"var expansion\"",
563 "\"label target expansion\"", "\"unique label\"", "\"unique local\"",
564 "\"string constant\"", "\"number constant\"", "\"integer constant\"",
565 "','", "'('", "')'", "'{'", "'}'", "$accept", "program", "opt_nl",
566 "statements", "newline", "statement", "line_directive", "opt_filename",
567 "anything", "any", "include_statement", "macro_const_definition",
568 "macro_definition", "opt_macro_body", "macro_body", "body_token",
569 "label_declaration", "local_declaration", "type", "parameters",
570 "opt_param_list", "param_list", "arguments", "opt_arg_list", "arg_list",
571 "arg", "braced_arg", "long_arg", "expression", 0
576 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
578 static const yytype_uint16 yytoknum
[] =
580 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
581 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
582 275, 276, 277, 278, 279, 280, 281, 282, 44, 40,
587 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
588 static const yytype_uint8 yyr1
[] =
590 0, 33, 34, 34, 35, 35, 36, 36, 37, 38,
591 38, 38, 38, 38, 39, 40, 40, 41, 41, 42,
592 42, 42, 42, 42, 42, 43, 44, 45, 46, 46,
593 47, 47, 48, 48, 48, 49, 50, 51, 51, 51,
594 51, 52, 52, 53, 53, 54, 54, 55, 55, 56,
595 56, 57, 57, 58, 58, 59, 60, 60, 61, 61,
599 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
600 static const yytype_uint8 yyr2
[] =
602 0, 2, 0, 3, 0, 1, 1, 3, 1, 1,
603 1, 1, 1, 1, 3, 0, 2, 1, 2, 1,
604 2, 1, 1, 1, 1, 2, 3, 6, 0, 1,
605 1, 2, 1, 1, 1, 2, 3, 1, 1, 1,
606 1, 0, 3, 0, 1, 1, 3, 0, 3, 0,
607 1, 1, 3, 1, 1, 3, 0, 2, 1, 1,
611 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
612 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
613 means the default is an error. */
614 static const yytype_uint8 yydefact
[] =
616 4, 5, 0, 0, 1, 0, 0, 0, 0, 19,
617 47, 24, 21, 22, 23, 4, 6, 12, 13, 17,
618 10, 11, 9, 41, 25, 0, 15, 49, 20, 8,
619 3, 0, 18, 43, 0, 58, 61, 59, 60, 26,
620 0, 14, 56, 0, 50, 51, 54, 53, 7, 45,
621 0, 44, 28, 16, 0, 48, 0, 42, 0, 0,
622 0, 32, 0, 29, 30, 33, 34, 57, 55, 52,
623 46, 37, 39, 40, 38, 0, 35, 27, 31, 36
626 /* YYDEFGOTO[NTERM-NUM]. */
627 static const yytype_int8 yydefgoto
[] =
629 -1, 2, 3, 15, 31, 16, 17, 41, 18, 19,
630 20, 21, 22, 62, 63, 64, 65, 66, 75, 34,
631 50, 51, 28, 43, 44, 45, 46, 54, 47
634 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
636 #define YYPACT_NINF -18
637 static const yytype_int8 yypact
[] =
639 2, -18, 5, -3, -18, -5, -14, 8, 1, -18,
640 -17, -18, -18, -18, -18, 23, -18, -18, 19, -18,
641 -18, -18, -18, 9, -18, 7, 3, -1, -18, 29,
642 -18, -3, -18, 21, 35, -18, -18, -18, -18, -18,
643 24, -18, -18, 18, 22, -18, -18, -18, -18, -18,
644 25, 26, 0, -18, -15, -18, -1, -18, 36, 33,
645 34, -18, 47, 0, -18, -18, -18, -18, -18, -18,
646 -18, -18, -18, -18, -18, 37, -18, -18, -18, -18
649 /* YYPGOTO[NTERM-NUM]. */
650 static const yytype_int8 yypgoto
[] =
652 -18, -18, 41, -18, -18, 27, -18, -18, -18, 42,
653 -18, -18, -18, -18, -18, -4, -18, -18, -18, -18,
654 -18, -18, -18, -18, -18, 6, -18, -18, 38
657 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
658 positive, shift that token. If negative, reduce the rule which
659 number is the opposite. If zero, do what YYDEFACT says.
660 If YYTABLE_NINF, syntax error. */
661 #define YYTABLE_NINF -6
662 static const yytype_int8 yytable
[] =
664 5, 67, -2, 6, 7, 4, 1, 8, 59, 60,
665 23, 24, 27, 9, 35, 10, 61, 68, 11, 12,
666 13, 14, 35, 25, 36, 37, 38, 29, 26, -5,
667 42, 40, 36, 37, 38, 9, 49, 10, 33, 52,
668 11, 12, 13, 14, 71, 72, 73, 74, 55, 53,
669 56, 70, 77, 76, 58, 57, 30, 79, 48, 78,
673 static const yytype_int8 yycheck
[] =
675 3, 16, 0, 6, 7, 0, 4, 10, 8, 9,
676 15, 25, 29, 16, 15, 18, 16, 32, 21, 22,
677 23, 24, 15, 15, 25, 26, 27, 4, 27, 0,
678 31, 28, 25, 26, 27, 16, 15, 18, 29, 4,
679 21, 22, 23, 24, 11, 12, 13, 14, 30, 25,
680 28, 15, 5, 19, 28, 30, 15, 20, 31, 63,
684 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
685 symbol of state STATE-NUM. */
686 static const yytype_uint8 yystos
[] =
688 0, 4, 34, 35, 0, 3, 6, 7, 10, 16,
689 18, 21, 22, 23, 24, 36, 38, 39, 41, 42,
690 43, 44, 45, 15, 25, 15, 27, 29, 55, 4,
691 35, 37, 42, 29, 52, 15, 25, 26, 27, 61,
692 28, 40, 31, 56, 57, 58, 59, 61, 38, 15,
693 53, 54, 4, 25, 60, 30, 28, 30, 28, 8,
694 9, 16, 46, 47, 48, 49, 50, 16, 32, 58,
695 15, 11, 12, 13, 14, 51, 19, 5, 48, 20
698 #define yyerrok (yyerrstatus = 0)
699 #define yyclearin (yychar = YYEMPTY)
703 #define YYACCEPT goto yyacceptlab
704 #define YYABORT goto yyabortlab
705 #define YYERROR goto yyerrorlab
708 /* Like YYERROR except do call yyerror. This remains here temporarily
709 to ease the transition to the new meaning of YYERROR, for GCC.
710 Once GCC version 2 has supplanted version 1, this can go. */
712 #define YYFAIL goto yyerrlab
714 #define YYRECOVERING() (!!yyerrstatus)
716 #define YYBACKUP(Token, Value) \
718 if (yychar == YYEMPTY && yylen == 1) \
722 yytoken = YYTRANSLATE (yychar); \
728 yyerror (yyscanner, lexer, YY_("syntax error: cannot back up")); \
735 #define YYERRCODE 256
738 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
739 If N is 0, then set CURRENT to the empty location which ends
740 the previous symbol: RHS[0] (always defined). */
742 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
743 #ifndef YYLLOC_DEFAULT
744 # define YYLLOC_DEFAULT(Current, Rhs, N) \
748 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
749 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
750 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
751 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
755 (Current).first_line = (Current).last_line = \
756 YYRHSLOC (Rhs, 0).last_line; \
757 (Current).first_column = (Current).last_column = \
758 YYRHSLOC (Rhs, 0).last_column; \
764 /* YY_LOCATION_PRINT -- Print the location on the stream.
765 This macro was not mandated originally: define only if we know
766 we won't break user code: when these are the locations we know. */
768 #ifndef YY_LOCATION_PRINT
769 # if YYLTYPE_IS_TRIVIAL
770 # define YY_LOCATION_PRINT(File, Loc) \
771 fprintf (File, "%d.%d-%d.%d", \
772 (Loc).first_line, (Loc).first_column, \
773 (Loc).last_line, (Loc).last_column)
775 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
780 /* YYLEX -- calling `yylex' with the right arguments. */
783 # define YYLEX yylex (&yylval, YYLEX_PARAM)
785 # define YYLEX yylex (&yylval, yyscanner)
788 /* Enable debugging if requested. */
792 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
793 # define YYFPRINTF fprintf
796 # define YYDPRINTF(Args) \
802 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
806 YYFPRINTF (stderr, "%s ", Title); \
807 yy_symbol_print (stderr, \
808 Type, Value, yyscanner, lexer); \
809 YYFPRINTF (stderr, "\n"); \
814 /*--------------------------------.
815 | Print this symbol on YYOUTPUT. |
816 `--------------------------------*/
819 #if (defined __STDC__ || defined __C99__FUNC__ \
820 || defined __cplusplus || defined _MSC_VER)
822 yy_symbol_value_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
, yyscan_t yyscanner
, struct lexer_state
*lexer
)
825 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
, yyscanner
, lexer
)
828 YYSTYPE
const * const yyvaluep
;
830 struct lexer_state
*lexer
;
838 if (yytype
< YYNTOKENS
)
839 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
851 /*--------------------------------.
852 | Print this symbol on YYOUTPUT. |
853 `--------------------------------*/
855 #if (defined __STDC__ || defined __C99__FUNC__ \
856 || defined __cplusplus || defined _MSC_VER)
858 yy_symbol_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
, yyscan_t yyscanner
, struct lexer_state
*lexer
)
861 yy_symbol_print (yyoutput
, yytype
, yyvaluep
, yyscanner
, lexer
)
864 YYSTYPE
const * const yyvaluep
;
866 struct lexer_state
*lexer
;
869 if (yytype
< YYNTOKENS
)
870 YYFPRINTF (yyoutput
, "token %s (", yytname
[yytype
]);
872 YYFPRINTF (yyoutput
, "nterm %s (", yytname
[yytype
]);
874 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
, yyscanner
, lexer
);
875 YYFPRINTF (yyoutput
, ")");
878 /*------------------------------------------------------------------.
879 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
881 `------------------------------------------------------------------*/
883 #if (defined __STDC__ || defined __C99__FUNC__ \
884 || defined __cplusplus || defined _MSC_VER)
886 yy_stack_print (yytype_int16
*bottom
, yytype_int16
*top
)
889 yy_stack_print (bottom
, top
)
890 yytype_int16
*bottom
;
894 YYFPRINTF (stderr
, "Stack now");
895 for (; bottom
<= top
; ++bottom
)
896 YYFPRINTF (stderr
, " %d", *bottom
);
897 YYFPRINTF (stderr
, "\n");
900 # define YY_STACK_PRINT(Bottom, Top) \
903 yy_stack_print ((Bottom), (Top)); \
907 /*------------------------------------------------.
908 | Report that the YYRULE is going to be reduced. |
909 `------------------------------------------------*/
911 #if (defined __STDC__ || defined __C99__FUNC__ \
912 || defined __cplusplus || defined _MSC_VER)
914 yy_reduce_print (YYSTYPE
*yyvsp
, int yyrule
, yyscan_t yyscanner
, struct lexer_state
*lexer
)
917 yy_reduce_print (yyvsp
, yyrule
, yyscanner
, lexer
)
921 struct lexer_state
*lexer
;
924 int yynrhs
= yyr2
[yyrule
];
926 unsigned long int yylno
= yyrline
[yyrule
];
927 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
929 /* The symbols being reduced. */
930 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
932 fprintf (stderr
, " $%d = ", yyi
+ 1);
933 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
934 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
936 fprintf (stderr
, "\n");
940 # define YY_REDUCE_PRINT(Rule) \
943 yy_reduce_print (yyvsp, Rule, yyscanner, lexer); \
946 /* Nonzero means print parse trace. It is left uninitialized so that
947 multiple parsers can coexist. */
950 # define YYDPRINTF(Args)
951 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
952 # define YY_STACK_PRINT(Bottom, Top)
953 # define YY_REDUCE_PRINT(Rule)
954 #endif /* !YYDEBUG */
957 /* YYINITDEPTH -- initial size of the parser's stacks. */
959 # define YYINITDEPTH 200
962 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
963 if the built-in stack extension method is used).
965 Do not make this value too large; the results are undefined if
966 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
967 evaluated with infinite-precision integer arithmetic. */
970 # define YYMAXDEPTH 10000
978 # if defined __GLIBC__ && defined _STRING_H
979 # define yystrlen strlen
981 /* Return the length of YYSTR. */
982 #if (defined __STDC__ || defined __C99__FUNC__ \
983 || defined __cplusplus || defined _MSC_VER)
985 yystrlen (const char *yystr
)
993 for (yylen
= 0; yystr
[yylen
]; yylen
++)
1001 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1002 # define yystpcpy stpcpy
1004 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1006 #if (defined __STDC__ || defined __C99__FUNC__ \
1007 || defined __cplusplus || defined _MSC_VER)
1009 yystpcpy (char *yydest
, const char *yysrc
)
1012 yystpcpy (yydest
, yysrc
)
1018 const char *yys
= yysrc
;
1020 while ((*yyd
++ = *yys
++) != '\0')
1029 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1030 quotes and backslashes, so that it's suitable for yyerror. The
1031 heuristic is that double-quoting is unnecessary unless the string
1032 contains an apostrophe, a comma, or backslash (other than
1033 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1034 null, do not copy; instead, return the length of what the result
1037 yytnamerr (char *yyres
, const char *yystr
)
1042 char const *yyp
= yystr
;
1049 goto do_not_strip_quotes
;
1053 goto do_not_strip_quotes
;
1066 do_not_strip_quotes
: ;
1070 return yystrlen (yystr
);
1072 return yystpcpy (yyres
, yystr
) - yyres
;
1076 /* Copy into YYRESULT an error message about the unexpected token
1077 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1078 including the terminating null byte. If YYRESULT is null, do not
1079 copy anything; just return the number of bytes that would be
1080 copied. As a special case, return 0 if an ordinary "syntax error"
1081 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1082 size calculation. */
1084 yysyntax_error (char *yyresult
, int yystate
, int yychar
)
1086 int yyn
= yypact
[yystate
];
1088 if (! (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
))
1092 int yytype
= YYTRANSLATE (yychar
);
1093 YYSIZE_T yysize0
= yytnamerr (0, yytname
[yytype
]);
1094 YYSIZE_T yysize
= yysize0
;
1096 int yysize_overflow
= 0;
1097 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1098 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1102 /* This is so xgettext sees the translatable formats that are
1103 constructed on the fly. */
1104 YY_("syntax error, unexpected %s");
1105 YY_("syntax error, unexpected %s, expecting %s");
1106 YY_("syntax error, unexpected %s, expecting %s or %s");
1107 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1108 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1112 static char const yyunexpected
[] = "syntax error, unexpected %s";
1113 static char const yyexpecting
[] = ", expecting %s";
1114 static char const yyor
[] = " or %s";
1115 char yyformat
[sizeof yyunexpected
1116 + sizeof yyexpecting
- 1
1117 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1118 * (sizeof yyor
- 1))];
1119 char const *yyprefix
= yyexpecting
;
1121 /* Start YYX at -YYN if negative to avoid negative indexes in
1123 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1125 /* Stay within bounds of both yycheck and yytname. */
1126 int yychecklim
= YYLAST
- yyn
+ 1;
1127 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1130 yyarg
[0] = yytname
[yytype
];
1131 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1133 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1134 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1136 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1140 yyformat
[sizeof yyunexpected
- 1] = '\0';
1143 yyarg
[yycount
++] = yytname
[yyx
];
1144 yysize1
= yysize
+ yytnamerr (0, yytname
[yyx
]);
1145 yysize_overflow
|= (yysize1
< yysize
);
1147 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1151 yyf
= YY_(yyformat
);
1152 yysize1
= yysize
+ yystrlen (yyf
);
1153 yysize_overflow
|= (yysize1
< yysize
);
1156 if (yysize_overflow
)
1157 return YYSIZE_MAXIMUM
;
1161 /* Avoid sprintf, as that infringes on the user's name space.
1162 Don't have undefined behavior even if the translation
1163 produced a string with the wrong number of "%s"s. */
1164 char *yyp
= yyresult
;
1166 while ((*yyp
= *yyf
) != '\0')
1168 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1170 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1183 #endif /* YYERROR_VERBOSE */
1186 /*-----------------------------------------------.
1187 | Release the memory associated to this symbol. |
1188 `-----------------------------------------------*/
1191 #if (defined __STDC__ || defined __C99__FUNC__ \
1192 || defined __cplusplus || defined _MSC_VER)
1194 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
, yyscan_t yyscanner
, struct lexer_state
*lexer
)
1197 yydestruct (yymsg
, yytype
, yyvaluep
, yyscanner
, lexer
)
1202 struct lexer_state
*lexer
;
1211 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1222 /* Prevent warnings from -Wmissing-prototypes. */
1224 #ifdef YYPARSE_PARAM
1225 #if defined __STDC__ || defined __cplusplus
1226 int yyparse (void *YYPARSE_PARAM
);
1230 #else /* ! YYPARSE_PARAM */
1231 #if defined __STDC__ || defined __cplusplus
1232 int yyparse (yyscan_t yyscanner
, struct lexer_state
*lexer
);
1236 #endif /* ! YYPARSE_PARAM */
1247 #ifdef YYPARSE_PARAM
1248 #if (defined __STDC__ || defined __C99__FUNC__ \
1249 || defined __cplusplus || defined _MSC_VER)
1251 yyparse (void *YYPARSE_PARAM
)
1254 yyparse (YYPARSE_PARAM
)
1255 void *YYPARSE_PARAM
;
1257 #else /* ! YYPARSE_PARAM */
1258 #if (defined __STDC__ || defined __C99__FUNC__ \
1259 || defined __cplusplus || defined _MSC_VER)
1261 yyparse (yyscan_t yyscanner
, struct lexer_state
*lexer
)
1264 yyparse (yyscanner
, lexer
)
1266 struct lexer_state
*lexer
;
1270 /* The look-ahead symbol. */
1273 /* The semantic value of the look-ahead symbol. */
1276 /* Number of syntax errors so far. */
1282 /* Number of tokens to shift before error messages enabled. */
1284 /* Look-ahead token as an internal (translated) token number. */
1287 /* Buffer for error messages, and its allocated size. */
1289 char *yymsg
= yymsgbuf
;
1290 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1293 /* Three stacks and their tools:
1294 `yyss': related to states,
1295 `yyvs': related to semantic values,
1296 `yyls': related to locations.
1298 Refer to the stacks thru separate pointers, to allow yyoverflow
1299 to reallocate them elsewhere. */
1301 /* The state stack. */
1302 yytype_int16 yyssa
[YYINITDEPTH
];
1303 yytype_int16
*yyss
= yyssa
;
1304 yytype_int16
*yyssp
;
1306 /* The semantic value stack. */
1307 YYSTYPE yyvsa
[YYINITDEPTH
];
1308 YYSTYPE
*yyvs
= yyvsa
;
1313 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1315 YYSIZE_T yystacksize
= YYINITDEPTH
;
1317 /* The variables used to return semantic value and location from the
1322 /* The number of symbols on the RHS of the reduced rule.
1323 Keep to zero when no symbol should be popped. */
1326 YYDPRINTF ((stderr
, "Starting parse\n"));
1331 yychar
= YYEMPTY
; /* Cause a token to be read. */
1333 /* Initialize stack pointers.
1334 Waste one element of value and location stack
1335 so that they stay on the same level as the state stack.
1336 The wasted elements are never initialized. */
1343 /*------------------------------------------------------------.
1344 | yynewstate -- Push a new state, which is found in yystate. |
1345 `------------------------------------------------------------*/
1347 /* In all cases, when you get here, the value and location stacks
1348 have just been pushed. So pushing a state here evens the stacks. */
1354 if (yyss
+ yystacksize
- 1 <= yyssp
)
1356 /* Get the current used size of the three stacks, in elements. */
1357 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1361 /* Give user a chance to reallocate the stack. Use copies of
1362 these so that the &'s don't force the real ones into
1364 YYSTYPE
*yyvs1
= yyvs
;
1365 yytype_int16
*yyss1
= yyss
;
1368 /* Each stack pointer address is followed by the size of the
1369 data in use in that stack, in bytes. This used to be a
1370 conditional around just the two extra args, but that might
1371 be undefined if yyoverflow is a macro. */
1372 yyoverflow (YY_("memory exhausted"),
1373 &yyss1
, yysize
* sizeof (*yyssp
),
1374 &yyvs1
, yysize
* sizeof (*yyvsp
),
1381 #else /* no yyoverflow */
1382 # ifndef YYSTACK_RELOCATE
1383 goto yyexhaustedlab
;
1385 /* Extend the stack our own way. */
1386 if (YYMAXDEPTH
<= yystacksize
)
1387 goto yyexhaustedlab
;
1389 if (YYMAXDEPTH
< yystacksize
)
1390 yystacksize
= YYMAXDEPTH
;
1393 yytype_int16
*yyss1
= yyss
;
1394 union yyalloc
*yyptr
=
1395 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1397 goto yyexhaustedlab
;
1398 YYSTACK_RELOCATE (yyss
);
1399 YYSTACK_RELOCATE (yyvs
);
1401 # undef YYSTACK_RELOCATE
1403 YYSTACK_FREE (yyss1
);
1406 #endif /* no yyoverflow */
1408 yyssp
= yyss
+ yysize
- 1;
1409 yyvsp
= yyvs
+ yysize
- 1;
1412 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1413 (unsigned long int) yystacksize
));
1415 if (yyss
+ yystacksize
- 1 <= yyssp
)
1419 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1428 /* Do appropriate processing given the current state. Read a
1429 look-ahead token if we need one and don't already have one. */
1431 /* First try to decide what to do without reference to look-ahead token. */
1432 yyn
= yypact
[yystate
];
1433 if (yyn
== YYPACT_NINF
)
1436 /* Not known => get a look-ahead token if don't already have one. */
1438 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1439 if (yychar
== YYEMPTY
)
1441 YYDPRINTF ((stderr
, "Reading a token: "));
1445 if (yychar
<= YYEOF
)
1447 yychar
= yytoken
= YYEOF
;
1448 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1452 yytoken
= YYTRANSLATE (yychar
);
1453 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1456 /* If the proper action on seeing token YYTOKEN is to reduce or to
1457 detect an error, take that action. */
1459 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1464 if (yyn
== 0 || yyn
== YYTABLE_NINF
)
1473 /* Count tokens shifted since error; after three, turn off error
1478 /* Shift the look-ahead token. */
1479 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1481 /* Discard the shifted token unless it is eof. */
1482 if (yychar
!= YYEOF
)
1491 /*-----------------------------------------------------------.
1492 | yydefault -- do the default action for the current state. |
1493 `-----------------------------------------------------------*/
1495 yyn
= yydefact
[yystate
];
1501 /*-----------------------------.
1502 | yyreduce -- Do a reduction. |
1503 `-----------------------------*/
1505 /* yyn is the number of a rule to reduce with. */
1508 /* If YYLEN is nonzero, implement the default value of the action:
1511 Otherwise, the following line sets YYVAL to garbage.
1512 This behavior is undocumented and Bison
1513 users should not rely upon it. Assigning to YYVAL
1514 unconditionally makes the parser a bit smaller, and it avoids a
1515 GCC warning that YYVAL may be used uninitialized. */
1516 yyval
= yyvsp
[1-yylen
];
1519 YY_REDUCE_PRINT (yyn
);
1524 { emit("\n"); /* after each statement, emit a newline */ ;}
1530 emit((yyvsp
[(2) - (3)].sval
));
1537 emit((yyvsp
[(2) - (2)].sval
));
1544 { emit((yyvsp
[(1) - (1)].sval
)); ;}
1549 { expand((yyvsp
[(1) - (2)].mval
), (yyvsp
[(2) - (2)].lval
), lexer
); ;}
1554 { char *label
= munge_id((yyvsp
[(1) - (1)].sval
), 1, lexer
);
1561 { char *label
= munge_id((yyvsp
[(1) - (1)].sval
), 1, lexer
);
1568 { char *local
= munge_id((yyvsp
[(1) - (1)].sval
), 0, lexer
);
1575 { char *label
= munge_id((yyvsp
[(1) - (1)].sval
), 0, lexer
);
1582 { include_file((yyvsp
[(2) - (2)].sval
), lexer
); ;}
1587 { define_constant(lexer
->globaldefinitions
, (yyvsp
[(2) - (3)].sval
), (yyvsp
[(3) - (3)].sval
)); ;}
1592 { define_macro(lexer
->globaldefinitions
, (yyvsp
[(2) - (6)].sval
), (yyvsp
[(3) - (6)].lval
), (yyvsp
[(5) - (6)].sval
)); ;}
1597 { (yyval
.sval
) = ""; ;}
1602 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1607 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1612 { (yyval
.sval
) = concat((yyvsp
[(1) - (2)].sval
), (yyvsp
[(2) - (2)].sval
), 1); ;}
1617 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1622 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1627 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1632 { (yyval
.sval
) = (yyvsp
[(2) - (2)].sval
); ;}
1637 { /* create a string like ".local <type> <id>" */
1638 (yyval
.sval
) = dupstr(".local");
1639 (yyval
.sval
) = concat((yyval
.sval
), (yyvsp
[(2) - (3)].sval
), 1);
1640 (yyval
.sval
) = concat((yyval
.sval
), (yyvsp
[(3) - (3)].sval
), 1);
1646 { (yyval
.lval
) = NULL
; ;}
1651 { (yyval
.lval
) = (yyvsp
[(2) - (3)].lval
); ;}
1656 { (yyval
.lval
) = NULL
; ;}
1661 { (yyval
.lval
) = (yyvsp
[(1) - (1)].lval
); ;}
1666 { (yyval
.lval
) = new_list((yyvsp
[(1) - (1)].sval
)); ;}
1671 { (yyval
.lval
) = add_item((yyvsp
[(1) - (3)].lval
), (yyvsp
[(3) - (3)].sval
)); ;}
1676 { (yyval
.lval
) = NULL
; ;}
1681 { (yyval
.lval
) = (yyvsp
[(2) - (3)].lval
); ;}
1686 { (yyval
.lval
) = NULL
; ;}
1691 { (yyval
.lval
) = (yyvsp
[(1) - (1)].lval
); ;}
1696 { (yyval
.lval
) = new_list((yyvsp
[(1) - (1)].sval
)); ;}
1701 { (yyval
.lval
) = add_item((yyvsp
[(1) - (3)].lval
), (yyvsp
[(3) - (3)].sval
)); ;}
1706 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1711 { (yyval
.sval
) = (yyvsp
[(1) - (1)].sval
); ;}
1716 { (yyval
.sval
) = (yyvsp
[(2) - (3)].sval
); ;}
1721 { (yyval
.sval
) = ""; ;}
1726 { (yyval
.sval
) = concat((yyvsp
[(1) - (2)].sval
), (yyvsp
[(2) - (2)].sval
), 0); ;}
1730 /* Line 1267 of yacc.c. */
1731 #line 1732 "macroparser.c"
1734 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1738 YY_STACK_PRINT (yyss
, yyssp
);
1743 /* Now `shift' the result of the reduction. Determine what state
1744 that goes to, based on the state we popped back to and the rule
1745 number reduced by. */
1749 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1750 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1751 yystate
= yytable
[yystate
];
1753 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1758 /*------------------------------------.
1759 | yyerrlab -- here on detecting error |
1760 `------------------------------------*/
1762 /* If not already recovering from an error, report this error. */
1766 #if ! YYERROR_VERBOSE
1767 yyerror (yyscanner
, lexer
, YY_("syntax error"));
1770 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
1771 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
1773 YYSIZE_T yyalloc
= 2 * yysize
;
1774 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
1775 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1776 if (yymsg
!= yymsgbuf
)
1777 YYSTACK_FREE (yymsg
);
1778 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
1780 yymsg_alloc
= yyalloc
;
1784 yymsg_alloc
= sizeof yymsgbuf
;
1788 if (0 < yysize
&& yysize
<= yymsg_alloc
)
1790 (void) yysyntax_error (yymsg
, yystate
, yychar
);
1791 yyerror (yyscanner
, lexer
, yymsg
);
1795 yyerror (yyscanner
, lexer
, YY_("syntax error"));
1797 goto yyexhaustedlab
;
1805 if (yyerrstatus
== 3)
1807 /* If just tried and failed to reuse look-ahead token after an
1808 error, discard it. */
1810 if (yychar
<= YYEOF
)
1812 /* Return failure if at end of input. */
1813 if (yychar
== YYEOF
)
1818 yydestruct ("Error: discarding",
1819 yytoken
, &yylval
, yyscanner
, lexer
);
1824 /* Else will try to reuse look-ahead token after shifting the error
1829 /*---------------------------------------------------.
1830 | yyerrorlab -- error raised explicitly by YYERROR. |
1831 `---------------------------------------------------*/
1834 /* Pacify compilers like GCC when the user code never invokes
1835 YYERROR and the label yyerrorlab therefore never appears in user
1837 if (/*CONSTCOND*/ 0)
1840 /* Do not reclaim the symbols of the rule which action triggered
1844 YY_STACK_PRINT (yyss
, yyssp
);
1849 /*-------------------------------------------------------------.
1850 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1851 `-------------------------------------------------------------*/
1853 yyerrstatus
= 3; /* Each real token shifted decrements this. */
1857 yyn
= yypact
[yystate
];
1858 if (yyn
!= YYPACT_NINF
)
1861 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
1869 /* Pop the current state because it cannot handle the error token. */
1874 yydestruct ("Error: popping",
1875 yystos
[yystate
], yyvsp
, yyscanner
, lexer
);
1878 YY_STACK_PRINT (yyss
, yyssp
);
1887 /* Shift the error token. */
1888 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
1894 /*-------------------------------------.
1895 | yyacceptlab -- YYACCEPT comes here. |
1896 `-------------------------------------*/
1901 /*-----------------------------------.
1902 | yyabortlab -- YYABORT comes here. |
1903 `-----------------------------------*/
1909 /*-------------------------------------------------.
1910 | yyexhaustedlab -- memory exhaustion comes here. |
1911 `-------------------------------------------------*/
1913 yyerror (yyscanner
, lexer
, YY_("memory exhausted"));
1919 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
1920 yydestruct ("Cleanup: discarding lookahead",
1921 yytoken
, &yylval
, yyscanner
, lexer
);
1922 /* Do not reclaim the symbols of the rule which action triggered
1923 this YYABORT or YYACCEPT. */
1925 YY_STACK_PRINT (yyss
, yyssp
);
1926 while (yyssp
!= yyss
)
1928 yydestruct ("Cleanup: popping",
1929 yystos
[*yyssp
], yyvsp
, yyscanner
, lexer
);
1934 YYSTACK_FREE (yyss
);
1937 if (yymsg
!= yymsgbuf
)
1938 YYSTACK_FREE (yymsg
);
1940 /* Make sure YYID is used. */
1941 return YYID (yyresult
);
1957 Create a new list node. The specified item is assigned to the node's value.
1958 Returns the newly created node.
1964 new_list(char *first_item
) {
1965 list
*L
= (list
*)malloc(sizeof (list
));
1967 memset(L
, 0, sizeof (list
));
1968 L
->item
= first_item
;
1976 Add a new item to the specified list. The item is added
1977 at the back of the list, so items added are kept in order.
1979 A pointer to the beginning of the list is returned (the
1980 same as was specified).
1986 add_item(list
*L
, char *item
) {
1988 assert(iter
!= NULL
);
1990 /* the item is added at the end of the list. This
1991 * can be done more efficiently, but for now this works.
1993 while (iter
->next
!= NULL
) {
1996 /* iter->next is now NULL, link the new node onto it. */
1997 iter
->next
= new_list(item
);
2004 =item C<include_file>
2006 Process the specified file.
2013 include_file(char *filename
, lexer_state
*lexer
) {
2014 assert(filename
!= NULL
);
2015 fprintf(stderr
, "including: %s\n", filename
);
2016 /* remove closing quote */
2017 filename
[strlen(filename
) - 1] = '\0';
2018 /* give address of string, skipping opening quote */
2019 process_file(filename
+ 1, lexer
);
2024 =item C<update_unique_id>
2030 update_unique_id(lexer_state
*lexer
) {
2031 /* each expansion has a unique id that is used for label/local munging */
2033 /* Count number of digits:
2034 * log10 returns a double, get the part before the dot (so, "3.14" -> "3")
2035 * using the floor() function.
2036 * log10(1000) -> 3, so add 1 more digit.
2038 lexer
->num_digits
= floor(log10(lexer
->id_gen
)) + 1;
2046 Expand the specified macro (or constant).
2052 expand(macro_def
*macro
, list
*args
, lexer_state
*lexer
) {
2053 /* construct a map data structure that maps the argument values to the parameter names */
2054 /* enter the parameters as temporary symbols (.macro_const) */
2055 constant_table
*macro_params
= new_constant_table(lexer
->globaldefinitions
, lexer
);
2056 list
*params
= macro
->parameters
;
2058 int current_scope_nr
;
2059 char *current_macro_id
;
2061 while (params
&& args
) {
2062 define_constant(macro_params
, params
->item
, args
->item
);
2063 params
= params
->next
;
2067 /* check for both conditions; either can be non-null, indicating an error.
2068 * If both are null, then all went ok.
2070 if (params
!= NULL
) { /* args must be null, so too few arguments */
2071 fprintf(stderr
, "Too few arguments for macro expansion %s.\n", macro
->name
);
2073 if (args
!= NULL
) { /* params must be null, so too many arguments */
2074 fprintf(stderr
, "Too many arguments for macro expansion %s.\n", macro
->name
);
2077 fprintf(stderr, "expanding '%s'\n", macro->name);
2078 fprintf(stderr, "[%s]\n", macro->body);
2080 /* parse the macro body */
2083 fprintf(stderr, "expansion '%s' starting\n", macro->name);
2085 current_macro_id
= lexer
->macro_id
;
2086 lexer
->macro_id
= macro
->name
;
2087 /* save current scope id */
2088 current_scope_nr
= lexer
->unique_id
;
2089 update_unique_id(lexer
);
2090 lexer
->unique_id
= lexer
->id_gen
;
2091 process_string(macro
->body
, lexer
);
2093 /* restore current scope id */
2094 lexer
->unique_id
= current_scope_nr
;
2095 lexer
->macro_id
= current_macro_id
;
2097 fprintf(stderr, "expansion '%s' done\n", macro->name);
2100 /* now remove the temporary constant definitions */
2101 pop_constant_table(lexer
);
2102 delete_constant_table(macro_params
);
2104 update_unique_id(lexer);
2110 =item C<define_constant>
2112 Define the specified name as an alias for the specified value.
2118 define_constant(constant_table
*table
, char *name
, char *value
) {
2119 macro_def
*def
= (macro_def
*)malloc(sizeof (macro_def
));
2120 assert(def
!= NULL
);
2121 memset(def
, 0, sizeof (macro_def
));
2126 def
->next
= table
->definitions
;
2127 table
->definitions
= def
;
2134 =item C<define_macro>
2136 Define a macro by the given name, parameters and body.
2142 define_macro(constant_table
*table
, char *name
, list
*parameters
, char *body
) {
2143 macro_def
*macro
= (macro_def
*)malloc(sizeof (macro_def
));
2144 assert(macro
!= NULL
);
2145 memset(macro
, 0, sizeof (macro_def
));
2147 /* initialize the fields */
2150 macro
->parameters
= parameters
;
2152 /* link the macro in the list */
2153 macro
->next
= table
->definitions
;
2154 table
->definitions
= macro
;
2162 Find the specified macro. If the specified macro does not exist,
2169 find_macro(constant_table
*table
, char *name
) {
2170 macro_def
*iter
= table
->definitions
;
2171 assert(name
!= NULL
);
2173 /* iterate over the list and compare each node's name */
2174 while (iter
!= NULL
) {
2175 if (strcmp(iter
->name
, name
) == 0)
2181 return find_macro(table
->prev
, name
);
2190 Concatenate two strings, and return the result. If the first string is NULL, then
2191 the result consists of the second string. If need_space is true, a space is
2192 inserted between the two strings.
2198 concat(char *str1
, char *str2
, int need_space
) {
2199 assert (str2
!= NULL
);
2204 /* allocate a new buffer large enough to hold both strings, a space, and the NULL char. */
2205 /* TODO: make this more efficient; don't malloc every time, just allocate a big enough
2206 * buffer, and only increase it if it's full. For now this is the easiest solution.
2208 int strlen1
= strlen(str1
);
2209 char *newbuffer
= (char *)calloc(strlen1
+ strlen(str2
) + 1 + (need_space
? 1 : 0), sizeof (char));
2211 assert(newbuffer
!= NULL
);
2212 sprintf(newbuffer
, "%s%s%s", str1
, need_space
? " " : "", str2
);
2222 /* short-cut to check for a label; last character must be ":" */
2223 #define is_label(X) (X[strlen(X) - 1] == ':')
2225 /* short-cut to check for token equality */
2226 #define is_token(X,Y) (strcmp(X,Y) == 0)
2233 Emit the specified string. This function will be the "gateway" to the
2234 output file. All tokens except C<.sub>, C<.end> and C<.namespace> are indented.
2235 All tokens are separated with a space, C<)>, C<]>, C<,>.
2242 FILE *output
= stdout
;
2244 static int just_nl
= 1;
2245 static int need_space
= 1;
2247 /* emit a newline between .subs and .namespaces */
2248 if (is_token(str
, ".sub") || is_token(str
, ".namespace"))
2249 fprintf(output
, "\n");
2251 /* if the token needs indention, all except .sub, .end and .namespace. */
2252 if (!is_token(str
, ".sub") && !is_token(str
, ".end") && !is_token(str
, ".namespace")) {
2253 if (just_nl
) { /* just a newline means we need some indention */
2254 if (is_label(str
)) { /* indent labels a bit less than other tokens */
2255 fprintf(output
, " ");
2257 else { /* not a label */
2258 fprintf(output
, " ");
2262 /* print the token; if it's a token like a comma, that shouldn't be prefixed with space,
2263 * remove the space (backspace)
2266 if (is_token(str, ",") || is_token(str, ")") || is_token(str, "]")) {
2267 fprintf(output, "%c", '\b');
2271 if (is_token(str
, "(") || is_token(str
, "[")) {
2272 need_space
= 0; /* no separation needed after these tokens */
2274 else { /* all normal cases emit a separation space for tokens */
2277 /* print the token */
2278 fprintf(output
, "%s", str
);
2279 /* check for newline */
2280 if (is_token(str
, "\n"))
2285 fprintf(output
, " ");
2292 FILE *output
= stdout
;
2293 fprintf(output
, "%d ", val
);
2298 =item C<new_constant_table>
2303 static constant_table
*
2304 new_constant_table(constant_table
*current
, lexer_state
*lexer
) {
2305 constant_table
*table
= (constant_table
*)malloc(sizeof (constant_table
));
2306 assert(table
!= NULL
);
2307 table
->definitions
= NULL
;
2308 table
->prev
= current
;
2310 lexer
->globaldefinitions
= table
;
2317 =item C<pop_constant_table>
2322 static constant_table
*
2323 pop_constant_table(lexer_state
*lexer
) {
2324 constant_table
*popped
= lexer
->globaldefinitions
;
2325 lexer
->globaldefinitions
= popped
->prev
;
2331 =item C<delete_constant_table>
2337 delete_constant_table(constant_table
*table
) {
2338 /* destroy all definitions */
2339 macro_def
*iter
= table
->definitions
;
2340 while (iter
!= NULL
) {
2341 macro_def
*temp
= iter
;
2354 Generate an identifier based on a macro label or locaal declaration, or a macro label
2357 A label declaration looks like: ".label $LABEL:", from which a normal
2358 PIR label is created, formatted as: "_unique_MACRO_LABEL_?:".
2360 A label expansion looks like ".$LABEL", from which a label identifier is
2361 generated, formatted as: "_unique_MACRO_LABEL_?"
2362 (note the difference, there is no colon at the end.
2364 The same works for local identifiers, but of course the is_label_declaration
2365 argument must be 0 for that.
2371 munge_id(char *id
, int is_label_declaration
, lexer_state
*lexer
) {
2372 /* the format of the generated label: */
2373 char const * const format
= "_unique_%s_%s_%d%s";
2374 int const format_length
= strlen(format
);
2376 /* calculate length of the generated label: length of macro name,
2377 * plus length of label name.
2379 int length
= format_length
+ strlen(lexer
->macro_id
) + lexer
->num_digits
;
2380 char *munged_id
= NULL
;
2382 length
+= strlen(id
);
2384 if (is_label_declaration
)
2385 length
++; /* reserve 1 more byte for the ":" */
2387 munged_id
= (char *)calloc(length
+ 1, sizeof (char));
2388 assert(munged_id
!= NULL
);
2389 /* generate the identifier; if it's a declaration, then add the colon. */
2390 sprintf(munged_id
, format
, lexer
->macro_id
, id
, lexer
->unique_id
,
2391 is_label_declaration
? ":" : "");
2399 =item C<process_string>
2401 Process the string stored in C<buffer>. First a new yyscan_t
2402 object is created, initialized, after which the specified
2403 buffer is parsed. Afterwards the yyscan_t object is destroyed.
2409 process_string(char *buffer
, lexer_state
*lexer
) {
2410 /* initialize a yyscan_t object */
2412 macrolex_init(&yyscanner
);
2414 macroset_debug(lexer
->flexdebug
, yyscanner
);
2415 macroset_extra(lexer
, yyscanner
);
2416 assert(buffer
!= NULL
);
2417 /* set the scanner to a string buffer and go parse */
2418 macro_scan_string(buffer
, yyscanner
);
2419 yyparse(yyscanner
, lexer
);
2420 /* clean up after playing */
2421 macrolex_destroy(yyscanner
);
2426 =item C<process_file>
2428 Process the specified file.
2434 process_file(char *filename
, lexer_state
*lexer
) {
2438 if (filename
== NULL
) { /* no file name means reading from stdin. */
2441 else { /* open the specified file */
2442 fp
= fopen(filename
, "r");
2446 fprintf(stderr
, "Failed to open file %s\n", filename
);
2449 /* save current state of lexer, these are overwritten, so that
2450 * error messages indicate an error in the string (macro body).
2452 int temp_line
= lexer
->line
;
2453 char *temp_file
= lexer
->currentfile
;
2455 /* construct a yylex_t object */
2456 macrolex_init(&yyscanner
);
2457 macroset_in(fp
, yyscanner
);
2458 macroset_debug(lexer
->flexdebug
, yyscanner
);
2459 macroset_extra(lexer
, yyscanner
);
2461 /* emit directives that set the file/line */
2462 /* they must be within compilation unit; this doesn't happen right now...
2469 /* go parse the file */
2470 yyparse(yyscanner
, lexer
);
2472 macrolex_destroy(yyscanner
);
2474 /* restore state of lexer */
2475 lexer
->line
= temp_line
;
2476 lexer
->currentfile
= temp_file
;
2488 print_help(char const * const programname
) {
2489 fprintf(stderr
, "Usage: %s [options] [input]\n", programname
);
2490 fprintf(stderr
, "where options are:\n");
2491 fprintf(stderr
, " -d debug the generated parser\n");
2492 fprintf(stderr
, " -f debug the generated lexer\n\n");
2493 fprintf(stderr
, "If no input is specified, the program reads from stdin.\n");
2501 Function for syntax error handling.
2507 yyerror(yyscan_t yyscanner
, lexer_state
*lexer
, char *message
) {
2508 fprintf(stderr
, "Error in '%s' (line %d): %s\n", lexer
->currentfile
, lexer
->line
, message
);
2518 Pre-processor main function.
2524 main(int argc
, char *argv
[]) {
2525 lexer_state
*lexer
= NULL
;
2526 char const * const programname
= argv
[0];
2528 /* skip program name */
2532 lexer
= (lexer_state
*)malloc(sizeof (lexer_state
));
2533 memset(lexer
, 0, sizeof (lexer_state
));
2534 assert(lexer
!= NULL
);
2535 lexer
->unique_id
= 0;
2538 lexer
->flexdebug
= 0;
2539 lexer
->macro_id
= NULL
;
2540 lexer
->globaldefinitions
= new_constant_table(NULL
, lexer
);
2543 /* very basic argument handling; I'm too lazy to check out
2544 * the standard funtion for that, right now. This is a TODO.
2546 while (argc
> 0 && argv
[0][0] == '-') {
2547 switch (argv
[0][1]) {
2548 /* Only allow for debug flag if the generated parser supports it */
2555 lexer
->flexdebug
= 1;
2558 print_help(programname
);
2559 exit(EXIT_SUCCESS
); /* asking for help doesn't make you a failure */
2562 fprintf(stderr
, "Unknown option: '%c'\n", argv
[0][1]);
2565 /* goto next command line argument */
2570 if (argc
> 0) { /* a command line argument was given */
2571 lexer
->currentfile
= argv
[0];
2572 process_file(argv
[0], lexer
);
2574 else { /* no filename */
2575 lexer
->currentfile
= "STDIN";
2576 process_file(NULL
, lexer
);
2579 if (lexer
->errors
> 0)
2580 fprintf(stderr
, "There were %d error(s)\n", lexer
->errors
);
2583 /* clean up and go home */
2584 delete_constant_table(lexer
->globaldefinitions
);
2602 * c-file-style: "parrot"
2604 * vim: expandtab shiftwidth=4: