lex.l revision 1.11       1 /*	$NetBSD: lex.l,v 1.11 2003/04/21 08:41:28 bjh21 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 #ifndef lint
     46 #if 0
     47 static char sccsid[] = "@(#)lex.l	8.1 (Berkeley) 6/6/93";
     48 #else
     49 #ifdef __RCSID
     50 __RCSID("$NetBSD: lex.l,v 1.11 2003/04/21 08:41:28 bjh21 Exp $");
     51 #endif
     52 #endif
     53 #endif /* not lint */
     54 
     55 #include "locale/runetype.h"
     56 #include <stdio.h>
     57 #include <stdlib.h>
     58 
     59 #include "ldef.h"
     60 #include "yacc.h"
     61 
     62 int yylex __P((void));
     63 %}
     64 
     65 ODIGIT	[0-7]
     66 DIGIT	[0-9]
     67 XDIGIT	[0-9a-fA-F]
     68 W	[\t\n\r ]
     69 
     70 %%
     71 \'.\'				{ yylval.rune = (unsigned char)yytext[1];
     72 				  return(RUNE); }
     73 
     74 '\\a'				{ yylval.rune = '\a';
     75 				  return(RUNE); }
     76 '\\b'				{ yylval.rune = '\b';
     77 				  return(RUNE); }
     78 '\\f'				{ yylval.rune = '\f';
     79 				  return(RUNE); }
     80 '\\n'				{ yylval.rune = '\n';
     81 				  return(RUNE); }
     82 '\\r'				{ yylval.rune = '\r';
     83 				  return(RUNE); }
     84 '\\t'				{ yylval.rune = '\t';
     85 				  return(RUNE); }
     86 '\\v'				{ yylval.rune = '\v';
     87 				  return(RUNE); }
     88 
     89 0x{XDIGIT}+			{ yylval.rune = strtoul(yytext, 0, 16);
     90 				  return(RUNE); }
     91 0{ODIGIT}+			{ yylval.rune = strtoul(yytext, 0, 8);
     92 				  return(RUNE); }
     93 {DIGIT}+			{ yylval.rune = strtoul(yytext, 0, 10);
     94 				  return(RUNE); }
     95 
     96 
     97 MAPLOWER			{ return(MAPLOWER); }
     98 MAPUPPER			{ return(MAPUPPER); }
     99 TODIGIT				{ return(DIGITMAP); }
    100 INVALID				{ return(INVALID); }
    101 
    102 ALPHA				{ yylval.i = _RUNETYPE_A|_RUNETYPE_R|_RUNETYPE_G;
    103 				  return(LIST); }
    104 CONTROL				{ yylval.i = _RUNETYPE_C;
    105 				  return(LIST); }
    106 DIGIT				{ yylval.i = _RUNETYPE_D|_RUNETYPE_R|_RUNETYPE_G;
    107 				  return(LIST); }
    108 GRAPH				{ yylval.i = _RUNETYPE_G|_RUNETYPE_R;
    109 				  return(LIST); }
    110 LOWER				{ yylval.i = _RUNETYPE_L|_RUNETYPE_R|_RUNETYPE_G;
    111 				  return(LIST); }
    112 PUNCT				{ yylval.i = _RUNETYPE_P|_RUNETYPE_R|_RUNETYPE_G;
    113 				  return(LIST); }
    114 SPACE				{ yylval.i = _RUNETYPE_S;
    115 				  return(LIST); }
    116 UPPER				{ yylval.i = _RUNETYPE_U|_RUNETYPE_R|_RUNETYPE_G;
    117 				  return(LIST); }
    118 XDIGIT				{ yylval.i = _RUNETYPE_X|_RUNETYPE_R|_RUNETYPE_G;
    119 				  return(LIST); }
    120 BLANK				{ yylval.i = _RUNETYPE_B;
    121 				  return(LIST); }
    122 PRINT				{ yylval.i = _RUNETYPE_R;
    123 				  return(LIST); }
    124 IDEOGRAM			{ yylval.i = _RUNETYPE_I|_RUNETYPE_R|_RUNETYPE_G;
    125 				  return(LIST); }
    126 SPECIAL				{ yylval.i = _RUNETYPE_T|_RUNETYPE_R|_RUNETYPE_G;
    127 				  return(LIST); }
    128 PHONOGRAM			{ yylval.i = _RUNETYPE_Q|_RUNETYPE_R|_RUNETYPE_G;
    129 				  return(LIST); }
    130 SWIDTH0				{ yylval.i = _RUNETYPE_SW0; return(LIST); }
    131 SWIDTH1				{ yylval.i = _RUNETYPE_SW1; return(LIST); }
    132 SWIDTH2				{ yylval.i = _RUNETYPE_SW2; return(LIST); }
    133 SWIDTH3				{ yylval.i = _RUNETYPE_SW3; return(LIST); }
    134 
    135 VARIABLE[\t ]			{ static char vbuf[1024];
    136 				  char *v = vbuf;
    137 				  while ((*v = input()) && *v != '\n')
    138 					++v;
    139                                   if (*v) {
    140 					unput(*v);
    141 					*v = 0;
    142 				  }
    143 				  yylval.str = vbuf;
    144 				  return(VARIABLE);
    145 				}
    146 
    147 CHARSET				{ return(CHARSET); }
    148 
    149 ENCODING			{ return(ENCODING); }
    150 
    151 \".*\"				{ char *e = yytext + 1;
    152 				  yylval.str = e;
    153 				  while (*e && *e != '"')
    154 					++e;
    155 				  *e = 0;
    156 				  return(STRING); }
    157 
    158 \<|\(|\[			{ return(LBRK); }
    159 
    160 \>|\)|\]			{ return(RBRK); }
    161 
    162 \-				{ return(THRU); }
    163 \.\.\.				{ return(THRU); }
    164 
    165 \:				{ return(':'); }
    166 
    167 {W}+				;
    168 
    169 ^\#.*\n				;
    170 \/\*				{ char lc = 0;
    171 				  do {
    172 				    while ((lc) != '*')
    173 					if ((lc = input()) == 0)
    174 					    break;
    175 				  } while((lc = input()) != '/');
    176 				}
    177 
    178 \\$				;
    179 .				{ printf("Lex is skipping '%s'\n", yytext); }
    180 %%
    181 
    182 #if	!defined(yywrap)
    183 int
    184 yywrap()
    185 {
    186 	return(1);
    187 }
    188 #endif
    189