~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to agraph/grammar.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* A Bison parser, made from grammar.y
 
3
   by GNU bison 1.30.  */
 
4
 
 
5
#define YYBISON 1  /* Identify Bison output.  */
 
6
 
 
7
# define        T_graph 257
 
8
# define        T_node  258
 
9
# define        T_edge  259
 
10
# define        T_digraph       260
 
11
# define        T_subgraph      261
 
12
# define        T_strict        262
 
13
# define        T_edgeop        263
 
14
# define        T_list  264
 
15
# define        T_attr  265
 
16
# define        T_atom  266
 
17
 
 
18
#line 1 "grammar.y"
 
19
 
 
20
/*
 
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.
 
28
*/
 
29
#pragma prototyped
 
30
 
 
31
#include <stdio.h>  /* SAFE */
 
32
#include <aghdr.h>      /* SAFE */
 
33
 
 
34
#ifdef _WIN32
 
35
#define gettxt(a,b)     (b)
 
36
#endif
 
37
 
 
38
static char Key[] = "key";
 
39
 
 
40
typedef union s {                                       /* possible items in generic list */
 
41
                Agnode_t                *n;
 
42
                Agraph_t                *subg;
 
43
                Agedge_t                *e;
 
44
                Agsym_t                 *asym;  /* bound attribute */
 
45
                char                    *name;  /* unbound attribute */
 
46
                struct item_s   *list;  /* list-of-lists (for edgestmt) */
 
47
} val_t;
 
48
 
 
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 */
 
53
        struct item_s   *next;
 
54
} item;
 
55
 
 
56
typedef struct list_s {         /* maintain head and tail ptrs for fast append */
 
57
        item                    *first;
 
58
        item                    *last;
 
59
} list_t;
 
60
 
 
61
/* functions */
 
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);
 
74
 
 
75
static void opensubg(char *name);
 
76
static void closesubg(void);
 
77
 
 
78
/* global */
 
79
static Agraph_t *G;
 
80
 
 
81
 
 
82
#line 65 "grammar.y"
 
83
typedef union   {
 
84
                        int                             i;
 
85
                        char                    *str;
 
86
                        struct Agnode_s *n;
 
87
} YYSTYPE;
 
88
#include <stdio.h>
 
89
 
 
90
 
 
91
 
 
92
#define YYFINAL         74
 
93
#define YYFLAG          -32768
 
94
#define YYNTBASE        22
 
95
 
 
96
/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
 
97
#define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? ag_yytranslate[x] : 54)
 
98
 
 
99
/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
 
100
static const char ag_yytranslate[] =
 
101
{
 
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
 
129
};
 
130
 
 
131
#if YYDEBUG != 0
 
132
static const short ag_yyprhs[] =
 
133
{
 
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
 
140
};
 
141
static const short ag_yyrhs[] =
 
142
{
 
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,
 
156
       0
 
157
};
 
158
 
 
159
#endif
 
160
 
 
161
#if YYDEBUG != 0
 
162
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
 
163
static const short ag_yyrline[] =
 
164
{
 
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
 
171
};
 
172
#endif
 
173
 
 
174
 
 
175
#if YYDEBUG != 0 || defined YYERROR_VERBOSE
 
176
 
 
177
/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
 
178
static const char *const ag_yytname[] =
 
179
{
 
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
 
189
};
 
190
#endif
 
191
 
 
192
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
 
193
static const short ag_yyr1[] =
 
194
{
 
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
 
201
};
 
202
 
 
203
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
 
204
static const short ag_yyr2[] =
 
205
{
 
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
 
212
};
 
213
 
 
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
 
216
   error. */
 
217
static const short ag_yydefact[] =
 
218
{
 
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,
 
226
       0,    44,     0,     0,     0
 
227
};
 
228
 
 
229
static const short ag_yydefgoto[] =
 
230
{
 
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,
 
234
      27,    70
 
235
};
 
236
 
 
237
static const short ag_yypact[] =
 
238
{
 
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
 
247
};
 
248
 
 
249
static const short ag_yypgoto[] =
 
250
{
 
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,
 
254
  -32768,-32768
 
255
};
 
256
 
 
257
 
 
258
#define YYLAST          53
 
259
 
 
260
 
 
261
static const short ag_yytable[] =
 
262
{
 
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,
 
268
       0,    41,    53,    54
 
269
};
 
270
 
 
271
static const short ag_yycheck[] =
 
272
{
 
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,
 
278
      -1,    22,    43,    43
 
279
};
 
280
/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
 
281
#line 3 "/usr/share/bison/bison.simple"
 
282
 
 
283
/* Skeleton output parser for bison,
 
284
   Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
 
285
 
 
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)
 
289
   any later version.
 
290
 
 
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.
 
295
 
 
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.  */
 
300
 
 
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.  */
 
305
 
 
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.  */
 
310
 
 
311
#ifndef YYSTACK_USE_ALLOCA
 
312
# ifdef alloca
 
313
#  define YYSTACK_USE_ALLOCA 1
 
314
# else /* alloca not defined */
 
315
#  ifdef __GNUC__
 
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
 
321
#    include <alloca.h>
 
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__)
 
327
#     if 0
 
328
       /* No need for malloc.h, which pollutes the namespace; instead,
 
329
          just don't use alloca.  */
 
330
#      include <malloc.h>
 
331
#     endif
 
332
#    else /* not MSDOS, or __TURBOC__ */
 
333
#     if defined(_AIX)
 
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>  */
 
337
 #pragma alloca
 
338
#      define YYSTACK_USE_ALLOCA 1
 
339
#     else /* not MSDOS, or __TURBOC__, or _AIX */
 
340
#      if 0
 
341
        /* haible@ilog.fr says this works for HPUX 9.05 and up, and on
 
342
           HPUX 10.  Eventually we can turn this on.  */
 
343
#       ifdef __hpux
 
344
#        define YYSTACK_USE_ALLOCA 1
 
345
#        define alloca __builtin_alloca
 
346
#       endif /* __hpux */
 
