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