gmlparse.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715
  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 GMLSTYPE
  50. /* Substitute the variable and function names. */
  51. #define yyparse gmlparse
  52. #define yylex gmllex
  53. #define yyerror gmlerror
  54. #define yydebug gmldebug
  55. #define yynerrs gmlnerrs
  56. #define yylval gmllval
  57. #define yychar gmlchar
  58. /* First part of user prologue. */
  59. #line 19 "../../cmd/tools/gmlparse.y"
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include <arith.h>
  63. #include <gml2gv.h>
  64. #include <assert.h>
  65. #include <cgraph/list.h>
  66. #include <util/agxbuf.h>
  67. #include <util/alloc.h>
  68. #include <util/exit.h>
  69. static gmlgraph* G;
  70. static gmlnode* N;
  71. static gmledge* E;
  72. static Dt_t* L;
  73. DEFINE_LIST(dts, Dt_t *)
  74. static dts_t liststk;
  75. static void free_attr(void *attr);
  76. static char *sortToStr(unsigned short sort);
  77. static void free_node(void *node) {
  78. gmlnode *p = node;
  79. if (!p) return;
  80. if (p->attrlist) dtclose (p->attrlist);
  81. free (p);
  82. }
  83. static void free_edge(void *edge) {
  84. gmledge *p = edge;
  85. if (!p) return;
  86. if (p->attrlist) dtclose (p->attrlist);
  87. free (p);
  88. }
  89. static void free_graph(void *graph) {
  90. gmlgraph *p = graph;
  91. if (!p) return;
  92. if (p->nodelist)
  93. dtclose (p->nodelist);
  94. if (p->edgelist)
  95. dtclose (p->edgelist);
  96. if (p->attrlist)
  97. dtclose (p->attrlist);
  98. if (p->graphlist)
  99. dtclose (p->graphlist);
  100. free (p);
  101. }
  102. static Dtdisc_t nodeDisc = {
  103. .key = offsetof(gmlnode, attrlist),
  104. .size = sizeof(Dt_t *),
  105. .link = offsetof(gmlnode, link),
  106. .freef = free_node,
  107. };
  108. static Dtdisc_t edgeDisc = {
  109. .key = offsetof(gmledge, attrlist),
  110. .size = sizeof(Dt_t *),
  111. .link = offsetof(gmledge, link),
  112. .freef = free_edge,
  113. };
  114. static Dtdisc_t attrDisc = {
  115. .key = offsetof(gmlattr, name),
  116. .size = sizeof(char *),
  117. .link = offsetof(gmlattr, link),
  118. .freef = free_attr,
  119. };
  120. static Dtdisc_t graphDisc = {
  121. .key = offsetof(gmlgraph, nodelist),
  122. .size = sizeof(Dt_t *),
  123. .link = offsetof(gmlgraph, link),
  124. .freef = free_graph,
  125. };
  126. static void
  127. cleanup (void)
  128. {
  129. while (!dts_is_empty(&liststk)) {
  130. Dt_t *dt = dts_pop_back(&liststk);
  131. dtclose(dt);
  132. }
  133. dts_free(&liststk);
  134. if (L) {
  135. dtclose (L);
  136. L = NULL;
  137. }
  138. if (N) {
  139. free_node(N);
  140. N = NULL;
  141. }
  142. if (E) {
  143. free_edge(E);
  144. E = NULL;
  145. }
  146. if (G) {
  147. free_graph(G);
  148. G = NULL;
  149. }
  150. }
  151. static void
  152. pushAlist (void)
  153. {
  154. Dt_t* lp = dtopen (&attrDisc, Dtqueue);
  155. if (L) {
  156. dts_push_back(&liststk, L);
  157. }
  158. L = lp;
  159. }
  160. static Dt_t*
  161. popAlist (void)
  162. {
  163. Dt_t* lp = L;
  164. if (!dts_is_empty(&liststk))
  165. L = dts_pop_back(&liststk);
  166. else
  167. L = NULL;
  168. return lp;
  169. }
  170. static void
  171. popG (void)
  172. {
  173. G = G->parent;
  174. }
  175. static void
  176. pushG (void)
  177. {
  178. gmlgraph* g = gv_alloc(sizeof(gmlgraph));
  179. g->attrlist = dtopen(&attrDisc, Dtqueue);
  180. g->nodelist = dtopen(&nodeDisc, Dtqueue);
  181. g->edgelist = dtopen(&edgeDisc, Dtqueue);
  182. g->graphlist = dtopen(&graphDisc, Dtqueue);
  183. g->parent = G;
  184. g->directed = -1;
  185. if (G)
  186. dtinsert (G->graphlist, g);
  187. G = g;
  188. }
  189. static gmlnode*
  190. mkNode (void)
  191. {
  192. gmlnode* np = gv_alloc(sizeof(gmlnode));
  193. np->attrlist = dtopen (&attrDisc, Dtqueue);
  194. np->id = NULL;
  195. return np;
  196. }
  197. static gmledge*
  198. mkEdge (void)
  199. {
  200. gmledge* ep = gv_alloc(sizeof(gmledge));
  201. ep->attrlist = dtopen (&attrDisc, Dtqueue);
  202. ep->source = NULL;
  203. ep->target = NULL;
  204. return ep;
  205. }
  206. static gmlattr *mkAttr(char* name, unsigned short sort, unsigned short kind,
  207. char* str, Dt_t* list) {
  208. gmlattr* gp = gv_alloc(sizeof(gmlattr));
  209. assert (name || sort);
  210. if (!name)
  211. name = gv_strdup (sortToStr (sort));
  212. gp->sort = sort;
  213. gp->kind = kind;
  214. gp->name = name;
  215. if (str)
  216. gp->u.value = str;
  217. else {
  218. if (dtsize (list) == 0) {
  219. dtclose (list);
  220. list = 0;
  221. }
  222. gp->u.lp = list;
  223. }
  224. /* fprintf (stderr, "[%x] %hu %hu \"%s\" \"%s\" \n", gp, sort, kind, (name?name:""), (str?str:"")); */
  225. return gp;
  226. }
  227. static int
  228. setDir (char* d)
  229. {
  230. gmlgraph* g;
  231. int dir = atoi (d);
  232. free (d);
  233. if (dir < 0) dir = -1;
  234. else if (dir > 0) dir = 1;
  235. else dir = 0;
  236. G->directed = dir;
  237. if (dir >= 0) {
  238. for (g = G->parent; g; g = g->parent) {
  239. if (g->directed < 0)
  240. g->directed = dir;
  241. else if (g->directed != dir)
  242. return 1;
  243. }
  244. }
  245. return 0;
  246. }
  247. #line 297 "gmlparse.c"
  248. # ifndef YY_CAST
  249. # ifdef __cplusplus
  250. # define YY_CAST(Type, Val) static_cast<Type> (Val)
  251. # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
  252. # else
  253. # define YY_CAST(Type, Val) ((Type) (Val))
  254. # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
  255. # endif
  256. # endif
  257. # ifndef YY_NULLPTR
  258. # if defined __cplusplus
  259. # if 201103L <= __cplusplus
  260. # define YY_NULLPTR nullptr
  261. # else
  262. # define YY_NULLPTR 0
  263. # endif
  264. # else
  265. # define YY_NULLPTR ((void*)0)
  266. # endif
  267. # endif
  268. /* Enabling verbose error messages. */
  269. #ifdef YYERROR_VERBOSE
  270. # undef YYERROR_VERBOSE
  271. # define YYERROR_VERBOSE 1
  272. #else
  273. # define YYERROR_VERBOSE 0
  274. #endif
  275. /* Use api.header.include to #include this header
  276. instead of duplicating it here. */
  277. #ifndef YY_GML_GMLPARSE_H_INCLUDED
  278. # define YY_GML_GMLPARSE_H_INCLUDED
  279. /* Debug traces. */
  280. #ifndef GMLDEBUG
  281. # if defined YYDEBUG
  282. #if YYDEBUG
  283. # define GMLDEBUG 1
  284. # else
  285. # define GMLDEBUG 0
  286. # endif
  287. # else /* ! defined YYDEBUG */
  288. # define GMLDEBUG 0
  289. # endif /* ! defined YYDEBUG */
  290. #endif /* ! defined GMLDEBUG */
  291. #if GMLDEBUG
  292. extern int gmldebug;
  293. #endif
  294. /* Token type. */
  295. #ifndef GMLTOKENTYPE
  296. # define GMLTOKENTYPE
  297. enum gmltokentype
  298. {
  299. GRAPH = 258,
  300. NODE = 259,
  301. EDGE = 260,
  302. DIRECTED = 261,
  303. SOURCE = 262,
  304. TARGET = 263,
  305. XVAL = 264,
  306. YVAL = 265,
  307. WVAL = 266,
  308. HVAL = 267,
  309. LABEL = 268,
  310. GRAPHICS = 269,
  311. LABELGRAPHICS = 270,
  312. TYPE = 271,
  313. FILL = 272,
  314. OUTLINE = 273,
  315. OUTLINESTYLE = 274,
  316. OUTLINEWIDTH = 275,
  317. WIDTH = 276,
  318. STYLE = 277,
  319. LINE = 278,
  320. POINT = 279,
  321. TEXT = 280,
  322. FONTSIZE = 281,
  323. FONTNAME = 282,
  324. COLOR = 283,
  325. INTEGER = 284,
  326. REAL = 285,
  327. STRING = 286,
  328. ID = 287,
  329. NAME = 288,
  330. LIST = 289
  331. };
  332. #endif
  333. /* Tokens. */
  334. #define GRAPH 258
  335. #define NODE 259
  336. #define EDGE 260
  337. #define DIRECTED 261
  338. #define SOURCE 262
  339. #define TARGET 263
  340. #define XVAL 264
  341. #define YVAL 265
  342. #define WVAL 266
  343. #define HVAL 267
  344. #define LABEL 268
  345. #define GRAPHICS 269
  346. #define LABELGRAPHICS 270
  347. #define TYPE 271
  348. #define FILL 272
  349. #define OUTLINE 273
  350. #define OUTLINESTYLE 274
  351. #define OUTLINEWIDTH 275
  352. #define WIDTH 276
  353. #define STYLE 277
  354. #define LINE 278
  355. #define POINT 279
  356. #define TEXT 280
  357. #define FONTSIZE 281
  358. #define FONTNAME 282
  359. #define COLOR 283
  360. #define INTEGER 284
  361. #define REAL 285
  362. #define STRING 286
  363. #define ID 287
  364. #define NAME 288
  365. #define LIST 289
  366. /* Value type. */
  367. #if ! defined GMLSTYPE && ! defined GMLSTYPE_IS_DECLARED
  368. union GMLSTYPE
  369. {
  370. #line 237 "../../cmd/tools/gmlparse.y"
  371. int i;
  372. char *str;
  373. gmlnode* np;
  374. gmledge* ep;
  375. gmlattr* ap;
  376. Dt_t* list;
  377. #line 434 "gmlparse.c"
  378. };
  379. typedef union GMLSTYPE GMLSTYPE;
  380. # define GMLSTYPE_IS_TRIVIAL 1
  381. # define GMLSTYPE_IS_DECLARED 1
  382. #endif
  383. extern GMLSTYPE gmllval;
  384. int gmlparse (void);
  385. #endif /* !YY_GML_GMLPARSE_H_INCLUDED */
  386. #ifdef short
  387. # undef short
  388. #endif
  389. /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
  390. <limits.h> and (if available) <stdint.h> are included
  391. so that the code can choose integer types of a good width. */
  392. #ifndef __PTRDIFF_MAX__
  393. # include <limits.h> /* INFRINGES ON USER NAME SPACE */
  394. # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
  395. # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
  396. # define YY_STDINT_H
  397. # endif
  398. #endif
  399. /* Narrow types that promote to a signed type and that can represent a
  400. signed or unsigned integer of at least N bits. In tables they can
  401. save space and decrease cache pressure. Promoting to a signed type
  402. helps avoid bugs in integer arithmetic. */
  403. #ifdef __INT_LEAST8_MAX__
  404. typedef __INT_LEAST8_TYPE__ yytype_int8;
  405. #elif defined YY_STDINT_H
  406. typedef int_least8_t yytype_int8;
  407. #else
  408. typedef signed char yytype_int8;
  409. #endif
  410. #ifdef __INT_LEAST16_MAX__
  411. typedef __INT_LEAST16_TYPE__ yytype_int16;
  412. #elif defined YY_STDINT_H
  413. typedef int_least16_t yytype_int16;
  414. #else
  415. typedef short yytype_int16;
  416. #endif
  417. #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
  418. typedef __UINT_LEAST8_TYPE__ yytype_uint8;
  419. #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
  420. && UINT_LEAST8_MAX <= INT_MAX)
  421. typedef uint_least8_t yytype_uint8;
  422. #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
  423. typedef unsigned char yytype_uint8;
  424. #else
  425. typedef short yytype_uint8;
  426. #endif
  427. #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
  428. typedef __UINT_LEAST16_TYPE__ yytype_uint16;
  429. #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
  430. && UINT_LEAST16_MAX <= INT_MAX)
  431. typedef uint_least16_t yytype_uint16;
  432. #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
  433. typedef unsigned short yytype_uint16;
  434. #else
  435. typedef int yytype_uint16;
  436. #endif
  437. #ifndef YYPTRDIFF_T
  438. # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
  439. # define YYPTRDIFF_T __PTRDIFF_TYPE__
  440. # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
  441. # elif defined PTRDIFF_MAX
  442. # ifndef ptrdiff_t
  443. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  444. # endif
  445. # define YYPTRDIFF_T ptrdiff_t
  446. # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
  447. # else
  448. # define YYPTRDIFF_T long
  449. # define YYPTRDIFF_MAXIMUM LONG_MAX
  450. # endif
  451. #endif
  452. #ifndef YYSIZE_T
  453. # ifdef __SIZE_TYPE__
  454. # define YYSIZE_T __SIZE_TYPE__
  455. # elif defined size_t
  456. # define YYSIZE_T size_t
  457. # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
  458. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  459. # define YYSIZE_T size_t
  460. # else
  461. # define YYSIZE_T unsigned
  462. # endif
  463. #endif
  464. #define YYSIZE_MAXIMUM \
  465. YY_CAST (YYPTRDIFF_T, \
  466. (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
  467. ? YYPTRDIFF_MAXIMUM \
  468. : YY_CAST (YYSIZE_T, -1)))
  469. #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
  470. /* Stored state numbers (used for stacks). */
  471. typedef yytype_int8 yy_state_t;
  472. /* State numbers in computations. */
  473. typedef int yy_state_fast_t;
  474. #ifndef YY_
  475. # if defined YYENABLE_NLS && YYENABLE_NLS
  476. # if ENABLE_NLS
  477. # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  478. # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
  479. # endif
  480. # endif
  481. # ifndef YY_
  482. # define YY_(Msgid) Msgid
  483. # endif
  484. #endif
  485. #ifndef YY_ATTRIBUTE_PURE
  486. # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
  487. # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
  488. # else
  489. # define YY_ATTRIBUTE_PURE
  490. # endif
  491. #endif
  492. #ifndef YY_ATTRIBUTE_UNUSED
  493. # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
  494. # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
  495. # else
  496. # define YY_ATTRIBUTE_UNUSED
  497. # endif
  498. #endif
  499. /* Suppress unused-variable warnings by "using" E. */
  500. #if ! defined lint || defined __GNUC__
  501. # define YYUSE(E) ((void) (E))
  502. #else
  503. # define YYUSE(E) /* empty */
  504. #endif
  505. #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
  506. /* Suppress an incorrect diagnostic about yylval being uninitialized. */
  507. # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
  508. _Pragma ("GCC diagnostic push") \
  509. _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
  510. _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
  511. # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
  512. _Pragma ("GCC diagnostic pop")
  513. #else
  514. # define YY_INITIAL_VALUE(Value) Value
  515. #endif
  516. #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  517. # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  518. # define YY_IGNORE_MAYBE_UNINITIALIZED_END
  519. #endif
  520. #ifndef YY_INITIAL_VALUE
  521. # define YY_INITIAL_VALUE(Value) /* Nothing. */
  522. #endif
  523. #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
  524. # define YY_IGNORE_USELESS_CAST_BEGIN \
  525. _Pragma ("GCC diagnostic push") \
  526. _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
  527. # define YY_IGNORE_USELESS_CAST_END \
  528. _Pragma ("GCC diagnostic pop")
  529. #endif
  530. #ifndef YY_IGNORE_USELESS_CAST_BEGIN
  531. # define YY_IGNORE_USELESS_CAST_BEGIN
  532. # define YY_IGNORE_USELESS_CAST_END
  533. #endif
  534. #define YY_ASSERT(E) ((void) (0 && (E)))
  535. #if ! defined yyoverflow || YYERROR_VERBOSE
  536. /* The parser invokes alloca or malloc; define the necessary symbols. */
  537. # ifdef YYSTACK_USE_ALLOCA
  538. # if YYSTACK_USE_ALLOCA
  539. # ifdef __GNUC__
  540. # define YYSTACK_ALLOC __builtin_alloca
  541. # elif defined __BUILTIN_VA_ARG_INCR
  542. # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  543. # elif defined _AIX
  544. # define YYSTACK_ALLOC __alloca
  545. # elif defined _MSC_VER
  546. # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  547. # define alloca _alloca
  548. # else
  549. # define YYSTACK_ALLOC alloca
  550. # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
  551. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  552. /* Use EXIT_SUCCESS as a witness for stdlib.h. */
  553. # ifndef EXIT_SUCCESS
  554. # define EXIT_SUCCESS 0
  555. # endif
  556. # endif
  557. # endif
  558. # endif
  559. # endif
  560. # ifdef YYSTACK_ALLOC
  561. /* Pacify GCC's 'empty if-body' warning. */
  562. # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
  563. # ifndef YYSTACK_ALLOC_MAXIMUM
  564. /* The OS might guarantee only one guard page at the bottom of the stack,
  565. and a page size can be as small as 4096 bytes. So we cannot safely
  566. invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
  567. to allow for a few compiler-allocated temporary stack slots. */
  568. # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  569. # endif
  570. # else
  571. # define YYSTACK_ALLOC YYMALLOC
  572. # define YYSTACK_FREE YYFREE
  573. # ifndef YYSTACK_ALLOC_MAXIMUM
  574. # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  575. # endif
  576. # if (defined __cplusplus && ! defined EXIT_SUCCESS \
  577. && ! ((defined YYMALLOC || defined malloc) \
  578. && (defined YYFREE || defined free)))
  579. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  580. # ifndef EXIT_SUCCESS
  581. # define EXIT_SUCCESS 0
  582. # endif
  583. # endif
  584. # ifndef YYMALLOC
  585. # define YYMALLOC malloc
  586. # if ! defined malloc && ! defined EXIT_SUCCESS
  587. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  588. # endif
  589. # endif
  590. # ifndef YYFREE
  591. # define YYFREE free
  592. # if ! defined free && ! defined EXIT_SUCCESS
  593. void free (void *); /* INFRINGES ON USER NAME SPACE */
  594. # endif
  595. # endif
  596. # endif
  597. #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  598. #if (! defined yyoverflow \
  599. && (! defined __cplusplus \
  600. || (defined GMLSTYPE_IS_TRIVIAL && GMLSTYPE_IS_TRIVIAL)))
  601. /* A type that is properly aligned for any stack member. */
  602. union yyalloc
  603. {
  604. yy_state_t yyss_alloc;
  605. YYSTYPE yyvs_alloc;
  606. };
  607. /* The size of the maximum gap between one aligned stack and the next. */
  608. # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
  609. /* The size of an array large to enough to hold all stacks, each with
  610. N elements. */
  611. # define YYSTACK_BYTES(N) \
  612. ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
  613. + YYSTACK_GAP_MAXIMUM)
  614. # define YYCOPY_NEEDED 1
  615. /* Relocate STACK from its old location to the new one. The
  616. local variables YYSIZE and YYSTACKSIZE give the old and new number of
  617. elements in the stack, and YYPTR gives the new location of the
  618. stack. Advance YYPTR to a properly aligned location for the next
  619. stack. */
  620. # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
  621. do \
  622. { \
  623. YYPTRDIFF_T yynewbytes; \
  624. YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
  625. Stack = &yyptr->Stack_alloc; \
  626. yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
  627. yyptr += yynewbytes / YYSIZEOF (*yyptr); \
  628. } \
  629. while (0)
  630. #endif
  631. #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
  632. /* Copy COUNT objects from SRC to DST. The source and destination do
  633. not overlap. */
  634. # ifndef YYCOPY
  635. # if defined __GNUC__ && 1 < __GNUC__
  636. # define YYCOPY(Dst, Src, Count) \
  637. __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
  638. # else
  639. # define YYCOPY(Dst, Src, Count) \
  640. do \
  641. { \
  642. YYPTRDIFF_T yyi; \
  643. for (yyi = 0; yyi < (Count); yyi++) \
  644. (Dst)[yyi] = (Src)[yyi]; \
  645. } \
  646. while (0)
  647. # endif
  648. # endif
  649. #endif /* !YYCOPY_NEEDED */
  650. /* YYFINAL -- State number of the termination state. */
  651. #define YYFINAL 55
  652. /* YYLAST -- Last index in YYTABLE. */
  653. #define YYLAST 226
  654. /* YYNTOKENS -- Number of terminals. */
  655. #define YYNTOKENS 37
  656. /* YYNNTS -- Number of nonterminals. */
  657. #define YYNNTS 20
  658. /* YYNRULES -- Number of rules. */
  659. #define YYNRULES 63
  660. /* YYNSTATES -- Number of states. */
  661. #define YYNSTATES 102
  662. #define YYUNDEFTOK 2
  663. #define YYMAXUTOK 289
  664. /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
  665. as returned by yylex, with out-of-bounds checking. */
  666. #define YYTRANSLATE(YYX) \
  667. (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  668. /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
  669. as returned by yylex. */
  670. static const yytype_int8 yytranslate[] =
  671. {
  672. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  673. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  674. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  675. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  676. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  677. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  678. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  679. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  680. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  681. 2, 35, 2, 36, 2, 2, 2, 2, 2, 2,
  682. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  683. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  684. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  685. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  686. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  687. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  688. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  689. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  690. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  691. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  692. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  693. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  694. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  695. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  696. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  697. 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  698. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  699. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  700. 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
  701. };
  702. #if GMLDEBUG
  703. /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
  704. static const yytype_int16 yyrline[] =
  705. {
  706. 0, 260, 260, 261, 262, 265, 268, 271, 272, 275,
  707. 276, 279, 280, 281, 282, 289, 290, 293, 293, 296,
  708. 297, 300, 301, 304, 304, 307, 308, 311, 312, 313,
  709. 314, 317, 317, 320, 321, 324, 325, 328, 329, 330,
  710. 331, 332, 333, 334, 335, 336, 337, 338, 339, 340,
  711. 341, 342, 343, 344, 345, 346, 347, 348, 349, 350,
  712. 351, 352, 353, 354
  713. };
  714. #endif
  715. #if GMLDEBUG || YYERROR_VERBOSE || 0
  716. /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  717. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  718. static const char *const yytname[] =
  719. {
  720. "$end", "error", "$undefined", "GRAPH", "NODE", "EDGE", "DIRECTED",
  721. "SOURCE", "TARGET", "XVAL", "YVAL", "WVAL", "HVAL", "LABEL", "GRAPHICS",
  722. "LABELGRAPHICS", "TYPE", "FILL", "OUTLINE", "OUTLINESTYLE",
  723. "OUTLINEWIDTH", "WIDTH", "STYLE", "LINE", "POINT", "TEXT", "FONTSIZE",
  724. "FONTNAME", "COLOR", "INTEGER", "REAL", "STRING", "ID", "NAME", "LIST",
  725. "'['", "']'", "$accept", "graph", "hdr", "body", "optglist", "glist",
  726. "glistitem", "node", "$@1", "nlist", "nlistitem", "edge", "$@2", "elist",
  727. "elistitem", "attrlist", "$@3", "optalist", "alist", "alistitem", YY_NULLPTR
  728. };
  729. #endif
  730. # ifdef YYPRINT
  731. /* YYTOKNUM[NUM] -- (External) token number corresponding to the
  732. (internal) symbol number NUM (which must be that of a token). */
  733. static const yytype_int16 yytoknum[] =
  734. {
  735. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  736. 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  737. 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
  738. 285, 286, 287, 288, 289, 91, 93
  739. };
  740. # endif
  741. #define YYPACT_NINF (-29)
  742. #define yypact_value_is_default(Yyn) \
  743. ((Yyn) == YYPACT_NINF)
  744. #define YYTABLE_NINF (-35)
  745. #define yytable_value_is_error(Yyn) \
  746. 0
  747. /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  748. STATE-NUM. */
  749. static const yytype_int16 yypact[] =
  750. {
  751. 1, -29, -24, 0, 2, 3, 5, 11, 11, 6,
  752. 17, 18, 19, 22, -21, -28, 11, 11, 21, 24,
  753. 25, 28, 12, 54, 52, 193, -29, -29, -29, -29,
  754. -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
  755. -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
  756. -29, -29, -29, -29, -29, -29, -29, 30, -29, 193,
  757. 58, -29, 51, -29, -29, 59, 60, 30, 78, 58,
  758. -29, -29, -29, -29, -29, 80, 81, -29, -29, -29,
  759. -29, -29, 168, 143, 90, 113, -29, -29, 91, 114,
  760. 115, 85, -29, -29, -29, -29, -29, -29, -29, -29,
  761. -29, -29
  762. };
  763. /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
  764. Performed when YYTABLE does not specify something else to do. Zero
  765. means the default is an error. */
  766. static const yytype_int8 yydefact[] =
  767. {
  768. 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
  769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  770. 0, 0, 0, 0, 0, 33, 36, 42, 41, 43,
  771. 44, 45, 46, 31, 47, 48, 49, 50, 51, 52,
  772. 53, 55, 54, 56, 57, 58, 59, 60, 62, 61,
  773. 63, 37, 38, 39, 40, 1, 5, 0, 35, 34,
  774. 8, 2, 0, 17, 23, 0, 0, 0, 0, 7,
  775. 10, 11, 12, 16, 32, 0, 0, 14, 15, 13,
  776. 6, 9, 0, 0, 0, 0, 20, 22, 0, 0,
  777. 0, 0, 26, 30, 21, 18, 19, 27, 28, 29,
  778. 24, 25
  779. };
  780. /* YYPGOTO[NTERM-NUM]. */
  781. static const yytype_int16 yypgoto[] =
  782. {
  783. -29, -29, 118, 105, -29, -29, 79, -29, -29, -29,
  784. 62, -29, -29, -29, 82, 23, -29, 138, -29, -25
  785. };
  786. /* YYDEFGOTO[NTERM-NUM]. */
  787. static const yytype_int8 yydefgoto[] =
  788. {
  789. -1, 23, 67, 61, 68, 69, 70, 71, 75, 85,
  790. 86, 72, 76, 91, 92, 34, 59, 24, 25, 26
  791. };
  792. /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
  793. positive, shift that token. If negative, reduce the rule whose
  794. number is the opposite. If YYTABLE_NINF, syntax error. */
  795. static const yytype_int8 yytable[] =
  796. {
  797. 58, -4, 1, 43, -34, 27, 28, 33, 41, 42,
  798. 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  799. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  800. 29, 35, 30, 31, 22, 73, 32, 36, 44, 45,
  801. 46, 51, 52, 53, 73, 54, 33, 33, 37, 38,
  802. 39, 40, 47, 48, 55, 56, 49, 87, 93, 50,
  803. 87, 56, 63, 64, 65, 60, 93, 2, 3, 4,
  804. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  805. 15, 16, 17, 18, 19, 20, 21, 74, 77, 78,
  806. 66, 22, 88, 89, 2, 3, 4, 5, 6, 7,
  807. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  808. 18, 19, 20, 21, 80, 82, 83, 90, 22, 94,
  809. 97, 100, 2, 3, 4, 5, 6, 7, 8, 9,
  810. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  811. 20, 21, 57, 98, 99, 84, 22, 96, 81, 95,
  812. 88, 89, 2, 3, 4, 5, 6, 7, 8, 9,
  813. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  814. 20, 21, 79, 101, 0, 90, 22, 2, 3, 4,
  815. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  816. 15, 16, 17, 18, 19, 20, 21, 62, 0, 0,
  817. 84, 22, 2, 3, 4, 5, 6, 7, 8, 9,
  818. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  819. 20, 21, 0, 0, 0, 0, 22
  820. };
  821. static const yytype_int8 yycheck[] =
  822. {
  823. 25, 0, 1, 31, 3, 29, 30, 35, 29, 30,
  824. 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
  825. 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
  826. 30, 8, 30, 30, 33, 60, 31, 31, 15, 16,
  827. 17, 29, 30, 31, 69, 22, 35, 35, 31, 31,
  828. 31, 29, 31, 29, 0, 3, 31, 82, 83, 31,
  829. 85, 3, 4, 5, 6, 35, 91, 9, 10, 11,
  830. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  831. 22, 23, 24, 25, 26, 27, 28, 36, 29, 29,
  832. 32, 33, 7, 8, 9, 10, 11, 12, 13, 14,
  833. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  834. 25, 26, 27, 28, 36, 35, 35, 32, 33, 29,
  835. 29, 36, 9, 10, 11, 12, 13, 14, 15, 16,
  836. 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  837. 27, 28, 24, 29, 29, 32, 33, 85, 69, 36,
  838. 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  839. 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  840. 27, 28, 67, 91, -1, 32, 33, 9, 10, 11,
  841. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  842. 22, 23, 24, 25, 26, 27, 28, 59, -1, -1,
  843. 32, 33, 9, 10, 11, 12, 13, 14, 15, 16,
  844. 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  845. 27, 28, -1, -1, -1, -1, 33
  846. };
  847. /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  848. symbol of state STATE-NUM. */
  849. static const yytype_int8 yystos[] =
  850. {
  851. 0, 1, 9, 10, 11, 12, 13, 14, 15, 16,
  852. 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  853. 27, 28, 33, 38, 54, 55, 56, 29, 30, 30,
  854. 30, 30, 31, 35, 52, 52, 31, 31, 31, 31,
  855. 29, 29, 30, 31, 52, 52, 52, 31, 29, 31,
  856. 31, 29, 30, 31, 52, 0, 3, 39, 56, 53,
  857. 35, 40, 54, 4, 5, 6, 32, 39, 41, 42,
  858. 43, 44, 48, 56, 36, 45, 49, 29, 29, 40,
  859. 36, 43, 35, 35, 32, 46, 47, 56, 7, 8,
  860. 32, 50, 51, 56, 29, 36, 47, 29, 29, 29,
  861. 36, 51
  862. };
  863. /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  864. static const yytype_int8 yyr1[] =
  865. {
  866. 0, 37, 38, 38, 38, 39, 40, 41, 41, 42,
  867. 42, 43, 43, 43, 43, 43, 43, 45, 44, 46,
  868. 46, 47, 47, 49, 48, 50, 50, 51, 51, 51,
  869. 51, 53, 52, 54, 54, 55, 55, 56, 56, 56,
  870. 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  871. 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  872. 56, 56, 56, 56
  873. };
  874. /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
  875. static const yytype_int8 yyr2[] =
  876. {
  877. 0, 2, 3, 1, 0, 1, 3, 1, 0, 2,
  878. 1, 1, 1, 2, 2, 2, 1, 0, 5, 2,
  879. 1, 2, 1, 0, 5, 2, 1, 2, 2, 2,
  880. 1, 0, 4, 1, 0, 2, 1, 2, 2, 2,
  881. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  882. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  883. 2, 2, 2, 2
  884. };
  885. #define yyerrok (yyerrstatus = 0)
  886. #define yyclearin (yychar = YYEMPTY)
  887. #define YYEMPTY (-2)
  888. #define YYEOF 0
  889. #define YYACCEPT goto yyacceptlab
  890. #define YYABORT goto yyabortlab
  891. #define YYERROR goto yyerrorlab
  892. #define YYRECOVERING() (!!yyerrstatus)
  893. #define YYBACKUP(Token, Value) \
  894. do \
  895. if (yychar == YYEMPTY) \
  896. { \
  897. yychar = (Token); \
  898. yylval = (Value); \
  899. YYPOPSTACK (yylen); \
  900. yystate = *yyssp; \
  901. goto yybackup; \
  902. } \
  903. else \
  904. { \
  905. yyerror (YY_("syntax error: cannot back up")); \
  906. YYERROR; \
  907. } \
  908. while (0)
  909. /* Error token number */
  910. #define YYTERROR 1
  911. #define YYERRCODE 256
  912. /* Enable debugging if requested. */
  913. #if GMLDEBUG
  914. # ifndef YYFPRINTF
  915. # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  916. # define YYFPRINTF fprintf
  917. # endif
  918. # define YYDPRINTF(Args) \
  919. do { \
  920. if (yydebug) \
  921. YYFPRINTF Args; \
  922. } while (0)
  923. /* This macro is provided for backward compatibility. */
  924. #ifndef YY_LOCATION_PRINT
  925. # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  926. #endif
  927. # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  928. do { \
  929. if (yydebug) \
  930. { \
  931. YYFPRINTF (stderr, "%s ", Title); \
  932. yy_symbol_print (stderr, \
  933. Type, Value); \
  934. YYFPRINTF (stderr, "\n"); \
  935. } \
  936. } while (0)
  937. /*-----------------------------------.
  938. | Print this symbol's value on YYO. |
  939. `-----------------------------------*/
  940. static void
  941. yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
  942. {
  943. FILE *yyoutput = yyo;
  944. YYUSE (yyoutput);
  945. if (!yyvaluep)
  946. return;
  947. # ifdef YYPRINT
  948. if (yytype < YYNTOKENS)
  949. YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
  950. # endif
  951. YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  952. YYUSE (yytype);
  953. YY_IGNORE_MAYBE_UNINITIALIZED_END
  954. }
  955. /*---------------------------.
  956. | Print this symbol on YYO. |
  957. `---------------------------*/
  958. static void
  959. yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
  960. {
  961. YYFPRINTF (yyo, "%s %s (",
  962. yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
  963. yy_symbol_value_print (yyo, yytype, yyvaluep);
  964. YYFPRINTF (yyo, ")");
  965. }
  966. /*------------------------------------------------------------------.
  967. | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  968. | TOP (included). |
  969. `------------------------------------------------------------------*/
  970. static void
  971. yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
  972. {
  973. YYFPRINTF (stderr, "Stack now");
  974. for (; yybottom <= yytop; yybottom++)
  975. {
  976. int yybot = *yybottom;
  977. YYFPRINTF (stderr, " %d", yybot);
  978. }
  979. YYFPRINTF (stderr, "\n");
  980. }
  981. # define YY_STACK_PRINT(Bottom, Top) \
  982. do { \
  983. if (yydebug) \
  984. yy_stack_print ((Bottom), (Top)); \
  985. } while (0)
  986. /*------------------------------------------------.
  987. | Report that the YYRULE is going to be reduced. |
  988. `------------------------------------------------*/
  989. static void
  990. yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule)
  991. {
  992. int yylno = yyrline[yyrule];
  993. int yynrhs = yyr2[yyrule];
  994. int yyi;
  995. YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
  996. yyrule - 1, yylno);
  997. /* The symbols being reduced. */
  998. for (yyi = 0; yyi < yynrhs; yyi++)
  999. {
  1000. YYFPRINTF (stderr, " $%d = ", yyi + 1);
  1001. yy_symbol_print (stderr,
  1002. yystos[+yyssp[yyi + 1 - yynrhs]],
  1003. &yyvsp[(yyi + 1) - (yynrhs)]
  1004. );
  1005. YYFPRINTF (stderr, "\n");
  1006. }
  1007. }
  1008. # define YY_REDUCE_PRINT(Rule) \
  1009. do { \
  1010. if (yydebug) \
  1011. yy_reduce_print (yyssp, yyvsp, Rule); \
  1012. } while (0)
  1013. /* Nonzero means print parse trace. It is left uninitialized so that
  1014. multiple parsers can coexist. */
  1015. int yydebug;
  1016. #else /* !GMLDEBUG */
  1017. # define YYDPRINTF(Args)
  1018. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  1019. # define YY_STACK_PRINT(Bottom, Top)
  1020. # define YY_REDUCE_PRINT(Rule)
  1021. #endif /* !GMLDEBUG */
  1022. /* YYINITDEPTH -- initial size of the parser's stacks. */
  1023. #ifndef YYINITDEPTH
  1024. # define YYINITDEPTH 200
  1025. #endif
  1026. /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  1027. if the built-in stack extension method is used).
  1028. Do not make this value too large; the results are undefined if
  1029. YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  1030. evaluated with infinite-precision integer arithmetic. */
  1031. #ifndef YYMAXDEPTH
  1032. # define YYMAXDEPTH 10000
  1033. #endif
  1034. #if YYERROR_VERBOSE
  1035. # ifndef yystrlen
  1036. # if defined __GLIBC__ && defined _STRING_H
  1037. # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
  1038. # else
  1039. /* Return the length of YYSTR. */
  1040. static YYPTRDIFF_T
  1041. yystrlen (const char *yystr)
  1042. {
  1043. YYPTRDIFF_T yylen;
  1044. for (yylen = 0; yystr[yylen]; yylen++)
  1045. continue;
  1046. return yylen;
  1047. }
  1048. # endif
  1049. # endif
  1050. # ifndef yystpcpy
  1051. # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
  1052. # define yystpcpy stpcpy
  1053. # else
  1054. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  1055. YYDEST. */
  1056. static char *
  1057. yystpcpy (char *yydest, const char *yysrc)
  1058. {
  1059. char *yyd = yydest;
  1060. const char *yys = yysrc;
  1061. while ((*yyd++ = *yys++) != '\0')
  1062. continue;
  1063. return yyd - 1;
  1064. }
  1065. # endif
  1066. # endif
  1067. # ifndef yytnamerr
  1068. /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
  1069. quotes and backslashes, so that it's suitable for yyerror. The
  1070. heuristic is that double-quoting is unnecessary unless the string
  1071. contains an apostrophe, a comma, or backslash (other than
  1072. backslash-backslash). YYSTR is taken from yytname. If YYRES is
  1073. null, do not copy; instead, return the length of what the result
  1074. would have been. */
  1075. static YYPTRDIFF_T
  1076. yytnamerr (char *yyres, const char *yystr)
  1077. {
  1078. if (*yystr == '"')
  1079. {
  1080. YYPTRDIFF_T yyn = 0;
  1081. char const *yyp = yystr;
  1082. for (;;)
  1083. switch (*++yyp)
  1084. {
  1085. case '\'':
  1086. case ',':
  1087. goto do_not_strip_quotes;
  1088. case '\\':
  1089. if (*++yyp != '\\')
  1090. goto do_not_strip_quotes;
  1091. else
  1092. goto append;
  1093. append:
  1094. default:
  1095. if (yyres)
  1096. yyres[yyn] = *yyp;
  1097. yyn++;
  1098. break;
  1099. case '"':
  1100. if (yyres)
  1101. yyres[yyn] = '\0';
  1102. return yyn;
  1103. }
  1104. do_not_strip_quotes: ;
  1105. }
  1106. if (yyres)
  1107. return yystpcpy (yyres, yystr) - yyres;
  1108. else
  1109. return yystrlen (yystr);
  1110. }
  1111. # endif
  1112. /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
  1113. about the unexpected token YYTOKEN for the state stack whose top is
  1114. YYSSP.
  1115. Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
  1116. not large enough to hold the message. In that case, also set
  1117. *YYMSG_ALLOC to the required number of bytes. Return 2 if the
  1118. required number of bytes is too large to store. */
  1119. static int
  1120. yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
  1121. yy_state_t *yyssp, int yytoken)
  1122. {
  1123. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  1124. /* Internationalized format string. */
  1125. const char *yyformat = YY_NULLPTR;
  1126. /* Arguments of yyformat: reported tokens (one for the "unexpected",
  1127. one per "expected"). */
  1128. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  1129. /* Actual size of YYARG. */
  1130. int yycount = 0;
  1131. /* Cumulated lengths of YYARG. */
  1132. YYPTRDIFF_T yysize = 0;
  1133. /* There are many possibilities here to consider:
  1134. - If this state is a consistent state with a default action, then
  1135. the only way this function was invoked is if the default action
  1136. is an error action. In that case, don't check for expected
  1137. tokens because there are none.
  1138. - The only way there can be no lookahead present (in yychar) is if
  1139. this state is a consistent state with a default action. Thus,
  1140. detecting the absence of a lookahead is sufficient to determine
  1141. that there is no unexpected or expected token to report. In that
  1142. case, just report a simple "syntax error".
  1143. - Don't assume there isn't a lookahead just because this state is a
  1144. consistent state with a default action. There might have been a
  1145. previous inconsistent state, consistent state with a non-default
  1146. action, or user semantic action that manipulated yychar.
  1147. - Of course, the expected token list depends on states to have
  1148. correct lookahead information, and it depends on the parser not
  1149. to perform extra reductions after fetching a lookahead from the
  1150. scanner and before detecting a syntax error. Thus, state merging
  1151. (from LALR or IELR) and default reductions corrupt the expected
  1152. token list. However, the list is correct for canonical LR with
  1153. one exception: it will still contain any token that will not be
  1154. accepted due to an error action in a later state.
  1155. */
  1156. if (yytoken != YYEMPTY)
  1157. {
  1158. int yyn = yypact[+*yyssp];
  1159. YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
  1160. yysize = yysize0;
  1161. yyarg[yycount++] = yytname[yytoken];
  1162. if (!yypact_value_is_default (yyn))
  1163. {
  1164. /* Start YYX at -YYN if negative to avoid negative indexes in
  1165. YYCHECK. In other words, skip the first -YYN actions for
  1166. this state because they are default actions. */
  1167. int yyxbegin = yyn < 0 ? -yyn : 0;
  1168. /* Stay within bounds of both yycheck and yytname. */
  1169. int yychecklim = YYLAST - yyn + 1;
  1170. int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1171. int yyx;
  1172. for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1173. if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
  1174. && !yytable_value_is_error (yytable[yyx + yyn]))
  1175. {
  1176. if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  1177. {
  1178. yycount = 1;
  1179. yysize = yysize0;
  1180. break;
  1181. }
  1182. yyarg[yycount++] = yytname[yyx];
  1183. {
  1184. YYPTRDIFF_T yysize1
  1185. = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
  1186. if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
  1187. yysize = yysize1;
  1188. else
  1189. return 2;
  1190. }
  1191. }
  1192. }
  1193. }
  1194. switch (yycount)
  1195. {
  1196. # define YYCASE_(N, S) \
  1197. case N: \
  1198. yyformat = S; \
  1199. break
  1200. default: /* Avoid compiler warnings. */
  1201. YYCASE_(0, YY_("syntax error"));
  1202. YYCASE_(1, YY_("syntax error, unexpected %s"));
  1203. YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
  1204. YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
  1205. YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
  1206. YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
  1207. # undef YYCASE_
  1208. }
  1209. {
  1210. /* Don't count the "%s"s in the final size, but reserve room for
  1211. the terminator. */
  1212. YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1;
  1213. if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
  1214. yysize = yysize1;
  1215. else
  1216. return 2;
  1217. }
  1218. if (*yymsg_alloc < yysize)
  1219. {
  1220. *yymsg_alloc = 2 * yysize;
  1221. if (! (yysize <= *yymsg_alloc
  1222. && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
  1223. *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
  1224. return 1;
  1225. }
  1226. /* Avoid sprintf, as that infringes on the user's name space.
  1227. Don't have undefined behavior even if the translation
  1228. produced a string with the wrong number of "%s"s. */
  1229. {
  1230. char *yyp = *yymsg;
  1231. int yyi = 0;
  1232. while ((*yyp = *yyformat) != '\0')
  1233. if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
  1234. {
  1235. yyp += yytnamerr (yyp, yyarg[yyi++]);
  1236. yyformat += 2;
  1237. }
  1238. else
  1239. {
  1240. ++yyp;
  1241. ++yyformat;
  1242. }
  1243. }
  1244. return 0;
  1245. }
  1246. #endif /* YYERROR_VERBOSE */
  1247. /*-----------------------------------------------.
  1248. | Release the memory associated to this symbol. |
  1249. `-----------------------------------------------*/
  1250. static void
  1251. yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
  1252. {
  1253. YYUSE (yyvaluep);
  1254. if (!yymsg)
  1255. yymsg = "Deleting";
  1256. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  1257. YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  1258. YYUSE (yytype);
  1259. YY_IGNORE_MAYBE_UNINITIALIZED_END
  1260. }
  1261. /* The lookahead symbol. */
  1262. int yychar;
  1263. /* The semantic value of the lookahead symbol. */
  1264. YYSTYPE yylval;
  1265. /* Number of syntax errors so far. */
  1266. int yynerrs;
  1267. /*----------.
  1268. | yyparse. |
  1269. `----------*/
  1270. int
  1271. yyparse (void)
  1272. {
  1273. yy_state_fast_t yystate;
  1274. /* Number of tokens to shift before error messages enabled. */
  1275. int yyerrstatus;
  1276. /* The stacks and their tools:
  1277. 'yyss': related to states.
  1278. 'yyvs': related to semantic values.
  1279. Refer to the stacks through separate pointers, to allow yyoverflow
  1280. to reallocate them elsewhere. */
  1281. /* The state stack. */
  1282. yy_state_t yyssa[YYINITDEPTH];
  1283. yy_state_t *yyss;
  1284. yy_state_t *yyssp;
  1285. /* The semantic value stack. */
  1286. YYSTYPE yyvsa[YYINITDEPTH];
  1287. YYSTYPE *yyvs;
  1288. YYSTYPE *yyvsp;
  1289. YYPTRDIFF_T yystacksize;
  1290. int yyn;
  1291. int yyresult;
  1292. /* Lookahead token as an internal (translated) token number. */
  1293. int yytoken = 0;
  1294. /* The variables used to return semantic value and location from the
  1295. action routines. */
  1296. YYSTYPE yyval;
  1297. #if YYERROR_VERBOSE
  1298. /* Buffer for error messages, and its allocated size. */
  1299. char yymsgbuf[128];
  1300. char *yymsg = yymsgbuf;
  1301. YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
  1302. #endif
  1303. #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
  1304. /* The number of symbols on the RHS of the reduced rule.
  1305. Keep to zero when no symbol should be popped. */
  1306. int yylen = 0;
  1307. yyssp = yyss = yyssa;
  1308. yyvsp = yyvs = yyvsa;
  1309. yystacksize = YYINITDEPTH;
  1310. YYDPRINTF ((stderr, "Starting parse\n"));
  1311. yystate = 0;
  1312. yyerrstatus = 0;
  1313. yynerrs = 0;
  1314. yychar = YYEMPTY; /* Cause a token to be read. */
  1315. goto yysetstate;
  1316. /*------------------------------------------------------------.
  1317. | yynewstate -- push a new state, which is found in yystate. |
  1318. `------------------------------------------------------------*/
  1319. yynewstate:
  1320. /* In all cases, when you get here, the value and location stacks
  1321. have just been pushed. So pushing a state here evens the stacks. */
  1322. yyssp++;
  1323. /*--------------------------------------------------------------------.
  1324. | yysetstate -- set current state (the top of the stack) to yystate. |
  1325. `--------------------------------------------------------------------*/
  1326. yysetstate:
  1327. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  1328. YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
  1329. YY_IGNORE_USELESS_CAST_BEGIN
  1330. *yyssp = YY_CAST (yy_state_t, yystate);
  1331. YY_IGNORE_USELESS_CAST_END
  1332. if (yyss + yystacksize - 1 <= yyssp)
  1333. #if !defined yyoverflow && !defined YYSTACK_RELOCATE
  1334. goto yyexhaustedlab;
  1335. #else
  1336. {
  1337. /* Get the current used size of the three stacks, in elements. */
  1338. YYPTRDIFF_T yysize = yyssp - yyss + 1;
  1339. # if defined yyoverflow
  1340. {
  1341. /* Give user a chance to reallocate the stack. Use copies of
  1342. these so that the &'s don't force the real ones into
  1343. memory. */
  1344. yy_state_t *yyss1 = yyss;
  1345. YYSTYPE *yyvs1 = yyvs;
  1346. /* Each stack pointer address is followed by the size of the
  1347. data in use in that stack, in bytes. This used to be a
  1348. conditional around just the two extra args, but that might
  1349. be undefined if yyoverflow is a macro. */
  1350. yyoverflow (YY_("memory exhausted"),
  1351. &yyss1, yysize * YYSIZEOF (*yyssp),
  1352. &yyvs1, yysize * YYSIZEOF (*yyvsp),
  1353. &yystacksize);
  1354. yyss = yyss1;
  1355. yyvs = yyvs1;
  1356. }
  1357. # else /* defined YYSTACK_RELOCATE */
  1358. /* Extend the stack our own way. */
  1359. if (YYMAXDEPTH <= yystacksize)
  1360. goto yyexhaustedlab;
  1361. yystacksize *= 2;
  1362. if (YYMAXDEPTH < yystacksize)
  1363. yystacksize = YYMAXDEPTH;
  1364. {
  1365. yy_state_t *yyss1 = yyss;
  1366. union yyalloc *yyptr =
  1367. YY_CAST (union yyalloc *,
  1368. YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
  1369. if (! yyptr)
  1370. goto yyexhaustedlab;
  1371. YYSTACK_RELOCATE (yyss_alloc, yyss);
  1372. YYSTACK_RELOCATE (yyvs_alloc, yyvs);
  1373. # undef YYSTACK_RELOCATE
  1374. if (yyss1 != yyssa)
  1375. YYSTACK_FREE (yyss1);
  1376. }
  1377. # endif
  1378. yyssp = yyss + yysize - 1;
  1379. yyvsp = yyvs + yysize - 1;
  1380. YY_IGNORE_USELESS_CAST_BEGIN
  1381. YYDPRINTF ((stderr, "Stack size increased to %ld\n",
  1382. YY_CAST (long, yystacksize)));
  1383. YY_IGNORE_USELESS_CAST_END
  1384. if (yyss + yystacksize - 1 <= yyssp)
  1385. YYABORT;
  1386. }
  1387. #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
  1388. if (yystate == YYFINAL)
  1389. YYACCEPT;
  1390. goto yybackup;
  1391. /*-----------.
  1392. | yybackup. |
  1393. `-----------*/
  1394. yybackup:
  1395. /* Do appropriate processing given the current state. Read a
  1396. lookahead token if we need one and don't already have one. */
  1397. /* First try to decide what to do without reference to lookahead token. */
  1398. yyn = yypact[yystate];
  1399. if (yypact_value_is_default (yyn))
  1400. goto yydefault;
  1401. /* Not known => get a lookahead token if don't already have one. */
  1402. /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
  1403. if (yychar == YYEMPTY)
  1404. {
  1405. YYDPRINTF ((stderr, "Reading a token: "));
  1406. yychar = yylex ();
  1407. }
  1408. if (yychar <= YYEOF)
  1409. {
  1410. yychar = yytoken = YYEOF;
  1411. YYDPRINTF ((stderr, "Now at end of input.\n"));
  1412. }
  1413. else
  1414. {
  1415. yytoken = YYTRANSLATE (yychar);
  1416. YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1417. }
  1418. /* If the proper action on seeing token YYTOKEN is to reduce or to
  1419. detect an error, take that action. */
  1420. yyn += yytoken;
  1421. if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1422. goto yydefault;
  1423. yyn = yytable[yyn];
  1424. if (yyn <= 0)
  1425. {
  1426. if (yytable_value_is_error (yyn))
  1427. goto yyerrlab;
  1428. yyn = -yyn;
  1429. goto yyreduce;
  1430. }
  1431. /* Count tokens shifted since error; after three, turn off error
  1432. status. */
  1433. if (yyerrstatus)
  1434. yyerrstatus--;
  1435. /* Shift the lookahead token. */
  1436. YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1437. yystate = yyn;
  1438. YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  1439. *++yyvsp = yylval;
  1440. YY_IGNORE_MAYBE_UNINITIALIZED_END
  1441. /* Discard the shifted token. */
  1442. yychar = YYEMPTY;
  1443. goto yynewstate;
  1444. /*-----------------------------------------------------------.
  1445. | yydefault -- do the default action for the current state. |
  1446. `-----------------------------------------------------------*/
  1447. yydefault:
  1448. yyn = yydefact[yystate];
  1449. if (yyn == 0)
  1450. goto yyerrlab;
  1451. goto yyreduce;
  1452. /*-----------------------------.
  1453. | yyreduce -- do a reduction. |
  1454. `-----------------------------*/
  1455. yyreduce:
  1456. /* yyn is the number of a rule to reduce with. */
  1457. yylen = yyr2[yyn];
  1458. /* If YYLEN is nonzero, implement the default value of the action:
  1459. '$$ = $1'.
  1460. Otherwise, the following line sets YYVAL to garbage.
  1461. This behavior is undocumented and Bison
  1462. users should not rely upon it. Assigning to YYVAL
  1463. unconditionally makes the parser a bit smaller, and it avoids a
  1464. GCC warning that YYVAL may be used uninitialized. */
  1465. yyval = yyvsp[1-yylen];
  1466. YY_REDUCE_PRINT (yyn);
  1467. switch (yyn)
  1468. {
  1469. case 2:
  1470. #line 260 "../../cmd/tools/gmlparse.y"
  1471. {gmllexeof(); if (G->parent) popG(); }
  1472. #line 1702 "gmlparse.c"
  1473. break;
  1474. case 3:
  1475. #line 261 "../../cmd/tools/gmlparse.y"
  1476. { cleanup(); YYABORT; }
  1477. #line 1708 "gmlparse.c"
  1478. break;
  1479. case 5:
  1480. #line 265 "../../cmd/tools/gmlparse.y"
  1481. { pushG(); }
  1482. #line 1714 "gmlparse.c"
  1483. break;
  1484. case 11:
  1485. #line 279 "../../cmd/tools/gmlparse.y"
  1486. { dtinsert (G->nodelist, (yyvsp[0].np)); }
  1487. #line 1720 "gmlparse.c"
  1488. break;
  1489. case 12:
  1490. #line 280 "../../cmd/tools/gmlparse.y"
  1491. { dtinsert (G->edgelist, (yyvsp[0].ep)); }
  1492. #line 1726 "gmlparse.c"
  1493. break;
  1494. case 14:
  1495. #line 282 "../../cmd/tools/gmlparse.y"
  1496. {
  1497. if (setDir((yyvsp[0].str))) {
  1498. yyerror("mixed directed and undirected graphs");
  1499. cleanup ();
  1500. YYABORT;
  1501. }
  1502. }
  1503. #line 1738 "gmlparse.c"
  1504. break;
  1505. case 15:
  1506. #line 289 "../../cmd/tools/gmlparse.y"
  1507. { dtinsert (G->attrlist, mkAttr(gv_strdup("id"), 0, INTEGER, (yyvsp[0].str), 0)); }
  1508. #line 1744 "gmlparse.c"
  1509. break;
  1510. case 16:
  1511. #line 290 "../../cmd/tools/gmlparse.y"
  1512. { dtinsert (G->attrlist, (yyvsp[0].ap)); }
  1513. #line 1750 "gmlparse.c"
  1514. break;
  1515. case 17:
  1516. #line 293 "../../cmd/tools/gmlparse.y"
  1517. { N = mkNode(); }
  1518. #line 1756 "gmlparse.c"
  1519. break;
  1520. case 18:
  1521. #line 293 "../../cmd/tools/gmlparse.y"
  1522. { (yyval.np) = N; N = NULL; }
  1523. #line 1762 "gmlparse.c"
  1524. break;
  1525. case 21:
  1526. #line 300 "../../cmd/tools/gmlparse.y"
  1527. { N->id = (yyvsp[0].str); }
  1528. #line 1768 "gmlparse.c"
  1529. break;
  1530. case 22:
  1531. #line 301 "../../cmd/tools/gmlparse.y"
  1532. { dtinsert (N->attrlist, (yyvsp[0].ap)); }
  1533. #line 1774 "gmlparse.c"
  1534. break;
  1535. case 23:
  1536. #line 304 "../../cmd/tools/gmlparse.y"
  1537. { E = mkEdge(); }
  1538. #line 1780 "gmlparse.c"
  1539. break;
  1540. case 24:
  1541. #line 304 "../../cmd/tools/gmlparse.y"
  1542. { (yyval.ep) = E; E = NULL; }
  1543. #line 1786 "gmlparse.c"
  1544. break;
  1545. case 27:
  1546. #line 311 "../../cmd/tools/gmlparse.y"
  1547. { E->source = (yyvsp[0].str); }
  1548. #line 1792 "gmlparse.c"
  1549. break;
  1550. case 28:
  1551. #line 312 "../../cmd/tools/gmlparse.y"
  1552. { E->target = (yyvsp[0].str); }
  1553. #line 1798 "gmlparse.c"
  1554. break;
  1555. case 29:
  1556. #line 313 "../../cmd/tools/gmlparse.y"
  1557. { dtinsert (E->attrlist, mkAttr(gv_strdup("id"), 0, INTEGER, (yyvsp[0].str), 0)); }
  1558. #line 1804 "gmlparse.c"
  1559. break;
  1560. case 30:
  1561. #line 314 "../../cmd/tools/gmlparse.y"
  1562. { dtinsert (E->attrlist, (yyvsp[0].ap)); }
  1563. #line 1810 "gmlparse.c"
  1564. break;
  1565. case 31:
  1566. #line 317 "../../cmd/tools/gmlparse.y"
  1567. {pushAlist(); }
  1568. #line 1816 "gmlparse.c"
  1569. break;
  1570. case 32:
  1571. #line 317 "../../cmd/tools/gmlparse.y"
  1572. { (yyval.list) = popAlist(); }
  1573. #line 1822 "gmlparse.c"
  1574. break;
  1575. case 35:
  1576. #line 324 "../../cmd/tools/gmlparse.y"
  1577. { dtinsert (L, (yyvsp[0].ap)); }
  1578. #line 1828 "gmlparse.c"
  1579. break;
  1580. case 36:
  1581. #line 325 "../../cmd/tools/gmlparse.y"
  1582. { dtinsert (L, (yyvsp[0].ap)); }
  1583. #line 1834 "gmlparse.c"
  1584. break;
  1585. case 37:
  1586. #line 328 "../../cmd/tools/gmlparse.y"
  1587. { (yyval.ap) = mkAttr ((yyvsp[-1].str), 0, INTEGER, (yyvsp[0].str), 0); }
  1588. #line 1840 "gmlparse.c"
  1589. break;
  1590. case 38:
  1591. #line 329 "../../cmd/tools/gmlparse.y"
  1592. { (yyval.ap) = mkAttr ((yyvsp[-1].str), 0, REAL, (yyvsp[0].str), 0); }
  1593. #line 1846 "gmlparse.c"
  1594. break;
  1595. case 39:
  1596. #line 330 "../../cmd/tools/gmlparse.y"
  1597. { (yyval.ap) = mkAttr ((yyvsp[-1].str), 0, STRING, (yyvsp[0].str), 0); }
  1598. #line 1852 "gmlparse.c"
  1599. break;
  1600. case 40:
  1601. #line 331 "../../cmd/tools/gmlparse.y"
  1602. { (yyval.ap) = mkAttr ((yyvsp[-1].str), 0, LIST, 0, (yyvsp[0].list)); }
  1603. #line 1858 "gmlparse.c"
  1604. break;
  1605. case 41:
  1606. #line 332 "../../cmd/tools/gmlparse.y"
  1607. { (yyval.ap) = mkAttr (0, XVAL, REAL, (yyvsp[0].str), 0); }
  1608. #line 1864 "gmlparse.c"
  1609. break;
  1610. case 42:
  1611. #line 333 "../../cmd/tools/gmlparse.y"
  1612. { (yyval.ap) = mkAttr (0, XVAL, REAL, (yyvsp[0].str), 0); }
  1613. #line 1870 "gmlparse.c"
  1614. break;
  1615. case 43:
  1616. #line 334 "../../cmd/tools/gmlparse.y"
  1617. { (yyval.ap) = mkAttr (0, YVAL, REAL, (yyvsp[0].str), 0); }
  1618. #line 1876 "gmlparse.c"
  1619. break;
  1620. case 44:
  1621. #line 335 "../../cmd/tools/gmlparse.y"
  1622. { (yyval.ap) = mkAttr (0, WVAL, REAL, (yyvsp[0].str), 0); }
  1623. #line 1882 "gmlparse.c"
  1624. break;
  1625. case 45:
  1626. #line 336 "../../cmd/tools/gmlparse.y"
  1627. { (yyval.ap) = mkAttr (0, HVAL, REAL, (yyvsp[0].str), 0); }
  1628. #line 1888 "gmlparse.c"
  1629. break;
  1630. case 46:
  1631. #line 337 "../../cmd/tools/gmlparse.y"
  1632. { (yyval.ap) = mkAttr (0, LABEL, STRING, (yyvsp[0].str), 0); }
  1633. #line 1894 "gmlparse.c"
  1634. break;
  1635. case 47:
  1636. #line 338 "../../cmd/tools/gmlparse.y"
  1637. { (yyval.ap) = mkAttr (0, GRAPHICS, LIST, 0, (yyvsp[0].list)); }
  1638. #line 1900 "gmlparse.c"
  1639. break;
  1640. case 48:
  1641. #line 339 "../../cmd/tools/gmlparse.y"
  1642. { (yyval.ap) = mkAttr (0, LABELGRAPHICS, LIST, 0, (yyvsp[0].list)); }
  1643. #line 1906 "gmlparse.c"
  1644. break;
  1645. case 49:
  1646. #line 340 "../../cmd/tools/gmlparse.y"
  1647. { (yyval.ap) = mkAttr (0, TYPE, STRING, (yyvsp[0].str), 0); }
  1648. #line 1912 "gmlparse.c"
  1649. break;
  1650. case 50:
  1651. #line 341 "../../cmd/tools/gmlparse.y"
  1652. { (yyval.ap) = mkAttr (0, FILL, STRING, (yyvsp[0].str), 0); }
  1653. #line 1918 "gmlparse.c"
  1654. break;
  1655. case 51:
  1656. #line 342 "../../cmd/tools/gmlparse.y"
  1657. { (yyval.ap) = mkAttr (0, OUTLINE, STRING, (yyvsp[0].str), 0); }
  1658. #line 1924 "gmlparse.c"
  1659. break;
  1660. case 52:
  1661. #line 343 "../../cmd/tools/gmlparse.y"
  1662. { (yyval.ap) = mkAttr (0, OUTLINESTYLE, STRING, (yyvsp[0].str), 0); }
  1663. #line 1930 "gmlparse.c"
  1664. break;
  1665. case 53:
  1666. #line 344 "../../cmd/tools/gmlparse.y"
  1667. { (yyval.ap) = mkAttr (0, OUTLINEWIDTH, INTEGER, (yyvsp[0].str), 0); }
  1668. #line 1936 "gmlparse.c"
  1669. break;
  1670. case 54:
  1671. #line 345 "../../cmd/tools/gmlparse.y"
  1672. { (yyval.ap) = mkAttr (0, WIDTH, REAL, (yyvsp[0].str), 0); }
  1673. #line 1942 "gmlparse.c"
  1674. break;
  1675. case 55:
  1676. #line 346 "../../cmd/tools/gmlparse.y"
  1677. { (yyval.ap) = mkAttr (0, WIDTH, INTEGER, (yyvsp[0].str), 0); }
  1678. #line 1948 "gmlparse.c"
  1679. break;
  1680. case 56:
  1681. #line 347 "../../cmd/tools/gmlparse.y"
  1682. { (yyval.ap) = mkAttr (0, STYLE, STRING, (yyvsp[0].str), 0); }
  1683. #line 1954 "gmlparse.c"
  1684. break;
  1685. case 57:
  1686. #line 348 "../../cmd/tools/gmlparse.y"
  1687. { (yyval.ap) = mkAttr (0, STYLE, LIST, 0, (yyvsp[0].list)); }
  1688. #line 1960 "gmlparse.c"
  1689. break;
  1690. case 58:
  1691. #line 349 "../../cmd/tools/gmlparse.y"
  1692. { (yyval.ap) = mkAttr (0, LINE, LIST, 0, (yyvsp[0].list)); }
  1693. #line 1966 "gmlparse.c"
  1694. break;
  1695. case 59:
  1696. #line 350 "../../cmd/tools/gmlparse.y"
  1697. { (yyval.ap) = mkAttr (0, POINT, LIST, 0, (yyvsp[0].list)); }
  1698. #line 1972 "gmlparse.c"
  1699. break;
  1700. case 60:
  1701. #line 351 "../../cmd/tools/gmlparse.y"
  1702. { (yyval.ap) = mkAttr (0, TEXT, STRING, (yyvsp[0].str), 0); }
  1703. #line 1978 "gmlparse.c"
  1704. break;
  1705. case 61:
  1706. #line 352 "../../cmd/tools/gmlparse.y"
  1707. { (yyval.ap) = mkAttr (0, FONTNAME, STRING, (yyvsp[0].str), 0); }
  1708. #line 1984 "gmlparse.c"
  1709. break;
  1710. case 62:
  1711. #line 353 "../../cmd/tools/gmlparse.y"
  1712. { (yyval.ap) = mkAttr (0, FONTNAME, INTEGER, (yyvsp[0].str), 0); }
  1713. #line 1990 "gmlparse.c"
  1714. break;
  1715. case 63:
  1716. #line 354 "../../cmd/tools/gmlparse.y"
  1717. { (yyval.ap) = mkAttr (0, COLOR, STRING, (yyvsp[0].str), 0); }
  1718. #line 1996 "gmlparse.c"
  1719. break;
  1720. #line 2000 "gmlparse.c"
  1721. default: break;
  1722. }
  1723. /* User semantic actions sometimes alter yychar, and that requires
  1724. that yytoken be updated with the new translation. We take the
  1725. approach of translating immediately before every use of yytoken.
  1726. One alternative is translating here after every semantic action,
  1727. but that translation would be missed if the semantic action invokes
  1728. YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
  1729. if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
  1730. incorrect destructor might then be invoked immediately. In the
  1731. case of YYERROR or YYBACKUP, subsequent parser actions might lead
  1732. to an incorrect destructor call or verbose syntax error message
  1733. before the lookahead is translated. */
  1734. YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
  1735. YYPOPSTACK (yylen);
  1736. yylen = 0;
  1737. YY_STACK_PRINT (yyss, yyssp);
  1738. *++yyvsp = yyval;
  1739. /* Now 'shift' the result of the reduction. Determine what state
  1740. that goes to, based on the state we popped back to and the rule
  1741. number reduced by. */
  1742. {
  1743. const int yylhs = yyr1[yyn] - YYNTOKENS;
  1744. const int yyi = yypgoto[yylhs] + *yyssp;
  1745. yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
  1746. ? yytable[yyi]
  1747. : yydefgoto[yylhs]);
  1748. }
  1749. goto yynewstate;
  1750. /*--------------------------------------.
  1751. | yyerrlab -- here on detecting error. |
  1752. `--------------------------------------*/
  1753. yyerrlab:
  1754. /* Make sure we have latest lookahead translation. See comments at
  1755. user semantic actions for why this is necessary. */
  1756. yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
  1757. /* If not already recovering from an error, report this error. */
  1758. if (!yyerrstatus)
  1759. {
  1760. ++yynerrs;
  1761. #if ! YYERROR_VERBOSE
  1762. yyerror (YY_("syntax error"));
  1763. #else
  1764. # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
  1765. yyssp, yytoken)
  1766. {
  1767. char const *yymsgp = YY_("syntax error");
  1768. int yysyntax_error_status;
  1769. yysyntax_error_status = YYSYNTAX_ERROR;
  1770. if (yysyntax_error_status == 0)
  1771. yymsgp = yymsg;
  1772. else if (yysyntax_error_status == 1)
  1773. {
  1774. if (yymsg != yymsgbuf)
  1775. YYSTACK_FREE (yymsg);
  1776. yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
  1777. if (!yymsg)
  1778. {
  1779. yymsg = yymsgbuf;
  1780. yymsg_alloc = sizeof yymsgbuf;
  1781. yysyntax_error_status = 2;
  1782. }
  1783. else
  1784. {
  1785. yysyntax_error_status = YYSYNTAX_ERROR;
  1786. yymsgp = yymsg;
  1787. }
  1788. }
  1789. yyerror (yymsgp);
  1790. if (yysyntax_error_status == 2)
  1791. goto yyexhaustedlab;
  1792. }
  1793. # undef YYSYNTAX_ERROR
  1794. #endif
  1795. }
  1796. if (yyerrstatus == 3)
  1797. {
  1798. /* If just tried and failed to reuse lookahead token after an
  1799. error, discard it. */
  1800. if (yychar <= YYEOF)
  1801. {
  1802. /* Return failure if at end of input. */
  1803. if (yychar == YYEOF)
  1804. YYABORT;
  1805. }
  1806. else
  1807. {
  1808. yydestruct ("Error: discarding",
  1809. yytoken, &yylval);
  1810. yychar = YYEMPTY;
  1811. }
  1812. }
  1813. /* Else will try to reuse lookahead token after shifting the error
  1814. token. */
  1815. goto yyerrlab1;
  1816. /*---------------------------------------------------.
  1817. | yyerrorlab -- error raised explicitly by YYERROR. |
  1818. `---------------------------------------------------*/
  1819. yyerrorlab:
  1820. /* Pacify compilers when the user code never invokes YYERROR and the
  1821. label yyerrorlab therefore never appears in user code. */
  1822. if (0)
  1823. YYERROR;
  1824. /* Do not reclaim the symbols of the rule whose action triggered
  1825. this YYERROR. */
  1826. YYPOPSTACK (yylen);
  1827. yylen = 0;
  1828. YY_STACK_PRINT (yyss, yyssp);
  1829. yystate = *yyssp;
  1830. goto yyerrlab1;
  1831. /*-------------------------------------------------------------.
  1832. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  1833. `-------------------------------------------------------------*/
  1834. yyerrlab1:
  1835. yyerrstatus = 3; /* Each real token shifted decrements this. */
  1836. for (;;)
  1837. {
  1838. yyn = yypact[yystate];
  1839. if (!yypact_value_is_default (yyn))
  1840. {
  1841. yyn += YYTERROR;
  1842. if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  1843. {
  1844. yyn = yytable[yyn];
  1845. if (0 < yyn)
  1846. break;
  1847. }
  1848. }
  1849. /* Pop the current state because it cannot handle the error token. */
  1850. if (yyssp == yyss)
  1851. YYABORT;
  1852. yydestruct ("Error: popping",
  1853. yystos[yystate], yyvsp);
  1854. YYPOPSTACK (1);
  1855. yystate = *yyssp;
  1856. YY_STACK_PRINT (yyss, yyssp);
  1857. }
  1858. YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  1859. *++yyvsp = yylval;
  1860. YY_IGNORE_MAYBE_UNINITIALIZED_END
  1861. /* Shift the error token. */
  1862. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  1863. yystate = yyn;
  1864. goto yynewstate;
  1865. /*-------------------------------------.
  1866. | yyacceptlab -- YYACCEPT comes here. |
  1867. `-------------------------------------*/
  1868. yyacceptlab:
  1869. yyresult = 0;
  1870. goto yyreturn;
  1871. /*-----------------------------------.
  1872. | yyabortlab -- YYABORT comes here. |
  1873. `-----------------------------------*/
  1874. yyabortlab:
  1875. yyresult = 1;
  1876. goto yyreturn;
  1877. #if !defined yyoverflow || YYERROR_VERBOSE
  1878. /*-------------------------------------------------.
  1879. | yyexhaustedlab -- memory exhaustion comes here. |
  1880. `-------------------------------------------------*/
  1881. yyexhaustedlab:
  1882. yyerror (YY_("memory exhausted"));
  1883. yyresult = 2;
  1884. /* Fall through. */
  1885. #endif
  1886. /*-----------------------------------------------------.
  1887. | yyreturn -- parsing is finished, return the result. |
  1888. `-----------------------------------------------------*/
  1889. yyreturn:
  1890. if (yychar != YYEMPTY)
  1891. {
  1892. /* Make sure we have latest lookahead translation. See comments at
  1893. user semantic actions for why this is necessary. */
  1894. yytoken = YYTRANSLATE (yychar);
  1895. yydestruct ("Cleanup: discarding lookahead",
  1896. yytoken, &yylval);
  1897. }
  1898. /* Do not reclaim the symbols of the rule whose action triggered
  1899. this YYABORT or YYACCEPT. */
  1900. YYPOPSTACK (yylen);
  1901. YY_STACK_PRINT (yyss, yyssp);
  1902. while (yyssp != yyss)
  1903. {
  1904. yydestruct ("Cleanup: popping",
  1905. yystos[+*yyssp], yyvsp);
  1906. YYPOPSTACK (1);
  1907. }
  1908. #ifndef yyoverflow
  1909. if (yyss != yyssa)
  1910. YYSTACK_FREE (yyss);
  1911. #endif
  1912. #if YYERROR_VERBOSE
  1913. if (yymsg != yymsgbuf)
  1914. YYSTACK_FREE (yymsg);
  1915. #endif
  1916. return yyresult;
  1917. }
  1918. #line 357 "../../cmd/tools/gmlparse.y"
  1919. static void free_attr(void *attr) {
  1920. gmlattr *p = attr;
  1921. if (!p) return;
  1922. if (p->kind == LIST && p->u.lp)
  1923. dtclose (p->u.lp);
  1924. else
  1925. free (p->u.value);
  1926. free (p->name);
  1927. free (p);
  1928. }
  1929. static void deparseList (Dt_t* alist, agxbuf* xb); /* forward declaration */
  1930. static void
  1931. deparseAttr (gmlattr* ap, agxbuf* xb)
  1932. {
  1933. if (ap->kind == LIST) {
  1934. agxbprint (xb, "%s ", ap->name);
  1935. deparseList (ap->u.lp, xb);
  1936. }
  1937. else if (ap->kind == STRING) {
  1938. agxbprint (xb, "%s \"%s\"", ap->name, ap->u.value);
  1939. }
  1940. else {
  1941. agxbprint (xb, "%s %s", ap->name, ap->u.value);
  1942. }
  1943. }
  1944. static void
  1945. deparseList (Dt_t* alist, agxbuf* xb)
  1946. {
  1947. gmlattr* ap;
  1948. agxbput (xb, "[ ");
  1949. if (alist) for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  1950. deparseAttr (ap, xb);
  1951. agxbputc (xb, ' ');
  1952. }
  1953. agxbput (xb, "]");
  1954. }
  1955. static void
  1956. unknown (Agobj_t* obj, gmlattr* ap, agxbuf* xb)
  1957. {
  1958. char* str;
  1959. if (ap->kind == LIST) {
  1960. deparseList (ap->u.lp, xb);
  1961. str = agxbuse (xb);
  1962. }
  1963. else
  1964. str = ap->u.value;
  1965. agsafeset (obj, ap->name, str, "");
  1966. }
  1967. static void addNodeLabelGraphics(Agnode_t* np, Dt_t* alist, agxbuf* unk) {
  1968. gmlattr* ap;
  1969. int cnt = 0;
  1970. if (!alist)
  1971. return;
  1972. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  1973. if (ap->sort == TEXT) {
  1974. agsafeset (np, "label", ap->u.value, "");
  1975. }
  1976. else if (ap->sort == COLOR) {
  1977. agsafeset (np, "fontcolor", ap->u.value, "");
  1978. }
  1979. else if (ap->sort == FONTSIZE) {
  1980. agsafeset (np, "fontsize", ap->u.value, "");
  1981. }
  1982. else if (ap->sort == FONTNAME) {
  1983. agsafeset (np, "fontname", ap->u.value, "");
  1984. }
  1985. else {
  1986. if (cnt)
  1987. agxbputc (unk, ' ');
  1988. else {
  1989. agxbput (unk, "[ ");
  1990. }
  1991. deparseAttr (ap, unk);
  1992. cnt++;
  1993. }
  1994. }
  1995. if (cnt) {
  1996. agxbput (unk, " ]");
  1997. agsafeset (np, "LabelGraphics", agxbuse (unk), "");
  1998. }
  1999. else
  2000. agxbclear (unk);
  2001. }
  2002. static void
  2003. addEdgeLabelGraphics (Agedge_t* ep, Dt_t* alist, agxbuf* xb, agxbuf* unk)
  2004. {
  2005. gmlattr* ap;
  2006. char* x = "0";
  2007. char* y = "0";
  2008. int cnt = 0;
  2009. if (!alist)
  2010. return;
  2011. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  2012. if (ap->sort == TEXT) {
  2013. agsafeset (ep, "label", ap->u.value, "");
  2014. }
  2015. else if (ap->sort == COLOR) {
  2016. agsafeset (ep, "fontcolor", ap->u.value, "");
  2017. }
  2018. else if (ap->sort == FONTSIZE) {
  2019. agsafeset (ep, "fontsize", ap->u.value, "");
  2020. }
  2021. else if (ap->sort == FONTNAME) {
  2022. agsafeset (ep, "fontname", ap->u.value, "");
  2023. }
  2024. else if (ap->sort == XVAL) {
  2025. x = ap->u.value;
  2026. }
  2027. else if (ap->sort == YVAL) {
  2028. y = ap->u.value;
  2029. }
  2030. else {
  2031. if (cnt)
  2032. agxbputc (unk, ' ');
  2033. else {
  2034. agxbput (unk, "[ ");
  2035. }
  2036. deparseAttr (ap, unk);
  2037. cnt++;
  2038. }
  2039. }
  2040. agxbprint (xb, "%s,%s", x, y);
  2041. agsafeset (ep, "lp", agxbuse (xb), "");
  2042. if (cnt) {
  2043. agxbput (unk, " ]");
  2044. agsafeset (ep, "LabelGraphics", agxbuse (unk), "");
  2045. }
  2046. else
  2047. agxbclear (unk);
  2048. }
  2049. static void
  2050. addNodeGraphics (Agnode_t* np, Dt_t* alist, agxbuf* xb, agxbuf* unk)
  2051. {
  2052. gmlattr* ap;
  2053. char* x = "0";
  2054. char* y = "0";
  2055. char buf[BUFSIZ];
  2056. double d;
  2057. int cnt = 0;
  2058. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  2059. if (ap->sort == XVAL) {
  2060. x = ap->u.value;
  2061. }
  2062. else if (ap->sort == YVAL) {
  2063. y = ap->u.value;
  2064. }
  2065. else if (ap->sort == WVAL) {
  2066. d = atof (ap->u.value);
  2067. snprintf(buf, sizeof(buf), "%.04f", d/72.0);
  2068. agsafeset (np, "width", buf, "");
  2069. }
  2070. else if (ap->sort == HVAL) {
  2071. d = atof (ap->u.value);
  2072. snprintf(buf, sizeof(buf), "%.04f", d/72.0);
  2073. agsafeset (np, "height", buf, "");
  2074. }
  2075. else if (ap->sort == TYPE) {
  2076. agsafeset (np, "shape", ap->u.value, "");
  2077. }
  2078. else if (ap->sort == FILL) {
  2079. agsafeset (np, "color", ap->u.value, "");
  2080. }
  2081. else if (ap->sort == OUTLINE) {
  2082. agsafeset (np, "pencolor", ap->u.value, "");
  2083. }
  2084. else if (ap->sort == WIDTH || ap->sort == OUTLINEWIDTH) {
  2085. agsafeset (np, "penwidth", ap->u.value, "");
  2086. }
  2087. else if (ap->sort == STYLE || ap->sort == OUTLINESTYLE) {
  2088. agsafeset (np, "style", ap->u.value, "");
  2089. }
  2090. else {
  2091. if (cnt)
  2092. agxbputc (unk, ' ');
  2093. else {
  2094. agxbput (unk, "[ ");
  2095. }
  2096. deparseAttr (ap, unk);
  2097. cnt++;
  2098. }
  2099. }
  2100. agxbprint (xb, "%s,%s", x, y);
  2101. agsafeset (np, "pos", agxbuse (xb), "");
  2102. if (cnt) {
  2103. agxbput (unk, " ]");
  2104. agsafeset (np, "graphics", agxbuse (unk), "");
  2105. }
  2106. else
  2107. agxbclear (unk);
  2108. }
  2109. static void
  2110. addEdgePoint (Agedge_t* ep, Dt_t* alist, agxbuf* xb)
  2111. {
  2112. gmlattr* ap;
  2113. char* x = "0";
  2114. char* y = "0";
  2115. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  2116. if (ap->sort == XVAL) {
  2117. x = ap->u.value;
  2118. }
  2119. else if (ap->sort == YVAL) {
  2120. y = ap->u.value;
  2121. }
  2122. else {
  2123. fprintf (stderr, "non-X/Y field in point attribute");
  2124. unknown ((Agobj_t*)ep, ap, xb);
  2125. }
  2126. }
  2127. if (agxblen(xb)) agxbputc (xb, ' ');
  2128. agxbprint (xb, "%s,%s", x, y);
  2129. }
  2130. static void
  2131. addEdgePos (Agedge_t* ep, Dt_t* alist, agxbuf* xb)
  2132. {
  2133. gmlattr* ap;
  2134. if (!alist) return;
  2135. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  2136. if (ap->sort == POINT) {
  2137. addEdgePoint (ep, ap->u.lp, xb);
  2138. }
  2139. else {
  2140. fprintf (stderr, "non-point field in line attribute");
  2141. unknown ((Agobj_t*)ep, ap, xb);
  2142. }
  2143. }
  2144. agsafeset (ep, "pos", agxbuse (xb), "");
  2145. }
  2146. static void
  2147. addEdgeGraphics (Agedge_t* ep, Dt_t* alist, agxbuf* xb, agxbuf* unk)
  2148. {
  2149. gmlattr* ap;
  2150. int cnt = 0;
  2151. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  2152. if (ap->sort == WIDTH) {
  2153. agsafeset (ep, "penwidth", ap->u.value, "");
  2154. }
  2155. else if (ap->sort == STYLE) {
  2156. agsafeset (ep, "style", ap->u.value, "");
  2157. }
  2158. else if (ap->sort == FILL) {
  2159. agsafeset (ep, "color", ap->u.value, "");
  2160. }
  2161. else if (ap->sort == LINE) {
  2162. addEdgePos (ep, ap->u.lp, xb);
  2163. }
  2164. else {
  2165. if (cnt)
  2166. agxbputc (unk, ' ');
  2167. else {
  2168. agxbput (unk, "[ ");
  2169. }
  2170. deparseAttr (ap, unk);
  2171. cnt++;
  2172. }
  2173. }
  2174. if (cnt) {
  2175. agxbput (unk, " ]");
  2176. agsafeset (ep, "graphics", agxbuse (unk), "");
  2177. }
  2178. else
  2179. agxbclear(unk);
  2180. }
  2181. static void
  2182. addAttrs (Agobj_t* obj, Dt_t* alist, agxbuf* xb, agxbuf* unk)
  2183. {
  2184. gmlattr* ap;
  2185. for (ap = dtfirst(alist); ap; ap = dtnext (alist, ap)) {
  2186. if (ap->sort == GRAPHICS) {
  2187. if (AGTYPE(obj) == AGNODE)
  2188. addNodeGraphics ((Agnode_t*)obj, ap->u.lp, xb, unk);
  2189. else if (AGTYPE(obj) == AGEDGE)
  2190. addEdgeGraphics ((Agedge_t*)obj, ap->u.lp, xb, unk);
  2191. else
  2192. unknown (obj, ap, xb);
  2193. }
  2194. else if (ap->sort == LABELGRAPHICS) {
  2195. if (AGTYPE(obj) == AGNODE)
  2196. addNodeLabelGraphics ((Agnode_t*)obj, ap->u.lp, unk);
  2197. else if (AGTYPE(obj) == AGEDGE)
  2198. addEdgeLabelGraphics ((Agedge_t*)obj, ap->u.lp, xb, unk);
  2199. else
  2200. unknown (obj, ap, xb);
  2201. }
  2202. else
  2203. unknown (obj, ap, xb);
  2204. }
  2205. }
  2206. static Agraph_t *mkGraph(gmlgraph *graph, Agraph_t *parent, char *name,
  2207. agxbuf *xb, agxbuf *unk) {
  2208. Agraph_t* g;
  2209. Agnode_t* n;
  2210. Agnode_t* h;
  2211. Agedge_t* e;
  2212. gmlnode* np;
  2213. gmledge* ep;
  2214. gmlgraph* gp;
  2215. if (parent) {
  2216. g = agsubg (parent, NULL, 1);
  2217. }
  2218. else if (graph->directed >= 1)
  2219. g = agopen (name, Agdirected, 0);
  2220. else
  2221. g = agopen (name, Agundirected, 0);
  2222. if (!parent && L) {
  2223. addAttrs ((Agobj_t*)g, L, xb, unk);
  2224. }
  2225. for (np = dtfirst(graph->nodelist); np; np = dtnext(graph->nodelist, np)) {
  2226. if (!np->id) {
  2227. fprintf (stderr, "node without an id attribute");
  2228. graphviz_exit (1);
  2229. }
  2230. n = agnode (g, np->id, 1);
  2231. addAttrs ((Agobj_t*)n, np->attrlist, xb, unk);
  2232. }
  2233. for (ep = dtfirst(graph->edgelist); ep; ep = dtnext(graph->edgelist, ep)) {
  2234. if (!ep->source) {
  2235. fprintf (stderr, "edge without an source attribute");
  2236. graphviz_exit (1);
  2237. }
  2238. if (!ep->target) {
  2239. fprintf (stderr, "node without an target attribute");
  2240. graphviz_exit (1);
  2241. }
  2242. n = agnode (g, ep->source, 1);
  2243. h = agnode (g, ep->target, 1);
  2244. e = agedge (g, n, h, NULL, 1);
  2245. addAttrs ((Agobj_t*)e, ep->attrlist, xb, unk);
  2246. }
  2247. for (gp = dtfirst(graph->graphlist); gp; gp = dtnext(graph->graphlist, gp)) {
  2248. mkGraph (gp, g, NULL, xb, unk);
  2249. }
  2250. addAttrs ((Agobj_t*)g, graph->attrlist, xb, unk);
  2251. return g;
  2252. }
  2253. Agraph_t*
  2254. gml_to_gv (char* name, FILE* fp, int cnt, int* errors)
  2255. {
  2256. Agraph_t* g;
  2257. int error;
  2258. if (cnt == 0)
  2259. initgmlscan(fp);
  2260. else
  2261. initgmlscan(0);
  2262. L = NULL;
  2263. pushAlist ();
  2264. gmlparse ();
  2265. error = gmlerrors();
  2266. *errors |= error;
  2267. if (!G || error)
  2268. g = NULL;
  2269. else {
  2270. agxbuf xb = {0};
  2271. agxbuf unk = {0};
  2272. g = mkGraph (G, NULL, name, &xb, &unk);
  2273. agxbfree (&xb);
  2274. agxbfree(&unk);
  2275. }
  2276. cleanup ();
  2277. return g;
  2278. }
  2279. static char *sortToStr(unsigned short sort) {
  2280. char* s;
  2281. switch (sort) {
  2282. case GRAPH :
  2283. s = "graph"; break;
  2284. case NODE :
  2285. s = "node"; break;
  2286. case EDGE :
  2287. s = "edge"; break;
  2288. case DIRECTED :
  2289. s = "directed"; break;
  2290. case ID :
  2291. s = "id"; break;
  2292. case SOURCE :
  2293. s = "source"; break;
  2294. case TARGET :
  2295. s = "target"; break;
  2296. case XVAL :
  2297. s = "xval"; break;
  2298. case YVAL :
  2299. s = "yval"; break;
  2300. case WVAL :
  2301. s = "wval"; break;
  2302. case HVAL :
  2303. s = "hval"; break;
  2304. case LABEL :
  2305. s = "label"; break;
  2306. case GRAPHICS :
  2307. s = "graphics"; break;
  2308. case LABELGRAPHICS :
  2309. s = "labelGraphics"; break;
  2310. case TYPE :
  2311. s = "type"; break;
  2312. case FILL :
  2313. s = "fill"; break;
  2314. case OUTLINE :
  2315. s = "outline"; break;
  2316. case OUTLINESTYLE :
  2317. s = "outlineStyle"; break;
  2318. case OUTLINEWIDTH :
  2319. s = "outlineWidth"; break;
  2320. case WIDTH :
  2321. s = "width"; break;
  2322. case STYLE :
  2323. s = "style"; break;
  2324. case LINE :
  2325. s = "line"; break;
  2326. case POINT :
  2327. s = "point"; break;
  2328. case TEXT :
  2329. s = "text"; break;
  2330. case FONTSIZE :
  2331. s = "fontSize"; break;
  2332. case FONTNAME :
  2333. s = "fontName"; break;
  2334. case COLOR :
  2335. s = "color"; break;
  2336. case INTEGER :
  2337. s = "integer"; break;
  2338. case REAL :
  2339. s = "real"; break;
  2340. case STRING :
  2341. s = "string"; break;
  2342. case NAME :
  2343. s = "name"; break;
  2344. case LIST :
  2345. s = "list"; break;
  2346. case '[' :
  2347. s = "["; break;
  2348. case ']' :
  2349. s = "]"; break;
  2350. default :
  2351. s = NULL;break;
  2352. }
  2353. return s;
  2354. }