347
#      endif
 
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 */
 
354
 
 
355
#ifndef YYSTACK_USE_ALLOCA
 
356
# define YYSTACK_USE_ALLOCA 0
 
357
#endif
 
358
 
 
359
#if YYSTACK_USE_ALLOCA
 
360
# define YYSTACK_ALLOC alloca
 
361
#else
 
362
# define YYSTACK_ALLOC malloc
 
363
#endif
 
364
 
 
365
#define ag_yyerrok              (ag_yyerrstatus = 0)
 
366
#define ag_yyclearin    (ag_yychar = YYEMPTY)
 
367
#define YYEMPTY         -2
 
368
#define YYEOF           0
 
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)                                  \
 
378
do                                                              \
 
379
  if (ag_yychar == YYEMPTY && ag_yylen == 1)                            \
 
380
    {                                                           \
 
381
      ag_yychar = (Token);                                              \
 
382
      ag_yylval = (Value);                                              \
 
383
      ag_yychar1 = YYTRANSLATE (ag_yychar);                             \
 
384
      YYPOPSTACK;                                               \
 
385
      goto ag_yybackup;                                         \
 
386
    }                                                           \
 
387
  else                                                          \
 
388
    {                                                           \
 
389
      ag_yyerror ("syntax error: cannot back up");                      \
 
390
      YYERROR;                                                  \
 
391
    }                                                           \
 
392
while (0)
 
393
 
 
394
#define YYTERROR        1
 
395
#define YYERRCODE       256
 
396
 
 
397
 
 
398
/* YYLLOC_DEFAULT -- Compute the default location (before the actions
 
399
   are run).
 
400
 
 
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.  */
 
404
 
 
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;
 
409
#endif
 
410
 
 
411
 
 
412
/* YYLEX -- calling `ag_yylex' with the right arguments.  */
 
413
 
 
414
#if YYPURE
 
415
# if YYLSP_NEEDED
 
416
#  ifdef YYLEX_PARAM
 
417
#   define YYLEX                ag_yylex (&ag_yylval, &ag_yylloc, YYLEX_PARAM)
 
418
#  else
 
419
#   define YYLEX                ag_yylex (&ag_yylval, &ag_yylloc)
 
420
#  endif
 
421
# else /* !YYLSP_NEEDED */
 
422
#  ifdef YYLEX_PARAM
 
423
#   define YYLEX                ag_yylex (&ag_yylval, YYLEX_PARAM)
 
424
#  else
 
425
#   define YYLEX                ag_yylex (&ag_yylval)
 
426
#  endif
 
427
# endif /* !YYLSP_NEEDED */
 
428
#else /* !YYPURE */
 
429
# define YYLEX                  ag_yylex ()
 
430
#endif /* !YYPURE */
 
431
 
 
432
 
 
433
/* Enable debugging if requested.  */
 
434
#if YYDEBUG
 
435
# define YYDPRINTF(Args)                        \
 
436
do {                                            \
 
437
  if (ag_yydebug)                                       \
 
438
    fprintf Args;                               \
 
439
} while (0)
 
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.
 
443
   */
 
444
int ag_yydebug;
 
445
#else /* !YYDEBUG */
 
446
# define YYDPRINTF(Args)
 
447
#endif /* !YYDEBUG */
 
448
 
 
449
/* YYINITDEPTH -- initial size of the parser's stacks.  */
 
450
#ifndef YYINITDEPTH
 
451
# define YYINITDEPTH 200
 
452
#endif
 
453
 
 
454
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
 
455
   if the built-in stack extension method is used).  */
 
456
#if YYMAXDEPTH == 0
 
457
# undef YYMAXDEPTH
 
458
#endif
 
459
 
 
460
#ifndef YYMAXDEPTH
 
461
# define YYMAXDEPTH 10000
 
462
#endif
 
463
 
 
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.  */
 
468
 
 
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++ */
 
472
 
 
473
/* This is the most reliable way to avoid incompatibilities
 
474
   in available built-in functions on various systems.  */
 
475
static void
 
476
# ifndef __cplusplus
 
477
__ag_yy_memcpy (to, from, count)
 
478
     char *to;
 
479
     const char *from;
 
480
     unsigned int count;
 
481
# else /* __cplusplus */
 
482
__ag_yy_memcpy (char *to, const char *from, unsigned int count)
 
483
# endif
 
484
{
 
485
  register const char *f = from;
 
486
  register char *t = to;
 
487
  register int i = count;
 
488
 
 
489
  while (i-- > 0)
 
490
    *t++ = *f++;
 
491
}
 
492
 
 
493
#endif
 
494
 
 
495
#line 216 "/usr/share/bison/bison.simple"
 
496
 
 
497
 
 
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.  */
 
503
 
 
504
#ifdef YYPARSE_PARAM
 
505
# ifdef __cplusplus
 
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 */
 
516
 
 
517
/* Prevent warning if -Wstrict-prototypes.  */
 
518
#ifdef __GNUC__
 
519
# ifdef YYPARSE_PARAM
 
520
int ag_yyparse (void *);
 
521
# else
 
522
int ag_yyparse (void);
 
523
# endif
 
524
#endif
 
525
 
 
526
/* YY_DECL_VARIABLES -- depending whether we use a pure parser,
 
527
   variables are global, or local to YYPARSE.  */
 
528
 
 
529
#define _YY_DECL_VARIABLES                              \
 
530
/* The lookahead symbol.  */                            \
 
531
int ag_yychar;                                          \
 
532
                                                        \
 
533
/* The semantic value of the lookahead symbol. */       \
 
534
YYSTYPE ag_yylval;                                              \
 
535
                                                        \
 
536
/* Number of parse errors so far.  */                   \
 
537
int ag_yynerrs;
 
538
 
 
539
#if YYLSP_NEEDED
 
540
# define YY_DECL_VARIABLES                      \
 
541
_YY_DECL_VARIABLES                              \
 
542
                                                \
 
543
/* Location data for the lookahead symbol.  */  \
 
