lex.l revision 1.2 1 1.2 itojun /* $NetBSD: lex.l,v 1.2 2000/12/22 01:31:49 itojun Exp $ */
2 1.2 itojun
3 1.2 itojun %{
4 1.2 itojun /*-
5 1.2 itojun * Copyright (c) 1993
6 1.2 itojun * The Regents of the University of California. All rights reserved.
7 1.2 itojun *
8 1.2 itojun * This code is derived from software contributed to Berkeley by
9 1.2 itojun * Paul Borman at Krystal Technologies.
10 1.2 itojun *
11 1.2 itojun * Redistribution and use in source and binary forms, with or without
12 1.2 itojun * modification, are permitted provided that the following conditions
13 1.2 itojun * are met:
14 1.2 itojun * 1. Redistributions of source code must retain the above copyright
15 1.2 itojun * notice, this list of conditions and the following disclaimer.
16 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
17 1.2 itojun * notice, this list of conditions and the following disclaimer in the
18 1.2 itojun * documentation and/or other materials provided with the distribution.
19 1.2 itojun * 3. All advertising materials mentioning features or use of this software
20 1.2 itojun * must display the following acknowledgement:
21 1.2 itojun * This product includes software developed by the University of
22 1.2 itojun * California, Berkeley and its contributors.
23 1.2 itojun * 4. Neither the name of the University nor the names of its contributors
24 1.2 itojun * may be used to endorse or promote products derived from this software
25 1.2 itojun * without specific prior written permission.
26 1.2 itojun *
27 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.2 itojun * SUCH DAMAGE.
38 1.2 itojun */
39 1.2 itojun
40 1.2 itojun #include <sys/cdefs.h>
41 1.2 itojun #ifndef lint
42 1.2 itojun #if 0
43 1.2 itojun static char sccsid[] = "@(#)lex.l 8.1 (Berkeley) 6/6/93";
44 1.2 itojun #else
45 1.2 itojun __RCSID("$NetBSD: lex.l,v 1.2 2000/12/22 01:31:49 itojun Exp $");
46 1.2 itojun #endif
47 1.2 itojun #endif /* not lint */
48 1.2 itojun
49 1.2 itojun #if !defined(__FreeBSD__)
50 1.2 itojun #define _BSD_RUNE_T_ int
51 1.2 itojun #define _BSD_CT_RUNE_T_ rune_t
52 1.2 itojun #include "runetype.h"
53 1.2 itojun #else
54 1.2 itojun #include <ctype.h>
55 1.2 itojun #endif
56 1.2 itojun #include <stdio.h>
57 1.2 itojun #include <stdlib.h>
58 1.2 itojun
59 1.2 itojun #include "ldef.h"
60 1.2 itojun #ifdef __NetBSD__
61 1.2 itojun #include "yacc.h"
62 1.2 itojun #else
63 1.2 itojun #include "y.tab.h"
64 1.2 itojun #endif
65 1.2 itojun
66 1.2 itojun int yylex __P((void));
67 1.2 itojun %}
68 1.2 itojun
69 1.2 itojun ODIGIT [0-7]
70 1.2 itojun DIGIT [0-9]
71 1.2 itojun XDIGIT [0-9a-fA-F]
72 1.2 itojun W [\t\n\r ]
73 1.2 itojun
74 1.2 itojun %%
75 1.2 itojun \'.\' { yylval.rune = (unsigned char)yytext[1];
76 1.2 itojun return(RUNE); }
77 1.2 itojun
78 1.2 itojun '\\a' { yylval.rune = '\a';
79 1.2 itojun return(RUNE); }
80 1.2 itojun '\\b' { yylval.rune = '\b';
81 1.2 itojun return(RUNE); }
82 1.2 itojun '\\f' { yylval.rune = '\f';
83 1.2 itojun return(RUNE); }
84 1.2 itojun '\\n' { yylval.rune = '\n';
85 1.2 itojun return(RUNE); }
86 1.2 itojun '\\r' { yylval.rune = '\r';
87 1.2 itojun return(RUNE); }
88 1.2 itojun '\\t' { yylval.rune = '\t';
89 1.2 itojun return(RUNE); }
90 1.2 itojun '\\v' { yylval.rune = '\v';
91 1.2 itojun return(RUNE); }
92 1.2 itojun
93 1.2 itojun 0x{XDIGIT}+ { yylval.rune = strtol(yytext, 0, 16);
94 1.2 itojun return(RUNE); }
95 1.2 itojun 0{ODIGIT}+ { yylval.rune = strtol(yytext, 0, 8);
96 1.2 itojun return(RUNE); }
97 1.2 itojun {DIGIT}+ { yylval.rune = strtol(yytext, 0, 10);
98 1.2 itojun return(RUNE); }
99 1.2 itojun
100 1.2 itojun
101 1.2 itojun MAPLOWER { return(MAPLOWER); }
102 1.2 itojun MAPUPPER { return(MAPUPPER); }
103 1.2 itojun TODIGIT { return(DIGITMAP); }
104 1.2 itojun INVALID { return(INVALID); }
105 1.2 itojun
106 1.2 itojun ALPHA { yylval.i = _CTYPE_A|_CTYPE_R|_CTYPE_G;
107 1.2 itojun return(LIST); }
108 1.2 itojun CONTROL { yylval.i = _CTYPE_C;
109 1.2 itojun return(LIST); }
110 1.2 itojun DIGIT { yylval.i = _CTYPE_D|_CTYPE_R|_CTYPE_G;
111 1.2 itojun return(LIST); }
112 1.2 itojun GRAPH { yylval.i = _CTYPE_G|_CTYPE_R;
113 1.2 itojun return(LIST); }
114 1.2 itojun LOWER { yylval.i = _CTYPE_L|_CTYPE_R|_CTYPE_G;
115 1.2 itojun return(LIST); }
116 1.2 itojun PUNCT { yylval.i = _CTYPE_P|_CTYPE_R|_CTYPE_G;
117 1.2 itojun return(LIST); }
118 1.2 itojun SPACE { yylval.i = _CTYPE_S;
119 1.2 itojun return(LIST); }
120 1.2 itojun UPPER { yylval.i = _CTYPE_U|_CTYPE_R|_CTYPE_G;
121 1.2 itojun return(LIST); }
122 1.2 itojun XDIGIT { yylval.i = _CTYPE_X|_CTYPE_R|_CTYPE_G;
123 1.2 itojun return(LIST); }
124 1.2 itojun BLANK { yylval.i = _CTYPE_B;
125 1.2 itojun return(LIST); }
126 1.2 itojun PRINT { yylval.i = _CTYPE_R;
127 1.2 itojun return(LIST); }
128 1.2 itojun IDEOGRAM { yylval.i = _CTYPE_I|_CTYPE_R|_CTYPE_G;
129 1.2 itojun return(LIST); }
130 1.2 itojun SPECIAL { yylval.i = _CTYPE_T|_CTYPE_R|_CTYPE_G;
131 1.2 itojun return(LIST); }
132 1.2 itojun PHONOGRAM { yylval.i = _CTYPE_Q|_CTYPE_R|_CTYPE_G;
133 1.2 itojun return(LIST); }
134 1.2 itojun SWIDTH0 { yylval.i = _CTYPE_SW0; return(LIST); }
135 1.2 itojun SWIDTH1 { yylval.i = _CTYPE_SW1; return(LIST); }
136 1.2 itojun SWIDTH2 { yylval.i = _CTYPE_SW2; return(LIST); }
137 1.2 itojun SWIDTH3 { yylval.i = _CTYPE_SW3; return(LIST); }
138 1.2 itojun
139 1.2 itojun VARIABLE[\t ] { static char vbuf[1024];
140 1.2 itojun char *v = vbuf;
141 1.2 itojun while ((*v = input()) && *v != '\n')
142 1.2 itojun ++v;
143 1.2 itojun if (*v) {
144 1.2 itojun unput(*v);
145 1.2 itojun *v = 0;
146 1.2 itojun }
147 1.2 itojun yylval.str = vbuf;
148 1.2 itojun return(VARIABLE);
149 1.2 itojun }
150 1.2 itojun
151 1.2 itojun CHARSET { return(CHARSET); }
152 1.2 itojun
153 1.2 itojun ENCODING { return(ENCODING); }
154 1.2 itojun
155 1.2 itojun \".*\" { char *e = yytext + 1;
156 1.2 itojun yylval.str = e;
157 1.2 itojun while (*e && *e != '"')
158 1.2 itojun ++e;
159 1.2 itojun *e = 0;
160 1.2 itojun return(STRING); }
161 1.2 itojun
162 1.2 itojun \<|\(|\[ { return(LBRK); }
163 1.2 itojun
164 1.2 itojun \>|\)|\] { return(RBRK); }
165 1.2 itojun
166 1.2 itojun \- { return(THRU); }
167 1.2 itojun \.\.\. { return(THRU); }
168 1.2 itojun
169 1.2 itojun \: { return(':'); }
170 1.2 itojun
171 1.2 itojun {W}+ ;
172 1.2 itojun
173 1.2 itojun ^\#.*\n ;
174 1.2 itojun \/\* { char lc = 0;
175 1.2 itojun do {
176 1.2 itojun while ((lc) != '*')
177 1.2 itojun if ((lc = input()) == 0)
178 1.2 itojun break;
179 1.2 itojun } while((lc = input()) != '/');
180 1.2 itojun }
181 1.2 itojun
182 1.2 itojun \\$ ;
183 1.2 itojun . { printf("Lex is skipping '%s'\n", yytext); }
184 1.2 itojun %%
185 1.2 itojun
186 1.2 itojun #if !defined(yywrap)
187 1.2 itojun int
188 1.2 itojun yywrap()
189 1.2 itojun {
190 1.2 itojun return(1);
191 1.2 itojun }
192 1.2 itojun #endif
193