No empty .Rs/.Re
[netbsd-mini2440.git] / usr.bin / lex / yylex.c
blobe336ee0c90667bc3ce3f7a8f48d6528697ed6a57
1 /* yylex - scanner front-end for flex */
3 /*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Vern Paxson.
9 *
10 * The United States Government has rights in this work pursuant
11 * to contract no. DE-AC03-76SF00098 between the United States
12 * Department of Energy and the University of California.
14 * Redistribution and use in source and binary forms are permitted provided
15 * that: (1) source distributions retain this entire copyright notice and
16 * comment, and (2) distributions including binaries display the following
17 * acknowledgement: ``This product includes software developed by the
18 * University of California, Berkeley and its contributors'' in the
19 * documentation or other materials provided with the distribution and in
20 * all advertising materials mentioning features or use of this software.
21 * Neither the name of the University nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 /* $NetBSD: yylex.c,v 1.8 1998/01/05 05:16:00 perry Exp $ */
31 #include <ctype.h>
32 #include "flexdef.h"
33 #include "parse.h"
36 /* yylex - scan for a regular expression token */
38 extern char *yytext;
39 int yylex()
41 int toktype;
42 static int beglin = false;
44 if ( eofseen )
45 toktype = EOF;
46 else
47 toktype = flexscan();
49 if ( toktype == EOF || toktype == 0 )
51 eofseen = 1;
53 if ( sectnum == 1 )
55 synerr( _( "premature EOF" ) );
56 sectnum = 2;
57 toktype = SECTEND;
60 else
61 toktype = 0;
64 if ( trace )
66 if ( beglin )
68 fprintf( stderr, "%d\t", num_rules + 1 );
69 beglin = 0;
72 switch ( toktype )
74 case '<':
75 case '>':
76 case '^':
77 case '$':
78 case '"':
79 case '[':
80 case ']':
81 case '{':
82 case '}':
83 case '|':
84 case '(':
85 case ')':
86 case '-':
87 case '/':
88 case '\\':
89 case '?':
90 case '.':
91 case '*':
92 case '+':
93 case ',':
94 (void) putc( toktype, stderr );
95 break;
97 case '\n':
98 (void) putc( '\n', stderr );
100 if ( sectnum == 2 )
101 beglin = 1;
103 break;
105 case SCDECL:
106 fputs( "%s", stderr );
107 break;
109 case XSCDECL:
110 fputs( "%x", stderr );
111 break;
113 case SECTEND:
114 fputs( "%%\n", stderr );
116 /* We set beglin to be true so we'll start
117 * writing out numbers as we echo rules.
118 * flexscan() has already assigned sectnum.
120 if ( sectnum == 2 )
121 beglin = 1;
123 break;
125 case NAME:
126 fprintf( stderr, "'%s'", nmstr );
127 break;
129 case CHAR:
130 switch ( yylval )
132 case '<':
133 case '>':
134 case '^':
135 case '$':
136 case '"':
137 case '[':
138 case ']':
139 case '{':
140 case '}':
141 case '|':
142 case '(':
143 case ')':
144 case '-':
145 case '/':
146 case '\\':
147 case '?':
148 case '.':
149 case '*':
150 case '+':
151 case ',':
152 fprintf( stderr, "\\%c",
153 yylval );
154 break;
156 default:
157 if ( ! isascii( yylval ) ||
158 ! isprint( yylval ) )
159 fprintf( stderr,
160 "\\%.3o",
161 (unsigned int) yylval );
162 else
163 (void) putc( yylval,
164 stderr );
165 break;
168 break;
170 case NUMBER:
171 fprintf( stderr, "%d", yylval );
172 break;
174 case PREVCCL:
175 fprintf( stderr, "[%d]", yylval );
176 break;
178 case EOF_OP:
179 fprintf( stderr, "<<EOF>>" );
180 break;
182 case OPTION_OP:
183 fprintf( stderr, "%s ", yytext );
184 break;
186 case OPT_OUTFILE:
187 case OPT_PREFIX:
188 case CCE_ALNUM:
189 case CCE_ALPHA:
190 case CCE_BLANK:
191 case CCE_CNTRL:
192 case CCE_DIGIT:
193 case CCE_GRAPH:
194 case CCE_LOWER:
195 case CCE_PRINT:
196 case CCE_PUNCT:
197 case CCE_SPACE:
198 case CCE_UPPER:
199 case CCE_XDIGIT:
200 fprintf( stderr, "%s", yytext );
201 break;
203 case 0:
204 fprintf( stderr, _( "End Marker\n" ) );
205 break;
207 default:
208 fprintf( stderr,
209 _( "*Something Weird* - tok: %d val: %d\n" ),
210 toktype, yylval );
211 break;
215 return toktype;