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