home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d170 / dis6502.lha / Dis6502 / lex.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  9KB  |  485 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 BUFSIZ
  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. #undef ECHO
  29. #include "dis.h"
  30. #ifndef AMIGA
  31. int lineno = 0;
  32. #endif
  33. char *strcpy();
  34. # define YYNEWLINE 10
  35. yylex(){
  36. int nstr; extern int yyprevious;
  37. while((nstr = yylook()) >= 0)
  38. yyfussy: switch(nstr){
  39. case 0:
  40. if(yywrap()) return(0); break;
  41. case 1:
  42. { ; }
  43. break;
  44. case 2:
  45. {    lineno++;
  46.                 return '\n';
  47. }
  48. break;
  49. case 3:
  50.                 return EQ;
  51. }
  52. break;
  53. case 4:
  54.                 return LI;
  55. }
  56. break;
  57. case 5:
  58.                 return EQ;
  59. }
  60. break;
  61. case 6:
  62.                 return LI;
  63. }
  64. break;
  65. case 7:
  66. {
  67.                 return TSTART;
  68. }
  69. break;
  70. case 8:
  71. {
  72.                 return TSTOP;
  73. }
  74. break;
  75. case 9:
  76. {
  77.                 (void)sscanf(yytext, "%d", &token.ival); 
  78.                 return NUMBER;
  79. }
  80. break;
  81. case 10:
  82. {
  83.                 (void)sscanf(yytext+1, "%x", &token.ival);
  84.                 return NUMBER;
  85. }
  86. break;
  87. case 11:
  88. {
  89.                 token.sval = emalloc((unsigned) strlen(yytext)+1);
  90.                 (void)strcpy((char *)token.sval, (char *)yytext);
  91.                 return NAME;
  92. }
  93. break;
  94. case 12:
  95. {
  96.                 return COMMENT;
  97. }
  98. break;
  99. case 13:
  100.         { return yytext[0]; }
  101. break;
  102. case -1:
  103. break;
  104. default:
  105. fprintf(yyout,"bad switch yylook %d",nstr);
  106. } return(0); }
  107. /* end of yylex */
  108.  
  109. char *
  110. emalloc(n)
  111. unsigned n;
  112. {
  113.     char *ptr, *malloc();
  114.  
  115.     if ((ptr = malloc(n)) == (char *) 0) {
  116.         (void) fprintf(stderr,"out of core");
  117.         exit(1);
  118.     }
  119.     return ptr;
  120. }
  121. int yyvstop[] = {
  122. 0,
  123.  
  124. 13,
  125. 0,
  126.  
  127. 1,
  128. 13,
  129. 0,
  130.  
  131. 2,
  132. 0,
  133.  
  134. 13,
  135. 0,
  136.  
  137. 12,
  138. 13,
  139. 0,
  140.  
  141. 13,
  142. 0,
  143.  
  144. 9,
  145. 13,
  146. 0,
  147.  
  148. 11,
  149. 13,
  150. 0,
  151.  
  152. 10,
  153. 0,
  154.  
  155. 12,
  156. 0,
  157.  
  158. 9,
  159. 0,
  160.  
  161. 11,
  162. 0,
  163.  
  164. 3,
  165. 0,
  166.  
  167. 4,
  168. 0,
  169.  
  170. 5,
  171. 0,
  172.  
  173. 6,
  174. 0,
  175.  
  176. 8,
  177. 0,
  178.  
  179. 7,
  180. 0,
  181. 0};
  182. # define YYTYPE char
  183. struct yywork { YYTYPE verify, advance; } yycrank[] = {
  184. 0,0,    0,0,    1,3,    0,0,    
  185. 0,0,    0,0,    0,0,    0,0,    
  186. 0,0,    0,0,    1,4,    1,5,    
  187. 0,0,    0,0,    0,0,    0,0,    
  188. 0,0,    0,0,    0,0,    0,0,    
  189. 7,12,    0,0,    0,0,    0,0,    
  190. 0,0,    0,0,    0,0,    0,0,    
  191. 7,12,    7,0,    12,0,    0,0,    
  192. 0,0,    0,0,    0,0,    0,0,    
  193. 0,0,    1,6,    2,6,    0,0,    
  194. 0,0,    0,0,    0,0,    1,7,    
  195. 2,7,    0,0,    0,0,    1,8,    
  196. 2,8,    1,9,    0,0,    0,0,    
  197. 0,0,    0,0,    0,0,    0,0,    
  198. 6,11,    6,11,    6,11,    6,11,    
  199. 6,11,    6,11,    6,11,    6,11,    
  200. 6,11,    6,11,    1,10,    7,12,    
  201. 0,0,    0,0,    0,0,    0,0,    
  202. 1,10,    6,11,    6,11,    6,11,    
  203. 6,11,    6,11,    6,11,    8,13,    
  204. 0,0,    0,0,    0,0,    0,0,    
  205. 7,12,    0,0,    8,14,    0,0,    
  206. 0,0,    0,0,    7,12,    0,0,    
  207. 0,0,    14,22,    0,0,    0,0,    
  208. 1,3,    0,0,    0,0,    0,0,    
  209. 0,0,    13,21,    0,0,    0,0,    
  210. 0,0,    6,11,    6,11,    6,11,    
  211. 6,11,    6,11,    6,11,    8,15,    
  212. 0,0,    0,0,    7,12,    0,0,    
  213. 0,0,    0,0,    8,16,    0,0,    
  214. 0,0,    0,0,    26,28,    0,0,    
  215. 0,0,    8,17,    8,18,    9,19,    
  216. 9,19,    9,19,    9,19,    9,19,    
  217. 9,19,    9,19,    9,19,    9,19,    
  218. 9,19,    10,20,    10,20,    10,20,    
  219. 10,20,    10,20,    10,20,    10,20,    
  220. 10,20,    10,20,    10,20,    15,23,    
  221. 16,24,    17,25,    18,26,    25,27,    
  222. 27,29,    28,30,    10,20,    10,20,    
  223. 10,20,    10,20,    10,20,    10,20,    
  224. 10,20,    10,20,    10,20,    10,20,    
  225. 10,20,    10,20,    10,20,    10,20,    
  226. 10,20,    10,20,    10,20,    10,20,    
  227. 10,20,    10,20,    10,20,    10,20,    
  228. 10,20,    10,20,    10,20,    10,20,    
  229. 30,31,    0,0,    0,0,    0,0,    
  230. 10,20,    0,0,    10,20,    10,20,    
  231. 10,20,    10,20,    10,20,    10,20,    
  232. 10,20,    10,20,    10,20,    10,20,    
  233. 10,20,    10,20,    10,20,    10,20,    
  234. 10,20,    10,20,    10,20,    10,20,    
  235. 10,20,    10,20,    10,20,    10,20,    
  236. 10,20,    10,20,    10,20,    10,20,    
  237. 0,0};
  238. struct yysvf yysvec[] = {
  239. 0,    0,    0,
  240. yycrank+-1,    0,        0,    
  241. yycrank+-2,    yysvec+1,    0,    
  242. yycrank+0,    0,        yyvstop+1,
  243. yycrank+0,    0,        yyvstop+3,
  244. yycrank+0,    0,        yyvstop+6,
  245. yycrank+8,    0,        yyvstop+8,
  246. yycrank+-19,    0,        yyvstop+10,
  247. yycrank+10,    0,        yyvstop+13,
  248. yycrank+79,    0,        yyvstop+15,
  249. yycrank+89,    0,        yyvstop+18,
  250. yycrank+0,    yysvec+6,    yyvstop+21,
  251. yycrank+-20,    yysvec+7,    yyvstop+23,
  252. yycrank+20,    0,        0,    
  253. yycrank+20,    0,        0,    
  254. yycrank+34,    0,        0,    
  255. yycrank+43,    0,        0,    
  256. yycrank+33,    0,        0,    
  257. yycrank+36,    0,        0,    
  258. yycrank+0,    yysvec+9,    yyvstop+25,
  259. yycrank+0,    yysvec+10,    yyvstop+27,
  260. yycrank+0,    0,        yyvstop+29,
  261. yycrank+0,    0,        yyvstop+31,
  262. yycrank+0,    0,        yyvstop+33,
  263. yycrank+0,    0,        yyvstop+35,
  264. yycrank+40,    0,        0,    
  265. yycrank+25,    0,        0,    
  266. yycrank+40,    0,        0,    
  267. yycrank+54,    0,        0,    
  268. yycrank+0,    0,        yyvstop+37,
  269. yycrank+79,    0,        0,    
  270. yycrank+0,    0,        yyvstop+39,
  271. 0,    0,    0};
  272. struct yywork *yytop = yycrank+211;
  273. struct yysvf *yybgin = yysvec+1;
  274. char yymatch[] = {
  275. 00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  276. 01  ,011 ,012 ,01  ,01  ,01  ,01  ,01  ,
  277. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  278. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  279. 011 ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  280. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  281. '0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
  282. '0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
  283. 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'G' ,
  284. 'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,
  285. 'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,
  286. 'G' ,'G' ,'G' ,01  ,01  ,01  ,01  ,'_' ,
  287. 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'G' ,
  288. 'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,
  289. 'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,'G' ,
  290. 'G' ,'G' ,'G' ,01  ,01  ,01  ,01  ,01  ,
  291. 0};
  292. char yyextra[] = {
  293. 0,0,0,0,0,0,0,0,
  294. 0,0,0,0,0,0,0,0,
  295. 0};
  296. #ifndef lint
  297. static    char ncform_sccsid[] = "@(#)ncform 1.2 86/10/08 SMI"; /* from S5R2 1.2 */
  298. #endif
  299.  
  300. int yylineno =1;
  301. # define YYU(x) x
  302. # define NLSTATE yyprevious=YYNEWLINE
  303. char yytext[YYLMAX];
  304. struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
  305. char yysbuf[YYLMAX];
  306. char *yysptr = yysbuf;
  307. int *yyfnd;
  308. extern struct yysvf *yyestate;
  309. int yyprevious = YYNEWLINE;
  310. yylook(){
  311.     register struct yysvf *yystate, **lsp;
  312.     register struct yywork *yyt;
  313.     struct yysvf *yyz;
  314.     int yych, yyfirst;
  315.     struct yywork *yyr;
  316. # ifdef LEXDEBUG
  317.     int debug;
  318. # endif
  319.     char *yylastch;
  320.     /* start off machines */
  321. # ifdef LEXDEBUG
  322.     debug = 0;
  323. # endif
  324.     yyfirst=1;
  325.     if (!yymorfg)
  326.         yylastch = yytext;
  327.     else {
  328.         yymorfg=0;
  329.         yylastch = yytext+yyleng;
  330.         }
  331.     for(;;){
  332.         lsp = yylstate;
  333.         yyestate = yystate = yybgin;
  334.         if (yyprevious==YYNEWLINE) yystate++;
  335.         for (;;){
  336. # ifdef LEXDEBUG
  337.             if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
  338. # endif
  339.             yyt = yystate->yystoff;
  340.             if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
  341.                 yyz = yystate->yyother;
  342.                 if(yyz == 0)break;
  343.                 if(yyz->yystoff == yycrank)break;
  344.                 }
  345.             *yylastch++ = yych = input();
  346.             yyfirst=0;
  347.         tryagain:
  348. # ifdef LEXDEBUG
  349.             if(debug){
  350.                 fprintf(yyout,"char ");
  351.                 allprint(yych);
  352.                 putchar('\n');
  353.                 }
  354. # endif
  355.             yyr = yyt;
  356.             if ( (int)yyt > (int)yycrank){
  357.                 yyt = yyr + yych;
  358.                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
  359.                     if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  360.                         {unput(*--yylastch);break;}
  361.                     *lsp++ = yystate = yyt->advance+yysvec;
  362.                     goto contin;
  363.                     }
  364.                 }
  365. # ifdef YYOPTIM
  366.             else if((int)yyt < (int)yycrank) {        /* r < yycrank */
  367.                 yyt = yyr = yycrank+(yycrank-yyt);
  368. # ifdef LEXDEBUG
  369.                 if(debug)fprintf(yyout,"compressed state\n");
  370. # endif
  371.                 yyt = yyt + yych;
  372.                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
  373.                     if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  374.                         {unput(*--yylastch);break;}
  375.                     *lsp++ = yystate = yyt->advance+yysvec;
  376.                     goto contin;
  377.                     }
  378.                 yyt = yyr + YYU(yymatch[yych]);
  379. # ifdef LEXDEBUG
  380.                 if(debug){
  381.                     fprintf(yyout,"try fall back character ");
  382.                     allprint(YYU(yymatch[yych]));
  383.                     putchar('\n');
  384.                     }
  385. # endif
  386.                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
  387.                     if(yyt->advance+yysvec == YYLERR)    /* error transition */
  388.                         {unput(*--yylastch);break;}
  389.                     *lsp++ = yystate = yyt->advance+yysvec;
  390.                     goto contin;
  391.                     }
  392.                 }
  393.             if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
  394. # ifdef LEXDEBUG
  395.                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
  396. # endif
  397.                 goto tryagain;
  398.                 }
  399. # endif
  400.             else
  401.                 {unput(*--yylastch);break;}
  402.         contin:
  403. # ifdef LEXDEBUG
  404.             if(debug){
  405.                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
  406.                 allprint(yych);
  407.                 putchar('\n');
  408.                 }
  409. # endif
  410.             ;
  411.             }
  412. # ifdef LEXDEBUG
  413.         if(debug){
  414.             fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
  415.             allprint(yych);
  416.             putchar('\n');
  417.             }
  418. # endif
  419.         while (lsp-- > yylstate){
  420.             *yylastch-- = 0;
  421.             if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
  422.                 yyolsp = lsp;
  423.                 if(yyextra[*yyfnd]){        /* must backup */
  424.                     while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
  425.                         lsp--;
  426.                         unput(*yylastch--);
  427.                         }
  428.                     }
  429.                 yyprevious = YYU(*yylastch);
  430.                 yylsp = lsp;
  431.                 yyleng = yylastch-yytext+1;
  432.                 yytext[yyleng] = 0;
  433. # ifdef LEXDEBUG
  434.                 if(debug){
  435.                     fprintf(yyout,"\nmatch ");
  436.                     sprint(yytext);
  437.                     fprintf(yyout," action %d\n",*yyfnd);
  438.                     }
  439. # endif
  440.                 return(*yyfnd++);
  441.                 }
  442.             unput(*yylastch);
  443.             }
  444.         if (yytext[0] == 0  /* && feof(yyin) */)
  445.             {
  446.             yysptr=yysbuf;
  447.             return(0);
  448.             }
  449.         yyprevious = yytext[0] = input();
  450.         if (yyprevious>0)
  451.             output(yyprevious);
  452.         yylastch=yytext;
  453. # ifdef LEXDEBUG
  454.         if(debug)putchar('\n');
  455. # endif
  456.         }
  457.     }
  458. yyback(p, m)
  459.     int *p;
  460. {
  461. if (p==0) return(0);
  462. while (*p)
  463.     {
  464.     if (*p++ == m)
  465.         return(1);
  466.     }
  467. return(0);
  468. }
  469.     /* the following are only used in the lex library */
  470. yyinput(){
  471.     return(input());
  472.     }
  473. yyoutput(c)
  474.   int c; {
  475.     output(c);
  476.     }
  477. yyunput(c)
  478.    int c; {
  479.     unput(c);
  480.     }
  481.