inpcb: Use netisr_ncpus for listing inpcbs.
[dragonfly.git] / contrib / flex / yylex.c
blobf06e5e6a2659ce032c4c33189ffeca3dc6f5eb7c
1 /* yylex - scanner front-end for flex */
3 /* Copyright (c) 1990 The Regents of the University of California. */
4 /* All rights reserved. */
6 /* This code is derived from software contributed to Berkeley by */
7 /* Vern Paxson. */
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. */
13 /* This file is part of flex. */
15 /* Redistribution and use in source and binary forms, with or without */
16 /* modification, are permitted provided that the following conditions */
17 /* are met: */
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. */
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. */
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. */
34 #include <ctype.h>
35 #include "flexdef.h"
36 #include "parse.h"
39 /* yylex - scan for a regular expression token */
41 int yylex ()
43 int toktype;
44 static int beglin = false;
45 extern char *yytext;
47 if (eofseen)
48 toktype = EOF;
49 else
50 toktype = flexscan ();
52 if (toktype == EOF || toktype == 0) {
53 eofseen = 1;
55 if (sectnum == 1) {
56 synerr (_("premature EOF"));
57 sectnum = 2;
58 toktype = SECTEND;
61 else
62 toktype = 0;
65 if (trace) {
66 if (beglin) {
67 fprintf (stderr, "%d\t", num_rules + 1);
68 beglin = 0;
71 switch (toktype) {
72 case '<':
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 (void) putc (toktype, stderr);
93 break;
95 case '\n':
96 (void) putc ('\n', stderr);
98 if (sectnum == 2)
99 beglin = 1;
101 break;
103 case SCDECL:
104 fputs ("%s", stderr);
105 break;
107 case XSCDECL:
108 fputs ("%x", stderr);
109 break;
111 case SECTEND:
112 fputs ("%%\n", stderr);
114 /* We set beglin to be true so we'll start
115 * writing out numbers as we echo rules.
116 * flexscan() has already assigned sectnum.
118 if (sectnum == 2)
119 beglin = 1;
121 break;
123 case NAME:
124 fprintf (stderr, "'%s'", nmstr);
125 break;
127 case CHAR:
128 switch (yylval) {
129 case '<':
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 fprintf (stderr, "\\%c", yylval);
150 break;
152 default:
153 if (!isascii (yylval) || !isprint (yylval))
154 fprintf (stderr,
155 "\\%.3o",
156 (unsigned int) yylval);
157 else
158 (void) putc (yylval, stderr);
159 break;
162 break;
164 case NUMBER:
165 fprintf (stderr, "%d", yylval);
166 break;
168 case PREVCCL:
169 fprintf (stderr, "[%d]", yylval);
170 break;
172 case EOF_OP:
173 fprintf (stderr, "<<EOF>>");
174 break;
176 case OPTION_OP:
177 fprintf (stderr, "%s ", yytext);
178 break;
180 case OPT_OUTFILE:
181 case OPT_PREFIX:
182 case CCE_ALNUM:
183 case CCE_ALPHA:
184 case CCE_BLANK:
185 case CCE_CNTRL:
186 case CCE_DIGIT:
187 case CCE_GRAPH:
188 case CCE_LOWER:
189 case CCE_PRINT:
190 case CCE_PUNCT:
191 case CCE_SPACE:
192 case CCE_UPPER:
193 case CCE_XDIGIT:
194 fprintf (stderr, "%s", yytext);
195 break;
197 case 0:
198 fprintf (stderr, _("End Marker\n"));
199 break;
201 default:
202 fprintf (stderr,
204 ("*Something Weird* - tok: %d val: %d\n"),
205 toktype, yylval);
206 break;
210 return toktype;