544
YYLTYPE ag_yylloc;
 
545
#else
 
546
# define YY_DECL_VARIABLES                      \
 
547
_YY_DECL_VARIABLES
 
548
#endif
 
549
 
 
550
 
 
551
/* If nonreentrant, generate the variables here. */
 
552
 
 
553
#if !YYPURE
 
554
YY_DECL_VARIABLES
 
555
#endif  /* !YYPURE */
 
556
 
 
557
int
 
558
ag_yyparse (YYPARSE_PARAM_ARG)
 
559
     YYPARSE_PARAM_DECL
 
560
{
 
561
  /* If reentrant, generate the variables here. */
 
562
#if YYPURE
 
563
  YY_DECL_VARIABLES
 
564
#endif  /* !YYPURE */
 
565
 
 
566
  register int ag_yystate;
 
567
  register int ag_yyn;
 
568
  /* Number of tokens to shift before error messages enabled.  */
 
569
  int ag_yyerrstatus;
 
570
  /* Lookahead token as an internal (translated) token number.  */
 
571
  int ag_yychar1 = 0;
 
572
 
 
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.
 
577
 
 
578
     Refer to the stacks thru separate pointers, to allow ag_yyoverflow
 
579
     to reallocate them elsewhere.  */
 
580
 
 
581
  /* The state stack. */
 
582
  short ag_yyssa[YYINITDEPTH];
 
583
  short *ag_yyss = ag_yyssa;
 
584
  register short *ag_yyssp;
 
585
 
 
586
  /* The semantic value stack.  */
 
587
  YYSTYPE ag_yyvsa[YYINITDEPTH];
 
588
  YYSTYPE *ag_yyvs = ag_yyvsa;
 
589
  register YYSTYPE *ag_yyvsp;
 
590
 
 
591
#if YYLSP_NEEDED
 
592
  /* The location stack.  */
 
593
  YYLTYPE ag_yylsa[YYINITDEPTH];
 
594
  YYLTYPE *ag_yyls = ag_yylsa;
 
595
  YYLTYPE *ag_yylsp;
 
596
#endif
 
597
 
 
598
#if YYLSP_NEEDED
 
599
# define YYPOPSTACK   (ag_yyvsp--, ag_yyssp--, ag_yylsp--)
 
600
#else
 
601
# define YYPOPSTACK   (ag_yyvsp--, ag_yyssp--)
 
602
#endif
 
603
 
 
604
  int ag_yystacksize = YYINITDEPTH;
 
605
  int ag_yyfree_stacks = 0;
 
606
 
 
607
 
 
608
  /* The variables used to return semantic value and location from the
 
609
     action routines.  */
 
610
  YYSTYPE ag_yyval;
 
611
# if YYLSP_NEEDED
 
612
  YYLTYPE ag_yyloc;
 
613
# endif
 
614
 
 
615
  /* When reducing, the number of symbols on the RHS of the reduced
 
616
     rule. */
 
617
  int ag_yylen;
 
618
 
 
619
  YYDPRINTF ((stderr, "Starting parse\n"));
 
620
 
 
621
  ag_yystate = 0;
 
622
  ag_yyerrstatus = 0;
 
623
  ag_yynerrs = 0;
 
624
  ag_yychar = YYEMPTY;          /* Cause a token to be read.  */
 
625
 
 
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.  */
 
630
 
 
631
  ag_yyssp = ag_yyss;
 
632
  ag_yyvsp = ag_yyvs;
 
633
#if YYLSP_NEEDED
 
634
  ag_yylsp = ag_yyls;
 
635
#endif
 
636
  goto ag_yysetstate;
 
637
 
 
638
/*------------------------------------------------------------.
 
639
| ag_yynewstate -- Push a new state, which is found in ag_yystate.  |
 
640
`------------------------------------------------------------*/
 
641
 ag_yynewstate:
 
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.
 
644
     */
 
645
  ag_yyssp++;
 
646
 
 
647
 ag_yysetstate:
 
648
  *ag_yyssp = ag_yystate;
 
649
 
 
650
  if (ag_yyssp >= ag_yyss + ag_yystacksize - 1)
 
651
    {
 
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.
 
654
         */
 
655
      YYSTYPE *ag_yyvs1 = ag_yyvs;
 
656
      short *ag_yyss1 = ag_yyss;
 
657
#if YYLSP_NEEDED
 
658
      YYLTYPE *ag_yyls1 = ag_yyls;
 
659
#endif
 
660
 
 
661
      /* Get the current used size of the three stacks, in elements.  */
 
662
      int size = ag_yyssp - ag_yyss + 1;
 
663
 
 
664
#ifdef ag_yyoverflow
 
665
      /* Each stack pointer address is followed by the size of the
 
666
         data in use in that stack, in bytes.  */
 
667
# if YYLSP_NEEDED
 
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),
 
674
                  &ag_yystacksize);
 
675
# else
 
676
      ag_yyoverflow ("parser stack overflow",
 
677
                  &ag_yyss1, size * sizeof (*ag_yyssp),
 
678
                  &ag_yyvs1, size * sizeof (*ag_yyvsp),
 
679
                  &ag_yystacksize);
 
680
# endif
 
681
 
 
682
      ag_yyss = ag_yyss1; ag_yyvs = ag_yyvs1;
 
683
# if YYLSP_NEEDED
 
684
      ag_yyls = ag_yyls1;
 
685
# endif
 
686
#else /* no ag_yyoverflow */
 
687
      /* Extend the stack our own way.  */
 
688
      if (ag_yystacksize >= YYMAXDEPTH)
 
689
        {
 
690
          ag_yyerror ("parser stack overflow");
 
691
          if (ag_yyfree_stacks)
 
692
            {
 
693
              free (ag_yyss);
 
694
              free (ag_yyvs);
 
695
# if YYLSP_NEEDED
 
696
              free (ag_yyls);
 
697
# endif
 
698
            }
 
699
          return 2;
 
700
        }
 
701
      ag_yystacksize *= 2;
 
