grammar.c 66 KB

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