Lpars.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /* LLgen generated code from source . */
  2. #include "Lpars.h"
  3. #define LLNOFIRSTS
  4. #if __STDC__ || __cplusplus
  5. #define LL_ANSI_C 1
  6. #endif
  7. #define LL_LEXI scanner
  8. /* $Id$ */
  9. #ifdef LL_DEBUG
  10. #include <assert.h>
  11. #include <stdio.h>
  12. #define LL_assert(x) assert(x)
  13. #else
  14. #define LL_assert(x) /* nothing */
  15. #endif
  16. extern int LLsymb;
  17. #define LL_SAFE(x) /* Nothing */
  18. #define LL_SSCANDONE(x) if (LLsymb != x) LLsafeerror(x)
  19. #define LL_SCANDONE(x) if (LLsymb != x) LLerror(x)
  20. #define LL_NOSCANDONE(x) LLscan(x)
  21. #ifdef LL_FASTER
  22. #define LLscan(x) if ((LLsymb = LL_LEXI()) != x) LLerror(x)
  23. #endif
  24. extern unsigned int LLscnt[];
  25. extern unsigned int LLtcnt[];
  26. extern int LLcsymb;
  27. #if LL_NON_CORR
  28. extern int LLstartsymb;
  29. #endif
  30. #define LLsdecr(d) {LL_assert(LLscnt[d] > 0); LLscnt[d]--;}
  31. #define LLtdecr(d) {LL_assert(LLtcnt[d] > 0); LLtcnt[d]--;}
  32. #define LLsincr(d) LLscnt[d]++
  33. #define LLtincr(d) LLtcnt[d]++
  34. #if LL_ANSI_C
  35. extern int LL_LEXI(void);
  36. extern void LLread(void);
  37. extern int LLskip(void);
  38. extern int LLnext(int);
  39. extern void LLerror(int);
  40. extern void LLsafeerror(int);
  41. extern void LLnewlevel(unsigned int *);
  42. extern void LLoldlevel(unsigned int *);
  43. #ifndef LL_FASTER
  44. extern void LLscan(int);
  45. #endif
  46. #ifndef LLNOFIRSTS
  47. extern int LLfirst(int, int);
  48. #endif
  49. #if LL_NON_CORR
  50. extern void LLnc_recover(void);
  51. #endif
  52. #else /* not LL_ANSI_C */
  53. extern LLread();
  54. extern int LLskip();
  55. extern int LLnext();
  56. extern LLerror();
  57. extern LLsafeerror();
  58. extern LLnewlevel();
  59. extern LLoldlevel();
  60. #ifndef LL_FASTER
  61. extern LLscan();
  62. #endif
  63. #ifndef LLNOFIRSTS
  64. extern int LLfirst();
  65. #endif
  66. #if LL_NON_CORR
  67. extern LLnc_recover();
  68. #endif
  69. #endif /* not LL_ANSI_C */
  70. #define LL_SSIZE 4
  71. #define LL_NSETS 6
  72. #define LL_NTERMINALS 32
  73. #if LL_ANSI_C
  74. void LL0_spec(void);
  75. #endif
  76. #if LL_ANSI_C
  77. void LLparse(void)
  78. #else
  79. LLparse()
  80. #endif
  81. {
  82. unsigned int s[LL_NTERMINALS+LL_NSETS+2];
  83. LLnewlevel(s);
  84. LLread();
  85. LL0_spec();
  86. LL_SCANDONE(EOFILE);
  87. LLoldlevel(s);
  88. }
  89. static char LLsets[] = {
  90. '\204','\343','\1','\0',
  91. '\234','\4','\176','\354',
  92. '\0','\4','\6','\0',
  93. '\234','\0','\60','\350',
  94. '\10','\0','\0','\340',
  95. '\124','\0','\0','\0',
  96. 0 };
  97. #define LLindex (LL_index+1)
  98. static short LL_index[] = {0,0,
  99. -1,
  100. -1,
  101. -1,
  102. -1,
  103. -1,
  104. -1,
  105. -1,
  106. -1,
  107. -1,
  108. -1,
  109. -1,
  110. -1,
  111. -1,
  112. -1,
  113. -1,
  114. -1,
  115. -1,
  116. -1,
  117. -1,
  118. -1,
  119. -1,
  120. -1,
  121. -1,
  122. -1,
  123. -1,
  124. -1,
  125. -1,
  126. -1,
  127. -1,
  128. -1,
  129. -1,
  130. -1,
  131. -1,
  132. -1,
  133. -1,
  134. -1,
  135. -1,
  136. -1,
  137. -1,
  138. -1,
  139. -1,
  140. 30,
  141. 31,
  142. 23,
  143. -1,
  144. -1,
  145. -1,
  146. -1,
  147. -1,
  148. -1,
  149. -1,
  150. -1,
  151. -1,
  152. -1,
  153. -1,
  154. -1,
  155. -1,
  156. 25,
  157. 24,
  158. -1,
  159. -1,
  160. -1,
  161. 29,
  162. -1,
  163. -1,
  164. -1,
  165. -1,
  166. -1,
  167. -1,
  168. -1,
  169. -1,
  170. -1,
  171. -1,
  172. -1,
  173. -1,
  174. -1,
  175. -1,
  176. -1,
  177. -1,
  178. -1,
  179. -1,
  180. -1,
  181. -1,
  182. -1,
  183. -1,
  184. -1,
  185. -1,
  186. -1,
  187. -1,
  188. -1,
  189. 27,
  190. -1,
  191. 28,
  192. -1,
  193. -1,
  194. -1,
  195. -1,
  196. -1,
  197. -1,
  198. -1,
  199. -1,
  200. -1,
  201. -1,
  202. -1,
  203. -1,
  204. -1,
  205. -1,
  206. -1,
  207. -1,
  208. -1,
  209. -1,
  210. -1,
  211. -1,
  212. -1,
  213. -1,
  214. -1,
  215. -1,
  216. -1,
  217. -1,
  218. -1,
  219. -1,
  220. -1,
  221. -1,
  222. 26,
  223. -1,
  224. -1,
  225. -1,
  226. -1,
  227. -1,
  228. -1,
  229. -1,
  230. -1,
  231. -1,
  232. -1,
  233. -1,
  234. -1,
  235. -1,
  236. -1,
  237. -1,
  238. -1,
  239. -1,
  240. -1,
  241. -1,
  242. -1,
  243. -1,
  244. -1,
  245. -1,
  246. -1,
  247. -1,
  248. -1,
  249. -1,
  250. -1,
  251. -1,
  252. -1,
  253. -1,
  254. -1,
  255. -1,
  256. -1,
  257. -1,
  258. -1,
  259. -1,
  260. -1,
  261. -1,
  262. -1,
  263. -1,
  264. -1,
  265. -1,
  266. -1,
  267. -1,
  268. -1,
  269. -1,
  270. -1,
  271. -1,
  272. -1,
  273. -1,
  274. -1,
  275. -1,
  276. -1,
  277. -1,
  278. -1,
  279. -1,
  280. -1,
  281. -1,
  282. -1,
  283. -1,
  284. -1,
  285. -1,
  286. -1,
  287. -1,
  288. -1,
  289. -1,
  290. -1,
  291. -1,
  292. -1,
  293. -1,
  294. -1,
  295. -1,
  296. -1,
  297. -1,
  298. -1,
  299. -1,
  300. -1,
  301. -1,
  302. -1,
  303. -1,
  304. -1,
  305. -1,
  306. -1,
  307. -1,
  308. -1,
  309. -1,
  310. -1,
  311. -1,
  312. -1,
  313. -1,
  314. -1,
  315. -1,
  316. -1,
  317. -1,
  318. -1,
  319. -1,
  320. -1,
  321. -1,
  322. -1,
  323. -1,
  324. -1,
  325. -1,
  326. -1,
  327. -1,
  328. -1,
  329. -1,
  330. -1,
  331. -1,
  332. -1,
  333. -1,
  334. -1,
  335. -1,
  336. -1,
  337. -1,
  338. -1,
  339. -1,
  340. -1,
  341. -1,
  342. -1,
  343. -1,
  344. -1,
  345. -1,
  346. -1,
  347. -1,
  348. -1,
  349. -1,
  350. -1,
  351. -1,
  352. -1,
  353. -1,
  354. 0,
  355. 1,
  356. 2,
  357. 3,
  358. 4,
  359. 5,
  360. 6,
  361. 7,
  362. 8,
  363. 9,
  364. 10,
  365. 11,
  366. 12,
  367. 13,
  368. 14,
  369. 15,
  370. 16,
  371. 17,
  372. 18,
  373. 19,
  374. 20,
  375. 21,
  376. 22,
  377. 0 };
  378. #define LL_NEWMESS
  379. /*
  380. * Some grammar independent code.
  381. * This file is copied into Lpars.c.
  382. */
  383. unsigned int LLtcnt[LL_NTERMINALS];
  384. unsigned int LLscnt[LL_NSETS];
  385. int LLcsymb, LLsymb;
  386. static int LLlevel;
  387. #if LL_NON_CORR
  388. int LLstartsymb;
  389. static int fake_eof = 0;
  390. #endif
  391. #if LL_ANSI_C
  392. #define LL_VOIDCST (void)
  393. void LLmessage(int);
  394. #else
  395. #define LL_VOIDCST
  396. #endif
  397. #ifdef LL_USERHOOK
  398. #if LL_ANSI_C
  399. static int LLdoskip(int);
  400. static int LLuserhook(int, int*);
  401. #else
  402. static int LLdoskip();
  403. static int LLuserhook();
  404. #endif
  405. #endif
  406. #ifndef LL_FASTER
  407. #if LL_ANSI_C
  408. void LLscan(int t)
  409. #else
  410. LLscan(t)
  411. int t;
  412. #endif
  413. {
  414. /*
  415. * Check if the next symbol is equal to the parameter
  416. */
  417. #if LL_NON_CORR
  418. /* See if the error recovery has eaten an eof */
  419. if (fake_eof) {
  420. LLsymb = EOFILE;
  421. fake_eof = 0;
  422. }
  423. else {
  424. LLsymb = LL_LEXI();
  425. }
  426. if (LLsymb == t) {
  427. #else
  428. if ((LLsymb = LL_LEXI()) == t) {
  429. #endif
  430. #if LL_NON_CORR
  431. /* Check if a previous parser has 'crashed', in that
  432. * case continue with non-correcting parser
  433. */
  434. if (err_seen && !nc_done) {
  435. LLnc_recover();
  436. nc_done = 1;
  437. /* Remember that the error recovery has eaten an eof */
  438. fake_eof = 1;
  439. if (t != LLsymb) {
  440. LLerror(t);
  441. }
  442. else
  443. return;
  444. }
  445. #endif
  446. return;
  447. }
  448. /*
  449. * If we come here, an error has been detected
  450. */
  451. LLerror(t);
  452. }
  453. #endif
  454. #if LL_ANSI_C
  455. void LLread(void) {
  456. #else
  457. LLread() {
  458. #endif
  459. #if LL_NON_CORR
  460. /* Again, check if another parser has crashed,
  461. * in that case intercept and go to the
  462. * non-correcting parser
  463. */
  464. if (err_seen && !nc_done) {
  465. LLnc_recover();
  466. nc_done = 1;
  467. /* Pretend we read end of file */
  468. LLsymb = EOFILE;
  469. LLcsymb = LLindex[EOFILE];
  470. fake_eof = 0;
  471. return;
  472. }
  473. if (fake_eof) {
  474. LLsymb = EOFILE;
  475. LLcsymb = LLindex[EOFILE];
  476. fake_eof = 0;
  477. return;
  478. }
  479. #endif
  480. for (;;) {
  481. if ((LLcsymb = LLindex[(LLsymb = LL_LEXI())]) >= 0) return;
  482. LLmessage(0);
  483. }
  484. /* NOTREACHED */
  485. }
  486. #if LL_ANSI_C
  487. void LLerror(int t)
  488. #else
  489. LLerror(t)
  490. int t;
  491. #endif
  492. {
  493. register int i;
  494. if (t == EOFILE && LLsymb <= 0) return;
  495. #ifdef LL_NEWMESS
  496. if (t == EOFILE) {
  497. #ifdef LL_USERHOOK
  498. static int lst[] = { EOFILE, 0 };
  499. LL_VOIDCST LLuserhook(EOFILE, lst);
  500. #endif /* LL_USERHOOK */
  501. if (LLsymb != EOFILE && LLsymb > 0) {
  502. LLmessage(-1);
  503. while ((LLsymb = LL_LEXI()) > 0 && LLsymb != EOFILE)
  504. /* nothing */ ;
  505. }
  506. return;
  507. }
  508. #endif
  509. #if LL_NON_CORR
  510. if ((!nc_done) && (LLsymb > 0) && (LLsymb != EOFILE)) {
  511. LLmessage(0);
  512. LLnc_recover();
  513. nc_done = 1;
  514. LLsymb = EOFILE;
  515. }
  516. #endif
  517. if ((LLcsymb = LLindex[LLsymb]) < 0) {
  518. LLmessage(0);
  519. LLread();
  520. }
  521. i = LLindex[t];
  522. LLtcnt[i]++;
  523. #ifdef LL_USERHOOK
  524. LL_VOIDCST LLdoskip(t);
  525. #else
  526. LL_VOIDCST LLskip();
  527. #endif
  528. LLtcnt[i]--;
  529. if (LLsymb != t) {
  530. #if LL_NON_CORR
  531. /* A little kludge here; when using non-correcting recovery
  532. * it can happen that a program is correct but incomplete.
  533. * Here, we test this, and make sure the appropriate
  534. * message is generated
  535. */
  536. if (! nc_done) {
  537. int oldLLsymb;
  538. oldLLsymb = LLsymb;
  539. LLsymb = EOFILE;
  540. LLmessage(0);
  541. nc_done = 1;
  542. /* Not really, but to prevent more than 1 error message */
  543. LLsymb = oldLLsymb;
  544. }
  545. #endif
  546. LLmessage(t);
  547. }
  548. }
  549. #if LL_ANSI_C
  550. void LLsafeerror(int t)
  551. #else
  552. LLsafeerror(t)
  553. int t;
  554. #endif
  555. {
  556. if (t == EOFILE && LLsymb <= 0) return;
  557. #ifdef LL_NEWMESS
  558. if (t == EOFILE) {
  559. #ifdef LL_USERHOOK
  560. static int lst[] = { EOFILE, 0 };
  561. LL_VOIDCST LLuserhook(EOFILE, lst);
  562. #endif /* LL_USERHOOK */
  563. if (LLsymb != EOFILE && LLsymb > 0) {
  564. LLmessage(-1);
  565. while ((LLsymb = LL_LEXI()) > 0 && LLsymb != EOFILE)
  566. /* nothing */ ;
  567. }
  568. return;
  569. }
  570. #endif
  571. #if LL_NON_CORR
  572. if ((!nc_done) && (LLsymb > 0) && (LLsymb != EOFILE)) {
  573. LLmessage(0);
  574. LLnc_recover();
  575. nc_done = 1;
  576. LLsymb = EOFILE;
  577. }
  578. /* A little kludge here; when using non-correcting recovery
  579. * it can happen that a program is correct but incomplete.
  580. * Here, we test this, and make sure the appropriate
  581. * message is generated
  582. */
  583. if (! nc_done) {
  584. int oldLLsymb;
  585. oldLLsymb = LLsymb;
  586. LLsymb = EOFILE;
  587. LLmessage(0);
  588. nc_done = 1;
  589. /* Not really, but to prevent more than 1 error message */
  590. LLsymb = oldLLsymb;
  591. }
  592. #endif
  593. LLmessage(t);
  594. }
  595. #ifndef LLNOFIRSTS
  596. #if LL_ANSI_C
  597. int LLfirst(int x, int d) {
  598. #else
  599. int LLfirst(x, d) {
  600. #endif
  601. register int i;
  602. return (i = LLindex[x]) >= 0 &&
  603. (LLsets[d + (i >> 3)] & (1 << (i & 07)));
  604. }
  605. #endif
  606. #if LL_ANSI_C
  607. int LLnext(int n)
  608. #else
  609. int LLnext(n)
  610. int n;
  611. #endif
  612. {
  613. /* returns: 0 if the current symbol is'nt skipped, and it
  614. is'nt a member of "n",
  615. 1 if we have a new symbol, but it is'nt a member,
  616. 2 if the current symbol is a member,
  617. and 3 if we have a new symbol and it is a member.
  618. So, the low order bit indicates wether we have a new symbol,
  619. and the next bit indicates wether it is a member of "n".
  620. */
  621. int retval = 0;
  622. if (LLskip()) retval = 1;
  623. if (n <= 0 && LLsets[(LLcsymb >> 3) - n] & (1 << (LLcsymb & 07))) {
  624. retval |= 2;
  625. }
  626. else if (n > 0 && LLcsymb == LLindex[n]) retval |= 2;
  627. return retval;
  628. }
  629. #if LL_ANSI_C
  630. int LLskip(void) {
  631. #else
  632. int LLskip() {
  633. #endif
  634. /* returns 0 if the current symbol is'nt skipped, and
  635. 1 if it is, t.i., we have a new symbol
  636. */
  637. #ifdef LL_USERHOOK
  638. return LLdoskip(0);
  639. }
  640. #if LL_ANSI_C
  641. extern void LL_USERHOOK(int, int *);
  642. static int LLuserhook(int e, int *list)
  643. #else
  644. static int LLuserhook(e, list)
  645. int e;
  646. int *list;
  647. #endif
  648. {
  649. int old = LLsymb;
  650. LL_USERHOOK(e, list);
  651. LLread();
  652. return LLsymb != old;
  653. }
  654. #if LL_ANSI_C
  655. static void LLmklist(register int *list)
  656. #else
  657. static LLmklist(list)
  658. register int *list;
  659. #endif
  660. {
  661. char Xset[LL_SSIZE];
  662. register char *p;
  663. register int i;
  664. for (p = &Xset[0]; p < &Xset[LL_SSIZE]; ) *p++ = 0;
  665. for (i = 0; i < LL_NTERMINALS; i++) {
  666. if (LLtcnt[i] != 0) Xset[i >> 3] |= (1 << (i & 07));
  667. }
  668. for (i = LL_NSETS - 1; i >= 0; i--) if (LLscnt[i] != 0) {
  669. register char *q = &LLsets[LL_SSIZE * i];
  670. p = &Xset[0];
  671. while (p < &Xset[LL_SSIZE]) *p++ |= *q++;
  672. }
  673. for (i = 0; i < LL_NTERMINALS; i++) {
  674. if (Xset[i >> 3] & (1 << (i & 07))) {
  675. *list++ = LLtok[i];
  676. }
  677. }
  678. *list = 0;
  679. }
  680. #if LL_ANSI_C
  681. static int LLdoskip(int e)
  682. #else
  683. static int LLdoskip(e)
  684. int e;
  685. #endif
  686. {
  687. int LLx;
  688. int list[LL_NTERMINALS+1];
  689. #endif /* LL_USERHOOK */
  690. register int i;
  691. int retval;
  692. int LLi, LLb;
  693. retval = 0;
  694. #ifdef LL_USERHOOK
  695. LLmklist(list);
  696. LLx = LLuserhook(e, list);
  697. if (LLx) retval = 1;
  698. #endif /* LL_USERHOOK */
  699. for (;;) {
  700. if (LLtcnt[LLcsymb] != 0) {
  701. #ifdef LL_USERHOOK
  702. if (!e || !LLx || LLcsymb == LLindex[e])
  703. #endif
  704. return retval;
  705. }
  706. LLi = LLcsymb >> 3;
  707. LLb = 1 << (LLcsymb & 07);
  708. for (i = LL_NSETS - 1; i >= 0; i--) {
  709. if (LLscnt[i] != 0) {
  710. if (LLsets[LL_SSIZE*i+LLi] & LLb) {
  711. #ifdef LL_USERHOOK
  712. if (!e || !LLx || LLcsymb == LLindex[e])
  713. #endif
  714. return retval;
  715. }
  716. }
  717. }
  718. #ifdef LL_USERHOOK
  719. if (LLx) {
  720. LLx = LLuserhook(e, list);
  721. continue;
  722. }
  723. #endif /* LL_USERHOOK */
  724. #if LL_NON_CORR
  725. if ((!nc_done) && (LLsymb > 0)) {
  726. LLmessage(0);
  727. LLnc_recover();
  728. nc_done = 1;
  729. fake_eof = 1;
  730. }
  731. else {
  732. LLmessage(0);
  733. }
  734. #else
  735. LLmessage(0);
  736. #endif
  737. retval = 1;
  738. LLread();
  739. }
  740. /* NOTREACHED */
  741. }
  742. #if LL_ANSI_C
  743. void LLnewlevel(unsigned int *LLsinfo) {
  744. #else
  745. LLnewlevel(LLsinfo) unsigned int *LLsinfo; {
  746. #endif
  747. register int i;
  748. if (LLlevel++) {
  749. LLsinfo[LL_NSETS+LL_NTERMINALS] = (unsigned) LLsymb;
  750. LLsinfo[LL_NSETS+LL_NTERMINALS+1] = (unsigned) LLcsymb;
  751. for (i = LL_NTERMINALS - 1; i >= 0; i--) {
  752. LLsinfo[i] = LLtcnt[i];
  753. LLtcnt[i] = 0;
  754. }
  755. for (i = LL_NSETS - 1; i >= 0; i--) {
  756. LLsinfo[LL_NTERMINALS+i] = LLscnt[i];
  757. LLscnt[i] = 0;
  758. }
  759. }
  760. LLtincr(0);
  761. }
  762. #if LL_ANSI_C
  763. void LLoldlevel(unsigned int *LLsinfo) {
  764. #else
  765. LLoldlevel(LLsinfo) unsigned int *LLsinfo; {
  766. #endif
  767. register int i;
  768. LLtdecr(0);
  769. #ifdef LL_DEBUG
  770. for (i = 0; i < LL_NTERMINALS; i++) LL_assert(LLtcnt[i] == 0);
  771. for (i = 0; i < LL_NSETS; i++) LL_assert(LLscnt[i] == 0);
  772. #endif
  773. if (--LLlevel) {
  774. for (i = LL_NSETS - 1; i >= 0; i--) {
  775. LLscnt[i] = LLsinfo[LL_NTERMINALS+i];
  776. }
  777. for (i = LL_NTERMINALS - 1; i >= 0; i--) {
  778. LLtcnt[i] = LLsinfo[i];
  779. }
  780. LLsymb = (int) LLsinfo[LL_NSETS+LL_NTERMINALS];
  781. LLcsymb = (int) LLsinfo[LL_NSETS+LL_NTERMINALS+1];
  782. }
  783. }