702
      if (ag_yystacksize > YYMAXDEPTH)
 
703
        ag_yystacksize = YYMAXDEPTH;
 
704
# if !YYSTACK_USE_ALLOCA
 
705
      ag_yyfree_stacks = 1;
 
706
# endif
 
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));
 
713
# if YYLSP_NEEDED
 
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));
 
717
# endif
 
718
#endif /* no ag_yyoverflow */
 
719
 
 
720
      ag_yyssp = ag_yyss + size - 1;
 
721
      ag_yyvsp = ag_yyvs + size - 1;
 
722
#if YYLSP_NEEDED
 
723
      ag_yylsp = ag_yyls + size - 1;
 
724
#endif
 
725
 
 
726
      YYDPRINTF ((stderr, "Stack size increased to %d\n", ag_yystacksize));
 
727
 
 
728
      if (ag_yyssp >= ag_yyss + ag_yystacksize - 1)
 
729
        YYABORT;
 
730
    }
 
731
 
 
732
  YYDPRINTF ((stderr, "Entering state %d\n", ag_yystate));
 
733
 
 
734
  goto ag_yybackup;
 
735
 
 
736
 
 
737
/*-----------.
 
738
| ag_yybackup.  |
 
739
`-----------*/
 
740
ag_yybackup:
 
741
 
 
742
/* Do appropriate processing given the current state.  */
 
743
/* Read a lookahead token if we need one and don't already have one.  */
 
744
/* ag_yyresume: */
 
745
 
 
746
  /* First try to decide what to do without reference to lookahead token.  */
 
747
 
 
748
  ag_yyn = ag_yypact[ag_yystate];
 
749
  if (ag_yyn == YYFLAG)
 
750
    goto ag_yydefault;
 
751
 
 
752
  /* Not known => get a lookahead token if don't already have one.  */
 
753
 
 
754
  /* ag_yychar is either YYEMPTY or YYEOF
 
755
     or a valid token in external form.  */
 
756
 
 
757
  if (ag_yychar == YYEMPTY)
 
758
    {
 
759
      YYDPRINTF ((stderr, "Reading a token: "));
 
760
      ag_yychar = YYLEX;
 
761
    }
 
762
 
 
763
  /* Convert token to internal form (in ag_yychar1) for indexing tables with */
 
764
 
 
765
  if (ag_yychar <= 0)           /* This means end of input. */
 
766
    {
 
767
      ag_yychar1 = 0;
 
768
      ag_yychar = YYEOF;                /* Don't call YYLEX any more */
 
769
 
 
770
      YYDPRINTF ((stderr, "Now at end of input.\n"));
 
771
    }
 
772
  else
 
773
    {
 
774
      ag_yychar1 = YYTRANSLATE (ag_yychar);
 
775
 
 
776
#if YYDEBUG
 
777
     /* We have to keep this `#if YYDEBUG', since we use variables
 
778
        which are defined only if `YYDEBUG' is set.  */
 
779
      if (ag_yydebug)
 
780
        {
 
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.  */
 
784
# ifdef YYPRINT
 
785
          YYPRINT (stderr, ag_yychar, ag_yylval);
 
786
# endif
 
787
          fprintf (stderr, ")\n");
 
788
        }
 
789
#endif
 
790
    }
 
791
 
 
792
  ag_yyn += ag_yychar1;
 
793
  if (ag_yyn < 0 || ag_yyn > YYLAST || ag_yycheck[ag_yyn] != ag_yychar1)
 
794
    goto ag_yydefault;
 
795
 
 
796
  ag_yyn = ag_yytable[ag_yyn];
 
797
 
 
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,
 
802
       just return success.
 
803
     0, or most negative number => error.  */
 
804
 
 
805
  if (ag_yyn < 0)
 
806
    {
 
807
      if (ag_yyn == YYFLAG)
 
808
        goto ag_yyerrlab;
 
809
      ag_yyn = -ag_yyn;
 
810
      goto ag_yyreduce;
 
811
    }
 
812
  else if (ag_yyn == 0)
 
813
    goto ag_yyerrlab;
 
814
 
 
815
  if (ag_yyn == YYFINAL)
 
816
    YYACCEPT;
 
817
 
 
818
  /* Shift the lookahead token.  */
 
819
  YYDPRINTF ((stderr, "Shifting token %d (%s), ", ag_yychar, ag_yytname[ag_yychar1]));
 
820
 
 
821
  /* Discard the token being shifted unless it is eof.  */
 
822
  if (ag_yychar != YYEOF)
 
823
    ag_yychar = YYEMPTY;
 
824
 
 
825
  *++ag_yyvsp = ag_yylval;
 
826
#if YYLSP_NEEDED
 
827
  *++ag_yylsp = ag_yylloc;
 
828
#endif
 
829
 
 
830
  /* Count tokens shifted since error; after three, turn off error
 
831
     status.  */
 
832
  if (ag_yyerrstatus)
 
833
    ag_yyerrstatus--;
 
834
 
 
835
  ag_yystate = ag_yyn;
 
836
  goto ag_yynewstate;
 
837
 
 
838
 
 
839
/*-----------------------------------------------------------.
 
840
| ag_yydefault -- do the default action for the current state.  |
 
841
`-----------------------------------------------------------*/
 
842
ag_yydefault:
 
843
  ag_yyn = ag_yydefact[ag_yystate];
 
844
  if (ag_yyn == 0)
 
845
    goto ag_yyerrlab;
 
846
  goto ag_yyreduce;
 
847
 
 
848
 
 
849
/*-----------------------------.
 
850
| ag_yyreduce -- Do a reduction.  |
 
851
`-----------------------------*/
 
852
ag_yyreduce:
 
853
  /* ag_yyn is the number of a rule to reduce with.  */
 
854
  ag_yylen = ag_yyr2[ag_yyn];
 
