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