home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / lex / ncform next >
Text File  |  1990-09-07  |  4KB  |  212 lines

  1. /*    ncform    4.1    83/08/11    */
  2.  
  3. int yylineno =1;
  4. # define YYU(x) x
  5. # define NLSTATE yyprevious=YYNEWLINE
  6. char yytext[YYLMAX];
  7. struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
  8. char yysbuf[YYLMAX];
  9. char *yysptr = yysbuf;
  10. int *yyfnd;
  11. extern struct yysvf *yyestate;
  12. int yyprevious = YYNEWLINE;
  13. #if    NeXT
  14. int yylook(){
  15. #else
  16. yylook(){
  17. #endif    NeXT
  18.     register struct yysvf *yystate, **lsp;
  19.     register struct yywork *yyt;
  20.     struct yysvf *yyz;
  21.     int yych;
  22.     struct yywork *yyr;
  23. # ifdef LEXDEBUG
  24.     int debug;
  25. # endif
  26.     char *yylastch;
  27.     /* start off machines */
  28. # ifdef LEXDEBUG
  29.     debug = 0;
  30. # endif
  31.     if (!yymorfg)
  32.         yylastch = yytext;
  33.     else {
  34.         yymorfg=0;
  35.         yylastch = yytext+yyleng;
  36.         }
  37.     for(;;){
  38.         lsp = yylstate;
  39.         yyestate = yystate = yybgin;
  40.         if (yyprevious==YYNEWLINE) yystate++;
  41.         for (;;){
  42. # ifdef LEXDEBUG
  43.             if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
  44. # endif
  45.             yyt = yystate->yystoff;
  46.             if(yyt == yycrank){        /* may not be any transitions */
  47.                 yyz = yystate->yyother;
  48.                 if(yyz == 0)break;
  49.                 if(yyz->yystoff == yycrank)break;
  50.                 }
  51.             *yylastch++ = yych = input();
  52.         tryagain:
  53. # ifdef LEXDEBUG
  54.             if(debug){
  55.                 fprintf(yyout,"char ");
  56.                 allprint(yych);
  57.                 putchar('\n');
  58.                 }
  59. # endif
  60.             yyr = yyt;
  61.             if ( (int)yyt > (int)yycrank){
  62.                 yyt = yyr + yych;
  63.                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
  64.                     if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  65.                         {unput(*--yylastch);break;}
  66.                     *lsp++ = yystate = yyt->advance+yysvec;
  67.                     goto contin;
  68.                     }
  69.                 }
  70. # ifdef YYOPTIM
  71.             else if((int)yyt < (int)yycrank) {        /* r < yycrank */
  72.                 yyt = yyr = yycrank+(yycrank-yyt);
  73. # ifdef LEXDEBUG
  74.                 if(debug)fprintf(yyout,"compressed state\n");
  75. # endif
  76.                 yyt = yyt + yych;
  77.                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
  78.                     if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  79.                         {unput(*--yylastch);break;}
  80.                     *lsp++ = yystate = yyt->advance+yysvec;
  81.                     goto contin;
  82.                     }
  83.                 yyt = yyr + YYU(yymatch[yych]);
  84. # ifdef LEXDEBUG
  85.                 if(debug){
  86.                     fprintf(yyout,"try fall back character ");
  87.                     allprint(YYU(yymatch[yych]));
  88.                     putchar('\n');
  89.                     }
  90. # endif
  91.                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
  92.                     if(yyt->advance+yysvec == YYLERR)    /* error transition */
  93.                         {unput(*--yylastch);break;}
  94.                     *lsp++ = yystate = yyt->advance+yysvec;
  95.                     goto contin;
  96.                     }
  97.                 }
  98.             if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
  99. # ifdef LEXDEBUG
  100.                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
  101. # endif
  102.                 goto tryagain;
  103.                 }
  104. # endif
  105.             else
  106.                 {unput(*--yylastch);break;}
  107.         contin:
  108. # ifdef LEXDEBUG
  109.             if(debug){
  110.                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
  111.                 allprint(yych);
  112.                 putchar('\n');
  113.                 }
  114. # endif
  115.             ;
  116.             }
  117. # ifdef LEXDEBUG
  118.         if(debug){
  119.             fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
  120.             allprint(yych);
  121.             putchar('\n');
  122.             }
  123. # endif
  124.         while (lsp-- > yylstate){
  125.             *yylastch-- = 0;
  126.             if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
  127.                 yyolsp = lsp;
  128.                 if(yyextra[*yyfnd]){        /* must backup */
  129.                     while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
  130.                         lsp--;
  131.                         unput(*yylastch--);
  132.                         }
  133.                     }
  134.                 yyprevious = YYU(*yylastch);
  135.                 yylsp = lsp;
  136.                 yyleng = yylastch-yytext+1;
  137.                 yytext[yyleng] = 0;
  138. # ifdef LEXDEBUG
  139.                 if(debug){
  140.                     fprintf(yyout,"\nmatch ");
  141.                     sprint(yytext);
  142.                     fprintf(yyout," action %d\n",*yyfnd);
  143.                     }
  144. # endif
  145.                 return(*yyfnd++);
  146.                 }
  147.             unput(*yylastch);
  148.             }
  149.         if (yytext[0] == 0  /* && feof(yyin) */)
  150.             {
  151.             yysptr=yysbuf;
  152.             return(0);
  153.             }
  154.         yyprevious = yytext[0] = input();
  155.         if (yyprevious>0)
  156.             output(yyprevious);
  157.         yylastch=yytext;
  158. # ifdef LEXDEBUG
  159.         if(debug)putchar('\n');
  160. # endif
  161.         }
  162.     }
  163. #if    NeXT
  164. int yyback(p, m)
  165.     int *p;
  166.     int m;
  167. #else
  168. yyback(p, m)
  169.     int *p;
  170. #endif    NeXT
  171. {
  172. if (p==0) return(0);
  173. while (*p)
  174.     {
  175.     if (*p++ == m)
  176.         return(1);
  177.     }
  178. return(0);
  179. }
  180.     /* the following are only used in the lex library */
  181. #if    NeXT
  182. int yyinput(){
  183. #else
  184. yyinput(){
  185. #endif    NeXT
  186.     return(input());
  187.     }
  188. #if    NeXT
  189. void yyoutput(c)
  190.     int c; 
  191. {
  192.     output(c);
  193. }
  194. #else
  195. yyoutput(c)
  196.   int c; {
  197.     output(c);
  198.     }
  199. #endif    NeXT
  200. #if    NeXT
  201. void yyunput(c)
  202.     int c; 
  203. {
  204.     unput(c);
  205. }
  206. #else
  207. yyunput(c)
  208.    int c; {
  209.     unput(c);
  210.     }
  211. #endif    NeXT
  212.