855
 
 
856
  /* If YYLEN is nonzero, implement the default value of the action:
 
857
     `$$ = $1'.
 
858
 
 
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];
 
865
 
 
866
#if YYLSP_NEEDED
 
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);
 
871
#endif
 
872
 
 
873
#if YYDEBUG
 
874
  /* We have to keep this `#if YYDEBUG', since we use variables which
 
875
     are defined only if `YYDEBUG' is set.  */
 
876
  if (ag_yydebug)
 
877
    {
 
878
      int i;
 
879
 
 
880
      fprintf (stderr, "Reducing via rule %d (line %d), ",
 
881
               ag_yyn, ag_yyrline[ag_yyn]);
 
882
 
 
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]]);
 
887
    }
 
888
#endif
 
889
 
 
890
  switch (ag_yyn) {
 
891
 
 
892
case 1:
 
893
#line 82 "grammar.y"
 
894
{endgraph();;
 
895
    break;}
 
896
case 2:
 
897
#line 83 "grammar.y"
 
898
{if (G) {agclose(G); G = Ag_G_global = NIL(Agraph_t*);};
 
899
    break;}
 
900
case 5:
 
901
#line 89 "grammar.y"
 
902
{startgraph(ag_yyvsp[0].str,ag_yyvsp[-1].i,ag_yyvsp[-2].i);;
 
903
    break;}
 
904
case 6:
 
905
#line 91 "grammar.y"
 
906
{ag_yyval.str=ag_yyvsp[0].str;;
 
907
    break;}
 
908
case 7:
 
909
#line 91 "grammar.y"
 
910
{ag_yyval.str=0;;
 
911
    break;}
 
912
case 8:
 
913
#line 93 "grammar.y"
 
914
{ag_yyval.i=1;;
 
915
    break;}
 
916
case 9:
 
917
#line 93 "grammar.y"
 
918
{ag_yyval.i=0;;
 
919
    break;}
 
920
case 10:
 
921
#line 95 "grammar.y"
 
922
{ag_yyval.i = 0;;
 
923
    break;}
 
924
case 11:
 
925
#line 95 "grammar.y"
 
926
{ag_yyval.i = 1;;
 
927
    break;}
 
928
case 20:
 
929
#line 108 "grammar.y"
 
930
{if (ag_yyvsp[-1].i) endedge(); else endnode();;
 
931
    break;}
 
932
case 23:
 
933
#line 113 "grammar.y"
 
934
{bufferedges();;
 
935
    break;}
 
936
case 24:
 
937
#line 113 "grammar.y"
 
938
{ag_yyval.i = 1;;
 
939
    break;}
 
940
case 25:
 
941
#line 114 "grammar.y"
 
942
{ag_yyval.i = 0;;
 
943
    break;}
 
944
case 28:
 
945
#line 120 "grammar.y"
 
946
{appendnode(ag_yyvsp[-1].str,ag_yyvsp[0].str);;
 
947
    break;}
 
948
case 29:
 
949
#line 122 "grammar.y"
 
950
{ag_yyval.str = ag_yyvsp[0].str;;
 
951
    break;}
 
952
case 30:
 
953
#line 123 "grammar.y"
 
954
{ag_yyval.str = NIL(char*);;
 
955
    break;}
 
956
case 31:
 
957
#line 126 "grammar.y"
 
958
{attrstmt(ag_yyvsp[-2].i,ag_yyvsp[-1].str);;
 
959
    break;}
 
960
case 32:
 
961
#line 127 "grammar.y"
 
962
{attrstmt(T_graph,NIL(char*));;
 
963
    break;}
 
964
case 33:
 
965
#line 130 "grammar.y"
 
966
{ag_yyval.i = T_graph;;
 
967
    break;}
 
968
case 34:
 
969
#line 131 "grammar.y"
 
970
{ag_yyval.i = T_node;;
 
971
    break;}
 
972
case 35:
 
973
#line 132 "grammar.y"
 
974
{ag_yyval.i = T_edge;;
 
975
    break;}
 
976
case 36:
 
977
#line 135 "grammar.y"
 
978
{ag_yyval.str = ag_yyvsp[-1].str;;
 
979
    break;}
 
980
case 37:
 
981
#line 136 "grammar.y"
 
982
{ag_yyval.str = NIL(char*); ;
 
983
    break;}
 
984
case 47:
 
985
#line 151 "grammar.y"
 
986
{appendattr(ag_yyvsp[-2].str,ag_yyvsp[0].str);;
 
987
    break;}
 
988
case 48:
 
989
#line 154 "grammar.y"
 
990
{appendattr(ag_yyvsp[0].str,NIL(char*));;
 
991
    break;}
 
992
case 50:
 
993
#line 160 "grammar.y"
 
994
{opensubg(ag_yyvsp[0].str);;
 
995
    break;}
 
996
case 51:
 
997
#line 160 "grammar.y"
 
998
{closesubg();;
 
999
    break;}
 
1000
case 52:
 
1001
#line 163 "grammar.y"
 
1002
{ag_yyval.str=ag_yyvsp[0].str;;
 
1003
    break;}
 
1004
case 53:
 
1005
#line 164 "grammar.y"
 
1006
{ag_yyval.str=NIL(char*);;
 
1007
    break;}
 
1008
case 54:
 
1009
#line 165 "grammar.y"
 
1010
{ag_yyval.str=NIL(char*);;
 
1011
    break;}
 
1012
}
 
1013
 
 
1014
#line 610 "/usr/share/bison/bison.simple"
 
1015
 
 
1016
 
 
1017
  ag_yyvsp -= ag_yylen;
 
1018
  ag_yyssp -= ag_yylen;
 
1019
#if YYLSP_NEEDED
 
1020
  ag_yylsp -= ag_yylen;
 
1021
#endif
 
1022
 
 
1023
#if YYDEBUG
 
1024
  if (ag_yydebug)
 
1025
    {
 
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");
 
1031
    }
 
1032
#endif
 
1033
 
 
1034
  *++ag_yyvsp = ag_yyval;
 
1035
#if YYLSP_NEEDED
 
1036
  *++ag_yylsp = ag_yyloc;
 
