Line | Count | Source |
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; |
43 | | int yylex (void) |
44 | 6 | { |
45 | 6 | int toktype; |
46 | 6 | static int beglin = false; |
47 | | |
48 | 6 | if (eofseen) { |
49 | 1 | toktype = EOF; |
50 | 5 | } else { |
51 | 5 | toktype = flexscan (); |
52 | 5 | } |
53 | 6 | if (toktype == EOF || toktype == 0) { |
54 | 2 | eofseen = true; |
55 | | |
56 | 2 | if (sectnum == 1) { |
57 | 1 | synerr (_("premature EOF")); |
58 | 1 | sectnum = 2; |
59 | 1 | toktype = SECTEND; |
60 | 1 | } |
61 | | |
62 | 1 | else |
63 | 1 | toktype = 0; |
64 | 2 | } |
65 | | |
66 | 6 | if (env.trace) { |
67 | 0 | if (beglin) { |
68 | 0 | fprintf (stderr, "%d\t", num_rules + 1); |
69 | 0 | beglin = 0; |
70 | 0 | } |
71 | |
|
72 | 0 | switch (toktype) { |
73 | 0 | case '<': |
74 | 0 | case '>': |
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 | (void) putc (toktype, stderr); |
94 | 0 | break; |
95 | | |
96 | 0 | case '\n': |
97 | 0 | (void) putc ('\n', stderr); |
98 | |
|
99 | 0 | if (sectnum == 2) |
100 | 0 | beglin = 1; |
101 | |
|
102 | 0 | break; |
103 | | |
104 | 0 | case SCDECL: |
105 | 0 | fputs ("%s", stderr); |
106 | 0 | break; |
107 | | |
108 | 0 | case XSCDECL: |
109 | 0 | fputs ("%x", stderr); |
110 | 0 | break; |
111 | | |
112 | 0 | case SECTEND: |
113 | 0 | 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 | 0 | if (sectnum == 2) |
120 | 0 | beglin = 1; |
121 | |
|
122 | 0 | break; |
123 | | |
124 | 0 | case NAME: |
125 | 0 | fprintf (stderr, "'%s'", nmstr); |
126 | 0 | break; |
127 | | |
128 | 0 | case CHAR: |
129 | 0 | switch (yylval) { |
130 | 0 | case '<': |
131 | 0 | case '>': |
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 | fprintf (stderr, "\\%c", yylval); |
151 | 0 | break; |
152 | | |
153 | 0 | default: |
154 | 0 | if (!isascii (yylval) || !isprint (yylval)) { |
155 | 0 | if(env.trace_hex) |
156 | 0 | fprintf (stderr, "\\x%02x", (unsigned int) yylval); |
157 | 0 | else |
158 | 0 | fprintf (stderr, "\\%.3o", (unsigned int) yylval); |
159 | 0 | } else |
160 | 0 | (void) putc (yylval, stderr); |
161 | 0 | break; |
162 | 0 | } |
163 | | |
164 | 0 | break; |
165 | | |
166 | 0 | case NUMBER: |
167 | 0 | fprintf (stderr, "%d", yylval); |
168 | 0 | break; |
169 | | |
170 | 0 | case PREVCCL: |
171 | 0 | fprintf (stderr, "[%d]", yylval); |
172 | 0 | break; |
173 | | |
174 | 0 | case EOF_OP: |
175 | 0 | fprintf (stderr, "<<EOF>>"); |
176 | 0 | break; |
177 | | |
178 | 0 | case TOK_OPTION: |
179 | 0 | fprintf (stderr, "%s ", yytext); |
180 | 0 | break; |
181 | | |
182 | 0 | case TOK_OUTFILE: |
183 | 0 | case TOK_PREFIX: |
184 | 0 | case CCE_ALNUM: |
185 | 0 | case CCE_ALPHA: |
186 | 0 | case CCE_BLANK: |
187 | 0 | case CCE_CNTRL: |
188 | 0 | case CCE_DIGIT: |
189 | 0 | case CCE_GRAPH: |
190 | 0 | case CCE_LOWER: |
191 | 0 | case CCE_PRINT: |
192 | 0 | case CCE_PUNCT: |
193 | 0 | case CCE_SPACE: |
194 | 0 | case CCE_UPPER: |
195 | 0 | case CCE_XDIGIT: |
196 | 0 | fprintf (stderr, "%s", yytext); |
197 | 0 | break; |
198 | | |
199 | 0 | case 0: |
200 | 0 | fprintf (stderr, _("End Marker\n")); |
201 | 0 | break; |
202 | | |
203 | 0 | default: |
204 | 0 | fprintf (stderr, |
205 | 0 | _ |
206 | 0 | ("*Something Weird* - tok: %d val: %d\n"), |
207 | 0 | toktype, yylval); |
208 | 0 | break; |
209 | 0 | } |
210 | 0 | } |
211 | | |
212 | 6 | return toktype; |
213 | 6 | } |