yylex.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* yylex - scanner front-end for flex */
  2. /*-
  3. * Copyright (c) 1990 The Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Vern Paxson.
  8. *
  9. * The United States Government has rights in this work pursuant
  10. * to contract no. DE-AC03-76SF00098 between the United States
  11. * Department of Energy and the University of California.
  12. *
  13. * Redistribution and use in source and binary forms with or without
  14. * modification are permitted provided that: (1) source distributions retain
  15. * this entire copyright notice and comment, and (2) distributions including
  16. * binaries display the following acknowledgement: ``This product includes
  17. * software developed by the University of California, Berkeley and its
  18. * contributors'' in the documentation or other materials provided with the
  19. * distribution and in all advertising materials mentioning features or use
  20. * of this software. Neither the name of the University nor the names of
  21. * its contributors may be used to endorse or promote products derived from
  22. * this software without specific prior written permission.
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  26. */
  27. /* $Header: /opt/vlysenkov/CVSROOT/arcadia/contrib/tools/flex-old/yylex.c,v 1.2 2007-11-30 02:28:15 pg Exp $ */
  28. #include <ctype.h>
  29. #include "flexdef.h"
  30. #include "parse.h"
  31. /* yylex - scan for a regular expression token */
  32. int yylex()
  33. {
  34. int toktype;
  35. static int beglin = false;
  36. extern char *yytext;
  37. if ( eofseen )
  38. toktype = EOF;
  39. else
  40. toktype = flexscan();
  41. if ( toktype == EOF || toktype == 0 )
  42. {
  43. eofseen = 1;
  44. if ( sectnum == 1 )
  45. {
  46. synerr( _( "premature EOF" ) );
  47. sectnum = 2;
  48. toktype = SECTEND;
  49. }
  50. else
  51. toktype = 0;
  52. }
  53. if ( trace )
  54. {
  55. if ( beglin )
  56. {
  57. fprintf( stderr, "%d\t", num_rules + 1 );
  58. beglin = 0;
  59. }
  60. switch ( toktype )
  61. {
  62. case '<':
  63. case '>':
  64. case '^':
  65. case '$':
  66. case '"':
  67. case '[':
  68. case ']':
  69. case '{':
  70. case '}':
  71. case '|':
  72. case '(':
  73. case ')':
  74. case '-':
  75. case '/':
  76. case '\\':
  77. case '?':
  78. case '.':
  79. case '*':
  80. case '+':
  81. case ',':
  82. (void) putc( toktype, stderr );
  83. break;
  84. case '\n':
  85. (void) putc( '\n', stderr );
  86. if ( sectnum == 2 )
  87. beglin = 1;
  88. break;
  89. case SCDECL:
  90. fputs( "%s", stderr );
  91. break;
  92. case XSCDECL:
  93. fputs( "%x", stderr );
  94. break;
  95. case SECTEND:
  96. fputs( "%%\n", stderr );
  97. /* We set beglin to be true so we'll start
  98. * writing out numbers as we echo rules.
  99. * flexscan() has already assigned sectnum.
  100. */
  101. if ( sectnum == 2 )
  102. beglin = 1;
  103. break;
  104. case NAME:
  105. fprintf( stderr, "'%s'", nmstr );
  106. break;
  107. case CHAR:
  108. switch ( yylval )
  109. {
  110. case '<':
  111. case '>':
  112. case '^':
  113. case '$':
  114. case '"':
  115. case '[':
  116. case ']':
  117. case '{':
  118. case '}':
  119. case '|':
  120. case '(':
  121. case ')':
  122. case '-':
  123. case '/':
  124. case '\\':
  125. case '?':
  126. case '.':
  127. case '*':
  128. case '+':
  129. case ',':
  130. fprintf( stderr, "\\%c",
  131. yylval );
  132. break;
  133. default:
  134. if ( ! isascii( yylval ) ||
  135. ! isprint( yylval ) )
  136. fprintf( stderr,
  137. "\\%.3o",
  138. (unsigned int) yylval );
  139. else
  140. (void) putc( yylval,
  141. stderr );
  142. break;
  143. }
  144. break;
  145. case NUMBER:
  146. fprintf( stderr, "%d", yylval );
  147. break;
  148. case PREVCCL:
  149. fprintf( stderr, "[%d]", yylval );
  150. break;
  151. case EOF_OP:
  152. fprintf( stderr, "<<EOF>>" );
  153. break;
  154. case OPTION_OP:
  155. fprintf( stderr, "%s ", yytext );
  156. break;
  157. case OPT_OUTFILE:
  158. case OPT_PREFIX:
  159. case CCE_ALNUM:
  160. case CCE_ALPHA:
  161. case CCE_BLANK:
  162. case CCE_CNTRL:
  163. case CCE_DIGIT:
  164. case CCE_GRAPH:
  165. case CCE_LOWER:
  166. case CCE_PRINT:
  167. case CCE_PUNCT:
  168. case CCE_SPACE:
  169. case CCE_UPPER:
  170. case CCE_XDIGIT:
  171. fprintf( stderr, "%s", yytext );
  172. break;
  173. case 0:
  174. fprintf( stderr, _( "End Marker\n" ) );
  175. break;
  176. default:
  177. fprintf( stderr,
  178. _( "*Something Weird* - tok: %d val: %d\n" ),
  179. toktype, yylval );
  180. break;
  181. }
  182. }
  183. return toktype;
  184. }