1037
#endif
 
1038
 
 
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.  */
 
1042
 
 
1043
  ag_yyn = ag_yyr1[ag_yyn];
 
1044
 
 
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];
 
1048
  else
 
1049
    ag_yystate = ag_yydefgoto[ag_yyn - YYNTBASE];
 
1050
 
 
1051
  goto ag_yynewstate;
 
1052
 
 
1053
 
 
1054
/*------------------------------------.
 
1055
| ag_yyerrlab -- here on detecting error |
 
1056
`------------------------------------*/
 
1057
ag_yyerrlab:
 
1058
  /* If not already recovering from an error, report this error.  */
 
1059
  if (!ag_yyerrstatus)
 
1060
    {
 
1061
      ++ag_yynerrs;
 
1062
 
 
1063
#ifdef YYERROR_VERBOSE
 
1064
      ag_yyn = ag_yypact[ag_yystate];
 
1065
 
 
1066
      if (ag_yyn > YYFLAG && ag_yyn < YYLAST)
 
1067
        {
 
1068
          int size = 0;
 
1069
          char *msg;
 
1070
          int x, count;
 
1071
 
 
1072
          count = 0;
 
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);
 
1081
          if (msg != 0)
 
1082
            {
 
1083
              strcpy (msg, "parse error, unexpected `");
 
1084
              strcat (msg, ag_yytname[YYTRANSLATE (ag_yychar)]);
 
1085
              strcat (msg, "'");
 
1086
 
 
1087
              if (count < 5)
 
1088
                {
 
1089
                  count = 0;
 
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)
 
1093
                      {
 
1094
                        strcat (msg, count == 0 ? ", expecting `" : " or `");
 
1095
                        strcat (msg, ag_yytname[x]);
 
1096
                        strcat (msg, "'");
 
1097
                        count++;
 
1098
                      }
 
1099
                }
 
1100
              ag_yyerror (msg);
 
1101
              free (msg);
 
1102
            }
 
1103
          else
 
1104
            ag_yyerror ("parse error; also virtual memory exceeded");
 
1105
        }
 
1106
      else
 
1107
#endif /* YYERROR_VERBOSE */
 
1108
        ag_yyerror ("parse error");
 
1109
    }
 
1110
  goto ag_yyerrlab1;
 
1111
 
 
1112
 
 
1113
/*--------------------------------------------------.
 
1114
| ag_yyerrlab1 -- error raised explicitly by an action |
 
1115
`--------------------------------------------------*/
 
1116
ag_yyerrlab1:
 
1117
  if (ag_yyerrstatus == 3)
 
1118
    {
 
1119
      /* If just tried and failed to reuse lookahead token after an
 
1120
         error, discard it.  */
 
1121
 
 
1122
      /* return failure if at end of input */
 
1123
      if (ag_yychar == YYEOF)
 
1124
        YYABORT;
 
1125
      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
 
1126
                  ag_yychar, ag_yytname[ag_yychar1]));
 
1127
      ag_yychar = YYEMPTY;
 
1128
    }
 
1129
 
 
1130
  /* Else will try to reuse lookahead token after shifting the error
 
1131
     token.  */
 
1132
 
 
1133
  ag_yyerrstatus = 3;           /* Each real token shifted decrements this */
 
1134
 
 
1135
  goto ag_yyerrhandle;
 
1136
 
 
1137
 
 
1138
/*-------------------------------------------------------------------.
 
1139
| ag_yyerrdefault -- current state does not do anything special for the |
 
1140
| error token.                                                       |
 
1141
`-------------------------------------------------------------------*/
 
1142
ag_yyerrdefault:
 
1143
#if 0
 
1144
  /* This is wrong; only states that explicitly want error tokens
 
1145
     should shift them.  */
 
1146
 
 
1147
  /* If its default is to accept any token, ok.  Otherwise pop it.  */
 
1148
  ag_yyn = ag_yydefact[ag_yystate];
 
1149
  if (ag_yyn)
 
1150
    goto ag_yydefault;
 
1151
#endif
 
1152
 
 
1153
 
 
1154
/*---------------------------------------------------------------.
 
1155
| ag_yyerrpop -- pop the current state because it cannot handle the |
 
1156
| error token                                                    |
 
1157
`---------------------------------------------------------------*/
 
1158
ag_yyerrpop:
 
1159
  if (ag_yyssp == ag_yyss)
 
1160
    YYABORT;
 
1161
  ag_yyvsp--;
 
1162
  ag_yystate = *--ag_yyssp;
 
1163
#if YYLSP_NEEDED
 
1164
  ag_yylsp--;
 
1165
#endif
 
1166
 
 
1167
#if YYDEBUG
 
1168
  if (ag_yydebug)
 
1169
    {
 
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");
 
1175
    }
 
1176
#endif
 
1177
 
 
1178
/*--------------.
 
1179
| ag_yyerrhandle.  |
 
1180
`--------------*/
 
1181
ag_yyerrhandle:
 
1182
  ag_yyn = ag_yypact[ag_yystate];
 
1183
  if (ag_yyn == YYFLAG)
 
1184
    goto ag_yyerrdefault;
 
1185
 
 
1186
  ag_yyn += YYTERROR;
 
1187
  if (ag_yyn < 0 || ag_yyn > YYLAST || ag_yycheck[ag_yyn] != YYTERROR)
 
1188
    goto ag_yyerrdefault;
 
1189
 
 
1190
  ag_yyn = ag_yytable[ag_yyn];
 
1191
  if (ag_yyn < 0)
 
1192
    {
 
1193
      if (ag_yyn == YYFLAG)
 
1194
        goto ag_yyerrpop;
 
1195
      ag_yyn = -ag_yyn;
 
1196
      goto ag_yyreduce;
 
1197
    }
 
1198
  else if (ag_yyn == 0)
 
1199
    goto ag_yyerrpop;
 
1200
 
 
1201
  if (ag_yyn == YYFINAL)
 
1202
    YYACCEPT;
 
