1*525a267eSThomas Cort /* $NetBSD: scan.l,v 1.16 2012/03/06 16:55:18 mbalmer Exp $ */
2*525a267eSThomas Cort
3*525a267eSThomas Cort /*
4*525a267eSThomas Cort * Copyright 1997 Piermont Information Systems Inc.
5*525a267eSThomas Cort * All rights reserved.
6*525a267eSThomas Cort *
7*525a267eSThomas Cort * Written by Philip A. Nelson for Piermont Information Systems Inc.
8*525a267eSThomas Cort *
9*525a267eSThomas Cort * Redistribution and use in source and binary forms, with or without
10*525a267eSThomas Cort * modification, are permitted provided that the following conditions
11*525a267eSThomas Cort * are met:
12*525a267eSThomas Cort * 1. Redistributions of source code must retain the above copyright
13*525a267eSThomas Cort * notice, this list of conditions and the following disclaimer.
14*525a267eSThomas Cort * 2. Redistributions in binary form must reproduce the above copyright
15*525a267eSThomas Cort * notice, this list of conditions and the following disclaimer in the
16*525a267eSThomas Cort * documentation and/or other materials provided with the distribution.
17*525a267eSThomas Cort * 3. The name of Piermont Information Systems Inc. may not be used to endorse
18*525a267eSThomas Cort * or promote products derived from this software without specific prior
19*525a267eSThomas Cort * written permission.
20*525a267eSThomas Cort *
21*525a267eSThomas Cort * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
22*525a267eSThomas Cort * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*525a267eSThomas Cort * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*525a267eSThomas Cort * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
25*525a267eSThomas Cort * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26*525a267eSThomas Cort * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27*525a267eSThomas Cort * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*525a267eSThomas Cort * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29*525a267eSThomas Cort * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30*525a267eSThomas Cort * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31*525a267eSThomas Cort * THE POSSIBILITY OF SUCH DAMAGE.
32*525a267eSThomas Cort *
33*525a267eSThomas Cort */
34*525a267eSThomas Cort
35*525a267eSThomas Cort %{
36*525a267eSThomas Cort /* scan.l: scanner description for menu compiler. */
37*525a267eSThomas Cort
38*525a267eSThomas Cort #include <stdio.h>
39*525a267eSThomas Cort #include <string.h>
40*525a267eSThomas Cort #include "defs.h"
41*525a267eSThomas Cort #include "parse.h"
42*525a267eSThomas Cort
43*525a267eSThomas Cort static int level; /* For nested comments. */
44*525a267eSThomas Cort static int comstart; /* line number of comment start. */
45*525a267eSThomas Cort
46*525a267eSThomas Cort %}
47*525a267eSThomas Cort
48*525a267eSThomas Cort %x COMMENT
49*525a267eSThomas Cort %x BRACE
50*525a267eSThomas Cort
51*525a267eSThomas Cort %option noinput
52*525a267eSThomas Cort
53*525a267eSThomas Cort %%
54*525a267eSThomas Cort
55*525a267eSThomas Cort [ \t]+ { /* ignore spaces and tabs */ }
56*525a267eSThomas Cort
57*525a267eSThomas Cort [\n] { line_no++; }
58*525a267eSThomas Cort
59*525a267eSThomas Cort "="|";"|","|"("|")" { return (int)yytext[0]; }
60*525a267eSThomas Cort
61*525a267eSThomas Cort x { return X; }
62*525a267eSThomas Cort
63*525a267eSThomas Cort y { return Y; }
64*525a267eSThomas Cort
65*525a267eSThomas Cort w { return W; }
66*525a267eSThomas Cort
67*525a267eSThomas Cort h { return H; }
68*525a267eSThomas Cort
69*525a267eSThomas Cort no { return NO; }
70*525a267eSThomas Cort
71*525a267eSThomas Cort box { return BOX; }
72*525a267eSThomas Cort
73*525a267eSThomas Cort sub { return SUB; }
74*525a267eSThomas Cort
75*525a267eSThomas Cort help { return HELP; }
76*525a267eSThomas Cort
77*525a267eSThomas Cort menu { return MENU; }
78*525a267eSThomas Cort
79*525a267eSThomas Cort menus { return MENUS; }
80*525a267eSThomas Cort
81*525a267eSThomas Cort next { return NEXT; }
82*525a267eSThomas Cort
83*525a267eSThomas Cort exit { return EXIT; }
84*525a267eSThomas Cort
85*525a267eSThomas Cort exitstring { return EXITSTRING; }
86*525a267eSThomas Cort
87*525a267eSThomas Cort title { return TITLE; }
88*525a267eSThomas Cort
89*525a267eSThomas Cort action { return ACTION; }
90*525a267eSThomas Cort
91*525a267eSThomas Cort endwin { return ENDWIN; }
92*525a267eSThomas Cort
93*525a267eSThomas Cort option { return OPTION; }
94*525a267eSThomas Cort
95*525a267eSThomas Cort default { return DEFAULT; }
96*525a267eSThomas Cort
97*525a267eSThomas Cort display { return DISPLAY; }
98*525a267eSThomas Cort
99*525a267eSThomas Cort error { return ERROR; }
100*525a267eSThomas Cort
101*525a267eSThomas Cort allow { return ALLOW; }
102*525a267eSThomas Cort
103*525a267eSThomas Cort dynamic { return DYNAMIC; }
104*525a267eSThomas Cort
105*525a267eSThomas Cort messages { return MESSAGES; }
106*525a267eSThomas Cort
107*525a267eSThomas Cort scrollable { return SCROLLABLE; }
108*525a267eSThomas Cort
109*525a267eSThomas Cort shortcut { return SHORTCUT; }
110*525a267eSThomas Cort
111*525a267eSThomas Cort clear { return CLEAR; }
112*525a267eSThomas Cort
113*525a267eSThomas Cort always { return ALWAYS; }
114*525a267eSThomas Cort
115*525a267eSThomas Cort scroll { return SCROLL; }
116*525a267eSThomas Cort
117*525a267eSThomas Cort \"([^\"\n]*(\\\")?)*\" {
118*525a267eSThomas Cort yylval.s_value = strdup (yytext);
119*525a267eSThomas Cort max_strlen = max_strlen > strlen(yytext)
120*525a267eSThomas Cort ? max_strlen : strlen(yytext) + 1;
121*525a267eSThomas Cort return STRING;
122*525a267eSThomas Cort }
123*525a267eSThomas Cort
124*525a267eSThomas Cort [a-zA-Z][a-zA-Z0-9_]* {
125*525a267eSThomas Cort yylval.s_value = strdup(yytext);
126*525a267eSThomas Cort return(NAME);
127*525a267eSThomas Cort }
128*525a267eSThomas Cort
129*525a267eSThomas Cort 0|[-1-9][0-9]* {
130*525a267eSThomas Cort yylval.s_value = strdup(yytext);
131*525a267eSThomas Cort return(INT_CONST);
132*525a267eSThomas Cort }
133*525a267eSThomas Cort
134*525a267eSThomas Cort "'"[^'\\]|(\\[athrn])|(\\[0-9][0-9]?[0-9]?)"'" {
135*525a267eSThomas Cort yylval.s_value = strdup(yytext);
136*525a267eSThomas Cort return(CHAR_CONST);
137*525a267eSThomas Cort }
138*525a267eSThomas Cort
139*525a267eSThomas Cort "/*" { level = 1; comstart = line_no; BEGIN COMMENT; }
140*525a267eSThomas Cort
141*525a267eSThomas Cort <COMMENT>"/*" { level++; }
142*525a267eSThomas Cort
143*525a267eSThomas Cort <COMMENT>"*/" { if (level-- == 1) BEGIN 0; }
144*525a267eSThomas Cort
145*525a267eSThomas Cort <COMMENT>"\n" { line_no++; }
146*525a267eSThomas Cort
147*525a267eSThomas Cort <COMMENT><<EOF>> {
148*525a267eSThomas Cort yyerror ("EOF inside a comment that started at line %d",
149*525a267eSThomas Cort comstart);
150*525a267eSThomas Cort exit (1);
151*525a267eSThomas Cort }
152*525a267eSThomas Cort
153*525a267eSThomas Cort <COMMENT>. {/* eat character */}
154*525a267eSThomas Cort
155*525a267eSThomas Cort "{" { level = 1; BEGIN BRACE; }
156*525a267eSThomas Cort
157*525a267eSThomas Cort <BRACE>"{" { buff_add_ch(yytext[0]); level++; }
158*525a267eSThomas Cort
159*525a267eSThomas Cort <BRACE>"}" { if (level-- == 1) {
160*525a267eSThomas Cort BEGIN 0;
161*525a267eSThomas Cort yylval.s_value = buff_copy();
162*525a267eSThomas Cort return CODE;
163*525a267eSThomas Cort } else
164*525a267eSThomas Cort buff_add_ch (yytext[0]);
165*525a267eSThomas Cort }
166*525a267eSThomas Cort
167*525a267eSThomas Cort <BRACE>"\n" { buff_add_ch (yytext[0]); line_no++; }
168*525a267eSThomas Cort
169*525a267eSThomas Cort <BRACE>. { buff_add_ch (yytext[0]); }
170*525a267eSThomas Cort
171*525a267eSThomas Cort . {
172*525a267eSThomas Cort if (yytext[0] < ' ')
173*525a267eSThomas Cort yyerror ("illegal character: ^%c",yytext[0] + '@');
174*525a267eSThomas Cort else
175*525a267eSThomas Cort if (yytext[0] > '~')
176*525a267eSThomas Cort yyerror ("illegal character: \\%3d", (int) yytext[0]);
177*525a267eSThomas Cort else
178*525a267eSThomas Cort yyerror ("illegal character: %s",yytext);
179*525a267eSThomas Cort
180*525a267eSThomas Cort /* To quiet the compiler */
181*525a267eSThomas Cort if (0) unput(0);
182*525a267eSThomas Cort }
183*525a267eSThomas Cort %%
184*525a267eSThomas Cort
185*525a267eSThomas Cort #ifdef SCAN
186*525a267eSThomas Cort YYSTYPE yylval;
187*525a267eSThomas Cort
main()188*525a267eSThomas Cort main()
189*525a267eSThomas Cort {
190*525a267eSThomas Cort int val;
191*525a267eSThomas Cort
192*525a267eSThomas Cort line_no = 1;
193*525a267eSThomas Cort while ( (val = yylex()) != 0 )
194*525a267eSThomas Cort printf ("val = %d\n yytext = %s\n", val, yytext);
195*525a267eSThomas Cort }
196*525a267eSThomas Cort #endif
197