[BACK]Return to error_table.y CVS log [TXT][DIR] Up to [local] / src / usr.bin / compile_et

Annotation of src/usr.bin/compile_et/error_table.y, Revision 1.6

1.1       downsj      1: %{
1.3       hin         2: /*
                      3:  * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan
                      4:  * (Royal Institute of Technology, Stockholm, Sweden).
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  *
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  *
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  *
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *      This product includes software developed by Kungliga Tekniska
                     21:  *      Högskolan and its contributors.
                     22:  *
                     23:  * 4. Neither the name of the Institute 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.
1.1       downsj     26:  *
1.3       hin        27:  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
1.1       downsj     38:  */
                     39:
1.3       hin        40: #include "compile_et.h"
                     41: /* RCSID("$KTH: parse.y,v 1.9 1999/07/04 14:54:58 assar Exp $"); */
1.1       downsj     42:
1.3       hin        43: void yyerror (char *s);
                     44: long name2number(const char *str);
                     45: void error_message(char *, ...);
1.1       downsj     46:
1.3       hin        47: extern char *yytext;
1.5       deraadt    48: int yyparse(void);
1.1       downsj     49:
1.3       hin        50: /* This is for bison */
1.1       downsj     51:
1.3       hin        52: #if !defined(alloca) && !defined(HAVE_ALLOCA)
                     53: #define alloca(x) malloc(x)
1.1       downsj     54: #endif
                     55:
1.3       hin        56: %}
1.1       downsj     57:
1.3       hin        58: %union {
                     59:   char *string;
                     60:   int number;
1.1       downsj     61: }
                     62:
1.3       hin        63: %token ET INDEX PREFIX EC ID END
                     64: %token <string> STRING
                     65: %token <number> NUMBER
1.1       downsj     66:
1.3       hin        67: %%
1.1       downsj     68:
1.3       hin        69: file           : /* */
                     70:                | header statements
                     71:                ;
1.1       downsj     72:
1.3       hin        73: header         : id et
                     74:                | et
                     75:                ;
1.1       downsj     76:
1.3       hin        77: id             : ID STRING
                     78:                {
                     79:                    id_str = $2;
                     80:                }
                     81:                ;
                     82:
                     83: et             : ET STRING
                     84:                {
                     85:                    base = name2number($2);
1.6     ! jaredy     86:                    strlcpy(name, $2, sizeof(name));
1.3       hin        87:                    free($2);
                     88:                }
                     89:                | ET STRING STRING
                     90:                {
                     91:                    base = name2number($2);
1.6     ! jaredy     92:                    strlcpy(name, $3, sizeof(name));
1.3       hin        93:                    free($2);
                     94:                    free($3);
                     95:                }
                     96:                ;
                     97:
                     98: statements     : statement
                     99:                | statements statement
                    100:                ;
                    101:
                    102: statement      : INDEX NUMBER
                    103:                {
                    104:                        number = $2;
                    105:                }
                    106:                | PREFIX STRING
                    107:                {
1.4       deraadt   108:                    size_t len = strlen($2) + 2;
1.6     ! jaredy    109:
        !           110:                    if ((prefix = realloc(prefix, len)) == NULL) {
        !           111:                        yyerror(strerror(errno));
        !           112:                        exit(1);
        !           113:                    }
1.4       deraadt   114:                    strlcpy(prefix, $2, len);
                    115:                    strlcat(prefix, "_", len);
1.3       hin       116:                    free($2);
                    117:                }
                    118:                | PREFIX
                    119:                {
1.6     ! jaredy    120:                    if ((prefix = realloc(prefix, 1)) == NULL) {
        !           121:                        yyerror(strerror(errno));
        !           122:                        exit(1);
        !           123:                    }
1.3       hin       124:                    *prefix = '\0';
                    125:                }
                    126:                | EC STRING ',' STRING
                    127:                {
                    128:                    struct error_code *ec = malloc(sizeof(*ec));
1.6     ! jaredy    129:
        !           130:                    if (ec == NULL) {
        !           131:                        yyerror(strerror(errno));
        !           132:                        exit(1);
        !           133:                    }
1.3       hin       134:                    ec->next = NULL;
                    135:                    ec->number = number;
                    136:                    if(prefix && *prefix != '\0') {
1.6     ! jaredy    137:                        if (asprintf (&ec->name, "%s%s", prefix, $2) == -1) {
        !           138:                            yyerror(strerror(errno));
        !           139:                            exit(1);
        !           140:                        }
1.3       hin       141:                        free($2);
                    142:                    } else
                    143:                        ec->name = $2;
                    144:                    ec->string = $4;
                    145:                    APPEND(codes, ec);
                    146:                    number++;
                    147:                }
                    148:                | END
                    149:                {
                    150:                        YYACCEPT;
                    151:                }
                    152:                ;
1.1       downsj    153:
1.3       hin       154: %%
1.1       downsj    155:
1.3       hin       156: long
                    157: name2number(const char *str)
1.1       downsj    158: {
1.3       hin       159:     const char *p;
                    160:     long base = 0;
                    161:     const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    162:        "abcdefghijklmnopqrstuvwxyz0123456789_";
                    163:     if(strlen(str) > 4) {
                    164:        yyerror("table name too long");
                    165:        return 0;
                    166:     }
                    167:     for(p = str; *p; p++){
                    168:        char *q = strchr(x, *p);
                    169:        if(q == NULL) {
                    170:            yyerror("invalid character in table name");
                    171:            return 0;
                    172:        }
                    173:        base = (base << 6) + (q - x) + 1;
                    174:     }
                    175:     base <<= 8;
                    176:     if(base > 0x7fffffff)
                    177:        base = -(0xffffffff - base + 1);
                    178:     return base;
1.1       downsj    179: }
                    180:
1.2       art       181: void
1.3       hin       182: yyerror (char *s)
1.1       downsj    183: {
1.3       hin       184:      error_message ("%s\n", s);
1.1       downsj    185: }