1/* A Bison parser, made by GNU Bison 3.0.4. */
2
3/* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20/* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33/* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36/* All symbols defined below should begin with aag or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43/* Identify Bison output. */
44#define YYBISON 1
45
46/* Bison version. */
47#define YYBISON_VERSION "3.0.4"
48
49/* Skeleton name. */
50#define YYSKELETON_NAME "yacc.c"
51
52/* Pure parsers. */
53#define YYPURE 0
54
55/* Push parsers. */
56#define YYPUSH 0
57
58/* Pull parsers. */
59#define YYPULL 1
60
61
62
63
64/* Copy the first part of user declarations. */
65#line 14 "grammar.y" /* yacc.c:339 */
66
67
68#include <stdio.h> /* SAFE */
69#include <cghdr.h> /* SAFE */
70extern void aagerror(char *); /* gets mapped to aagerror, see below */
71
72#ifdef _WIN32
73#define gettxt(a,b) (b)
74#endif
75
76static char Key[] = "key";
77static int SubgraphDepth = 0;
78
79typedef union s { /* possible items in generic list */
80 Agnode_t *n;
81 Agraph_t *subg;
82 Agedge_t *e;
83 Agsym_t *asym; /* bound attribute */
84 char *name; /* unbound attribute */
85 struct item_s *list; /* list-of-lists (for edgestmt) */
86} val_t;
87
88typedef struct item_s { /* generic list */
89 int tag; /* T_node, T_subgraph, T_edge, T_attr */
90 val_t u; /* primary element */
91 char *str; /* secondary value - port or attr value */
92 struct item_s *next;
93} item;
94
95typedef struct list_s { /* maintain head and tail ptrs for fast append */
96 item *first;
97 item *last;
98} list_t;
99
100typedef struct gstack_s {
101 Agraph_t *g;
102 Agraph_t *subg;
103 list_t nodelist,edgelist,attrlist;
104 struct gstack_s *down;
105} gstack_t;
106
107/* functions */
108static void appendnode(char *name, char *port, char *sport);
109static void attrstmt(int tkind, char *macroname);
110static void startgraph(char *name, int directed, int strict);
111static void getedgeitems(int x);
112static void newedge(Agnode_t *t, char *tport, Agnode_t *h, char *hport, char *key);
113static void edgerhs(Agnode_t *n, char *tport, item *hlist, char *key);
114static void appendattr(char *name, char *value);
115static void bindattrs(int kind);
116static void applyattrs(void *obj);
117static void endgraph(void);
118static void endnode(void);
119static void endedge(void);
120static void freestack(void);
121static char* concat(char*, char*);
122static char* concatPort(char*, char*);
123
124static void opensubg(char *name);
125static void closesubg(void);
126
127/* global */
128static Agraph_t *G; /* top level graph */
129static Agdisc_t *Disc; /* discipline passed to agread or agconcat */
130static gstack_t *S;
131
132
133#line 134 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:339 */
134
135# ifndef YY_NULLPTR
136# if defined __cplusplus && 201103L <= __cplusplus
137# define YY_NULLPTR nullptr
138# else
139# define YY_NULLPTR 0
140# endif
141# endif
142
143/* Enabling verbose error messages. */
144#ifdef YYERROR_VERBOSE
145# undef YYERROR_VERBOSE
146# define YYERROR_VERBOSE 1
147#else
148# define YYERROR_VERBOSE 0
149#endif
150
151/* In a future release of Bison, this section will be replaced
152 by #include "grammar.h". */
153#ifndef YY_YY_WORKSPACE_GRAPHVIZ_BUILD_LIB_CGRAPH_GRAMMAR_H_INCLUDED
154# define YY_YY_WORKSPACE_GRAPHVIZ_BUILD_LIB_CGRAPH_GRAMMAR_H_INCLUDED
155/* Debug traces. */
156#ifndef YYDEBUG
157# define YYDEBUG 0
158#endif
159#if YYDEBUG
160extern int aagdebug;
161#endif
162
163/* Token type. */
164#ifndef YYTOKENTYPE
165# define YYTOKENTYPE
166 enum aagtokentype
167 {
168 T_graph = 258,
169 T_node = 259,
170 T_edge = 260,
171 T_digraph = 261,
172 T_subgraph = 262,
173 T_strict = 263,
174 T_edgeop = 264,
175 T_list = 265,
176 T_attr = 266,
177 T_atom = 267,
178 T_qatom = 268
179 };
180#endif
181
182/* Value type. */
183#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
184
185union YYSTYPE
186{
187#line 82 "grammar.y" /* yacc.c:355 */
188
189 int i;
190 char *str;
191 struct Agnode_s *n;
192
193#line 194 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:355 */
194};
195
196typedef union YYSTYPE YYSTYPE;
197# define YYSTYPE_IS_TRIVIAL 1
198# define YYSTYPE_IS_DECLARED 1
199#endif
200
201
202extern YYSTYPE aaglval;
203
204int aagparse (void);
205
206#endif /* !YY_YY_WORKSPACE_GRAPHVIZ_BUILD_LIB_CGRAPH_GRAMMAR_H_INCLUDED */
207
208/* Copy the second part of user declarations. */
209
210#line 211 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:358 */
211
212#ifdef short
213# undef short
214#endif
215
216#ifdef YYTYPE_UINT8
217typedef YYTYPE_UINT8 aagtype_uint8;
218#else
219typedef unsigned char aagtype_uint8;
220#endif
221
222#ifdef YYTYPE_INT8
223typedef YYTYPE_INT8 aagtype_int8;
224#else
225typedef signed char aagtype_int8;
226#endif
227
228#ifdef YYTYPE_UINT16
229typedef YYTYPE_UINT16 aagtype_uint16;
230#else
231typedef unsigned short int aagtype_uint16;
232#endif
233
234#ifdef YYTYPE_INT16
235typedef YYTYPE_INT16 aagtype_int16;
236#else
237typedef short int aagtype_int16;
238#endif
239
240#ifndef YYSIZE_T
241# ifdef __SIZE_TYPE__
242# define YYSIZE_T __SIZE_TYPE__
243# elif defined size_t
244# define YYSIZE_T size_t
245# elif ! defined YYSIZE_T
246# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
247# define YYSIZE_T size_t
248# else
249# define YYSIZE_T unsigned int
250# endif
251#endif
252
253#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
254
255#ifndef YY_
256# if defined YYENABLE_NLS && YYENABLE_NLS
257# if ENABLE_NLS
258# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
259# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
260# endif
261# endif
262# ifndef YY_
263# define YY_(Msgid) Msgid
264# endif
265#endif
266
267#ifndef YY_ATTRIBUTE
268# if (defined __GNUC__ \
269 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
270 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
271# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
272# else
273# define YY_ATTRIBUTE(Spec) /* empty */
274# endif
275#endif
276
277#ifndef YY_ATTRIBUTE_PURE
278# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
279#endif
280
281#ifndef YY_ATTRIBUTE_UNUSED
282# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
283#endif
284
285#if !defined _Noreturn \
286 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
287# if defined _MSC_VER && 1200 <= _MSC_VER
288# define _Noreturn __declspec (noreturn)
289# else
290# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
291# endif
292#endif
293
294/* Suppress unused-variable warnings by "using" E. */
295#if ! defined lint || defined __GNUC__
296# define YYUSE(E) ((void) (E))
297#else
298# define YYUSE(E) /* empty */
299#endif
300
301#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
302/* Suppress an incorrect diagnostic about aaglval being uninitialized. */
303# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
304 _Pragma ("GCC diagnostic push") \
305 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
306 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
307# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
308 _Pragma ("GCC diagnostic pop")
309#else
310# define YY_INITIAL_VALUE(Value) Value
311#endif
312#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
313# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
314# define YY_IGNORE_MAYBE_UNINITIALIZED_END
315#endif
316#ifndef YY_INITIAL_VALUE
317# define YY_INITIAL_VALUE(Value) /* Nothing. */
318#endif
319
320
321#if ! defined aagoverflow || YYERROR_VERBOSE
322
323/* The parser invokes alloca or malloc; define the necessary symbols. */
324
325# ifdef YYSTACK_USE_ALLOCA
326# if YYSTACK_USE_ALLOCA
327# ifdef __GNUC__
328# define YYSTACK_ALLOC __builtin_alloca
329# elif defined __BUILTIN_VA_ARG_INCR
330# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
331# elif defined _AIX
332# define YYSTACK_ALLOC __alloca
333# elif defined _MSC_VER
334# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
335# define alloca _alloca
336# else
337# define YYSTACK_ALLOC alloca
338# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
339# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
340 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
341# ifndef EXIT_SUCCESS
342# define EXIT_SUCCESS 0
343# endif
344# endif
345# endif
346# endif
347# endif
348
349# ifdef YYSTACK_ALLOC
350 /* Pacify GCC's 'empty if-body' warning. */
351# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
352# ifndef YYSTACK_ALLOC_MAXIMUM
353 /* The OS might guarantee only one guard page at the bottom of the stack,
354 and a page size can be as small as 4096 bytes. So we cannot safely
355 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
356 to allow for a few compiler-allocated temporary stack slots. */
357# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
358# endif
359# else
360# define YYSTACK_ALLOC YYMALLOC
361# define YYSTACK_FREE YYFREE
362# ifndef YYSTACK_ALLOC_MAXIMUM
363# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
364# endif
365# if (defined __cplusplus && ! defined EXIT_SUCCESS \
366 && ! ((defined YYMALLOC || defined malloc) \
367 && (defined YYFREE || defined free)))
368# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
369# ifndef EXIT_SUCCESS
370# define EXIT_SUCCESS 0
371# endif
372# endif
373# ifndef YYMALLOC
374# define YYMALLOC malloc
375# if ! defined malloc && ! defined EXIT_SUCCESS
376void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
377# endif
378# endif
379# ifndef YYFREE
380# define YYFREE free
381# if ! defined free && ! defined EXIT_SUCCESS
382void free (void *); /* INFRINGES ON USER NAME SPACE */
383# endif
384# endif
385# endif
386#endif /* ! defined aagoverflow || YYERROR_VERBOSE */
387
388
389#if (! defined aagoverflow \
390 && (! defined __cplusplus \
391 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
392
393/* A type that is properly aligned for any stack member. */
394union aagalloc
395{
396 aagtype_int16 aagss_alloc;
397 YYSTYPE aagvs_alloc;
398};
399
400/* The size of the maximum gap between one aligned stack and the next. */
401# define YYSTACK_GAP_MAXIMUM (sizeof (union aagalloc) - 1)
402
403/* The size of an array large to enough to hold all stacks, each with
404 N elements. */
405# define YYSTACK_BYTES(N) \
406 ((N) * (sizeof (aagtype_int16) + sizeof (YYSTYPE)) \
407 + YYSTACK_GAP_MAXIMUM)
408
409# define YYCOPY_NEEDED 1
410
411/* Relocate STACK from its old location to the new one. The
412 local variables YYSIZE and YYSTACKSIZE give the old and new number of
413 elements in the stack, and YYPTR gives the new location of the
414 stack. Advance YYPTR to a properly aligned location for the next
415 stack. */
416# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
417 do \
418 { \
419 YYSIZE_T aagnewbytes; \
420 YYCOPY (&aagptr->Stack_alloc, Stack, aagsize); \
421 Stack = &aagptr->Stack_alloc; \
422 aagnewbytes = aagstacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
423 aagptr += aagnewbytes / sizeof (*aagptr); \
424 } \
425 while (0)
426
427#endif
428
429#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
430/* Copy COUNT objects from SRC to DST. The source and destination do
431 not overlap. */
432# ifndef YYCOPY
433# if defined __GNUC__ && 1 < __GNUC__
434# define YYCOPY(Dst, Src, Count) \
435 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
436# else
437# define YYCOPY(Dst, Src, Count) \
438 do \
439 { \
440 YYSIZE_T aagi; \
441 for (aagi = 0; aagi < (Count); aagi++) \
442 (Dst)[aagi] = (Src)[aagi]; \
443 } \
444 while (0)
445# endif
446# endif
447#endif /* !YYCOPY_NEEDED */
448
449/* YYFINAL -- State number of the termination state. */
450#define YYFINAL 6
451/* YYLAST -- Last index in YYTABLE. */
452#define YYLAST 59
453
454/* YYNTOKENS -- Number of terminals. */
455#define YYNTOKENS 24
456/* YYNNTS -- Number of nonterminals. */
457#define YYNNTS 35
458/* YYNRULES -- Number of rules. */
459#define YYNRULES 62
460/* YYNSTATES -- Number of states. */
461#define YYNSTATES 80
462
463/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
464 by aaglex, with out-of-bounds checking. */
465#define YYUNDEFTOK 2
466#define YYMAXUTOK 268
467
468#define YYTRANSLATE(YYX) \
469 ((unsigned int) (YYX) <= YYMAXUTOK ? aagtranslate[YYX] : YYUNDEFTOK)
470
471/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
472 as returned by aaglex, without out-of-bounds checking. */
473static const aagtype_uint8 aagtranslate[] =
474{
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 2, 2, 2, 23, 17, 2, 2, 2, 2, 2,
480 2, 2, 2, 2, 2, 2, 2, 2, 18, 16,
481 2, 19, 2, 2, 22, 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, 20, 2, 21, 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, 14, 2, 15, 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
502};
503
504#if YYDEBUG
505 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
506static const aagtype_uint8 aagrline[] =
507{
508 0, 99, 99, 100, 101, 104, 106, 109, 109, 111,
509 111, 113, 113, 115, 115, 117, 117, 119, 119, 121,
510 122, 125, 129, 129, 131, 131, 131, 132, 136, 136,
511 138, 139, 140, 143, 144, 147, 148, 149, 152, 153,
512 156, 156, 158, 160, 161, 163, 166, 166, 168, 171,
513 174, 177, 177, 180, 181, 182, 185, 185, 185, 187,
514 188, 191, 192
515};
516#endif
517
518#if YYDEBUG || YYERROR_VERBOSE || 0
519/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
520 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
521static const char *const aagtname[] =
522{
523 "$end", "error", "$undefined", "T_graph", "T_node", "T_edge",
524 "T_digraph", "T_subgraph", "T_strict", "T_edgeop", "T_list", "T_attr",
525 "T_atom", "T_qatom", "'{'", "'}'", "';'", "','", "':'", "'='", "'['",
526 "']'", "'@'", "'+'", "$accept", "graph", "body", "hdr", "optgraphname",
527 "optstrict", "graphtype", "optstmtlist", "stmtlist", "optsemi", "stmt",
528 "compound", "simple", "rcompound", "$@1", "$@2", "nodelist", "node",
529 "attrstmt", "attrtype", "optmacroname", "optattr", "attrlist",
530 "optattrdefs", "attrdefs", "attritem", "attrassignment", "attrmacro",
531 "graphattrdefs", "subgraph", "$@3", "optsubghdr", "optseparator", "atom",
532 "qatom", YY_NULLPTR
533};
534#endif
535
536# ifdef YYPRINT
537/* YYTOKNUM[NUM] -- (External) token number corresponding to the
538 (internal) symbol number NUM (which must be that of a token). */
539static const aagtype_uint16 aagtoknum[] =
540{
541 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
542 265, 266, 267, 268, 123, 125, 59, 44, 58, 61,
543 91, 93, 64, 43
544};
545# endif
546
547#define YYPACT_NINF -18
548
549#define aagpact_value_is_default(Yystate) \
550 (!!((Yystate) == (-18)))
551
552#define YYTABLE_NINF -56
553
554#define aagtable_value_is_error(Yytable_value) \
555 0
556
557 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
558 STATE-NUM. */
559static const aagtype_int8 aagpact[] =
560{
561 18, -18, -18, 20, 9, 3, -18, -2, -18, -18,
562 -18, 1, -18, -18, -18, 1, -18, -18, 10, -2,
563 -18, 19, 25, 21, -18, 19, 1, -18, -18, -18,
564 -18, 11, 17, -18, -18, -18, -18, -18, -18, -18,
565 -18, -18, 1, -18, -18, 22, 9, 1, 1, 29,
566 15, 23, -18, -18, 26, 23, 27, -18, -18, 28,
567 -18, -18, -18, -18, 1, 25, -5, -18, -18, -18,
568 1, -18, 16, -18, -18, 30, -18, -18, -18, -18
569};
570
571 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
572 Performed when YYTABLE does not specify something else to do. Zero
573 means the default is an error. */
574static const aagtype_uint8 aagdefact[] =
575{
576 0, 3, 9, 0, 0, 0, 1, 14, 2, 11,
577 12, 8, 35, 36, 37, 54, 59, 61, 0, 13,
578 16, 18, 27, 22, 28, 18, 39, 50, 34, 23,
579 51, 30, 60, 6, 7, 53, 5, 15, 17, 20,
580 24, 41, 0, 19, 41, 0, 0, 0, 0, 0,
581 55, 21, 40, 29, 30, 0, 33, 38, 52, 31,
582 48, 62, 25, 44, 0, 27, 0, 32, 26, 42,
583 0, 43, 58, 46, 47, 0, 49, 56, 57, 45
584};
585
586 /* YYPGOTO[NTERM-NUM]. */
587static const aagtype_int8 aagpgoto[] =
588{
589 -18, -18, -1, -18, -18, -18, -18, -18, -18, 31,
590 32, -18, 0, -17, -18, -18, -18, 12, -18, -18,
591 -18, 8, 13, -18, -18, -18, -8, -18, -18, -18,
592 -18, -18, -18, -11, -18
593};
594
595 /* YYDEFGOTO[NTERM-NUM]. */
596static const aagtype_int8 aagdefgoto[] =
597{
598 -1, 3, 8, 4, 33, 5, 11, 18, 19, 39,
599 20, 21, 22, 41, 50, 65, 23, 24, 25, 26,
600 44, 51, 52, 66, 71, 72, 27, 74, 28, 29,
601 46, 30, 79, 31, 32
602};
603
604 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
605 positive, shift that token. If negative, reduce the rule whose
606 number is the opposite. If YYTABLE_NINF, syntax error. */
607static const aagtype_int8 aagtable[] =
608{
609 34, 12, 13, 14, 35, 15, 9, 16, 17, 10,
610 16, 17, -55, 16, 17, 45, 69, 70, -4, 1,
611 6, -10, 15, 7, -10, 36, 2, 16, 17, 47,
612 48, 54, 77, 78, 40, 38, 59, 60, 42, 54,
613 49, 57, 61, 63, 47, 58, 64, -40, 68, 48,
614 62, 37, 55, 67, 53, 75, 43, 56, 73, 76
615};
616
617static const aagtype_uint8 aagcheck[] =
618{
619 11, 3, 4, 5, 15, 7, 3, 12, 13, 6,
620 12, 13, 14, 12, 13, 26, 21, 22, 0, 1,
621 0, 3, 7, 14, 6, 15, 8, 12, 13, 18,
622 19, 42, 16, 17, 9, 16, 47, 48, 17, 50,
623 23, 19, 13, 20, 18, 46, 18, 20, 65, 19,
624 50, 19, 44, 64, 42, 66, 25, 44, 66, 70
625};
626
627 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
628 symbol of state STATE-NUM. */
629static const aagtype_uint8 aagstos[] =
630{
631 0, 1, 8, 25, 27, 29, 0, 14, 26, 3,
632 6, 30, 3, 4, 5, 7, 12, 13, 31, 32,
633 34, 35, 36, 40, 41, 42, 43, 50, 52, 53,
634 55, 57, 58, 28, 57, 57, 15, 34, 16, 33,
635 9, 37, 17, 33, 44, 57, 54, 18, 19, 23,
636 38, 45, 46, 41, 57, 45, 46, 19, 26, 57,
637 57, 13, 36, 20, 18, 39, 47, 57, 37, 21,
638 22, 48, 49, 50, 51, 57, 57, 16, 17, 56
639};
640
641 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
642static const aagtype_uint8 aagr1[] =
643{
644 0, 24, 25, 25, 25, 26, 27, 28, 28, 29,
645 29, 30, 30, 31, 31, 32, 32, 33, 33, 34,
646 34, 35, 36, 36, 38, 39, 37, 37, 40, 40,
647 41, 41, 41, 42, 42, 43, 43, 43, 44, 44,
648 45, 45, 46, 47, 47, 48, 49, 49, 50, 51,
649 52, 54, 53, 55, 55, 55, 56, 56, 56, 57,
650 57, 58, 58
651};
652
653 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
654static const aagtype_uint8 aagr2[] =
655{
656 0, 2, 2, 1, 0, 3, 3, 1, 0, 1,
657 0, 1, 1, 1, 0, 2, 1, 1, 0, 2,
658 2, 3, 1, 1, 0, 0, 5, 0, 1, 3,
659 1, 3, 5, 3, 1, 1, 1, 1, 2, 0,
660 1, 0, 4, 2, 0, 2, 1, 1, 3, 2,
661 1, 0, 3, 2, 1, 0, 1, 1, 0, 1,
662 1, 1, 3
663};
664
665
666#define aagerrok (aagerrstatus = 0)
667#define aagclearin (aagchar = YYEMPTY)
668#define YYEMPTY (-2)
669#define YYEOF 0
670
671#define YYACCEPT goto aagacceptlab
672#define YYABORT goto aagabortlab
673#define YYERROR goto aagerrorlab
674
675
676#define YYRECOVERING() (!!aagerrstatus)
677
678#define YYBACKUP(Token, Value) \
679do \
680 if (aagchar == YYEMPTY) \
681 { \
682 aagchar = (Token); \
683 aaglval = (Value); \
684 YYPOPSTACK (aaglen); \
685 aagstate = *aagssp; \
686 goto aagbackup; \
687 } \
688 else \
689 { \
690 aagerror (YY_("syntax error: cannot back up")); \
691 YYERROR; \
692 } \
693while (0)
694
695/* Error token number */
696#define YYTERROR 1
697#define YYERRCODE 256
698
699
700
701/* Enable debugging if requested. */
702#if YYDEBUG
703
704# ifndef YYFPRINTF
705# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
706# define YYFPRINTF fprintf
707# endif
708
709# define YYDPRINTF(Args) \
710do { \
711 if (aagdebug) \
712 YYFPRINTF Args; \
713} while (0)
714
715/* This macro is provided for backward compatibility. */
716#ifndef YY_LOCATION_PRINT
717# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
718#endif
719
720
721# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
722do { \
723 if (aagdebug) \
724 { \
725 YYFPRINTF (stderr, "%s ", Title); \
726 aag_symbol_print (stderr, \
727 Type, Value); \
728 YYFPRINTF (stderr, "\n"); \
729 } \
730} while (0)
731
732
733/*----------------------------------------.
734| Print this symbol's value on YYOUTPUT. |
735`----------------------------------------*/
736
737static void
738aag_symbol_value_print (FILE *aagoutput, int aagtype, YYSTYPE const * const aagvaluep)
739{
740 FILE *aago = aagoutput;
741 YYUSE (aago);
742 if (!aagvaluep)
743 return;
744# ifdef YYPRINT
745 if (aagtype < YYNTOKENS)
746 YYPRINT (aagoutput, aagtoknum[aagtype], *aagvaluep);
747# endif
748 YYUSE (aagtype);
749}
750
751
752/*--------------------------------.
753| Print this symbol on YYOUTPUT. |
754`--------------------------------*/
755
756static void
757aag_symbol_print (FILE *aagoutput, int aagtype, YYSTYPE const * const aagvaluep)
758{
759 YYFPRINTF (aagoutput, "%s %s (",
760 aagtype < YYNTOKENS ? "token" : "nterm", aagtname[aagtype]);
761
762 aag_symbol_value_print (aagoutput, aagtype, aagvaluep);
763 YYFPRINTF (aagoutput, ")");
764}
765
766/*------------------------------------------------------------------.
767| aag_stack_print -- Print the state stack from its BOTTOM up to its |
768| TOP (included). |
769`------------------------------------------------------------------*/
770
771static void
772aag_stack_print (aagtype_int16 *aagbottom, aagtype_int16 *aagtop)
773{
774 YYFPRINTF (stderr, "Stack now");
775 for (; aagbottom <= aagtop; aagbottom++)
776 {
777 int aagbot = *aagbottom;
778 YYFPRINTF (stderr, " %d", aagbot);
779 }
780 YYFPRINTF (stderr, "\n");
781}
782
783# define YY_STACK_PRINT(Bottom, Top) \
784do { \
785 if (aagdebug) \
786 aag_stack_print ((Bottom), (Top)); \
787} while (0)
788
789
790/*------------------------------------------------.
791| Report that the YYRULE is going to be reduced. |
792`------------------------------------------------*/
793
794static void
795aag_reduce_print (aagtype_int16 *aagssp, YYSTYPE *aagvsp, int aagrule)
796{
797 uint_64_t aaglno = aagrline[aagrule];
798 int aagnrhs = aagr2[aagrule];
799 int aagi;
800 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
801 aagrule - 1, aaglno);
802 /* The symbols being reduced. */
803 for (aagi = 0; aagi < aagnrhs; aagi++)
804 {
805 YYFPRINTF (stderr, " $%d = ", aagi + 1);
806 aag_symbol_print (stderr,
807 aagstos[aagssp[aagi + 1 - aagnrhs]],
808 &(aagvsp[(aagi + 1) - (aagnrhs)])
809 );
810 YYFPRINTF (stderr, "\n");
811 }
812}
813
814# define YY_REDUCE_PRINT(Rule) \
815do { \
816 if (aagdebug) \
817 aag_reduce_print (aagssp, aagvsp, Rule); \
818} while (0)
819
820/* Nonzero means print parse trace. It is left uninitialized so that
821 multiple parsers can coexist. */
822int aagdebug;
823#else /* !YYDEBUG */
824# define YYDPRINTF(Args)
825# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
826# define YY_STACK_PRINT(Bottom, Top)
827# define YY_REDUCE_PRINT(Rule)
828#endif /* !YYDEBUG */
829
830
831/* YYINITDEPTH -- initial size of the parser's stacks. */
832#ifndef YYINITDEPTH
833# define YYINITDEPTH 200
834#endif
835
836/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
837 if the built-in stack extension method is used).
838
839 Do not make this value too large; the results are undefined if
840 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
841 evaluated with infinite-precision integer arithmetic. */
842
843#ifndef YYMAXDEPTH
844# define YYMAXDEPTH 10000
845#endif
846
847
848#if YYERROR_VERBOSE
849
850# ifndef aagstrlen
851# if defined __GLIBC__ && defined _STRING_H
852# define aagstrlen strlen
853# else
854/* Return the length of YYSTR. */
855static YYSIZE_T
856aagstrlen (const char *aagstr)
857{
858 YYSIZE_T aaglen;
859 for (aaglen = 0; aagstr[aaglen]; aaglen++)
860 continue;
861 return aaglen;
862}
863# endif
864# endif
865
866# ifndef aagstpcpy
867# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
868# define aagstpcpy stpcpy
869# else
870/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
871 YYDEST. */
872static char *
873aagstpcpy (char *aagdest, const char *aagsrc)
874{
875 char *aagd = aagdest;
876 const char *aags = aagsrc;
877
878 while ((*aagd++ = *aags++) != '\0')
879 continue;
880
881 return aagd - 1;
882}
883# endif
884# endif
885
886# ifndef aagtnamerr
887/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
888 quotes and backslashes, so that it's suitable for aagerror. The
889 heuristic is that double-quoting is unnecessary unless the string
890 contains an apostrophe, a comma, or backslash (other than
891 backslash-backslash). YYSTR is taken from aagtname. If YYRES is
892 null, do not copy; instead, return the length of what the result
893 would have been. */
894static YYSIZE_T
895aagtnamerr (char *aagres, const char *aagstr)
896{
897 if (*aagstr == '"')
898 {
899 YYSIZE_T aagn = 0;
900 char const *aagp = aagstr;
901
902 for (;;)
903 switch (*++aagp)
904 {
905 case '\'':
906 case ',':
907 goto do_not_strip_quotes;
908
909 case '\\':
910 if (*++aagp != '\\')
911 goto do_not_strip_quotes;
912 /* Fall through. */
913 default:
914 if (aagres)
915 aagres[aagn] = *aagp;
916 aagn++;
917 break;
918
919 case '"':
920 if (aagres)
921 aagres[aagn] = '\0';
922 return aagn;
923 }
924 do_not_strip_quotes: ;
925 }
926
927 if (! aagres)
928 return aagstrlen (aagstr);
929
930 return aagstpcpy (aagres, aagstr) - aagres;
931}
932# endif
933
934/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
935 about the unexpected token YYTOKEN for the state stack whose top is
936 YYSSP.
937
938 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
939 not large enough to hold the message. In that case, also set
940 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
941 required number of bytes is too large to store. */
942static int
943aagsyntax_error (YYSIZE_T *aagmsg_alloc, char **aagmsg,
944 aagtype_int16 *aagssp, int aagtoken)
945{
946 YYSIZE_T aagsize0 = aagtnamerr (YY_NULLPTR, aagtname[aagtoken]);
947 YYSIZE_T aagsize = aagsize0;
948 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
949 /* Internationalized format string. */
950 const char *aagformat = YY_NULLPTR;
951 /* Arguments of aagformat. */
952 char const *aagarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
953 /* Number of reported tokens (one for the "unexpected", one per
954 "expected"). */
955 int aagcount = 0;
956
957 /* There are many possibilities here to consider:
958 - If this state is a consistent state with a default action, then
959 the only way this function was invoked is if the default action
960 is an error action. In that case, don't check for expected
961 tokens because there are none.
962 - The only way there can be no lookahead present (in aagchar) is if
963 this state is a consistent state with a default action. Thus,
964 detecting the absence of a lookahead is sufficient to determine
965 that there is no unexpected or expected token to report. In that
966 case, just report a simple "syntax error".
967 - Don't assume there isn't a lookahead just because this state is a
968 consistent state with a default action. There might have been a
969 previous inconsistent state, consistent state with a non-default
970 action, or user semantic action that manipulated aagchar.
971 - Of course, the expected token list depends on states to have
972 correct lookahead information, and it depends on the parser not
973 to perform extra reductions after fetching a lookahead from the
974 scanner and before detecting a syntax error. Thus, state merging
975 (from LALR or IELR) and default reductions corrupt the expected
976 token list. However, the list is correct for canonical LR with
977 one exception: it will still contain any token that will not be
978 accepted due to an error action in a later state.
979 */
980 if (aagtoken != YYEMPTY)
981 {
982 int aagn = aagpact[*aagssp];
983 aagarg[aagcount++] = aagtname[aagtoken];
984 if (!aagpact_value_is_default (aagn))
985 {
986 /* Start YYX at -YYN if negative to avoid negative indexes in
987 YYCHECK. In other words, skip the first -YYN actions for
988 this state because they are default actions. */
989 int aagxbegin = aagn < 0 ? -aagn : 0;
990 /* Stay within bounds of both aagcheck and aagtname. */
991 int aagchecklim = YYLAST - aagn + 1;
992 int aagxend = aagchecklim < YYNTOKENS ? aagchecklim : YYNTOKENS;
993 int aagx;
994
995 for (aagx = aagxbegin; aagx < aagxend; ++aagx)
996 if (aagcheck[aagx + aagn] == aagx && aagx != YYTERROR
997 && !aagtable_value_is_error (aagtable[aagx + aagn]))
998 {
999 if (aagcount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1000 {
1001 aagcount = 1;
1002 aagsize = aagsize0;
1003 break;
1004 }
1005 aagarg[aagcount++] = aagtname[aagx];
1006 {
1007 YYSIZE_T aagsize1 = aagsize + aagtnamerr (YY_NULLPTR, aagtname[aagx]);
1008 if (! (aagsize <= aagsize1
1009 && aagsize1 <= YYSTACK_ALLOC_MAXIMUM))
1010 return 2;
1011 aagsize = aagsize1;
1012 }
1013 }
1014 }
1015 }
1016
1017 switch (aagcount)
1018 {
1019# define YYCASE_(N, S) \
1020 case N: \
1021 aagformat = S; \
1022 break
1023 YYCASE_(0, YY_("syntax error"));
1024 YYCASE_(1, YY_("syntax error, unexpected %s"));
1025 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1026 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1027 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1028 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1029# undef YYCASE_
1030 }
1031
1032 {
1033 YYSIZE_T aagsize1 = aagsize + aagstrlen (aagformat);
1034 if (! (aagsize <= aagsize1 && aagsize1 <= YYSTACK_ALLOC_MAXIMUM))
1035 return 2;
1036 aagsize = aagsize1;
1037 }
1038
1039 if (*aagmsg_alloc < aagsize)
1040 {
1041 *aagmsg_alloc = 2 * aagsize;
1042 if (! (aagsize <= *aagmsg_alloc
1043 && *aagmsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1044 *aagmsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1045 return 1;
1046 }
1047
1048 /* Avoid sprintf, as that infringes on the user's name space.
1049 Don't have undefined behavior even if the translation
1050 produced a string with the wrong number of "%s"s. */
1051 {
1052 char *aagp = *aagmsg;
1053 int aagi = 0;
1054 while ((*aagp = *aagformat) != '\0')
1055 if (*aagp == '%' && aagformat[1] == 's' && aagi < aagcount)
1056 {
1057 aagp += aagtnamerr (aagp, aagarg[aagi++]);
1058 aagformat += 2;
1059 }
1060 else
1061 {
1062 aagp++;
1063 aagformat++;
1064 }
1065 }
1066 return 0;
1067}
1068#endif /* YYERROR_VERBOSE */
1069
1070/*-----------------------------------------------.
1071| Release the memory associated to this symbol. |
1072`-----------------------------------------------*/
1073
1074static void
1075aagdestruct (const char *aagmsg, int aagtype, YYSTYPE *aagvaluep)
1076{
1077 YYUSE (aagvaluep);
1078 if (!aagmsg)
1079 aagmsg = "Deleting";
1080 YY_SYMBOL_PRINT (aagmsg, aagtype, aagvaluep, aaglocationp);
1081
1082 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1083 YYUSE (aagtype);
1084 YY_IGNORE_MAYBE_UNINITIALIZED_END
1085}
1086
1087
1088
1089
1090/* The lookahead symbol. */
1091int aagchar;
1092
1093/* The semantic value of the lookahead symbol. */
1094YYSTYPE aaglval;
1095/* Number of syntax errors so far. */
1096int aagnerrs;
1097
1098
1099/*----------.
1100| aagparse. |
1101`----------*/
1102
1103int
1104aagparse (void)
1105{
1106 int aagstate;
1107 /* Number of tokens to shift before error messages enabled. */
1108 int aagerrstatus;
1109
1110 /* The stacks and their tools:
1111 'aagss': related to states.
1112 'aagvs': related to semantic values.
1113
1114 Refer to the stacks through separate pointers, to allow aagoverflow
1115 to reallocate them elsewhere. */
1116
1117 /* The state stack. */
1118 aagtype_int16 aagssa[YYINITDEPTH];
1119 aagtype_int16 *aagss;
1120 aagtype_int16 *aagssp;
1121
1122 /* The semantic value stack. */
1123 YYSTYPE aagvsa[YYINITDEPTH];
1124 YYSTYPE *aagvs;
1125 YYSTYPE *aagvsp;
1126
1127 YYSIZE_T aagstacksize;
1128
1129 int aagn;
1130 int aagresult;
1131 /* Lookahead token as an internal (translated) token number. */
1132 int aagtoken = 0;
1133 /* The variables used to return semantic value and location from the
1134 action routines. */
1135 YYSTYPE aagval;
1136
1137#if YYERROR_VERBOSE
1138 /* Buffer for error messages, and its allocated size. */
1139 char aagmsgbuf[128];
1140 char *aagmsg = aagmsgbuf;
1141 YYSIZE_T aagmsg_alloc = sizeof aagmsgbuf;
1142#endif
1143
1144#define YYPOPSTACK(N) (aagvsp -= (N), aagssp -= (N))
1145
1146 /* The number of symbols on the RHS of the reduced rule.
1147 Keep to zero when no symbol should be popped. */
1148 int aaglen = 0;
1149
1150 aagssp = aagss = aagssa;
1151 aagvsp = aagvs = aagvsa;
1152 aagstacksize = YYINITDEPTH;
1153
1154 YYDPRINTF ((stderr, "Starting parse\n"));
1155
1156 aagstate = 0;
1157 aagerrstatus = 0;
1158 aagnerrs = 0;
1159 aagchar = YYEMPTY; /* Cause a token to be read. */
1160 goto aagsetstate;
1161
1162/*------------------------------------------------------------.
1163| aagnewstate -- Push a new state, which is found in aagstate. |
1164`------------------------------------------------------------*/
1165 aagnewstate:
1166 /* In all cases, when you get here, the value and location stacks
1167 have just been pushed. So pushing a state here evens the stacks. */
1168 aagssp++;
1169
1170 aagsetstate:
1171 *aagssp = aagstate;
1172
1173 if (aagss + aagstacksize - 1 <= aagssp)
1174 {
1175 /* Get the current used size of the three stacks, in elements. */
1176 YYSIZE_T aagsize = aagssp - aagss + 1;
1177
1178#ifdef aagoverflow
1179 {
1180 /* Give user a chance to reallocate the stack. Use copies of
1181 these so that the &'s don't force the real ones into
1182 memory. */
1183 YYSTYPE *aagvs1 = aagvs;
1184 aagtype_int16 *aagss1 = aagss;
1185
1186 /* Each stack pointer address is followed by the size of the
1187 data in use in that stack, in bytes. This used to be a
1188 conditional around just the two extra args, but that might
1189 be undefined if aagoverflow is a macro. */
1190 aagoverflow (YY_("memory exhausted"),
1191 &aagss1, aagsize * sizeof (*aagssp),
1192 &aagvs1, aagsize * sizeof (*aagvsp),
1193 &aagstacksize);
1194
1195 aagss = aagss1;
1196 aagvs = aagvs1;
1197 }
1198#else /* no aagoverflow */
1199# ifndef YYSTACK_RELOCATE
1200 goto aagexhaustedlab;
1201# else
1202 /* Extend the stack our own way. */
1203 if (YYMAXDEPTH <= aagstacksize)
1204 goto aagexhaustedlab;
1205 aagstacksize *= 2;
1206 if (YYMAXDEPTH < aagstacksize)
1207 aagstacksize = YYMAXDEPTH;
1208
1209 {
1210 aagtype_int16 *aagss1 = aagss;
1211 union aagalloc *aagptr =
1212 (union aagalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (aagstacksize));
1213 if (! aagptr)
1214 goto aagexhaustedlab;
1215 YYSTACK_RELOCATE (aagss_alloc, aagss);
1216 YYSTACK_RELOCATE (aagvs_alloc, aagvs);
1217# undef YYSTACK_RELOCATE
1218 if (aagss1 != aagssa)
1219 YYSTACK_FREE (aagss1);
1220 }
1221# endif
1222#endif /* no aagoverflow */
1223
1224 aagssp = aagss + aagsize - 1;
1225 aagvsp = aagvs + aagsize - 1;
1226
1227 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1228 (uint_64_t) aagstacksize));
1229
1230 if (aagss + aagstacksize - 1 <= aagssp)
1231 YYABORT;
1232 }
1233
1234 YYDPRINTF ((stderr, "Entering state %d\n", aagstate));
1235
1236 if (aagstate == YYFINAL)
1237 YYACCEPT;
1238
1239 goto aagbackup;
1240
1241/*-----------.
1242| aagbackup. |
1243`-----------*/
1244aagbackup:
1245
1246 /* Do appropriate processing given the current state. Read a
1247 lookahead token if we need one and don't already have one. */
1248
1249 /* First try to decide what to do without reference to lookahead token. */
1250 aagn = aagpact[aagstate];
1251 if (aagpact_value_is_default (aagn))
1252 goto aagdefault;
1253
1254 /* Not known => get a lookahead token if don't already have one. */
1255
1256 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1257 if (aagchar == YYEMPTY)
1258 {
1259 YYDPRINTF ((stderr, "Reading a token: "));
1260 aagchar = aaglex ();
1261 }
1262
1263 if (aagchar <= YYEOF)
1264 {
1265 aagchar = aagtoken = YYEOF;
1266 YYDPRINTF ((stderr, "Now at end of input.\n"));
1267 }
1268 else
1269 {
1270 aagtoken = YYTRANSLATE (aagchar);
1271 YY_SYMBOL_PRINT ("Next token is", aagtoken, &aaglval, &aaglloc);
1272 }
1273
1274 /* If the proper action on seeing token YYTOKEN is to reduce or to
1275 detect an error, take that action. */
1276 aagn += aagtoken;
1277 if (aagn < 0 || YYLAST < aagn || aagcheck[aagn] != aagtoken)
1278 goto aagdefault;
1279 aagn = aagtable[aagn];
1280 if (aagn <= 0)
1281 {
1282 if (aagtable_value_is_error (aagn))
1283 goto aagerrlab;
1284 aagn = -aagn;
1285 goto aagreduce;
1286 }
1287
1288 /* Count tokens shifted since error; after three, turn off error
1289 status. */
1290 if (aagerrstatus)
1291 aagerrstatus--;
1292
1293 /* Shift the lookahead token. */
1294 YY_SYMBOL_PRINT ("Shifting", aagtoken, &aaglval, &aaglloc);
1295
1296 /* Discard the shifted token. */
1297 aagchar = YYEMPTY;
1298
1299 aagstate = aagn;
1300 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1301 *++aagvsp = aaglval;
1302 YY_IGNORE_MAYBE_UNINITIALIZED_END
1303
1304 goto aagnewstate;
1305
1306
1307/*-----------------------------------------------------------.
1308| aagdefault -- do the default action for the current state. |
1309`-----------------------------------------------------------*/
1310aagdefault:
1311 aagn = aagdefact[aagstate];
1312 if (aagn == 0)
1313 goto aagerrlab;
1314 goto aagreduce;
1315
1316
1317/*-----------------------------.
1318| aagreduce -- Do a reduction. |
1319`-----------------------------*/
1320aagreduce:
1321 /* aagn is the number of a rule to reduce with. */
1322 aaglen = aagr2[aagn];
1323
1324 /* If YYLEN is nonzero, implement the default value of the action:
1325 '$$ = $1'.
1326
1327 Otherwise, the following line sets YYVAL to garbage.
1328 This behavior is undocumented and Bison
1329 users should not rely upon it. Assigning to YYVAL
1330 unconditionally makes the parser a bit smaller, and it avoids a
1331 GCC warning that YYVAL may be used uninitialized. */
1332 aagval = aagvsp[1-aaglen];
1333
1334
1335 YY_REDUCE_PRINT (aagn);
1336 switch (aagn)
1337 {
1338 case 2:
1339#line 99 "grammar.y" /* yacc.c:1646 */
1340 {freestack(); endgraph();}
1341#line 1342 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1342 break;
1343
1344 case 3:
1345#line 100 "grammar.y" /* yacc.c:1646 */
1346 {if (G) {freestack(); endgraph(); agclose(G); G = Ag_G_global = NIL(Agraph_t*);}}
1347#line 1348 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1348 break;
1349
1350 case 6:
1351#line 106 "grammar.y" /* yacc.c:1646 */
1352 {startgraph((aagvsp[0].str),(aagvsp[-1].i),(aagvsp[-2].i));}
1353#line 1354 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1354 break;
1355
1356 case 7:
1357#line 109 "grammar.y" /* yacc.c:1646 */
1358 {(aagval.str)=(aagvsp[0].str);}
1359#line 1360 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1360 break;
1361
1362 case 8:
1363#line 109 "grammar.y" /* yacc.c:1646 */
1364 {(aagval.str)=0;}
1365#line 1366 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1366 break;
1367
1368 case 9:
1369#line 111 "grammar.y" /* yacc.c:1646 */
1370 {(aagval.i)=1;}
1371#line 1372 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1372 break;
1373
1374 case 10:
1375#line 111 "grammar.y" /* yacc.c:1646 */
1376 {(aagval.i)=0;}
1377#line 1378 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1378 break;
1379
1380 case 11:
1381#line 113 "grammar.y" /* yacc.c:1646 */
1382 {(aagval.i) = 0;}
1383#line 1384 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1384 break;
1385
1386 case 12:
1387#line 113 "grammar.y" /* yacc.c:1646 */
1388 {(aagval.i) = 1;}
1389#line 1390 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1390 break;
1391
1392 case 21:
1393#line 126 "grammar.y" /* yacc.c:1646 */
1394 {if ((aagvsp[-1].i)) endedge(); else endnode();}
1395#line 1396 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1396 break;
1397
1398 case 24:
1399#line 131 "grammar.y" /* yacc.c:1646 */
1400 {getedgeitems(1);}
1401#line 1402 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1402 break;
1403
1404 case 25:
1405#line 131 "grammar.y" /* yacc.c:1646 */
1406 {getedgeitems(2);}
1407#line 1408 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1408 break;
1409
1410 case 26:
1411#line 131 "grammar.y" /* yacc.c:1646 */
1412 {(aagval.i) = 1;}
1413#line 1414 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1414 break;
1415
1416 case 27:
1417#line 132 "grammar.y" /* yacc.c:1646 */
1418 {(aagval.i) = 0;}
1419#line 1420 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1420 break;
1421
1422 case 30:
1423#line 138 "grammar.y" /* yacc.c:1646 */
1424 {appendnode((aagvsp[0].str),NIL(char*),NIL(char*));}
1425#line 1426 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1426 break;
1427
1428 case 31:
1429#line 139 "grammar.y" /* yacc.c:1646 */
1430 {appendnode((aagvsp[-2].str),(aagvsp[0].str),NIL(char*));}
1431#line 1432 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1432 break;
1433
1434 case 32:
1435#line 140 "grammar.y" /* yacc.c:1646 */
1436 {appendnode((aagvsp[-4].str),(aagvsp[-2].str),(aagvsp[0].str));}
1437#line 1438 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1438 break;
1439
1440 case 33:
1441#line 143 "grammar.y" /* yacc.c:1646 */
1442 {attrstmt((aagvsp[-2].i),(aagvsp[-1].str));}
1443#line 1444 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1444 break;
1445
1446 case 34:
1447#line 144 "grammar.y" /* yacc.c:1646 */
1448 {attrstmt(T_graph,NIL(char*));}
1449#line 1450 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1450 break;
1451
1452 case 35:
1453#line 147 "grammar.y" /* yacc.c:1646 */
1454 {(aagval.i) = T_graph;}
1455#line 1456 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1456 break;
1457
1458 case 36:
1459#line 148 "grammar.y" /* yacc.c:1646 */
1460 {(aagval.i) = T_node;}
1461#line 1462 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1462 break;
1463
1464 case 37:
1465#line 149 "grammar.y" /* yacc.c:1646 */
1466 {(aagval.i) = T_edge;}
1467#line 1468 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1468 break;
1469
1470 case 38:
1471#line 152 "grammar.y" /* yacc.c:1646 */
1472 {(aagval.str) = (aagvsp[-1].str);}
1473#line 1474 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1474 break;
1475
1476 case 39:
1477#line 153 "grammar.y" /* yacc.c:1646 */
1478 {(aagval.str) = NIL(char*); }
1479#line 1480 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1480 break;
1481
1482 case 48:
1483#line 168 "grammar.y" /* yacc.c:1646 */
1484 {appendattr((aagvsp[-2].str),(aagvsp[0].str));}
1485#line 1486 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1486 break;
1487
1488 case 49:
1489#line 171 "grammar.y" /* yacc.c:1646 */
1490 {appendattr((aagvsp[0].str),NIL(char*));}
1491#line 1492 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1492 break;
1493
1494 case 51:
1495#line 177 "grammar.y" /* yacc.c:1646 */
1496 {opensubg((aagvsp[0].str));}
1497#line 1498 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1498 break;
1499
1500 case 52:
1501#line 177 "grammar.y" /* yacc.c:1646 */
1502 {closesubg();}
1503#line 1504 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1504 break;
1505
1506 case 53:
1507#line 180 "grammar.y" /* yacc.c:1646 */
1508 {(aagval.str)=(aagvsp[0].str);}
1509#line 1510 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1510 break;
1511
1512 case 54:
1513#line 181 "grammar.y" /* yacc.c:1646 */
1514 {(aagval.str)=NIL(char*);}
1515#line 1516 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1516 break;
1517
1518 case 55:
1519#line 182 "grammar.y" /* yacc.c:1646 */
1520 {(aagval.str)=NIL(char*);}
1521#line 1522 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1522 break;
1523
1524 case 59:
1525#line 187 "grammar.y" /* yacc.c:1646 */
1526 {(aagval.str) = (aagvsp[0].str);}
1527#line 1528 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1528 break;
1529
1530 case 60:
1531#line 188 "grammar.y" /* yacc.c:1646 */
1532 {(aagval.str) = (aagvsp[0].str);}
1533#line 1534 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1534 break;
1535
1536 case 61:
1537#line 191 "grammar.y" /* yacc.c:1646 */
1538 {(aagval.str) = (aagvsp[0].str);}
1539#line 1540 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1540 break;
1541
1542 case 62:
1543#line 192 "grammar.y" /* yacc.c:1646 */
1544 {(aagval.str) = concat((aagvsp[-2].str),(aagvsp[0].str));}
1545#line 1546 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1546 break;
1547
1548
1549#line 1550 "/workspace/graphviz/build/lib/cgraph/grammar.c" /* yacc.c:1646 */
1550 default: break;
1551 }
1552 /* User semantic actions sometimes alter aagchar, and that requires
1553 that aagtoken be updated with the new translation. We take the
1554 approach of translating immediately before every use of aagtoken.
1555 One alternative is translating here after every semantic action,
1556 but that translation would be missed if the semantic action invokes
1557 YYABORT, YYACCEPT, or YYERROR immediately after altering aagchar or
1558 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1559 incorrect destructor might then be invoked immediately. In the
1560 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1561 to an incorrect destructor call or verbose syntax error message
1562 before the lookahead is translated. */
1563 YY_SYMBOL_PRINT ("-> $$ =", aagr1[aagn], &aagval, &aagloc);
1564
1565 YYPOPSTACK (aaglen);
1566 aaglen = 0;
1567 YY_STACK_PRINT (aagss, aagssp);
1568
1569 *++aagvsp = aagval;
1570
1571 /* Now 'shift' the result of the reduction. Determine what state
1572 that goes to, based on the state we popped back to and the rule
1573 number reduced by. */
1574
1575 aagn = aagr1[aagn];
1576
1577 aagstate = aagpgoto[aagn - YYNTOKENS] + *aagssp;
1578 if (0 <= aagstate && aagstate <= YYLAST && aagcheck[aagstate] == *aagssp)
1579 aagstate = aagtable[aagstate];
1580 else
1581 aagstate = aagdefgoto[aagn - YYNTOKENS];
1582
1583 goto aagnewstate;
1584
1585
1586/*--------------------------------------.
1587| aagerrlab -- here on detecting error. |
1588`--------------------------------------*/
1589aagerrlab:
1590 /* Make sure we have latest lookahead translation. See comments at
1591 user semantic actions for why this is necessary. */
1592 aagtoken = aagchar == YYEMPTY ? YYEMPTY : YYTRANSLATE (aagchar);
1593
1594 /* If not already recovering from an error, report this error. */
1595 if (!aagerrstatus)
1596 {
1597 ++aagnerrs;
1598#if ! YYERROR_VERBOSE
1599 aagerror (YY_("syntax error"));
1600#else
1601# define YYSYNTAX_ERROR aagsyntax_error (&aagmsg_alloc, &aagmsg, \
1602 aagssp, aagtoken)
1603 {
1604 char const *aagmsgp = YY_("syntax error");
1605 int aagsyntax_error_status;
1606 aagsyntax_error_status = YYSYNTAX_ERROR;
1607 if (aagsyntax_error_status == 0)
1608 aagmsgp = aagmsg;
1609 else if (aagsyntax_error_status == 1)
1610 {
1611 if (aagmsg != aagmsgbuf)
1612 YYSTACK_FREE (aagmsg);
1613 aagmsg = (char *) YYSTACK_ALLOC (aagmsg_alloc);
1614 if (!aagmsg)
1615 {
1616 aagmsg = aagmsgbuf;
1617 aagmsg_alloc = sizeof aagmsgbuf;
1618 aagsyntax_error_status = 2;
1619 }
1620 else
1621 {
1622 aagsyntax_error_status = YYSYNTAX_ERROR;
1623 aagmsgp = aagmsg;
1624 }
1625 }
1626 aagerror (aagmsgp);
1627 if (aagsyntax_error_status == 2)
1628 goto aagexhaustedlab;
1629 }
1630# undef YYSYNTAX_ERROR
1631#endif
1632 }
1633
1634
1635
1636 if (aagerrstatus == 3)
1637 {
1638 /* If just tried and failed to reuse lookahead token after an
1639 error, discard it. */
1640
1641 if (aagchar <= YYEOF)
1642 {
1643 /* Return failure if at end of input. */
1644 if (aagchar == YYEOF)
1645 YYABORT;
1646 }
1647 else
1648 {
1649 aagdestruct ("Error: discarding",
1650 aagtoken, &aaglval);
1651 aagchar = YYEMPTY;
1652 }
1653 }
1654
1655 /* Else will try to reuse lookahead token after shifting the error
1656 token. */
1657 goto aagerrlab1;
1658
1659
1660/*---------------------------------------------------.
1661| aagerrorlab -- error raised explicitly by YYERROR. |
1662`---------------------------------------------------*/
1663aagerrorlab:
1664
1665 /* Pacify compilers like GCC when the user code never invokes
1666 YYERROR and the label aagerrorlab therefore never appears in user
1667 code. */
1668 if (/*CONSTCOND*/ 0)
1669 goto aagerrorlab;
1670
1671 /* Do not reclaim the symbols of the rule whose action triggered
1672 this YYERROR. */
1673 YYPOPSTACK (aaglen);
1674 aaglen = 0;
1675 YY_STACK_PRINT (aagss, aagssp);
1676 aagstate = *aagssp;
1677 goto aagerrlab1;
1678
1679
1680/*-------------------------------------------------------------.
1681| aagerrlab1 -- common code for both syntax error and YYERROR. |
1682`-------------------------------------------------------------*/
1683aagerrlab1:
1684 aagerrstatus = 3; /* Each real token shifted decrements this. */
1685
1686 for (;;)
1687 {
1688 aagn = aagpact[aagstate];
1689 if (!aagpact_value_is_default (aagn))
1690 {
1691 aagn += YYTERROR;
1692 if (0 <= aagn && aagn <= YYLAST && aagcheck[aagn] == YYTERROR)
1693 {
1694 aagn = aagtable[aagn];
1695 if (0 < aagn)
1696 break;
1697 }
1698 }
1699
1700 /* Pop the current state because it cannot handle the error token. */
1701 if (aagssp == aagss)
1702 YYABORT;
1703
1704
1705 aagdestruct ("Error: popping",
1706 aagstos[aagstate], aagvsp);
1707 YYPOPSTACK (1);
1708 aagstate = *aagssp;
1709 YY_STACK_PRINT (aagss, aagssp);
1710 }
1711
1712 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1713 *++aagvsp = aaglval;
1714 YY_IGNORE_MAYBE_UNINITIALIZED_END
1715
1716
1717 /* Shift the error token. */
1718 YY_SYMBOL_PRINT ("Shifting", aagstos[aagn], aagvsp, aaglsp);
1719
1720 aagstate = aagn;
1721 goto aagnewstate;
1722
1723
1724/*-------------------------------------.
1725| aagacceptlab -- YYACCEPT comes here. |
1726`-------------------------------------*/
1727aagacceptlab:
1728 aagresult = 0;
1729 goto aagreturn;
1730
1731/*-----------------------------------.
1732| aagabortlab -- YYABORT comes here. |
1733`-----------------------------------*/
1734aagabortlab:
1735 aagresult = 1;
1736 goto aagreturn;
1737
1738#if !defined aagoverflow || YYERROR_VERBOSE
1739/*-------------------------------------------------.
1740| aagexhaustedlab -- memory exhaustion comes here. |
1741`-------------------------------------------------*/
1742aagexhaustedlab:
1743 aagerror (YY_("memory exhausted"));
1744 aagresult = 2;
1745 /* Fall through. */
1746#endif
1747
1748aagreturn:
1749 if (aagchar != YYEMPTY)
1750 {
1751 /* Make sure we have latest lookahead translation. See comments at
1752 user semantic actions for why this is necessary. */
1753 aagtoken = YYTRANSLATE (aagchar);
1754 aagdestruct ("Cleanup: discarding lookahead",
1755 aagtoken, &aaglval);
1756 }
1757 /* Do not reclaim the symbols of the rule whose action triggered
1758 this YYABORT or YYACCEPT. */
1759 YYPOPSTACK (aaglen);
1760 YY_STACK_PRINT (aagss, aagssp);
1761 while (aagssp != aagss)
1762 {
1763 aagdestruct ("Cleanup: popping",
1764 aagstos[*aagssp], aagvsp);
1765 YYPOPSTACK (1);
1766 }
1767#ifndef aagoverflow
1768 if (aagss != aagssa)
1769 YYSTACK_FREE (aagss);
1770#endif
1771#if YYERROR_VERBOSE
1772 if (aagmsg != aagmsgbuf)
1773 YYSTACK_FREE (aagmsg);
1774#endif
1775 return aagresult;
1776}
1777#line 194 "grammar.y" /* yacc.c:1906 */
1778
1779
1780#define NILitem NIL(item*)
1781
1782
1783static item *newitem(int tag, void *p0, char *p1)
1784{
1785 item *rv = agalloc(G,sizeof(item));
1786 rv->tag = tag; rv->u.name = (char*)p0; rv->str = p1;
1787 return rv;
1788}
1789
1790static item *cons_node(Agnode_t *n, char *port)
1791 { return newitem(T_node,n,port); }
1792
1793static item *cons_attr(char *name, char *value)
1794 { return newitem(T_atom,name,value); }
1795
1796static item *cons_list(item *list)
1797 { return newitem(T_list,list,NIL(char*)); }
1798
1799static item *cons_subg(Agraph_t *subg)
1800 { return newitem(T_subgraph,subg,NIL(char*)); }
1801
1802static gstack_t *push(gstack_t *s, Agraph_t *subg) {
1803 gstack_t *rv;
1804 rv = agalloc(G,sizeof(gstack_t));
1805 rv->down = s;
1806 rv->g = subg;
1807 return rv;
1808}
1809
1810static gstack_t *pop(gstack_t *s)
1811{
1812 gstack_t *rv;
1813 rv = S->down;
1814 agfree(G,s);
1815 return rv;
1816}
1817
1818#ifdef NOTDEF
1819static item *cons_edge(Agedge_t *e)
1820 { return newitem(T_edge,e,NIL(char*)); }
1821#endif
1822
1823static void delete_items(item *ilist)
1824{
1825 item *p,*pn;
1826
1827 for (p = ilist; p; p = pn) {
1828 pn = p->next;
1829 switch(p->tag) {
1830 case T_list: delete_items(p->u.list); break;
1831 case T_atom: case T_attr: agstrfree(G,p->str); break;
1832 }
1833 agfree(G,p);
1834 }
1835}
1836
1837#ifdef NOTDEF
1838static void initlist(list_t *list)
1839{
1840 list->first = list->last = NILitem;
1841}
1842#endif
1843
1844static void deletelist(list_t *list)
1845{
1846 delete_items(list->first);
1847 list->first = list->last = NILitem;
1848}
1849
1850#ifdef NOTDEF
1851static void listins(list_t *list, item *v)
1852{
1853 v->next = list->first;
1854 list->first = v;
1855 if (list->last == NILitem) list->last = v;
1856}
1857#endif
1858
1859static void listapp(list_t *list, item *v)
1860{
1861 if (list->last) list->last->next = v;
1862 list->last = v;
1863 if (list->first == NILitem) list->first = v;
1864}
1865
1866
1867/* attrs */
1868static void appendattr(char *name, char *value)
1869{
1870 item *v;
1871
1872 assert(value != NIL(char*));
1873 v = cons_attr(name,value);
1874 listapp(&(S->attrlist),v);
1875}
1876
1877static void bindattrs(int kind)
1878{
1879 item *aptr;
1880 char *name;
1881
1882 for (aptr = S->attrlist.first; aptr; aptr = aptr->next) {
1883 assert(aptr->tag == T_atom); /* signifies unbound attr */
1884 name = aptr->u.name;
1885 if ((kind == AGEDGE) && streq(name,Key)) continue;
1886 if ((aptr->u.asym = agattr(S->g,kind,name,NIL(char*))) == NILsym)
1887 aptr->u.asym = agattr(S->g,kind,name,"");
1888 aptr->tag = T_attr; /* signifies bound attr */
1889 agstrfree(G,name);
1890 }
1891}
1892
1893/* attach node/edge specific attributes */
1894static void applyattrs(void *obj)
1895{
1896 item *aptr;
1897
1898 for (aptr = S->attrlist.first; aptr; aptr = aptr->next) {
1899 if (aptr->tag == T_attr) {
1900 if (aptr->u.asym) {
1901 agxset(obj,aptr->u.asym,aptr->str);
1902 }
1903 }
1904 else {
1905 assert(AGTYPE(obj) == AGEDGE);
1906 assert(aptr->tag == T_atom);
1907 assert(streq(aptr->u.name,Key));
1908 }
1909 }
1910}
1911
1912static void nomacros(void)
1913{
1914 agerr(AGWARN,"attribute macros not implemented");
1915}
1916
1917/* attrstmt:
1918 * First argument is always attrtype, so switch covers all cases.
1919 * This function is used to handle default attribute value assignment.
1920 */
1921static void attrstmt(int tkind, char *macroname)
1922{
1923 item *aptr;
1924 int kind = 0;
1925 Agsym_t* sym;
1926
1927 /* creating a macro def */
1928 if (macroname) nomacros();
1929 /* invoking a macro def */
1930 for (aptr = S->attrlist.first; aptr; aptr = aptr->next)
1931 if (aptr->str == NIL(char*)) nomacros();
1932
1933 switch(tkind) {
1934 case T_graph: kind = AGRAPH; break;
1935 case T_node: kind = AGNODE; break;
1936 case T_edge: kind = AGEDGE; break;
1937 }
1938 bindattrs(kind); /* set up defaults for new attributes */
1939 for (aptr = S->attrlist.first; aptr; aptr = aptr->next) {
1940 /* If the tag is still T_atom, aptr->u.asym has not been set */
1941 if (aptr->tag == T_atom) continue;
1942 if (!(aptr->u.asym->fixed) || (S->g != G))
1943 sym = agattr(S->g,kind,aptr->u.asym->name,aptr->str);
1944 else
1945 sym = aptr->u.asym;
1946 if (S->g == G)
1947 sym->print = TRUE;
1948 }
1949 deletelist(&(S->attrlist));
1950}
1951
1952/* nodes */
1953
1954static void appendnode(char *name, char *port, char *sport)
1955{
1956 item *elt;
1957
1958 if (sport) {
1959 port = concatPort (port, sport);
1960 }
1961 elt = cons_node(agnode(S->g,name,TRUE),port);
1962 listapp(&(S->nodelist),elt);
1963 agstrfree(G,name);
1964}
1965
1966/* apply current optional attrs to nodelist and clean up lists */
1967/* what's bad is that this could also be endsubg. also, you can't
1968clean up S->subg in closesubg() because S->subg might be needed
1969to construct edges. these are the sort of notes you write to yourself
1970in the future. */
1971static void endnode()
1972{
1973 item *ptr;
1974
1975 bindattrs(AGNODE);
1976 for (ptr = S->nodelist.first; ptr; ptr = ptr->next)
1977 applyattrs(ptr->u.n);
1978 deletelist(&(S->nodelist));
1979 deletelist(&(S->attrlist));
1980 deletelist(&(S->edgelist));
1981 S->subg = 0; /* notice a pattern here? :-( */
1982}
1983
1984/* edges - store up node/subg lists until optional edge key can be seen */
1985
1986static void getedgeitems(int x)
1987{
1988 item *v = 0;
1989
1990 if (S->nodelist.first) {
1991 v = cons_list(S->nodelist.first);
1992 S->nodelist.first = S->nodelist.last = NILitem;
1993 }
1994 else {if (S->subg) v = cons_subg(S->subg); S->subg = 0;}
1995 /* else nil append */
1996 if (v) listapp(&(S->edgelist),v);
1997}
1998
1999static void endedge(void)
2000{
2001 char *key;
2002 item *aptr,*tptr,*p;
2003
2004 Agnode_t *t;
2005 Agraph_t *subg;
2006
2007 bindattrs(AGEDGE);
2008
2009 /* look for "key" pseudo-attribute */
2010 key = NIL(char*);
2011 for (aptr = S->attrlist.first; aptr; aptr = aptr->next) {
2012 if ((aptr->tag == T_atom) && streq(aptr->u.name,Key))
2013 key = aptr->str;
2014 }
2015
2016 /* can make edges with node lists or subgraphs */
2017 for (p = S->edgelist.first; p->next; p = p->next) {
2018 if (p->tag == T_subgraph) {
2019 subg = p->u.subg;
2020 for (t = agfstnode(subg); t; t = agnxtnode(subg,t))
2021 edgerhs(agsubnode(S->g,t,FALSE),NIL(char*),p->next,key);
2022 }
2023 else {
2024 for (tptr = p->u.list; tptr; tptr = tptr->next)
2025 edgerhs(tptr->u.n,tptr->str,p->next,key);
2026 }
2027 }
2028 deletelist(&(S->nodelist));
2029 deletelist(&(S->edgelist));
2030 deletelist(&(S->attrlist));
2031 S->subg = 0;
2032}
2033
2034/* concat:
2035 */
2036static char*
2037concat (char* s1, char* s2)
2038{
2039 char* s;
2040 char buf[BUFSIZ];
2041 char* sym;
2042 size_t len = strlen(s1) + strlen(s2) + 1;
2043
2044 if (len <= BUFSIZ) sym = buf;
2045 else sym = (char*)malloc(len);
2046 strcpy(sym,s1);
2047 strcat(sym,s2);
2048 s = agstrdup (G,sym);
2049 agstrfree (G,s1);
2050 agstrfree (G,s2);
2051 if (sym != buf) free (sym);
2052 return s;
2053}
2054
2055/* concatPort:
2056 */
2057static char*
2058concatPort (char* s1, char* s2)
2059{
2060 char* s;
2061 char buf[BUFSIZ];
2062 char* sym;
2063 size_t len = strlen(s1) + strlen(s2) + 2; /* one more for ':' */
2064
2065 if (len <= BUFSIZ) sym = buf;
2066 else sym = (char*)malloc(len);
2067 sprintf (sym, "%s:%s", s1, s2);
2068 s = agstrdup (G,sym);
2069 agstrfree (G,s1);
2070 agstrfree (G,s2);
2071 if (sym != buf) free (sym);
2072 return s;
2073}
2074
2075
2076static void edgerhs(Agnode_t *tail, char *tport, item *hlist, char *key)
2077{
2078 Agnode_t *head;
2079 Agraph_t *subg;
2080 item *hptr;
2081
2082 if (hlist->tag == T_subgraph) {
2083 subg = hlist->u.subg;
2084 for (head = agfstnode(subg); head; head = agnxtnode(subg,head))
2085 newedge(tail,tport,agsubnode(S->g,head,FALSE),NIL(char*),key);
2086 }
2087 else {
2088 for (hptr = hlist->u.list; hptr; hptr = hptr->next)
2089 newedge(tail,tport,agsubnode(S->g,hptr->u.n,FALSE),hptr->str,key);
2090 }
2091}
2092
2093static void mkport(Agedge_t *e, char *name, char *val)
2094{
2095 Agsym_t *attr;
2096 if (val) {
2097 if ((attr = agattr(S->g,AGEDGE,name,NIL(char*))) == NILsym)
2098 attr = agattr(S->g,AGEDGE,name,"");
2099 agxset(e,attr,val);
2100 }
2101}
2102
2103static void newedge(Agnode_t *t, char *tport, Agnode_t *h, char *hport, char *key)
2104{
2105 Agedge_t *e;
2106
2107 e = agedge(S->g,t,h,key,TRUE);
2108 if (e) { /* can fail if graph is strict and t==h */
2109 char *tp = tport;
2110 char *hp = hport;
2111 if ((agtail(e) != aghead(e)) && (aghead(e) == t)) {
2112 /* could happen with an undirected edge */
2113 char *temp;
2114 temp = tp; tp = hp; hp = temp;
2115 }
2116 mkport(e,TAILPORT_ID,tp);
2117 mkport(e,HEADPORT_ID,hp);
2118 applyattrs(e);
2119 }
2120}
2121
2122/* graphs and subgraphs */
2123
2124
2125static void startgraph(char *name, int directed, int strict)
2126{
2127 static Agdesc_t req; /* get rid of warnings */
2128
2129 if (G == NILgraph) {
2130 SubgraphDepth = 0;
2131 req.directed = directed;
2132 req.strict = strict;
2133 req.maingraph = TRUE;
2134 Ag_G_global = G = agopen(name,req,Disc);
2135 }
2136 else {
2137 Ag_G_global = G;
2138 }
2139 S = push(S,G);
2140 agstrfree(NIL(Agraph_t*),name);
2141}
2142
2143static void endgraph()
2144{
2145 aglexeof();
2146 aginternalmapclearlocalnames(G);
2147}
2148
2149static void opensubg(char *name)
2150{
2151 if (++SubgraphDepth >= YYMAXDEPTH/2) {
2152 char buf[128];
2153 sprintf(buf,"subgraphs nested more than %d deep",YYMAXDEPTH);
2154 agerr(AGERR,buf);
2155 }
2156 S = push(S,agsubg(S->g,name,TRUE));
2157 agstrfree(G,name);
2158}
2159
2160static void closesubg()
2161{
2162 Agraph_t *subg = S->g;
2163 --SubgraphDepth;
2164 S = pop(S);
2165 S->subg = subg;
2166 assert(subg);
2167}
2168
2169static void freestack()
2170{
2171 while (S) {
2172 deletelist(&(S->nodelist));
2173 deletelist(&(S->attrlist));
2174 deletelist(&(S->edgelist));
2175 S = pop(S);
2176 }
2177}
2178
2179extern FILE *aagin;
2180Agraph_t *agconcat(Agraph_t *g, void *chan, Agdisc_t *disc)
2181{
2182 aagin = chan;
2183 G = g;
2184 Ag_G_global = NILgraph;
2185 Disc = (disc? disc : &AgDefaultDisc);
2186 aglexinit(Disc, chan);
2187 aagparse();
2188 if (Ag_G_global == NILgraph) aglexbad();
2189 return Ag_G_global;
2190}
2191
2192Agraph_t *agread(void *fp, Agdisc_t *disc) {return agconcat(NILgraph,fp,disc); }
2193
2194