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 /* This file is part of flex. */
14
15 /* Redistribution and use in source and binary forms, with or without */
16 /* modification, are permitted provided that the following conditions */
17 /* are met: */
18
19 /* 1. Redistributions of source code must retain the above copyright */
20 /* notice, this list of conditions and the following disclaimer. */
21 /* 2. Redistributions in binary form must reproduce the above copyright */
22 /* notice, this list of conditions and the following disclaimer in the */
23 /* documentation and/or other materials provided with the distribution. */
24
25 /* Neither the name of the University nor the names of its contributors */
26 /* may be used to endorse or promote products derived from this software */
27 /* without specific prior written permission. */
28
29 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
30 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
31 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
32 /* PURPOSE. */
33
34 #include <ctype.h>
35 #include "flexdef.h"
36 #include "parse.h"
37
38
39 /* yylex - scan for a regular expression token */
40 extern char *yytext;
41 extern FILE *yyout;
42 bool no_section3_escape = false;
yylex(void)43 int yylex (void)
44 {
45 int toktype;
46 static int beglin = false;
47
48 if (eofseen) {
49 toktype = EOF;
50 } else {
51 toktype = flexscan ();
52 }
53 if (toktype == EOF || toktype == 0) {
54 eofseen = 1;
55
56 if (sectnum == 1) {
57 synerr (_("premature EOF"));
58 sectnum = 2;
59 toktype = SECTEND;
60 }
61
62 else
63 toktype = 0;
64 }
65
66 if (trace) {
67 if (beglin) {
68 fprintf (stderr, "%d\t", num_rules + 1);
69 beglin = 0;
70 }
71
72 switch (toktype) {
73 case '<':
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 (void) putc (toktype, stderr);
94 break;
95
96 case '\n':
97 (void) putc ('\n', stderr);
98
99 if (sectnum == 2)
100 beglin = 1;
101
102 break;
103
104 case SCDECL:
105 fputs ("%s", stderr);
106 break;
107
108 case XSCDECL:
109 fputs ("%x", stderr);
110 break;
111
112 case SECTEND:
113 fputs ("%%\n", stderr);
114
115 /* We set beglin to be true so we'll start
116 * writing out numbers as we echo rules.
117 * flexscan() has already assigned sectnum.
118 */
119 if (sectnum == 2)
120 beglin = 1;
121
122 break;
123
124 case NAME:
125 fprintf (stderr, "'%s'", nmstr);
126 break;
127
128 case CHAR:
129 switch (yylval) {
130 case '<':
131 case '>':
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 fprintf (stderr, "\\%c", yylval);
151 break;
152
153 default:
154 if (!isascii (yylval) || !isprint (yylval)) {
155 if(trace_hex)
156 fprintf (stderr, "\\x%02x", (unsigned int) yylval);
157 else
158 fprintf (stderr, "\\%.3o", (unsigned int) yylval);
159 } else
160 (void) putc (yylval, stderr);
161 break;
162 }
163
164 break;
165
166 case NUMBER:
167 fprintf (stderr, "%d", yylval);
168 break;
169
170 case PREVCCL:
171 fprintf (stderr, "[%d]", yylval);
172 break;
173
174 case EOF_OP:
175 fprintf (stderr, "<<EOF>>");
176 break;
177
178 case TOK_OPTION:
179 fprintf (stderr, "%s ", yytext);
180 break;
181
182 case TOK_OUTFILE:
183 case TOK_PREFIX:
184 case CCE_ALNUM:
185 case CCE_ALPHA:
186 case CCE_BLANK:
187 case CCE_CNTRL:
188 case CCE_DIGIT:
189 case CCE_GRAPH:
190 case CCE_LOWER:
191 case CCE_PRINT:
192 case CCE_PUNCT:
193 case CCE_SPACE:
194 case CCE_UPPER:
195 case CCE_XDIGIT:
196 fprintf (stderr, "%s", yytext);
197 break;
198
199 case 0:
200 fprintf (stderr, _("End Marker\n"));
201 break;
202
203 default:
204 fprintf (stderr,
205 _
206 ("*Something Weird* - tok: %d val: %d\n"),
207 toktype, yylval);
208 break;
209 }
210 }
211
212 return toktype;
213 }
214