lex.l revision 1.12 1 1.12 agc /* $NetBSD: lex.l,v 1.12 2003/08/07 11:15:14 agc 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.12 agc * 3. Neither the name of the University nor the names of its contributors
20 1.2 itojun * may be used to endorse or promote products derived from this software
21 1.2 itojun * without specific prior written permission.
22 1.2 itojun *
23 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.2 itojun * SUCH DAMAGE.
34 1.2 itojun */
35 1.2 itojun
36 1.4 tv #if HAVE_CONFIG_H
37 1.4 tv #include "config.h"
38 1.4 tv #endif
39 1.4 tv
40 1.2 itojun #include <sys/cdefs.h>
41 1.10 christos #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.11 bjh21 #ifdef __RCSID
46 1.12 agc __RCSID("$NetBSD: lex.l,v 1.12 2003/08/07 11:15:14 agc Exp $");
47 1.11 bjh21 #endif
48 1.2 itojun #endif
49 1.10 christos #endif /* not lint */
50 1.2 itojun
51 1.7 tshiozak #include "locale/runetype.h"
52 1.2 itojun #include <stdio.h>
53 1.2 itojun #include <stdlib.h>
54 1.2 itojun
55 1.2 itojun #include "ldef.h"
56 1.2 itojun #include "yacc.h"
57 1.2 itojun
58 1.2 itojun int yylex __P((void));
59 1.2 itojun %}
60 1.2 itojun
61 1.2 itojun ODIGIT [0-7]
62 1.2 itojun DIGIT [0-9]
63 1.2 itojun XDIGIT [0-9a-fA-F]
64 1.2 itojun W [\t\n\r ]
65 1.2 itojun
66 1.2 itojun %%
67 1.2 itojun \'.\' { yylval.rune = (unsigned char)yytext[1];
68 1.2 itojun return(RUNE); }
69 1.2 itojun
70 1.2 itojun '\\a' { yylval.rune = '\a';
71 1.2 itojun return(RUNE); }
72 1.2 itojun '\\b' { yylval.rune = '\b';
73 1.2 itojun return(RUNE); }
74 1.2 itojun '\\f' { yylval.rune = '\f';
75 1.2 itojun return(RUNE); }
76 1.2 itojun '\\n' { yylval.rune = '\n';
77 1.2 itojun return(RUNE); }
78 1.2 itojun '\\r' { yylval.rune = '\r';
79 1.2 itojun return(RUNE); }
80 1.2 itojun '\\t' { yylval.rune = '\t';
81 1.2 itojun return(RUNE); }
82 1.2 itojun '\\v' { yylval.rune = '\v';
83 1.2 itojun return(RUNE); }
84 1.2 itojun
85 1.9 tshiozak 0x{XDIGIT}+ { yylval.rune = strtoul(yytext, 0, 16);
86 1.2 itojun return(RUNE); }
87 1.9 tshiozak 0{ODIGIT}+ { yylval.rune = strtoul(yytext, 0, 8);
88 1.2 itojun return(RUNE); }
89 1.9 tshiozak {DIGIT}+ { yylval.rune = strtoul(yytext, 0, 10);
90 1.2 itojun return(RUNE); }
91 1.2 itojun
92 1.2 itojun
93 1.2 itojun MAPLOWER { return(MAPLOWER); }
94 1.2 itojun MAPUPPER { return(MAPUPPER); }
95 1.2 itojun TODIGIT { return(DIGITMAP); }
96 1.2 itojun INVALID { return(INVALID); }
97 1.2 itojun
98 1.8 tshiozak ALPHA { yylval.i = _RUNETYPE_A|_RUNETYPE_R|_RUNETYPE_G;
99 1.2 itojun return(LIST); }
100 1.8 tshiozak CONTROL { yylval.i = _RUNETYPE_C;
101 1.2 itojun return(LIST); }
102 1.8 tshiozak DIGIT { yylval.i = _RUNETYPE_D|_RUNETYPE_R|_RUNETYPE_G;
103 1.2 itojun return(LIST); }
104 1.8 tshiozak GRAPH { yylval.i = _RUNETYPE_G|_RUNETYPE_R;
105 1.2 itojun return(LIST); }
106 1.8 tshiozak LOWER { yylval.i = _RUNETYPE_L|_RUNETYPE_R|_RUNETYPE_G;
107 1.2 itojun return(LIST); }
108 1.8 tshiozak PUNCT { yylval.i = _RUNETYPE_P|_RUNETYPE_R|_RUNETYPE_G;
109 1.2 itojun return(LIST); }
110 1.8 tshiozak SPACE { yylval.i = _RUNETYPE_S;
111 1.2 itojun return(LIST); }
112 1.8 tshiozak UPPER { yylval.i = _RUNETYPE_U|_RUNETYPE_R|_RUNETYPE_G;
113 1.2 itojun return(LIST); }
114 1.8 tshiozak XDIGIT { yylval.i = _RUNETYPE_X|_RUNETYPE_R|_RUNETYPE_G;
115 1.2 itojun return(LIST); }
116 1.8 tshiozak BLANK { yylval.i = _RUNETYPE_B;
117 1.2 itojun return(LIST); }
118 1.8 tshiozak PRINT { yylval.i = _RUNETYPE_R;
119 1.2 itojun return(LIST); }
120 1.8 tshiozak IDEOGRAM { yylval.i = _RUNETYPE_I|_RUNETYPE_R|_RUNETYPE_G;
121 1.2 itojun return(LIST); }
122 1.8 tshiozak SPECIAL { yylval.i = _RUNETYPE_T|_RUNETYPE_R|_RUNETYPE_G;
123 1.2 itojun return(LIST); }
124 1.8 tshiozak PHONOGRAM { yylval.i = _RUNETYPE_Q|_RUNETYPE_R|_RUNETYPE_G;
125 1.2 itojun return(LIST); }
126 1.8 tshiozak SWIDTH0 { yylval.i = _RUNETYPE_SW0; return(LIST); }
127 1.8 tshiozak SWIDTH1 { yylval.i = _RUNETYPE_SW1; return(LIST); }
128 1.8 tshiozak SWIDTH2 { yylval.i = _RUNETYPE_SW2; return(LIST); }
129 1.8 tshiozak SWIDTH3 { yylval.i = _RUNETYPE_SW3; return(LIST); }
130 1.2 itojun
131 1.2 itojun VARIABLE[\t ] { static char vbuf[1024];
132 1.2 itojun char *v = vbuf;
133 1.2 itojun while ((*v = input()) && *v != '\n')
134 1.2 itojun ++v;
135 1.2 itojun if (*v) {
136 1.2 itojun unput(*v);
137 1.2 itojun *v = 0;
138 1.2 itojun }
139 1.2 itojun yylval.str = vbuf;
140 1.2 itojun return(VARIABLE);
141 1.2 itojun }
142 1.2 itojun
143 1.2 itojun CHARSET { return(CHARSET); }
144 1.2 itojun
145 1.2 itojun ENCODING { return(ENCODING); }
146 1.2 itojun
147 1.2 itojun \".*\" { char *e = yytext + 1;
148 1.2 itojun yylval.str = e;
149 1.2 itojun while (*e && *e != '"')
150 1.2 itojun ++e;
151 1.2 itojun *e = 0;
152 1.2 itojun return(STRING); }
153 1.2 itojun
154 1.2 itojun \<|\(|\[ { return(LBRK); }
155 1.2 itojun
156 1.2 itojun \>|\)|\] { return(RBRK); }
157 1.2 itojun
158 1.2 itojun \- { return(THRU); }
159 1.2 itojun \.\.\. { return(THRU); }
160 1.2 itojun
161 1.2 itojun \: { return(':'); }
162 1.2 itojun
163 1.2 itojun {W}+ ;
164 1.2 itojun
165 1.2 itojun ^\#.*\n ;
166 1.2 itojun \/\* { char lc = 0;
167 1.2 itojun do {
168 1.2 itojun while ((lc) != '*')
169 1.2 itojun if ((lc = input()) == 0)
170 1.2 itojun break;
171 1.2 itojun } while((lc = input()) != '/');
172 1.2 itojun }
173 1.2 itojun
174 1.2 itojun \\$ ;
175 1.2 itojun . { printf("Lex is skipping '%s'\n", yytext); }
176 1.2 itojun %%
177 1.2 itojun
178 1.2 itojun #if !defined(yywrap)
179 1.2 itojun int
180 1.2 itojun yywrap()
181 1.2 itojun {
182 1.2 itojun return(1);
183 1.2 itojun }
184 1.2 itojun #endif
185