home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource5 / 310_01 / lexyy.c < prev    next >
Text File  |  1990-04-20  |  22KB  |  1,116 lines

  1. /* # include "stdio.h"     */
  2. # define U(x) x
  3. # define NLSTATE yyprevious=YYNEWLINE
  4. # define BEGIN yybgin = yysvec + 1 +
  5. # define INITIAL 0
  6. # define YYLERR yysvec
  7. # define YYSTATE (yyestate-yysvec-1)
  8. # define YYOPTIM 1
  9. # define YYLMAX 200
  10. # define output(c) putc(c,yyout)
  11. # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
  12. # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
  13. # define yymore() (yymorfg=1)
  14. # define ECHO fprintf(yyout, "%s",yytext)
  15. # define REJECT { nstr = yyreject(); goto yyfussy;}
  16. int yyleng; extern char yytext[];
  17. int yymorfg;
  18. extern char *yysptr, yysbuf[];
  19. int yytchar;
  20. FILE *yyin ={stdin}, *yyout ={stdout};
  21. extern int yylineno;
  22. struct yysvf { 
  23.     struct yywork *yystoff;
  24.     struct yysvf *yyother;
  25.     int *yystops;};
  26. struct yysvf *yyestate;
  27. extern struct yysvf yysvec[], *yybgin;
  28. /*
  29.         Little Smalltalk lexical analyzer
  30. */
  31. # include <math.h>
  32. # include "primnum.h"
  33.  
  34. # undef input
  35. # undef unput
  36.  
  37. double atof();
  38. int linenum = 1;
  39. # define YYNEWLINE 10
  40. yylex(){
  41. int nstr; extern int yyprevious;
  42. while((nstr = yylook()) >= 0)
  43. yyfussy: switch(nstr){
  44. case 0:
  45. if(yywrap()) return(0); break;
  46. case 1:
  47.                          {;}
  48. break;
  49. case 2:
  50.                              {linenum++;}
  51. break;
  52. case 3:
  53.                              {readcomment();}
  54. break;
  55. case 4:
  56.                            {return(ASSIGN);}
  57. break;
  58. case 5:
  59.                            {return(ASSIGN);}
  60. break;
  61. case 6:
  62.                           {return(lexsave(CLASS));}
  63. break;
  64. case 7:
  65.                            {yylval.p = selfvar;  return(PSEUDO);}
  66. break;
  67. case 8:
  68.         {yylval.p = procvar;  return(PSEUDO);}
  69. break;
  70. case 9:
  71.                           {yylval.p = supervar; return(PSEUDO);}
  72. break;
  73. case 10:
  74.                             {yylval.p = nilvar;   return(PSEUDO);}
  75. break;
  76. case 11:
  77.                            {yylval.p = truevar;  return(PSEUDO);}
  78. break;
  79. case 12:
  80.                           {yylval.p = falsevar; return(PSEUDO);}
  81. break;
  82. case 13:
  83.                       {yylval.p = smallvar; return(PSEUDO);}
  84. break;
  85. case 14:
  86.                             {yylval.i = yytext[1]; return(LITCHAR);}
  87. break;
  88. case 15:
  89.                               {return(PS);}
  90. break;
  91. case 16:
  92. {return(lexsave(LITFNUM));}
  93. break;
  94. case 17:
  95.                          {yylval.i = atoi(yytext); return(LITNUM);}
  96. break;
  97. case 18:
  98.   {return(lexsave(LITFNUM));}
  99. break;
  100. case 19:
  101.                         {char c; unput(c = input());
  102.                                  if (c == '\'') yymore();
  103.                                  else return(lexlstr());}
  104. break;
  105. case 20:
  106.                  {return(varlex());}
  107. break;
  108. case 21:
  109.                   {return(slexsave(COLONVAR));}
  110. break;
  111. case 22:
  112.                 {return(slexsave(LITSYM));}
  113. break;
  114. case 23:
  115.                             {return(lexsave(MINUS));}
  116. break;
  117. case 24:
  118.                             {return(LP);}
  119. break;
  120. case 25:
  121.                             {return(RP);}
  122. break;
  123. case 26:
  124.                             {return(LB);}
  125. break;
  126. case 27:
  127.                             {return(RB);}
  128. break;
  129. case 28:
  130.                             {return(PERIOD);}
  131. break;
  132. case 29:
  133.             {return(lexsave(MBAR));}
  134. break;
  135. case 30:
  136.             {return(lexsave(MBAR));}
  137. break;
  138. case 31:
  139.                             {return(lexsave(BAR));}
  140. break;
  141. case 32:
  142.                             {return(lexsave(BAR));}
  143. break;
  144. case 33:
  145.                             {return(SEMI);}
  146. break;
  147. case 34:
  148.                             {return(lexsave(UPARROW));}
  149. break;
  150. case 35:
  151.             {return(lexsave(PE));}
  152. break;
  153. case 36:
  154.               {return(lexsave(BINARY));}
  155. break;
  156. case 37:
  157.               {return(PRIMITIVE);}
  158. break;
  159. case 38:
  160.         {yylval.i = prim_number(&yytext[1]); return(NAMEDPRIM);}
  161. break;
  162. case -1:
  163. break;
  164. default:
  165. fprintf(yyout,"bad switch yylook %d",nstr);
  166. } return(0); }
  167. /* end of yylex */
  168. static int ocbuf = 0;
  169. static int pbbuf[400];
  170.  
  171. static int input()
  172. {    int c;
  173.  
  174.     if (ocbuf) {c = pbbuf[--ocbuf]; }
  175.     else {
  176.         c = getc(fp);
  177.         if (c == EOF) c = 0;
  178.         }
  179.     return(c);
  180. }
  181.  
  182. static unput(c)
  183. char c;
  184. {
  185.     if (c) pbbuf[ocbuf++] = c;
  186. }
  187.  
  188. # include <ctype.h>
  189.  
  190. static readcomment()
  191. {  char c;
  192.  
  193.    while ((c = input()) && c != '\"')
  194.     if (c == '\n') linenum++;
  195.    if (!c) yyerror("unterminated comment");
  196. }
  197.  
  198. char *walloc(s) char *s;
  199. {  char *p, *malloc();
  200.  
  201.    p = malloc((unsigned) (strlen(s) + 1));
  202.    if (p == (char *) 0) yyerror("out of variable string space");
  203.    strcpy(p, s);
  204.    return(p);
  205. }
  206.  
  207. static int slexsave(type)
  208. int type;
  209. {
  210.  
  211.     yylval.c = walloc(&yytext[1]);
  212.     if (yylval.c == 0) yerr("cannot create symbol %s", yytext);
  213.     return(type);
  214. }
  215.  
  216. static int lexsave(type)
  217. int type;
  218. {
  219.  
  220.     yylval.c = walloc(yytext);
  221.     if (yylval.c == 0) yerr("cannot create string %s", yytext);
  222.     return(type);
  223. }
  224.  
  225. static int varlex()
  226. {  
  227.  
  228.    lexsave(0);
  229.    if (yytext[yyleng-1] == ':') return(KEYWORD);
  230.    else if (islower(yytext[0])) return(LOWERCASEVAR);
  231.    else return(UPPERCASEVAR);
  232. }
  233.  
  234. static int lexlstr()
  235. {  char *p, *q;
  236.  
  237.    yylval.c = p = walloc(&yytext[1]);
  238.    *(p + yyleng -2) = '\0';
  239.    return(LITSTR);
  240. }
  241.  
  242. static int prim_number(name)
  243. char *name;
  244. {    struct prim_names *p;
  245.  
  246.     for (p = prim_table; *(p->p_name); p++) {
  247.         if (strcmp(p->p_name, name) == 0)
  248.             return(p->p_number);
  249.         }
  250.     yerr("unknown primitive name %s", name);
  251.     return(0);
  252. }
  253. int yyvstop[] ={
  254. 0,
  255.  
  256. 36,
  257. 0,
  258.  
  259. 1,
  260. 0,
  261.  
  262. 2,
  263. 0,
  264.  
  265. 32,
  266. 36,
  267. 0,
  268.  
  269. 3,
  270. 36,
  271. 0,
  272.  
  273. 15,
  274. 36,
  275. 0,
  276.  
  277. 36,
  278. 0,
  279.  
  280. 36,
  281. 0,
  282.  
  283. 24,
  284. 36,
  285. 0,
  286.  
  287. 25,
  288. 36,
  289. 0,
  290.  
  291. 23,
  292. 36,
  293. 0,
  294.  
  295. 28,
  296. 36,
  297. 0,
  298.  
  299. 17,
  300. 18,
  301. 20,
  302. 0,
  303.  
  304. 36,
  305. 0,
  306.  
  307. 33,
  308. 36,
  309. 0,
  310.  
  311. 36,
  312. 0,
  313.  
  314. 35,
  315. 36,
  316. 0,
  317.  
  318. 20,
  319. 0,
  320.  
  321. 20,
  322. 0,
  323.  
  324. 26,
  325. 36,
  326. 0,
  327.  
  328. 27,
  329. 36,
  330. 0,
  331.  
  332. 34,
  333. 36,
  334. 0,
  335.  
  336. 20,
  337. 0,
  338.  
  339. 20,
  340. 0,
  341.  
  342. 20,
  343. 0,
  344.  
  345. 20,
  346. 0,
  347.  
  348. 31,
  349. 36,
  350. 0,
  351.  
  352. 30,
  353. 32,
  354. 36,
  355. 0,
  356.  
  357. 29,
  358. 31,
  359. 36,
  360. 0,
  361.  
  362. 22,
  363. 0,
  364.  
  365. 14,
  366. 0,
  367.  
  368. 19,
  369. 0,
  370.  
  371. 20,
  372. 0,
  373.  
  374. 20,
  375. 0,
  376.  
  377. 20,
  378. 0,
  379.  
  380. 21,
  381. 0,
  382.  
  383. 4,
  384. 0,
  385.  
  386. 5,
  387. 0,
  388.  
  389. 38,
  390. 0,
  391.  
  392. 38,
  393. 0,
  394.  
  395. 20,
  396. 0,
  397.  
  398. 20,
  399. 0,
  400.  
  401. 20,
  402. 0,
  403.  
  404. 20,
  405. 0,
  406.  
  407. 20,
  408. 0,
  409.  
  410. 20,
  411. 0,
  412.  
  413. 20,
  414. 0,
  415.  
  416. 18,
  417. 0,
  418.  
  419. 18,
  420. 20,
  421. 0,
  422.  
  423. 16,
  424. 20,
  425. 0,
  426.  
  427. 38,
  428. 0,
  429.  
  430. 20,
  431. 0,
  432.  
  433. 20,
  434. 0,
  435.  
  436. 10,
  437. 20,
  438. 0,
  439.  
  440. 20,
  441. 0,
  442.  
  443. 20,
  444. 0,
  445.  
  446. 20,
  447. 0,
  448.  
  449. 20,
  450. 0,
  451.  
  452. 18,
  453. 0,
  454.  
  455. 16,
  456. 0,
  457.  
  458. 20,
  459. 0,
  460.  
  461. 38,
  462. 0,
  463.  
  464. 20,
  465. 0,
  466.  
  467. 20,
  468. 0,
  469.  
  470. 7,
  471. 20,
  472. 0,
  473.  
  474. 20,
  475. 0,
  476.  
  477. 20,
  478. 0,
  479.  
  480. 11,
  481. 20,
  482. 0,
  483.  
  484. 16,
  485. 0,
  486.  
  487. 16,
  488. 20,
  489. 0,
  490.  
  491. 38,
  492. 0,
  493.  
  494. 6,
  495. 20,
  496. 0,
  497.  
  498. 12,
  499. 20,
  500. 0,
  501.  
  502. 20,
  503. 0,
  504.  
  505. 20,
  506. 0,
  507.  
  508. 9,
  509. 20,
  510. 0,
  511.  
  512. 16,
  513. 0,
  514.  
  515. 38,
  516. 0,
  517.  
  518. 20,
  519. 0,
  520.  
  521. 20,
  522. 0,
  523.  
  524. 38,
  525. 0,
  526.  
  527. 20,
  528. 0,
  529.  
  530. 20,
  531. 0,
  532.  
  533. 38,
  534. 0,
  535.  
  536. 20,
  537. 0,
  538.  
  539. 20,
  540. 0,
  541.  
  542. 38,
  543. 0,
  544.  
  545. 20,
  546. 0,
  547.  
  548. 13,
  549. 20,
  550. 0,
  551.  
  552. 37,
  553. 38,
  554. 0,
  555.  
  556. 20,
  557. 0,
  558.  
  559. 8,
  560. 20,
  561. 0,
  562. 0};
  563. # define YYTYPE char
  564. struct yywork { YYTYPE verify, advance; } yycrank[] ={
  565. 0,0,    0,0,    1,3,    0,0,    
  566. 0,0,    0,0,    0,0,    0,0,    
  567. 0,0,    0,0,    1,4,    1,5,    
  568. 0,0,    0,0,    0,0,    4,4,    
  569. 0,0,    0,0,    0,0,    0,0,    
  570. 0,0,    0,0,    0,0,    0,0,    
  571. 0,0,    0,0,    0,0,    0,0,    
  572. 0,0,    0,0,    0,0,    0,0,    
  573. 0,0,    0,0,    1,6,    1,7,    
  574. 1,8,    1,9,    4,4,    0,0,    
  575. 1,10,    1,11,    1,12,    0,0,    
  576. 1,3,    0,0,    1,13,    1,14,    
  577. 0,0,    1,15,    0,0,    0,0,    
  578. 0,0,    0,0,    0,0,    0,0,    
  579. 0,0,    0,0,    0,0,    1,16,    
  580. 1,17,    1,18,    0,0,    1,19,    
  581. 0,0,    0,0,    1,20,    0,0,    
  582. 1,21,    0,0,    0,0,    65,53,    
  583. 0,0,    65,53,    0,0,    2,30,    
  584. 2,7,    2,8,    2,9,    0,0,    
  585. 0,0,    8,32,    0,0,    2,12,    
  586. 0,0,    0,0,    0,0,    2,13,    
  587. 2,14,    8,0,    8,0,    0,0,    
  588. 1,22,    0,0,    1,23,    1,24,    
  589. 0,0,    0,0,    1,20,    9,33,    
  590. 2,16,    2,17,    2,18,    1,25,    
  591. 2,19,    25,46,    45,58,    9,33,    
  592. 9,0,    2,21,    21,45,    1,26,    
  593. 8,0,    26,47,    46,59,    47,60,    
  594. 1,27,    1,28,    28,51,    8,32,    
  595. 8,0,    8,0,    10,34,    8,32,    
  596. 27,48,    1,29,    8,0,    44,57,    
  597. 8,32,    48,61,    10,34,    10,34,    
  598. 27,49,    2,22,    49,62,    2,23,    
  599. 2,24,    9,33,    9,33,    50,63,    
  600. 27,50,    9,33,    51,64,    52,65,    
  601. 2,25,    8,32,    9,33,    57,70,    
  602. 58,71,    59,72,    61,73,    62,74,    
  603. 2,26,    63,75,    64,76,    70,81,    
  604. 71,82,    2,27,    2,28,    67,68,    
  605. 10,35,    10,34,    72,83,    9,33,    
  606. 10,34,    73,84,    2,31,    74,85,    
  607. 75,86,    10,34,    78,77,    8,0,    
  608. 81,88,    84,89,    85,90,    88,91,    
  609. 89,92,    8,32,    90,93,    91,94,    
  610. 92,95,    93,96,    94,97,    95,98,    
  611. 96,99,    97,100,    10,34,    98,101,    
  612. 101,102,    0,0,    0,0,    0,0,    
  613. 0,0,    0,0,    0,0,    9,33,    
  614. 0,0,    0,0,    0,0,    0,0,    
  615. 15,36,    0,0,    15,15,    15,15,    
  616. 15,15,    15,15,    15,15,    15,15,    
  617. 15,15,    15,15,    15,15,    15,15,    
  618. 15,37,    0,0,    67,77,    0,0,    
  619. 0,0,    0,0,    10,34,    15,20,    
  620. 15,20,    15,20,    15,20,    15,20,    
  621. 15,20,    15,20,    15,20,