2
/* A Bison parser, made from grammar.y
5
#define YYBISON 1 /* Identify Bison output. */
10
# define T_digraph 260
11
# define T_subgraph 261
21
This software may only be used by you under license from AT&T Corp.
22
("AT&T"). A copy of AT&T's Source Code Agreement is available at
23
AT&T's Internet website having the URL:
24
<http://www.research.att.com/sw/tools/graphviz/license/source.html>
25
If you received this software without first entering into a license
26
with AT&T, you have an infringing copy of this software and cannot use
27
it without violating AT&T's intellectual property rights.
31
#include <stdio.h> /* SAFE */
32
#include <aghdr.h> /* SAFE */
35
#define gettxt(a,b) (b)
38
static char Key[] = "key";
40
typedef union s { /* possible items in generic list */
44
Agsym_t *asym; /* bound attribute */
45
char *name; /* unbound attribute */
46
struct item_s *list; /* list-of-lists (for edgestmt) */
49
typedef struct item_s { /* generic list */
50
int tag; /* T_node, T_subgraph, T_edge, T_attr */
51
val_t u; /* primary element */
52
char *str; /* secondary value - port or attr value */
56
typedef struct list_s { /* maintain head and tail ptrs for fast append */
62
static void appendnode(char *name, char *port);
63
static void attrstmt(int tkind, char *macroname);
64
static void startgraph(char *name, int directed, int strict);
65
static void bufferedges(void);
66
static void newedge(Agnode_t *t, char *tport, Agnode_t *h, char *hport, char *key);
67
static void edgerhs(Agnode_t *n, char *tport, item *hlist, char *key);
68
static void appendattr(char *name, char *value);
69
static void bindattrs(int kind);
70
static void applyattrs(void *obj);
71
static void endgraph(void);
72
static void endnode(void);
73
static void endedge(void);
75
static void opensubg(char *name);
76
static void closesubg(void);
96
/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
97
#define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? ag_yytranslate[x] : 54)
99
/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
100
static const char ag_yytranslate[] =
102
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
103
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
104
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
105
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
106
2, 2, 2, 2, 16, 2, 2, 2, 2, 2,
107
2, 2, 2, 2, 2, 2, 2, 2, 17, 15,
108
2, 18, 2, 2, 21, 2, 2, 2, 2, 2,
109
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
110
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
111
2, 19, 2, 20, 2, 2, 2, 2, 2, 2,
112
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
113
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
114
2, 2, 2, 13, 2, 14, 2, 2, 2, 2,
115
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
116
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
117
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
118
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
119
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
120
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
121
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
122
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
123
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
124
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
125
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
126
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
127
2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
128
6, 7, 8, 9, 10, 11, 12
132
static const short ag_yyprhs[] =
134
0, 0, 3, 5, 6, 10, 14, 16, 17, 19,
135
20, 22, 24, 26, 27, 30, 32, 34, 35, 38,
136
41, 45, 47, 49, 50, 55, 56, 58, 62, 65,
137
68, 69, 73, 75, 77, 79, 81, 84, 85, 87,
138
88, 93, 95, 96, 98, 102, 104, 106, 110, 113,
139
115, 116, 120, 123, 125, 126, 128, 130
141
static const short ag_yyrhs[] =
143
24, 23, 0, 1, 0, 0, 13, 28, 14, 0,
144
26, 27, 25, 0, 12, 0, 0, 8, 0, 0,
145
3, 0, 6, 0, 29, 0, 0, 29, 31, 0,
146
31, 0, 15, 0, 0, 39, 30, 0, 32, 30,
147
0, 33, 34, 42, 0, 36, 0, 50, 0, 0,
148
9, 35, 33, 34, 0, 0, 37, 0, 36, 16,
149
37, 0, 12, 38, 0, 17, 12, 0, 0, 40,
150
41, 43, 0, 49, 0, 3, 0, 4, 0, 5,
151
0, 12, 18, 0, 0, 43, 0, 0, 42, 19,
152
44, 20, 0, 45, 0, 0, 46, 0, 45, 53,
153
46, 0, 47, 0, 48, 0, 12, 18, 12, 0,
154
21, 12, 0, 47, 0, 0, 52, 51, 23, 0,
155
7, 12, 0, 7, 0, 0, 15, 0, 16, 0,
162
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
163
static const short ag_yyrline[] =
165
0, 82, 83, 84, 87, 89, 91, 91, 93, 93,
166
95, 95, 97, 97, 99, 99, 101, 101, 103, 104,
167
107, 111, 111, 113, 113, 114, 118, 118, 120, 122,
168
123, 126, 127, 130, 131, 132, 135, 136, 139, 139,
169
141, 143, 143, 145, 146, 149, 149, 151, 154, 157,
170
160, 160, 163, 164, 165, 168, 168, 168
175
#if YYDEBUG != 0 || defined YYERROR_VERBOSE
177
/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
178
static const char *const ag_yytname[] =
180
"$", "error", "$undefined.", "T_graph", "T_node", "T_edge", "T_digraph",
181
"T_subgraph", "T_strict", "T_edgeop", "T_list", "T_attr", "T_atom",
182
"'{'", "'}'", "';'", "','", "':'", "'='", "'['", "']'", "'@'", "graph",
183
"body", "hdr", "optgraphname", "optstrict", "graphtype", "optstmtlist",
184
"stmtlist", "optsemi", "stmt", "compound", "simple", "rcompound", "@1",
185
"nodelist", "node", "optport", "attrstmt", "attrtype", "optmacroname",
186
"optattr", "attrlist", "optattrdefs", "attrdefs", "attritem",
187
"attrassignment", "attrmacro", "graphattrdefs", "subgraph", "@2",
188
"optsubghdr", "optseparator", NULL
192
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
193
static const short ag_yyr1[] =
195
0, 22, 22, 22, 23, 24, 25, 25, 26, 26,
196
27, 27, 28, 28, 29, 29, 30, 30, 31, 31,
197
32, 33, 33, 35, 34, 34, 36, 36, 37, 38,
198
38, 39, 39, 40, 40, 40, 41, 41, 42, 42,
199
43, 44, 44, 45, 45, 46, 46, 47, 48, 49,
200
51, 50, 52, 52, 52, 53, 53, 53
203
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
204
static const short ag_yyr2[] =
206
0, 2, 1, 0, 3, 3, 1, 0, 1, 0,
207
1, 1, 1, 0, 2, 1, 1, 0, 2, 2,
208
3, 1, 1, 0, 4, 0, 1, 3, 2, 2,
209
0, 3, 1, 1, 1, 1, 2, 0, 1, 0,
210
4, 1, 0, 1, 3, 1, 1, 3, 2, 1,
211
0, 3, 2, 1, 0, 1, 1, 0
214
/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
215
doesn't specify something else to do. Zero means the default is an
217
static const short ag_yydefact[] =
219
0, 2, 8, 0, 0, 13, 1, 10, 11, 7,
220
33, 34, 35, 53, 30, 0, 12, 15, 17, 25,
221
21, 26, 17, 37, 49, 32, 22, 50, 6, 5,
222
52, 0, 0, 28, 4, 14, 16, 19, 23, 39,
223
0, 18, 0, 39, 0, 29, 47, 54, 20, 38,
224
30, 27, 36, 0, 31, 51, 25, 42, 24, 0,
225
0, 0, 57, 43, 45, 46, 48, 40, 55, 56,
229
static const short ag_yydefgoto[] =
231
72, 6, 3, 29, 4, 9, 15, 16, 37, 17,
232
18, 19, 39, 47, 20, 21, 33, 22, 23, 43,
233
48, 49, 61, 62, 63, 24, 65, 25, 26, 44,
237
static const short ag_yypact[] =
239
16,-32768,-32768, 1, 15, -2,-32768,-32768,-32768, 11,
240
-32768,-32768,-32768, 17, 8, 6, -2,-32768, 12, 19,
241
14,-32768, 12, 20,-32768,-32768,-32768,-32768,-32768,-32768,
242
-32768, 21, 22,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
243
23,-32768, 13,-32768, 1,-32768,-32768, -3, 18,-32768,
244
24,-32768,-32768, 18, 25,-32768, 19, -6,-32768, 27,
245
26, 28, -8,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
246
-6,-32768, 36, 39,-32768
249
static const short ag_yypgoto[] =
251
-32768, -4,-32768,-32768,-32768,-32768,-32768,-32768, 29, 30,
252
-32768, -5, -13,-32768,-32768, 7,-32768,-32768,-32768,-32768,
253
9, 10,-32768,-32768, -21, -57,-32768,-32768,-32768,-32768,
261
static const short ag_yytable[] =
263
64, 10, 11, 12, 13, 13, 59, 68, 69, 50,
264
14, -54, -41, 64, 5, 60, -3, 1, 7, -9,
265
34, 8, -9, 28, 2, 31, 32, 36, 38, 30,
266
40, 52, 42, 45, 46, 50, 73, 57, 66, 74,
267
55, 31, 56, 58, -38, 32, 35, 51, 67, 71,
271
static const short ag_yycheck[] =
273
57, 3, 4, 5, 7, 7, 12, 15, 16, 12,
274
12, 13, 20, 70, 13, 21, 0, 1, 3, 3,
275
14, 6, 6, 12, 8, 17, 18, 15, 9, 12,
276
16, 18, 12, 12, 12, 12, 0, 19, 12, 0,
277
44, 17, 47, 56, 19, 18, 16, 40, 20, 70,
280
/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
281
#line 3 "/usr/share/bison/bison.simple"
283
/* Skeleton output parser for bison,
284
Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
286
This program is free software; you can redistribute it and/or modify
287
it under the terms of the GNU General Public License as published by
288
the Free Software Foundation; either version 2, or (at your option)
291
This program is distributed in the hope that it will be useful,
292
but WITHOUT ANY WARRANTY; without even the implied warranty of
293
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
294
GNU General Public License for more details.
296
You should have received a copy of the GNU General Public License
297
along with this program; if not, write to the Free Software
298
Foundation, Inc., 59 Temple Place - Suite 330,
299
Boston, MA 02111-1307, USA. */
301
/* As a special exception, when this file is copied by Bison into a
302
Bison output file, you may use that output file without restriction.
303
This special exception was added by the Free Software Foundation
304
in version 1.24 of Bison. */
306
/* This is the parser code that is written into each bison parser when
307
the %semantic_parser declaration is not specified in the grammar.
308
It was written by Richard Stallman by simplifying the hairy parser
309
used when %semantic_parser is specified. */
311
#ifndef YYSTACK_USE_ALLOCA
313
# define YYSTACK_USE_ALLOCA 1
314
# else /* alloca not defined */
316
# define YYSTACK_USE_ALLOCA 1
317
# define alloca __builtin_alloca
318
# else /* not GNU C. */
319
# if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
320
# define YYSTACK_USE_ALLOCA 1
322
# else /* not sparc */
323
/* We think this test detects Watcom and Microsoft C. */
324
/* This used to test MSDOS, but that is a bad idea since that
325
symbol is in the user namespace. */
326
# if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
328
/* No need for malloc.h, which pollutes the namespace; instead,
329
just don't use alloca. */
332
# else /* not MSDOS, or __TURBOC__ */
334
/* I don't know what this was needed for, but it pollutes the
335
namespace. So I turned it off. rms, 2 May 1997. */
336
/* #include <malloc.h> */
338
# define YYSTACK_USE_ALLOCA 1
339
# else /* not MSDOS, or __TURBOC__, or _AIX */
341
/* haible@ilog.fr says this works for HPUX 9.05 and up, and on
342
HPUX 10. Eventually we can turn this on. */
344
# define YYSTACK_USE_ALLOCA 1
345
# define alloca __builtin_alloca
348
# endif /* not _AIX */
349
# endif /* not MSDOS, or __TURBOC__ */
350
# endif /* not sparc */
351
# endif /* not GNU C */
352
# endif /* alloca not defined */
353
#endif /* YYSTACK_USE_ALLOCA not defined */
355
#ifndef YYSTACK_USE_ALLOCA
356
# define YYSTACK_USE_ALLOCA 0
359
#if YYSTACK_USE_ALLOCA
360
# define YYSTACK_ALLOC alloca
362
# define YYSTACK_ALLOC malloc
365
#define ag_yyerrok (ag_yyerrstatus = 0)
366
#define ag_yyclearin (ag_yychar = YYEMPTY)
369
#define YYACCEPT goto ag_yyacceptlab
370
#define YYABORT goto ag_yyabortlab
371
#define YYERROR goto ag_yyerrlab1
372
/* Like YYERROR except do call ag_yyerror. This remains here temporarily
373
to ease the transition to the new meaning of YYERROR, for GCC.
374
Once GCC version 2 has supplanted version 1, this can go. */
375
#define YYFAIL goto ag_yyerrlab
376
#define YYRECOVERING() (!!ag_yyerrstatus)
377
#define YYBACKUP(Token, Value) \
379
if (ag_yychar == YYEMPTY && ag_yylen == 1) \
381
ag_yychar = (Token); \
382
ag_yylval = (Value); \
383
ag_yychar1 = YYTRANSLATE (ag_yychar); \
389
ag_yyerror ("syntax error: cannot back up"); \
395
#define YYERRCODE 256
398
/* YYLLOC_DEFAULT -- Compute the default location (before the actions
401
When YYLLOC_DEFAULT is run, CURRENT is set the location of the
402
first token. By default, to implement support for ranges, extend
403
its range to the last symbol. */
405
#ifndef YYLLOC_DEFAULT
406
# define YYLLOC_DEFAULT(Current, Rhs, N) \
407
Current.last_line = Rhs[N].last_line; \
408
Current.last_column = Rhs[N].last_column;
412
/* YYLEX -- calling `ag_yylex' with the right arguments. */
417
# define YYLEX ag_yylex (&ag_yylval, &ag_yylloc, YYLEX_PARAM)
419
# define YYLEX ag_yylex (&ag_yylval, &ag_yylloc)
421
# else /* !YYLSP_NEEDED */
423
# define YYLEX ag_yylex (&ag_yylval, YYLEX_PARAM)
425
# define YYLEX ag_yylex (&ag_yylval)
427
# endif /* !YYLSP_NEEDED */
429
# define YYLEX ag_yylex ()
433
/* Enable debugging if requested. */
435
# define YYDPRINTF(Args) \
440
/* Nonzero means print parse trace. [The following comment makes no
441
sense to me. Could someone clarify it? --akim] Since this is
442
uninitialized, it does not stop multiple parsers from coexisting.
446
# define YYDPRINTF(Args)
447
#endif /* !YYDEBUG */
449
/* YYINITDEPTH -- initial size of the parser's stacks. */
451
# define YYINITDEPTH 200
454
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
455
if the built-in stack extension method is used). */
461
# define YYMAXDEPTH 10000
464
/* Define __ag_yy_memcpy. Note that the size argument
465
should be passed with type unsigned int, because that is what the non-GCC
466
definitions require. With GCC, __builtin_memcpy takes an arg
467
of type size_t, but it can handle unsigned int. */
469
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
470
# define __ag_yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
471
#else /* not GNU C or C++ */
473
/* This is the most reliable way to avoid incompatibilities
474
in available built-in functions on various systems. */
477
__ag_yy_memcpy (to, from, count)
481
# else /* __cplusplus */
482
__ag_yy_memcpy (char *to, const char *from, unsigned int count)
485
register const char *f = from;
486
register char *t = to;
487
register int i = count;
495
#line 216 "/usr/share/bison/bison.simple"
498
/* The user can define YYPARSE_PARAM as the name of an argument to be passed
499
into ag_yyparse. The argument should have type void *.
500
It should actually point to an object.
501
Grammar actions can access the variable by casting it
502
to the proper pointer type. */
506
# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
507
# define YYPARSE_PARAM_DECL
508
# else /* !__cplusplus */
509
# define YYPARSE_PARAM_ARG YYPARSE_PARAM
510
# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
511
# endif /* !__cplusplus */
512
#else /* !YYPARSE_PARAM */
513
# define YYPARSE_PARAM_ARG
514
# define YYPARSE_PARAM_DECL
515
#endif /* !YYPARSE_PARAM */
517
/* Prevent warning if -Wstrict-prototypes. */
519
# ifdef YYPARSE_PARAM
520
int ag_yyparse (void *);
522
int ag_yyparse (void);
526
/* YY_DECL_VARIABLES -- depending whether we use a pure parser,
527
variables are global, or local to YYPARSE. */
529
#define _YY_DECL_VARIABLES \
530
/* The lookahead symbol. */ \
533
/* The semantic value of the lookahead symbol. */ \
536
/* Number of parse errors so far. */ \
540
# define YY_DECL_VARIABLES \
543
/* Location data for the lookahead symbol. */ \
546
# define YY_DECL_VARIABLES \
551
/* If nonreentrant, generate the variables here. */
558
ag_yyparse (YYPARSE_PARAM_ARG)
561
/* If reentrant, generate the variables here. */
566
register int ag_yystate;
568
/* Number of tokens to shift before error messages enabled. */
570
/* Lookahead token as an internal (translated) token number. */
573
/* Three stacks and their tools:
574
`ag_yyss': related to states,
575
`ag_yysv': related to semantic values,
576
`ag_yyls': related to locations.
578
Refer to the stacks thru separate pointers, to allow ag_yyoverflow
579
to reallocate them elsewhere. */
581
/* The state stack. */
582
short ag_yyssa[YYINITDEPTH];
583
short *ag_yyss = ag_yyssa;
584
register short *ag_yyssp;
586
/* The semantic value stack. */
587
YYSTYPE ag_yyvsa[YYINITDEPTH];
588
YYSTYPE *ag_yyvs = ag_yyvsa;
589
register YYSTYPE *ag_yyvsp;
592
/* The location stack. */
593
YYLTYPE ag_yylsa[YYINITDEPTH];
594
YYLTYPE *ag_yyls = ag_yylsa;
599
# define YYPOPSTACK (ag_yyvsp--, ag_yyssp--, ag_yylsp--)
601
# define YYPOPSTACK (ag_yyvsp--, ag_yyssp--)
604
int ag_yystacksize = YYINITDEPTH;
605
int ag_yyfree_stacks = 0;
608
/* The variables used to return semantic value and location from the
615
/* When reducing, the number of symbols on the RHS of the reduced
619
YYDPRINTF ((stderr, "Starting parse\n"));
624
ag_yychar = YYEMPTY; /* Cause a token to be read. */
626
/* Initialize stack pointers.
627
Waste one element of value and location stack
628
so that they stay on the same level as the state stack.
629
The wasted elements are never initialized. */
638
/*------------------------------------------------------------.
639
| ag_yynewstate -- Push a new state, which is found in ag_yystate. |
640
`------------------------------------------------------------*/
642
/* In all cases, when you get here, the value and location stacks
643
have just been pushed. so pushing a state here evens the stacks.
648
*ag_yyssp = ag_yystate;
650
if (ag_yyssp >= ag_yyss + ag_yystacksize - 1)
652
/* Give user a chance to reallocate the stack. Use copies of
653
these so that the &'s don't force the real ones into memory.
655
YYSTYPE *ag_yyvs1 = ag_yyvs;
656
short *ag_yyss1 = ag_yyss;
658
YYLTYPE *ag_yyls1 = ag_yyls;
661
/* Get the current used size of the three stacks, in elements. */
662
int size = ag_yyssp - ag_yyss + 1;
665
/* Each stack pointer address is followed by the size of the
666
data in use in that stack, in bytes. */
668
/* This used to be a conditional around just the two extra args,
669
but that might be undefined if ag_yyoverflow is a macro. */
670
ag_yyoverflow ("parser stack overflow",
671
&ag_yyss1, size * sizeof (*ag_yyssp),
672
&ag_yyvs1, size * sizeof (*ag_yyvsp),
673
&ag_yyls1, size * sizeof (*ag_yylsp),
676
ag_yyoverflow ("parser stack overflow",
677
&ag_yyss1, size * sizeof (*ag_yyssp),
678
&ag_yyvs1, size * sizeof (*ag_yyvsp),
682
ag_yyss = ag_yyss1; ag_yyvs = ag_yyvs1;
686
#else /* no ag_yyoverflow */
687
/* Extend the stack our own way. */
688
if (ag_yystacksize >= YYMAXDEPTH)
690
ag_yyerror ("parser stack overflow");
691
if (ag_yyfree_stacks)
702
if (ag_yystacksize > YYMAXDEPTH)
703
ag_yystacksize = YYMAXDEPTH;
704
# if !YYSTACK_USE_ALLOCA
705
ag_yyfree_stacks = 1;
707
ag_yyss = (short *) YYSTACK_ALLOC (ag_yystacksize * sizeof (*ag_yyssp));
708
__ag_yy_memcpy ((char *)ag_yyss, (char *)ag_yyss1,
709
size * (unsigned int) sizeof (*ag_yyssp));
710
ag_yyvs = (YYSTYPE *) YYSTACK_ALLOC (ag_yystacksize * sizeof (*ag_yyvsp));
711
__ag_yy_memcpy ((char *)ag_yyvs, (char *)ag_yyvs1,
712
size * (unsigned int) sizeof (*ag_yyvsp));
714
ag_yyls = (YYLTYPE *) YYSTACK_ALLOC (ag_yystacksize * sizeof (*ag_yylsp));
715
__ag_yy_memcpy ((char *)ag_yyls, (char *)ag_yyls1,
716
size * (unsigned int) sizeof (*ag_yylsp));
718
#endif /* no ag_yyoverflow */
720
ag_yyssp = ag_yyss + size - 1;
721
ag_yyvsp = ag_yyvs + size - 1;
723
ag_yylsp = ag_yyls + size - 1;
726
YYDPRINTF ((stderr, "Stack size increased to %d\n", ag_yystacksize));
728
if (ag_yyssp >= ag_yyss + ag_yystacksize - 1)
732
YYDPRINTF ((stderr, "Entering state %d\n", ag_yystate));
742
/* Do appropriate processing given the current state. */
743
/* Read a lookahead token if we need one and don't already have one. */
746
/* First try to decide what to do without reference to lookahead token. */
748
ag_yyn = ag_yypact[ag_yystate];
749
if (ag_yyn == YYFLAG)
752
/* Not known => get a lookahead token if don't already have one. */
754
/* ag_yychar is either YYEMPTY or YYEOF
755
or a valid token in external form. */
757
if (ag_yychar == YYEMPTY)
759
YYDPRINTF ((stderr, "Reading a token: "));
763
/* Convert token to internal form (in ag_yychar1) for indexing tables with */
765
if (ag_yychar <= 0) /* This means end of input. */
768
ag_yychar = YYEOF; /* Don't call YYLEX any more */
770
YYDPRINTF ((stderr, "Now at end of input.\n"));
774
ag_yychar1 = YYTRANSLATE (ag_yychar);
777
/* We have to keep this `#if YYDEBUG', since we use variables
778
which are defined only if `YYDEBUG' is set. */
781
fprintf (stderr, "Next token is %d (%s", ag_yychar, ag_yytname[ag_yychar1]);
782
/* Give the individual parser a way to print the precise
783
meaning of a token, for further debugging info. */
785
YYPRINT (stderr, ag_yychar, ag_yylval);
787
fprintf (stderr, ")\n");
792
ag_yyn += ag_yychar1;
793
if (ag_yyn < 0 || ag_yyn > YYLAST || ag_yycheck[ag_yyn] != ag_yychar1)
796
ag_yyn = ag_yytable[ag_yyn];
798
/* ag_yyn is what to do for this token type in this state.
799
Negative => reduce, -ag_yyn is rule number.
800
Positive => shift, ag_yyn is new state.
801
New state is final state => don't bother to shift,
803
0, or most negative number => error. */
807
if (ag_yyn == YYFLAG)
812
else if (ag_yyn == 0)
815
if (ag_yyn == YYFINAL)
818
/* Shift the lookahead token. */
819
YYDPRINTF ((stderr, "Shifting token %d (%s), ", ag_yychar, ag_yytname[ag_yychar1]));
821
/* Discard the token being shifted unless it is eof. */
822
if (ag_yychar != YYEOF)
825
*++ag_yyvsp = ag_yylval;
827
*++ag_yylsp = ag_yylloc;
830
/* Count tokens shifted since error; after three, turn off error
839
/*-----------------------------------------------------------.
840
| ag_yydefault -- do the default action for the current state. |
841
`-----------------------------------------------------------*/
843
ag_yyn = ag_yydefact[ag_yystate];
849
/*-----------------------------.
850
| ag_yyreduce -- Do a reduction. |
851
`-----------------------------*/
853
/* ag_yyn is the number of a rule to reduce with. */
854
ag_yylen = ag_yyr2[ag_yyn];
856
/* If YYLEN is nonzero, implement the default value of the action:
859
Otherwise, the following line sets YYVAL to the semantic value of
860
the lookahead token. This behavior is undocumented and Bison
861
users should not rely upon it. Assigning to YYVAL
862
unconditionally makes the parser a bit smaller, and it avoids a
863
GCC warning that YYVAL may be used uninitialized. */
864
ag_yyval = ag_yyvsp[1-ag_yylen];
867
/* Similarly for the default location. Let the user run additional
868
commands if for instance locations are ranges. */
869
ag_yyloc = ag_yylsp[1-ag_yylen];
870
YYLLOC_DEFAULT (ag_yyloc, (ag_yylsp - ag_yylen), ag_yylen);
874
/* We have to keep this `#if YYDEBUG', since we use variables which
875
are defined only if `YYDEBUG' is set. */
880
fprintf (stderr, "Reducing via rule %d (line %d), ",
881
ag_yyn, ag_yyrline[ag_yyn]);
883
/* Print the symbols being reduced, and their result. */
884
for (i = ag_yyprhs[ag_yyn]; ag_yyrhs[i] > 0; i++)
885
fprintf (stderr, "%s ", ag_yytname[ag_yyrhs[i]]);
886
fprintf (stderr, " -> %s\n", ag_yytname[ag_yyr1[ag_yyn]]);
898
{if (G) {agclose(G); G = Ag_G_global = NIL(Agraph_t*);};
902
{startgraph(ag_yyvsp[0].str,ag_yyvsp[-1].i,ag_yyvsp[-2].i);;
906
{ag_yyval.str=ag_yyvsp[0].str;;
929
#line 108 "grammar.y"
930
{if (ag_yyvsp[-1].i) endedge(); else endnode();;
933
#line 113 "grammar.y"
937
#line 113 "grammar.y"
941
#line 114 "grammar.y"
945
#line 120 "grammar.y"
946
{appendnode(ag_yyvsp[-1].str,ag_yyvsp[0].str);;
949
#line 122 "grammar.y"
950
{ag_yyval.str = ag_yyvsp[0].str;;
953
#line 123 "grammar.y"
954
{ag_yyval.str = NIL(char*);;
957
#line 126 "grammar.y"
958
{attrstmt(ag_yyvsp[-2].i,ag_yyvsp[-1].str);;
961
#line 127 "grammar.y"
962
{attrstmt(T_graph,NIL(char*));;
965
#line 130 "grammar.y"
966
{ag_yyval.i = T_graph;;
969
#line 131 "grammar.y"
970
{ag_yyval.i = T_node;;
973
#line 132 "grammar.y"
974
{ag_yyval.i = T_edge;;
977
#line 135 "grammar.y"
978
{ag_yyval.str = ag_yyvsp[-1].str;;
981
#line 136 "grammar.y"
982
{ag_yyval.str = NIL(char*); ;
985
#line 151 "grammar.y"
986
{appendattr(ag_yyvsp[-2].str,ag_yyvsp[0].str);;
989
#line 154 "grammar.y"
990
{appendattr(ag_yyvsp[0].str,NIL(char*));;
993
#line 160 "grammar.y"
994
{opensubg(ag_yyvsp[0].str);;
997
#line 160 "grammar.y"
1001
#line 163 "grammar.y"
1002
{ag_yyval.str=ag_yyvsp[0].str;;
1005
#line 164 "grammar.y"
1006
{ag_yyval.str=NIL(char*);;
1009
#line 165 "grammar.y"
1010
{ag_yyval.str=NIL(char*);;
1014
#line 610 "/usr/share/bison/bison.simple"
1017
ag_yyvsp -= ag_yylen;
1018
ag_yyssp -= ag_yylen;
1020
ag_yylsp -= ag_yylen;
1026
short *ssp1 = ag_yyss - 1;
1027
fprintf (stderr, "state stack now");
1028
while (ssp1 != ag_yyssp)
1029
fprintf (stderr, " %d", *++ssp1);
1030
fprintf (stderr, "\n");
1034
*++ag_yyvsp = ag_yyval;
1036
*++ag_yylsp = ag_yyloc;
1039
/* Now `shift' the result of the reduction. Determine what state
1040
that goes to, based on the state we popped back to and the rule
1041
number reduced by. */
1043
ag_yyn = ag_yyr1[ag_yyn];
1045
ag_yystate = ag_yypgoto[ag_yyn - YYNTBASE] + *ag_yyssp;
1046
if (ag_yystate >= 0 && ag_yystate <= YYLAST && ag_yycheck[ag_yystate] == *ag_yyssp)
1047
ag_yystate = ag_yytable[ag_yystate];
1049
ag_yystate = ag_yydefgoto[ag_yyn - YYNTBASE];
1054
/*------------------------------------.
1055
| ag_yyerrlab -- here on detecting error |
1056
`------------------------------------*/
1058
/* If not already recovering from an error, report this error. */
1059
if (!ag_yyerrstatus)
1063
#ifdef YYERROR_VERBOSE
1064
ag_yyn = ag_yypact[ag_yystate];
1066
if (ag_yyn > YYFLAG && ag_yyn < YYLAST)
1073
/* Start X at -ag_yyn if nec to avoid negative indexes in ag_yycheck. */
1074
for (x = (ag_yyn < 0 ? -ag_yyn : 0);
1075
x < (int) (sizeof (ag_yytname) / sizeof (char *)); x++)
1076
if (ag_yycheck[x + ag_yyn] == x)
1077
size += strlen (ag_yytname[x]) + 15, count++;
1078
size += strlen ("parse error, unexpected `") + 1;
1079
size += strlen (ag_yytname[YYTRANSLATE (ag_yychar)]);
1080
msg = (char *) malloc (size);
1083
strcpy (msg, "parse error, unexpected `");
1084
strcat (msg, ag_yytname[YYTRANSLATE (ag_yychar)]);
1090
for (x = (ag_yyn < 0 ? -ag_yyn : 0);
1091
x < (int) (sizeof (ag_yytname) / sizeof (char *)); x++)
1092
if (ag_yycheck[x + ag_yyn] == x)
1094
strcat (msg, count == 0 ? ", expecting `" : " or `");
1095
strcat (msg, ag_yytname[x]);
1104
ag_yyerror ("parse error; also virtual memory exceeded");
1107
#endif /* YYERROR_VERBOSE */
1108
ag_yyerror ("parse error");
1113
/*--------------------------------------------------.
1114
| ag_yyerrlab1 -- error raised explicitly by an action |
1115
`--------------------------------------------------*/
1117
if (ag_yyerrstatus == 3)
1119
/* If just tried and failed to reuse lookahead token after an
1120
error, discard it. */
1122
/* return failure if at end of input */
1123
if (ag_yychar == YYEOF)
1125
YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
1126
ag_yychar, ag_yytname[ag_yychar1]));
1127
ag_yychar = YYEMPTY;
1130
/* Else will try to reuse lookahead token after shifting the error
1133
ag_yyerrstatus = 3; /* Each real token shifted decrements this */
1135
goto ag_yyerrhandle;
1138
/*-------------------------------------------------------------------.
1139
| ag_yyerrdefault -- current state does not do anything special for the |
1141
`-------------------------------------------------------------------*/
1144
/* This is wrong; only states that explicitly want error tokens
1145
should shift them. */
1147
/* If its default is to accept any token, ok. Otherwise pop it. */
1148
ag_yyn = ag_yydefact[ag_yystate];
1154
/*---------------------------------------------------------------.
1155
| ag_yyerrpop -- pop the current state because it cannot handle the |
1157
`---------------------------------------------------------------*/
1159
if (ag_yyssp == ag_yyss)
1162
ag_yystate = *--ag_yyssp;
1170
short *ssp1 = ag_yyss - 1;
1171
fprintf (stderr, "Error: state stack now");
1172
while (ssp1 != ag_yyssp)
1173
fprintf (stderr, " %d", *++ssp1);
1174
fprintf (stderr, "\n");
1182
ag_yyn = ag_yypact[ag_yystate];
1183
if (ag_yyn == YYFLAG)
1184
goto ag_yyerrdefault;
1187
if (ag_yyn < 0 || ag_yyn > YYLAST || ag_yycheck[ag_yyn] != YYTERROR)
1188
goto ag_yyerrdefault;
1190
ag_yyn = ag_yytable[ag_yyn];
1193
if (ag_yyn == YYFLAG)
1198
else if (ag_yyn == 0)
1201
if (ag_yyn == YYFINAL)
1204
YYDPRINTF ((stderr, "Shifting error token, "));
1206
*++ag_yyvsp = ag_yylval;
1208
*++ag_yylsp = ag_yylloc;
1211
ag_yystate = ag_yyn;
1215
/*-------------------------------------.
1216
| ag_yyacceptlab -- YYACCEPT comes here. |
1217
`-------------------------------------*/
1219
if (ag_yyfree_stacks)
1230
/*-----------------------------------.
1231
| ag_yyabortlab -- YYABORT comes here. |
1232
`-----------------------------------*/
1234
if (ag_yyfree_stacks)
1244
#line 170 "grammar.y"
1247
#define NILitem NIL(item*)
1250
static Agraph_t *Subgraph; /* most recent subgraph that was opened */
1251
static Agdisc_t *Disc; /* discipline passed to agread or agconcat */
1252
static list_t Nodelist,Edgelist,Attrlist;
1254
static item *newitem(int tag, void *p0, char *p1)
1256
item *rv = agalloc(G,sizeof(item));
1257
rv->tag = tag; rv->u.name = (char*)p0; rv->str = p1;
1261
static item *cons_node(Agnode_t *n, char *port)
1262
{ return newitem(T_node,n,port); }
1264
static item *cons_attr(char *name, char *value)
1265
{ return newitem(T_atom,name,value); }
1267
static item *cons_list(item *list)
1268
{ return newitem(T_list,list,NIL(char*)); }
1270
static item *cons_subg(Agraph_t *subg)
1271
{ return newitem(T_subgraph,subg,NIL(char*)); }
1274
static item *cons_edge(Agedge_t *e)
1275
{ return newitem(T_edge,e,NIL(char*)); }
1278
static void delete_items(item *ilist)
1282
for (p = ilist; p; p = pn) {
1285
case T_list: delete_items(p->u.list); break;
1286
case T_atom: case T_attr: agstrfree(G,p->str); break;
1292
static void deletelist(list_t *list)
1294
delete_items(list->first);
1295
list->first = list->last = NILitem;
1299
static void listins(list_t *list, item *v)
1301
v->next = list->first;
1303
if (list->last == NILitem) list->last = v;
1307
static void listapp(list_t *list, item *v)
1309
if (list->last) list->last->next = v;
1311
if (list->first == NILitem) list->first = v;
1316
static void appendattr(char *name, char *value)
1320
assert(value != NIL(char*));
1321
v = cons_attr(name,value);
1322
listapp(&Attrlist,v);
1325
static void bindattrs(int kind)
1330
for (aptr = Attrlist.first; aptr; aptr = aptr->next) {
1331
assert(aptr->tag == T_atom); /* signifies unbound attr */
1332
name = aptr->u.name;
1333
if ((kind == AGEDGE) && streq(name,Key)) continue;
1334
if ((aptr->u.asym = agattr(G,kind,name,NIL(char*))) == NILsym)
1335
aptr->u.asym = agattr(G,kind,name,"");
1336
aptr->tag = T_attr; /* signifies bound attr */
1341
static void applyattrs(void *obj)
1345
for (aptr = Attrlist.first; aptr; aptr = aptr->next) {
1346
if (aptr->tag == T_attr) {
1348
agxset(obj,aptr->u.asym,aptr->str);
1352
assert(AGTYPE(obj) == AGEDGE);
1353
assert(aptr->tag == T_atom);
1354
assert(streq(aptr->u.name,Key));
1359
static void nomacros(void)
1361
agerror(AGERROR_UNIMPL,"attribute macros");
1364
static void attrstmt(int tkind, char *macroname)
1369
/* creating a macro def */
1370
if (macroname) nomacros();
1371
/* invoking a macro def */
1372
for (aptr = Attrlist.first; aptr; aptr = aptr->next)
1373
if (aptr->str == NIL(char*)) nomacros();
1376
case T_graph: kind = AGRAPH; break;
1377
case T_node: kind = AGNODE; break;
1378
case T_edge: kind = AGEDGE; break;
1381
bindattrs(kind); /* set up defaults for new attributes */
1382
for (aptr = Attrlist.first; aptr; aptr = aptr->next)
1383
agattr(G,kind,aptr->u.asym->name,aptr->str);
1384
deletelist(&Attrlist);
1389
static void appendnode(char *name, char *port)
1393
elt = cons_node(agnode(G,name,TRUE),port);
1394
listapp(&Nodelist,elt);
1398
/* apply current optional attrs to Nodelist and clean up lists */
1399
static void endnode()
1404
for (ptr = Nodelist.first; ptr; ptr = ptr->next)
1405
applyattrs(ptr->u.n);
1406
deletelist(&Nodelist);
1407
deletelist(&Attrlist);
1410
/* edges - store up node/subg lists until optional edge key can be seen */
1412
static void bufferedges()
1416
if (Nodelist.first) {
1417
v = cons_list(Nodelist.first);
1418
Nodelist.first = Nodelist.last = NILitem;
1420
else {v = cons_subg(Subgraph); Subgraph = NIL(Agraph_t*);}
1421
listapp(&Edgelist,v);
1424
static void endedge(void)
1427
item *aptr,*tptr,*p;
1432
bufferedges(); /* pick up the terminal nodelist or subg */
1435
/* look for "key" pseudo-attribute */
1437
for (aptr = Attrlist.first; aptr; aptr = aptr->next) {
1438
if ((aptr->tag == T_atom) && streq(aptr->u.name,Key))
1442
/* can make edges with node lists or subgraphs */
1443
for (p = Edgelist.first; p->next; p = p->next) {
1444
if (p->tag == T_subgraph) {
1446
for (t = agfstnode(subg); t; t = agnxtnode(t))
1447
edgerhs(agsubnode(G,t,FALSE),NIL(char*),p->next,key);
1450
for (tptr = p->u.list; tptr; tptr = tptr->next)
1451
edgerhs(tptr->u.n,tptr->str,p->next,key);
1454
deletelist(&Edgelist);
1455
deletelist(&Attrlist);
1458
static void edgerhs(Agnode_t *tail, char *tport, item *hlist, char *key)
1464
if (hlist->tag == T_subgraph) {
1465
subg = hlist->u.subg;
1466
for (head = agfstnode(subg); head; head = agnxtnode(head))
1467
newedge(tail,tport,agsubnode(G,head,FALSE),NIL(char*),key);
1470
for (hptr = hlist->u.list; hptr; hptr = hptr->next)
1471
newedge(tail,tport,agsubnode(G,hptr->u.n,FALSE),hptr->str,key);
1475
static void mkport(Agedge_t *e, char *name, char *val)
1479
if ((attr = agattr(G,AGEDGE,name,NIL(char*))) == NILsym)
1480
attr = agattr(G,AGEDGE,name,"");
1485
static void newedge(Agnode_t *t, char *tport, Agnode_t *h, char *hport, char *key)
1489
e = agedge(t,h,key,TRUE);
1490
if (e) { /* can fail if graph is strict and t==h */
1491
mkport(e,"tailport",tport);
1492
mkport(e,"headport",hport);
1497
/* graphs and subgraphs */
1500
static void startgraph(char *name, int directed, int strict)
1502
static Agdesc_t req; /* get rid of warnings */
1504
if (G == NILgraph) {
1505
req.directed = directed;
1506
req.strict = strict;
1507
req.flatlock = FALSE;
1508
req.maingraph = TRUE;
1509
Ag_G_global = G = agopen(name,req,Disc);
1514
agstrfree(NIL(Agraph_t*),name);
1517
static void endgraph()
1520
aginternalmapclearlocalnames(G);
1523
static void opensubg(char *name)
1525
G = agsubg(G,name,TRUE);
1529
static void closesubg()
1532
if ((G = agparent(G)) == NIL(Agraph_t*))
1533
ag_yyerror("libgraph: parser lost root graph\n");
1536
extern void *ag_yyin;
1537
Agraph_t *agconcat(Agraph_t *g, void *chan, Agdisc_t *disc)
1541
Ag_G_global = NILgraph;
1542
Disc = (disc? disc : &AgDefaultDisc);
1543
aglexinit(Disc, chan);
1548
Agraph_t *agread(void *fp, Agdisc_t *disc) {return agconcat(NILgraph,fp,disc); }