Annotation of 43BSDTahoe/ucb/window/parser1.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: static char sccsid[] = "@(#)parser1.c  3.20 (Berkeley) 6/29/88";
                     20: #endif /* not lint */
                     21: 
                     22: #include "parser.h"
                     23: 
                     24: p_start()
                     25: {
                     26:        char flag = 1;
                     27: 
                     28:        (void) s_gettok();
                     29:        for (;;) {
                     30:                p_statementlist(flag);
                     31:                if (token == T_EOF || p_abort())
                     32:                        break;
                     33:                flag = 0;
                     34:                p_synerror();
                     35:                while (token != T_EOL && token != T_EOF) {
                     36:                        if (token == T_STR)
                     37:                                str_free(token_str);
                     38:                        (void) s_gettok();
                     39:                }
                     40:                if (token == T_EOL)
                     41:                        (void) s_gettok();
                     42:                p_clearerr();
                     43:        }
                     44: }
                     45: 
                     46: p_statementlist(flag)
                     47: char flag;
                     48: {
                     49:        for (; p_statement(flag) >= 0; p_clearerr())
                     50:                ;
                     51: }
                     52: 
                     53: p_statement(flag)
                     54: char flag;
                     55: {
                     56:        switch (token) {
                     57:        case T_EOL:
                     58:                (void) s_gettok();
                     59:                return 0;
                     60:        case T_IF:
                     61:                return p_if(flag);
                     62:        default:
                     63:                return p_expression(flag);
                     64:        }
                     65: }
                     66: 
                     67: p_if(flag)
                     68: char flag;
                     69: {
                     70:        struct value t;
                     71:        char true = 0;
                     72: 
                     73: top:
                     74:        (void) s_gettok();
                     75: 
                     76:        if (p_expr(&t, flag) < 0) {
                     77:                p_synerror();
                     78:                return -1;
                     79:        }
                     80:        switch (t.v_type) {
                     81:        case V_NUM:
                     82:                true = !true && t.v_num != 0;
                     83:                break;
                     84:        case V_STR:
                     85:                p_error("if: Numeric value required.");
                     86:                str_free(t.v_str);
                     87:        case V_ERR:
                     88:                flag = 0;
                     89:                break;
                     90:        }
                     91: 
                     92:        if (token != T_THEN) {
                     93:                p_synerror();
                     94:                return -1;
                     95:        }
                     96: 
                     97:        (void) s_gettok();
                     98:        p_statementlist(flag && true);
                     99:        if (p_erred())
                    100:                return -1;
                    101: 
                    102:        if (token == T_ELSIF)
                    103:                goto top;
                    104: 
                    105:        if (token == T_ELSE) {
                    106:                (void) s_gettok();
                    107:                p_statementlist(flag && !true);
                    108:                if (p_erred())
                    109:                        return -1;
                    110:        }
                    111: 
                    112:        if (token == T_ENDIF) {
                    113:                (void) s_gettok();
                    114:                return 0;
                    115:        }
                    116: 
                    117:        p_synerror();
                    118:        return -1;
                    119: }
                    120: 
                    121: p_expression(flag)
                    122: char flag;
                    123: {
                    124:        struct value t;
                    125:        char *cmd;
                    126:        int p_function(), p_assign();
                    127: 
                    128:        switch (token) {
                    129:        case T_NUM:
                    130:                t.v_type = V_NUM;
                    131:                t.v_num = token_num;
                    132:                (void) s_gettok();
                    133:                break;
                    134:        case T_STR:
                    135:                t.v_type = V_STR;
                    136:                t.v_str = token_str;
                    137:                (void) s_gettok();
                    138:                break;
                    139:        default:
                    140:                if (p_expr(&t, flag) < 0)
                    141:                        return -1;
                    142:                if (token == T_EOF) {
                    143:                        val_free(t);
                    144:                        return 0;
                    145:                }
                    146:        }
                    147:        if (token != T_ASSIGN && p_convstr(&t) < 0)
                    148:                return -1;
                    149:        cmd = t.v_type == V_STR ? t.v_str : 0;
                    150:        if ((*(token == T_ASSIGN ? p_assign : p_function))(cmd, &t, flag) < 0) {
                    151:                if (cmd)
                    152:                        str_free(cmd);
                    153:                return -1;
                    154:        }
                    155:        if (cmd)
                    156:                str_free(cmd);
                    157:        val_free(t);
                    158:        if (token == T_EOL)
                    159:                (void) s_gettok();
                    160:        else if (token != T_EOF) {
                    161:                p_synerror();
                    162:                return -1;
                    163:        }
                    164:        return 0;
                    165: }
                    166: 
                    167: p_convstr(v)
                    168: register struct value *v;
                    169: {
                    170:        if (v->v_type != V_NUM)
                    171:                return 0;
                    172:        if ((v->v_str = str_itoa(v->v_num)) == 0) {
                    173:                p_memerror();
                    174:                v->v_type = V_ERR;
                    175:                return -1;
                    176:        }
                    177:        v->v_type = V_STR;
                    178:        return 0;
                    179: }
                    180: 
                    181: p_synerror()
                    182: {
                    183:        if (!cx.x_synerred) {
                    184:                cx.x_synerred = cx.x_erred = 1;
                    185:                error("Syntax error.");
                    186:        }
                    187: }
                    188: 
                    189: /*VARARGS1*/
                    190: p_error(msg, a, b, c)
                    191: char *msg;
                    192: {
                    193:        if (!cx.x_erred) {
                    194:                cx.x_erred = 1;
                    195:                error(msg, a, b, c);
                    196:        }
                    197: }
                    198: 
                    199: p_memerror()
                    200: {
                    201:        cx.x_erred = cx.x_abort = 1;
                    202:        error("Out of memory.");
                    203: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.