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