reject.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <stdio.h>
  12. extern FILE* yyout;
  13. extern FILE* yyin;
  14. extern int yyprevious, *yyfnd;
  15. extern char yyextra[];
  16. extern char yytext[];
  17. extern int yyleng;
  18. extern
  19. struct
  20. {
  21. int *yyaa, *yybb;
  22. int *yystops;
  23. } *yylstate [], **yylsp, **yyolsp;
  24. int yyback(int *p, int m);
  25. int yyinput(void);
  26. void yyoutput(int c);
  27. void yyunput(int c);
  28. int
  29. yyracc(int m)
  30. {
  31. yyolsp = yylsp;
  32. if(yyextra[m]) {
  33. while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) {
  34. yylsp--;
  35. yyunput(yytext[--yyleng]);
  36. }
  37. }
  38. yyprevious = yytext[yyleng-1];
  39. yytext[yyleng] = 0;
  40. return m;
  41. }
  42. int
  43. yyreject(void)
  44. {
  45. for(; yylsp < yyolsp; yylsp++)
  46. yytext[yyleng++] = yyinput();
  47. if(*yyfnd > 0)
  48. return yyracc(*yyfnd++);
  49. while(yylsp-- > yylstate) {
  50. yyunput(yytext[yyleng-1]);
  51. yytext[--yyleng] = 0;
  52. if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0)
  53. return yyracc(*yyfnd++);
  54. }
  55. if(yytext[0] == 0)
  56. return 0;
  57. yyoutput(yyprevious = yyinput());
  58. yyleng = 0;
  59. return -1;
  60. }