lex.l revision 201227
11590Srgrimes%{ 21590Srgrimes/*- 31590Srgrimes * Copyright (c) 1993 41590Srgrimes * The Regents of the University of California. All rights reserved. 51590Srgrimes * 61590Srgrimes * This code is derived from software contributed to Berkeley by 71590Srgrimes * Paul Borman at Krystal Technologies. 81590Srgrimes * 91590Srgrimes * Redistribution and use in source and binary forms, with or without 101590Srgrimes * modification, are permitted provided that the following conditions 111590Srgrimes * are met: 121590Srgrimes * 1. Redistributions of source code must retain the above copyright 131590Srgrimes * notice, this list of conditions and the following disclaimer. 141590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151590Srgrimes * notice, this list of conditions and the following disclaimer in the 161590Srgrimes * documentation and/or other materials provided with the distribution. 171590Srgrimes * 3. All advertising materials mentioning features or use of this software 181590Srgrimes * must display the following acknowledgement: 191590Srgrimes * This product includes software developed by the University of 201590Srgrimes * California, Berkeley and its contributors. 211590Srgrimes * 4. Neither the name of the University nor the names of its contributors 221590Srgrimes * may be used to endorse or promote products derived from this software 231590Srgrimes * without specific prior written permission. 241590Srgrimes * 251590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351590Srgrimes * SUCH DAMAGE. 361590Srgrimes */ 371590Srgrimes 381590Srgrimes#ifndef lint 3995643Smarkm#if 0 401590Srgrimesstatic char sccsid[] = "@(#)lex.l 8.1 (Berkeley) 6/6/93"; 4195643Smarkm#endif 421590Srgrimes#endif /* not lint */ 431590Srgrimes 4495643Smarkm#include <sys/cdefs.h> 4595643Smarkm__FBSDID("$FreeBSD: head/usr.bin/mklocale/lex.l 201227 2009-12-29 22:53:27Z ed $"); 4695643Smarkm 471590Srgrimes#include <ctype.h> 481590Srgrimes#include <stdio.h> 491590Srgrimes#include <stdlib.h> 501590Srgrimes 511590Srgrimes#include "ldef.h" 5216073Sphk#include "y.tab.h" 5395643Smarkm#include "extern.h" 541590Srgrimes%} 551590Srgrimes 561590SrgrimesODIGIT [0-7] 571590SrgrimesDIGIT [0-9] 581590SrgrimesXDIGIT [0-9a-fA-F] 591590SrgrimesW [\t\n\r ] 601590Srgrimes 611590Srgrimes%% 6245219Sache\'.\' { yylval.rune = (unsigned char)yytext[1]; 631590Srgrimes return(RUNE); } 641590Srgrimes 651590Srgrimes'\\a' { yylval.rune = '\a'; 661590Srgrimes return(RUNE); } 671590Srgrimes'\\b' { yylval.rune = '\b'; 681590Srgrimes return(RUNE); } 691590Srgrimes'\\f' { yylval.rune = '\f'; 701590Srgrimes return(RUNE); } 711590Srgrimes'\\n' { yylval.rune = '\n'; 721590Srgrimes return(RUNE); } 731590Srgrimes'\\r' { yylval.rune = '\r'; 741590Srgrimes return(RUNE); } 751590Srgrimes'\\t' { yylval.rune = '\t'; 761590Srgrimes return(RUNE); } 771590Srgrimes'\\v' { yylval.rune = '\v'; 781590Srgrimes return(RUNE); } 791590Srgrimes 801590Srgrimes0x{XDIGIT}+ { yylval.rune = strtol(yytext, 0, 16); 811590Srgrimes return(RUNE); } 821590Srgrimes0{ODIGIT}+ { yylval.rune = strtol(yytext, 0, 8); 831590Srgrimes return(RUNE); } 841590Srgrimes{DIGIT}+ { yylval.rune = strtol(yytext, 0, 10); 851590Srgrimes return(RUNE); } 861590Srgrimes 871590Srgrimes 881590SrgrimesMAPLOWER { return(MAPLOWER); } 891590SrgrimesMAPUPPER { return(MAPUPPER); } 901590SrgrimesTODIGIT { return(DIGITMAP); } 911590SrgrimesINVALID { return(INVALID); } 921590Srgrimes 9357035SobrienALPHA { yylval.i = _CTYPE_A|_CTYPE_R|_CTYPE_G; 9457035Sobrien return(LIST); } 9557035SobrienCONTROL { yylval.i = _CTYPE_C; 9657035Sobrien return(LIST); } 9757035SobrienDIGIT { yylval.i = _CTYPE_D|_CTYPE_R|_CTYPE_G; 9857035Sobrien return(LIST); } 9957035SobrienGRAPH { yylval.i = _CTYPE_G|_CTYPE_R; 10057035Sobrien return(LIST); } 10157035SobrienLOWER { yylval.i = _CTYPE_L|_CTYPE_R|_CTYPE_G; 10257035Sobrien return(LIST); } 10357035SobrienPUNCT { yylval.i = _CTYPE_P|_CTYPE_R|_CTYPE_G; 10457035Sobrien return(LIST); } 10557035SobrienSPACE { yylval.i = _CTYPE_S; 10657035Sobrien return(LIST); } 10757035SobrienUPPER { yylval.i = _CTYPE_U|_CTYPE_R|_CTYPE_G; 10857035Sobrien return(LIST); } 10957035SobrienXDIGIT { yylval.i = _CTYPE_X|_CTYPE_R|_CTYPE_G; 11057035Sobrien return(LIST); } 11157035SobrienBLANK { yylval.i = _CTYPE_B; 11257035Sobrien return(LIST); } 11357035SobrienPRINT { yylval.i = _CTYPE_R; 11457035Sobrien return(LIST); } 11557035SobrienIDEOGRAM { yylval.i = _CTYPE_I|_CTYPE_R|_CTYPE_G; 11657035Sobrien return(LIST); } 11757035SobrienSPECIAL { yylval.i = _CTYPE_T|_CTYPE_R|_CTYPE_G; 11857035Sobrien return(LIST); } 11957035SobrienPHONOGRAM { yylval.i = _CTYPE_Q|_CTYPE_R|_CTYPE_G; 12057035Sobrien return(LIST); } 121101986SkeichiiSWIDTH0 { yylval.i = _CTYPE_SW0; return(LIST); } 122101986SkeichiiSWIDTH1 { yylval.i = _CTYPE_SW1; return(LIST); } 123101986SkeichiiSWIDTH2 { yylval.i = _CTYPE_SW2; return(LIST); } 124101986SkeichiiSWIDTH3 { yylval.i = _CTYPE_SW3; return(LIST); } 1251590Srgrimes 1261590SrgrimesVARIABLE[\t ] { static char vbuf[1024]; 1271590Srgrimes char *v = vbuf; 1281590Srgrimes while ((*v = input()) && *v != '\n') 1291590Srgrimes ++v; 1301590Srgrimes if (*v) { 1311590Srgrimes unput(*v); 1321590Srgrimes *v = 0; 1331590Srgrimes } 1341590Srgrimes yylval.str = vbuf; 1351590Srgrimes return(VARIABLE); 1361590Srgrimes } 1371590Srgrimes 1381590SrgrimesENCODING { return(ENCODING); } 1391590Srgrimes 1401590Srgrimes\".*\" { char *e = yytext + 1; 1411590Srgrimes yylval.str = e; 1421590Srgrimes while (*e && *e != '"') 1431590Srgrimes ++e; 1441590Srgrimes *e = 0; 1451590Srgrimes return(STRING); } 1461590Srgrimes 1471590Srgrimes\<|\(|\[ { return(LBRK); } 1481590Srgrimes 1491590Srgrimes\>|\)|\] { return(RBRK); } 1501590Srgrimes 1511590Srgrimes\- { return(THRU); } 1521590Srgrimes\.\.\. { return(THRU); } 1531590Srgrimes 1541590Srgrimes\: { return(':'); } 1551590Srgrimes 1561590Srgrimes{W}+ ; 1571590Srgrimes 1581590Srgrimes^\#.*\n ; 1591590Srgrimes\/\* { char lc = 0; 1601590Srgrimes do { 1611590Srgrimes while ((lc) != '*') 1621590Srgrimes if ((lc = input()) == 0) 1631590Srgrimes break; 1641590Srgrimes } while((lc = input()) != '/'); 1651590Srgrimes } 1661590Srgrimes 1671590Srgrimes\\$ ; 1681590Srgrimes. { printf("Lex is skipping '%s'\n", yytext); } 1691590Srgrimes%% 1701590Srgrimes 1711590Srgrimes#if !defined(yywrap) 17295643Smarkmint 173201227Sedyywrap(void) 1741590Srgrimes{ 1751590Srgrimes return(1); 1761590Srgrimes} 1771590Srgrimes#endif 178