1203
 
 
1204
  YYDPRINTF ((stderr, "Shifting error token, "));
 
1205
 
 
1206
  *++ag_yyvsp = ag_yylval;
 
1207
#if YYLSP_NEEDED
 
1208
  *++ag_yylsp = ag_yylloc;
 
1209
#endif
 
1210
 
 
1211
  ag_yystate = ag_yyn;
 
1212
  goto ag_yynewstate;
 
1213
 
 
1214
 
 
1215
/*-------------------------------------.
 
1216
| ag_yyacceptlab -- YYACCEPT comes here.  |
 
1217
`-------------------------------------*/
 
1218
ag_yyacceptlab:
 
1219
  if (ag_yyfree_stacks)
 
1220
    {
 
1221
      free (ag_yyss);
 
1222
      free (ag_yyvs);
 
1223
#if YYLSP_NEEDED
 
1224
      free (ag_yyls);
 
1225
#endif
 
1226
    }
 
1227
  return 0;
 
1228
 
 
1229
 
 
1230
/*-----------------------------------.
 
1231
| ag_yyabortlab -- YYABORT comes here.  |
 
1232
`-----------------------------------*/
 
1233
ag_yyabortlab:
 
1234
  if (ag_yyfree_stacks)
 
1235
    {
 
1236
      free (ag_yyss);
 
1237
      free (ag_yyvs);
 
1238
#if YYLSP_NEEDED
 
1239
      free (ag_yyls);
 
1240
#endif
 
1241
    }
 
1242
  return 1;
 
1243
}
 
1244
#line 170 "grammar.y"
 
1245
 
 
1246
 
 
1247
#define NILitem  NIL(item*)
 
1248
 
 
1249
/* globals */
 
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;
 
1253
 
 
1254
static item *newitem(int tag, void *p0, char *p1)
 
1255
{
 
1256
        item    *rv = agalloc(G,sizeof(item));
 
1257
        rv->tag = tag; rv->u.name = (char*)p0; rv->str = p1;
 
1258
        return rv;
 
1259
}
 
1260
 
 
1261
static item *cons_node(Agnode_t *n, char *port)
 
1262
        { return newitem(T_node,n,port); }
 
1263
 
 
1264
static item *cons_attr(char *name, char *value)
 
1265
        { return newitem(T_atom,name,value); }
 
1266
 
 
1267
static item *cons_list(item *list)
 
1268
        { return newitem(T_list,list,NIL(char*)); }
 
1269
 
 
1270
static item *cons_subg(Agraph_t *subg)
 
1271
        { return newitem(T_subgraph,subg,NIL(char*)); }
 
1272
 
 
1273
#ifdef NOTDEF
 
1274
static item *cons_edge(Agedge_t *e)
 
1275
        { return newitem(T_edge,e,NIL(char*)); }
 
1276
#endif
 
1277
 
 
1278
static void delete_items(item *ilist)
 
1279
{
 
1280
        item    *p,*pn;
 
1281
 
 
1282
        for (p = ilist; p; p = pn) {
 
1283
                pn = p->next;
 
1284
                switch(p->tag) {
 
1285
                        case T_list: delete_items(p->u.list); break;
 
1286
                        case T_atom: case T_attr: agstrfree(G,p->str); break;
 
1287
                }
 
1288
                agfree(G,p);
 
1289
        }
 
1290
}
 
1291
 
 
1292
static void deletelist(list_t *list)
 
1293
{
 
1294
        delete_items(list->first);
 
1295
        list->first = list->last = NILitem;
 
1296
}
 
1297
 
 
1298
#ifdef NOTDEF
 
1299
static void listins(list_t *list, item *v)
 
1300
{
 
1301
        v->next = list->first;
 
1302
        list->first = v;
 
1303
        if (list->last == NILitem) list->last = v;
 
1304
}
 
1305
#endif
 
1306
 
 
1307
static void listapp(list_t *list, item *v)
 
1308
{
 
1309
        if (list->last) list->last->next = v;
 
1310
        list->last = v;
 
1311
        if (list->first == NILitem) list->first = v;
 
1312
}
 
1313
 
 
1314
 
 
1315
/* attrs */
 
1316
static void appendattr(char *name, char *value)
 
1317
{
 
1318
        item            *v;
 
1319
 
 
1320
        assert(value != NIL(char*));
 
1321
        v = cons_attr(name,value);
 
1322
        listapp(&Attrlist,v);
 
1323
}
 
1324
 
 
1325
static void bindattrs(int kind)
 
1326
{
 
1327
        item            *aptr;
 
1328
        char            *name;
 
1329
 
 
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 */
 
1337
                agstrfree(G,name);
 
1338
        }
 
1339
}
 
1340
 
 
1341
static void applyattrs(void *obj)
 
1342
{
 
1343
        item            *aptr;
 
1344
 
 
1345
        for (aptr = Attrlist.first; aptr; aptr = aptr->next) {
 
1346
                if (aptr->tag == T_attr) {
 
1347
                        if (aptr->u.asym) {
 
1348
                                agxset(obj,aptr->u.asym,aptr->str);
 
1349
                        }
 
1350
                }
 
1351
                else {
 
1352
                        assert(AGTYPE(obj) == AGEDGE);
 
1353
                        assert(aptr->tag == T_atom);
 
1354
                        assert(streq(aptr->u.name,Key));
 
1355
                }
 
1356
        }
 
1357
}
 
1358
 
 
1359
static void nomacros(void)
 
1360
{
 
1361
        agerror(AGERROR_UNIMPL,"attribute macros");
 
1362
}
 
1363
 
 
1364
static void attrstmt(int tkind, char *macroname)
 
1365
{
 
1366
        item                    *aptr;
 
1367
        int                             kind;
 
1368
 
 
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();
 
1374
 
 
1375
        switch(tkind) {
 
1376
                case T_graph: kind = AGRAPH; break;
 
1377
                case T_node: kind = AGNODE; break;
 
1378
                case T_edge: kind = AGEDGE; break;
 
1379
                default : abort();
 
1380
        }
 
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);
 
