[BACK]Return to lex.l CVS log [TXT][DIR] Up to [local] / src / usr.bin / mklocale

Annotation of src/usr.bin/mklocale/lex.l, Revision 1.2

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