BISON.SIM 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
  2. //#ln 3 "bison.simple"
  3. /* Skeleton output parser for bison,
  4. Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  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 1, or (at your option)
  8. 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, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  16. #ifdef __GNUC__
  17. #define alloca __builtin_alloca
  18. #else /* Not GNU C. */
  19. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  20. #include <alloca.h>
  21. #endif /* Sparc. */
  22. #endif /* Not GNU C. */
  23. /* This is the parser code that is written into each bison parser
  24. when the %semantic_parser declaration is not specified in the grammar.
  25. It was written by Richard Stallman by simplifying the hairy parser
  26. used when %semantic_parser is specified. */
  27. /* Note: there must be only one dollar sign in this file.
  28. It is replaced by the list of actions, each action
  29. as one case of the switch. */
  30. #define yyerrok (yyerrstatus = 0)
  31. #define yyclearin (yychar = YYEMPTY)
  32. #define YYEMPTY -2
  33. #define YYEOF 0
  34. #define YYACCEPT return(0)
  35. #define YYABORT return(1)
  36. #define YYERROR goto yyerrlab1
  37. /* Like YYERROR except do call yyerror.
  38. This remains here temporarily to ease the
  39. transition to the new meaning of YYERROR, for GCC.
  40. Once GCC version 2 has supplanted version 1, this can go. */
  41. #define YYFAIL goto yyerrlab
  42. #define YYRECOVERING() (!!yyerrstatus)
  43. #define YYBACKUP(token, value) \
  44. do \
  45. if (yychar == YYEMPTY && yylen == 1) \
  46. { yychar = (token), yylval = (value); \
  47. yychar1 = YYTRANSLATE (yychar); \
  48. YYPOPSTACK; \
  49. goto yybackup; \
  50. } \
  51. else \
  52. { yyerror ("Syntax error, cannot back up!"); YYERROR; } \
  53. while (0)
  54. #define YYTERROR 1
  55. #define YYERRCODE 256
  56. #ifndef YYIMPURE
  57. #define YYLEX yylex()
  58. #endif
  59. #ifndef YYPURE
  60. #define YYLEX yylex(&yylval)//, &yylloc) MY MODIF!
  61. #endif
  62. /* If nonreentrant, generate the variables here */
  63. #ifndef YYIMPURE
  64. int yychar; /* the lookahead symbol */
  65. YYSTYPE yylval; /* the semantic value of the */
  66. /* lookahead symbol */
  67. #ifdef YYLSP_NEEDED
  68. YYLTYPE yylloc; /* location data for the lookahead */
  69. /* symbol */
  70. #endif
  71. int yynerrs; /* number of parse errors so far */
  72. #endif /* YYIMPURE */
  73. #if YYDEBUG != 0
  74. int yydebug; /* nonzero means print parse trace */
  75. /* Since this is uninitialized, it does not stop multiple parsers
  76. from coexisting. */
  77. #endif
  78. /* YYINITDEPTH indicates the initial size of the parser's stacks */
  79. #ifndef YYINITDEPTH
  80. #define YYINITDEPTH 200
  81. #endif
  82. /* YYMAXDEPTH is the maximum size the stacks can grow to
  83. (effective only if the built-in stack extension method is used). */
  84. #if YYMAXDEPTH == 0
  85. #undef YYMAXDEPTH
  86. #endif
  87. #ifndef YYMAXDEPTH
  88. #define YYMAXDEPTH 10000
  89. #endif
  90. /* This is the most reliable way to avoid incompatibilities
  91. in available built-in functions on various systems. */
  92. static void
  93. __yy_bcopy (from, to, count)
  94. char *from;
  95. char *to;
  96. int count;
  97. {
  98. register char *f = from;
  99. register char *t = to;
  100. register int i = count;
  101. while (i-- > 0)
  102. *t++ = *f++;
  103. }
  104. //#ln 131 "bison.simple"
  105. int
  106. yyparse()
  107. {
  108. register int yystate;
  109. register int yyn;
  110. register short *yyssp;
  111. register YYSTYPE *yyvsp;
  112. int yyerrstatus; /* number of tokens to shift before error messages enabled */
  113. int yychar1; /* lookahead token as an internal (translated) token number */
  114. short yyssa[YYINITDEPTH]; /* the state stack */
  115. YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
  116. short *yyss = yyssa; /* refer to the stacks thru separate pointers */
  117. YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
  118. #ifdef YYLSP_NEEDED
  119. YYLTYPE *yyls = yylsa;
  120. YYLTYPE *yylsp;
  121. YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
  122. #define YYPOPSTACK (yyvsp--, yysp--, yylsp--)
  123. #else
  124. #define YYPOPSTACK (yyvsp--, yysp--)
  125. #endif
  126. int yystacksize = YYINITDEPTH;
  127. #ifndef YYPURE
  128. int yychar;
  129. YYSTYPE yylval;
  130. int yynerrs;
  131. #ifdef YYLSP_NEEDED
  132. YYLTYPE yylloc;
  133. #endif
  134. #endif
  135. YYSTYPE yyval; /* the variable used to return */
  136. /* semantic values from the action */
  137. /* routines */
  138. int yylen;
  139. #if YYDEBUG != 0
  140. if (yydebug)
  141. fprintf(stderr, "Starting parse\n");
  142. #endif
  143. yystate = 0;
  144. yyerrstatus = 0;
  145. yynerrs = 0;
  146. yychar = YYEMPTY; /* Cause a token to be read. */
  147. /* Initialize stack pointers.
  148. Waste one element of value and location stack
  149. so that they stay on the same level as the state stack. */
  150. yyssp = yyss - 1;
  151. yyvsp = yyvs;
  152. #ifdef YYLSP_NEEDED
  153. yylsp = yyls;
  154. #endif
  155. /* Push a new state, which is found in yystate . */
  156. /* In all cases, when you get here, the value and location stacks
  157. have just been pushed. so pushing a state here evens the stacks. */
  158. yynewstate:
  159. *++yyssp = yystate;
  160. if (yyssp >= yyss + yystacksize - 1)
  161. {
  162. /* Give user a chance to reallocate the stack */
  163. /* Use copies of these so that the &'s don't force the real ones into memory. */
  164. YYSTYPE *yyvs1 = yyvs;
  165. short *yyss1 = yyss;
  166. #ifdef YYLSP_NEEDED
  167. YYLTYPE *yyls1 = yyls;
  168. #endif
  169. /* Get the current used size of the three stacks, in elements. */
  170. int size = yyssp - yyss + 1;
  171. #ifdef yyoverflow
  172. /* Each stack pointer address is followed by the size of
  173. the data in use in that stack, in bytes. */
  174. yyoverflow("internal error: parser stack overflow",
  175. &yyss1, size * sizeof (*yyssp),
  176. &yyvs1, size * sizeof (*yyvsp),
  177. #ifdef YYLSP_NEEDED
  178. &yyls1, size * sizeof (*yylsp),
  179. #endif
  180. &yystacksize);
  181. yyss = yyss1; yyvs = yyvs1;
  182. #ifdef YYLSP_NEEDED
  183. yyls = yyls1;
  184. #endif
  185. #else /* no yyoverflow */
  186. /* Extend the stack our own way. */
  187. if (yystacksize >= YYMAXDEPTH)
  188. {
  189. yyerror("internal error: parser stack overflow");
  190. return 2;
  191. }
  192. yystacksize *= 2;
  193. if (yystacksize > YYMAXDEPTH)
  194. yystacksize = YYMAXDEPTH;
  195. yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  196. __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  197. yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  198. __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  199. #ifdef YYLSP_NEEDED
  200. yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  201. __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  202. #endif
  203. #endif /* no yyoverflow */
  204. yyssp = yyss + size - 1;
  205. yyvsp = yyvs + size - 1;
  206. #ifdef YYLSP_NEEDED
  207. yylsp = yyls + size - 1;
  208. #endif
  209. #if YYDEBUG != 0
  210. if (yydebug)
  211. fprintf(stderr, "stack size increased to %d\n", yystacksize);
  212. #endif
  213. if (yyssp >= yyss + yystacksize - 1)
  214. YYABORT;
  215. }
  216. #if YYDEBUG != 0
  217. if (yydebug)
  218. fprintf(stderr, "entering state %d\n", yystate);
  219. #endif
  220. yybackup:
  221. /* Do appropriate processing given the current state. */
  222. /* Read a lookahead token if we need one and don't already have one. */
  223. /* yyresume: */
  224. /* First try to decide what to do without reference to lookahead token. */
  225. yyn = yypact[yystate];
  226. if (yyn == YYFLAG)
  227. goto yydefault;
  228. /* Not known => get a lookahead token if don't already have one. */
  229. /* yychar is either YYEMPTY or YYEOF
  230. or a valid token in external form. */
  231. if (yychar == YYEMPTY)
  232. {
  233. #if YYDEBUG != 0
  234. if (yydebug)
  235. fprintf(stderr, "reading a token: ");
  236. #endif
  237. yyStackSize = yyssp - (yyss - 1);
  238. yychar = YYLEX;
  239. }
  240. /* Convert token to internal form (in yychar1) for indexing tables with */
  241. if (yychar <= 0) /* This means end of input. */
  242. {
  243. yychar1 = 0;
  244. yychar = YYEOF; /* Don't call YYLEX any more */
  245. #if YYDEBUG != 0
  246. if (yydebug)
  247. fprintf(stderr, "now at end of input.\n");
  248. #endif
  249. }
  250. else
  251. {
  252. yychar1 = YYTRANSLATE(yychar);
  253. #if YYDEBUG != 0
  254. if (yydebug)
  255. fprintf(stderr, "next token is %d (%s)\n", yychar, yytname[yychar1]);
  256. #endif
  257. }
  258. yyn += yychar1;
  259. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  260. goto yydefault;
  261. yyn = yytable[yyn];
  262. /* yyn is what to do for this token type in this state.
  263. Negative => reduce, -yyn is rule number.
  264. Positive => shift, yyn is new state.
  265. New state is final state => don't bother to shift,
  266. just return success.
  267. 0, or most negative number => error. */
  268. if (yyn < 0)
  269. {
  270. if (yyn == YYFLAG)
  271. goto yyerrlab;
  272. yyn = -yyn;
  273. goto yyreduce;
  274. }
  275. else if (yyn == 0)
  276. goto yyerrlab;
  277. if (yyn == YYFINAL)
  278. YYACCEPT;
  279. /* Shift the lookahead token. */
  280. #if YYDEBUG != 0
  281. if (yydebug)
  282. fprintf(stderr, "shifting token %d (%s), ", yychar, yytname[yychar1]);
  283. #endif
  284. /* Discard the token being shifted unless it is eof. */
  285. if (yychar != YYEOF)
  286. yychar = YYEMPTY;
  287. *++yyvsp = yylval;
  288. #ifdef YYLSP_NEEDED
  289. *++yylsp = yylloc;
  290. #endif
  291. /* count tokens shifted since error; after three, turn off error status. */
  292. if (yyerrstatus) yyerrstatus--;
  293. yystate = yyn;
  294. goto yynewstate;
  295. /* Do the default action for the current state. */
  296. yydefault:
  297. yyn = yydefact[yystate];
  298. if (yyn == 0)
  299. goto yyerrlab;
  300. /* Do a reduction. yyn is the number of a rule to reduce with. */
  301. yyreduce:
  302. yylen = yyr2[yyn];
  303. yyval = yyvsp[1-yylen]; /* implement default value of the action */
  304. #if YYDEBUG != 0
  305. if (yydebug)
  306. {
  307. if (yylen == 1)
  308. fprintf (stderr, "reducing 1 value via rule %d (line %d), ",
  309. yyn, yyrline[yyn]);
  310. else
  311. fprintf (stderr, "reducing %d values via rule %d (line %d), ",
  312. yylen, yyn, yyrline[yyn]);
  313. }
  314. #endif
  315. $ /* the action file gets copied in in place of this dollarsign */
  316. //#ln 362 "bison.simple"
  317. yyvsp -= yylen;
  318. yyssp -= yylen;
  319. #ifdef YYLSP_NEEDED
  320. yylsp -= yylen;
  321. #endif
  322. #if YYDEBUG != 0
  323. if (yydebug)
  324. {
  325. short *ssp1 = yyss - 1;
  326. fprintf (stderr, "state stack now");
  327. while (ssp1 != yyssp)
  328. fprintf (stderr, " %d", *++ssp1);
  329. fprintf (stderr, "\n");
  330. }
  331. #endif
  332. *++yyvsp = yyval;
  333. #ifdef YYLSP_NEEDED
  334. yylsp++;
  335. if (yylen == 0)
  336. {
  337. yylsp->first_line = yylloc.first_line;
  338. yylsp->first_column = yylloc.first_column;
  339. yylsp->last_line = (yylsp-1)->last_line;
  340. yylsp->last_column = (yylsp-1)->last_column;
  341. yylsp->text = 0;
  342. }
  343. else
  344. {
  345. yylsp->last_line = (yylsp+yylen-1)->last_line;
  346. yylsp->last_column = (yylsp+yylen-1)->last_column;
  347. }
  348. #endif
  349. /* Now "shift" the result of the reduction.
  350. Determine what state that goes to,
  351. based on the state we popped back to
  352. and the rule number reduced by. */
  353. yyn = yyr1[yyn];
  354. yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  355. if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  356. yystate = yytable[yystate];
  357. else
  358. yystate = yydefgoto[yyn - YYNTBASE];
  359. goto yynewstate;
  360. yyerrlab: /* here on detecting error */
  361. if (! yyerrstatus)
  362. /* If not already recovering from an error, report this error. */
  363. {
  364. ++yynerrs;
  365. #ifdef YYERROR_VERBOSE
  366. yyn = yypact[yystate];
  367. if (yyn > YYFLAG && yyn < YYLAST)
  368. {
  369. int size = 0;
  370. char *msg;
  371. int x, count;
  372. count = 0;
  373. for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  374. if (yycheck[x + yyn] == x)
  375. size += strlen(yytname[x]) + 15, count++;
  376. msg = (char *) xmalloc(size + 15);
  377. strcpy(msg, "syntax error");
  378. if (count < 5)
  379. {
  380. count = 0;
  381. for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  382. if (yycheck[x + yyn] == x)
  383. {
  384. strcat(msg, count == 0 ? ", expecting `" : " or `");
  385. strcat(msg, yytname[x]);
  386. strcat(msg, "'");
  387. count++;
  388. }
  389. }
  390. yyerror(msg);
  391. free(msg);
  392. }
  393. else
  394. #endif /* YYERROR_VERBOSE */
  395. yyerror("syntax error");
  396. }
  397. yyerrlab1: /* here on error raised explicitly by an action */
  398. if (yyerrstatus == 3)
  399. {
  400. /* if just tried and failed to reuse lookahead token after an error, discard it. */
  401. /* return failure if at end of input */
  402. if (yychar == YYEOF)
  403. YYABORT;
  404. #if YYDEBUG != 0
  405. if (yydebug)
  406. fprintf(stderr, "discarding token %d (%s).\n", yychar, yytname[yychar1]);
  407. #endif
  408. yychar = YYEMPTY;
  409. }
  410. /* Else will try to reuse lookahead token
  411. after shifting the error token. */
  412. yyerrstatus = 3; /* Each real token shifted decrements this */
  413. goto yyerrhandle;
  414. yyerrdefault: /* current state does not do anything special for the error token. */
  415. #if 0
  416. /* This is wrong; only states that explicitly want error tokens
  417. should shift them. */
  418. yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
  419. if (yyn) goto yydefault;
  420. #endif
  421. yyerrpop: /* pop the current state because it cannot handle the error token */
  422. if (yyssp == yyss) YYABORT;
  423. yyvsp--;
  424. yystate = *--yyssp;
  425. #ifdef YYLSP_NEEDED
  426. yylsp--;
  427. #endif
  428. #if YYDEBUG != 0
  429. if (yydebug)
  430. {
  431. short *ssp1 = yyss - 1;
  432. fprintf (stderr, "error: state stack now");
  433. while (ssp1 != yyssp)
  434. fprintf (stderr, " %d", *++ssp1);
  435. fprintf (stderr, "\n");
  436. }
  437. #endif
  438. yyerrhandle:
  439. yyn = yypact[yystate];
  440. if (yyn == YYFLAG)
  441. goto yyerrdefault;
  442. yyn += YYTERROR;
  443. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  444. goto yyerrdefault;
  445. yyn = yytable[yyn];
  446. if (yyn < 0)
  447. {
  448. if (yyn == YYFLAG)
  449. goto yyerrpop;
  450. yyn = -yyn;
  451. goto yyreduce;
  452. }
  453. else if (yyn == 0)
  454. goto yyerrpop;
  455. if (yyn == YYFINAL)
  456. YYACCEPT;
  457. #if YYDEBUG != 0
  458. if (yydebug)
  459. fprintf(stderr, "shifting error token, ");
  460. #endif
  461. *++yyvsp = yylval;
  462. #ifdef YYLSP_NEEDED
  463. *++yylsp = yylloc;
  464. #endif
  465. yystate = yyn;
  466. goto yynewstate;
  467. }