1385
}
 
1386
 
 
1387
/* nodes */
 
1388
 
 
1389
static void appendnode(char *name, char *port)
 
1390
{
 
1391
        item            *elt;
 
1392
 
 
1393
        elt = cons_node(agnode(G,name,TRUE),port);
 
1394
        listapp(&Nodelist,elt);
 
1395
        agstrfree(G,name);
 
1396
}
 
1397
 
 
1398
        /* apply current optional attrs to Nodelist and clean up lists */
 
1399
static void endnode()
 
1400
{
 
1401
        item    *ptr;
 
1402
 
 
1403
        bindattrs(AGNODE);
 
1404
        for (ptr = Nodelist.first; ptr; ptr = ptr->next)
 
1405
                applyattrs(ptr->u.n);
 
1406
        deletelist(&Nodelist);
 
1407
        deletelist(&Attrlist);
 
1408
}
 
1409
 
 
1410
/* edges - store up node/subg lists until optional edge key can be seen */
 
1411
 
 
1412
static void bufferedges()
 
1413
{
 
1414
        item    *v;
 
1415
 
 
1416
        if (Nodelist.first) {
 
1417
                v = cons_list(Nodelist.first);
 
1418
                Nodelist.first = Nodelist.last = NILitem;
 
1419
        }
 
1420
        else {v = cons_subg(Subgraph); Subgraph = NIL(Agraph_t*);}
 
1421
        listapp(&Edgelist,v);
 
1422
}
 
1423
 
 
1424
static void endedge(void)
 
1425
{
 
1426
        char                    *key;
 
1427
        item                    *aptr,*tptr,*p;
 
1428
 
 
1429
        Agnode_t                *t;
 
1430
        Agraph_t                *subg;
 
1431
 
 
1432
        bufferedges();  /* pick up the terminal nodelist or subg */
 
1433
        bindattrs(AGEDGE);
 
1434
 
 
1435
        /* look for "key" pseudo-attribute */
 
1436
        key = NIL(char*);
 
1437
        for (aptr = Attrlist.first; aptr; aptr = aptr->next) {
 
1438
                if ((aptr->tag == T_atom) && streq(aptr->u.name,Key))
 
1439
                        key = aptr->str;
 
1440
        }
 
1441
 
 
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) {
 
1445
                        subg = p->u.subg;
 
1446
                        for (t = agfstnode(subg); t; t = agnxtnode(t))
 
1447
                                edgerhs(agsubnode(G,t,FALSE),NIL(char*),p->next,key);
 
1448
                }
 
1449
                else {
 
1450
                        for (tptr = p->u.list; tptr; tptr = tptr->next)
 
1451
                                edgerhs(tptr->u.n,tptr->str,p->next,key);
 
1452
                }
 
1453
        }
 
1454
        deletelist(&Edgelist);
 
1455
        deletelist(&Attrlist);
 
1456
}
 
1457
 
 
1458
static void edgerhs(Agnode_t *tail, char *tport, item *hlist, char *key)
 
1459
{
 
1460
        Agnode_t                *head;
 
1461
        Agraph_t                *subg;
 
1462
        item                    *hptr;
 
1463
 
 
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);
 
1468
        }
 
1469
        else {
 
1470
                for (hptr = hlist->u.list; hptr; hptr = hptr->next)
 
1471
                        newedge(tail,tport,agsubnode(G,hptr->u.n,FALSE),hptr->str,key);
 
1472
        }
 
1473
}
 
1474
 
 
1475
static void mkport(Agedge_t *e, char *name, char *val)
 
1476
{
 
1477
        Agsym_t *attr;
 
1478
        if (val) {
 
1479
                if ((attr = agattr(G,AGEDGE,name,NIL(char*))) == NILsym)
 
1480
                        attr = agattr(G,AGEDGE,name,"");
 
1481
                agxset(e,attr,val);
 
1482
        }
 
1483
}
 
1484
 
 
1485
static void newedge(Agnode_t *t, char *tport, Agnode_t *h, char *hport, char *key)
 
1486
{
 
1487
        Agedge_t        *e;
 
1488
 
 
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);
 
1493
                applyattrs(e);
 
1494
        }
 
1495
}
 
1496
 
 
1497
/* graphs and subgraphs */
 
1498
 
 
1499
 
 
1500
static void startgraph(char *name, int directed, int strict)
 
1501
{
 
1502
        static Agdesc_t req;    /* get rid of warnings */
 
1503
 
 
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);
 
1510
        }
 
1511
        else {
 
1512
                Ag_G_global = G;
 
1513
        }
 
1514
        agstrfree(NIL(Agraph_t*),name);
 
1515
}
 
1516
 
 
1517
static void endgraph()
 
1518
{
 
1519
        aglexeof();
 
1520
        aginternalmapclearlocalnames(G);
 
1521
}
 
1522
 
 
1523
static void opensubg(char *name)
 
1524
{
 
1525
        G = agsubg(G,name,TRUE);
 
1526
        agstrfree(G,name);
 
1527
}
 
1528
 
 
1529
static void closesubg()
 
1530
{
 
1531
        Subgraph = G;
 
1532
        if ((G = agparent(G)) == NIL(Agraph_t*))
 
1533
                ag_yyerror("libgraph: parser lost root graph\n");
 
1534
}
 
1535
 
 
1536
extern void *ag_yyin;
 
1537
Agraph_t *agconcat(Agraph_t *g, void *chan, Agdisc_t *disc)
 
1538
{
 
1539
        ag_yyin = chan;
 
1540
        G = g;
 
1541
        Ag_G_global = NILgraph;
 
1542
        Disc = (disc? disc :  &AgDefaultDisc);
 
1543
        aglexinit(Disc, chan);
 
1544
        ag_yyparse();
 
1545
        return Ag_G_global;
 
1546
}
 
1547
 
 
1548
Agraph_t *agread(void *fp, Agdisc_t *disc) {return agconcat(NILgraph,fp,disc); }