Annotation of 43BSDReno/usr.bin/window/parser3.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Edward Wang at The University of California, Berkeley.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted provided
        !             9:  * that: (1) source distributions retain this entire copyright notice and
        !            10:  * comment, and (2) distributions including binaries display the following
        !            11:  * acknowledgement:  ``This product includes software developed by the
        !            12:  * University of California, Berkeley and its contributors'' in the
        !            13:  * documentation or other materials provided with the distribution and in
        !            14:  * all advertising materials mentioning features or use of this software.
        !            15:  * Neither the name of the University nor the names of its contributors may
        !            16:  * be used to endorse or promote products derived from this software without
        !            17:  * specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)parser3.c  3.9 (Berkeley) 6/6/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include "parser.h"
        !            28: 
        !            29: /*
        !            30:  * =
        !            31:  * ? :
        !            32:  * ||
        !            33:  * &&
        !            34:  * |
        !            35:  * ^
        !            36:  * &
        !            37:  * == !=
        !            38:  * <= >=
        !            39:  * << >>
        !            40:  * + -
        !            41:  * * / %
        !            42:  * unary - + ~ !
        !            43:  */
        !            44: p_expr(v, flag)
        !            45: register struct value *v;
        !            46: char flag;
        !            47: {
        !            48:        struct value t;
        !            49:        int ret;
        !            50: 
        !            51:        if (p_expr0(&t, flag) < 0)
        !            52:                return -1;
        !            53: 
        !            54:        if (token != T_ASSIGN) {
        !            55:                *v = t;
        !            56:                return 0;
        !            57:        }
        !            58:        switch (t.v_type) {
        !            59:        case V_NUM:
        !            60:                p_error("%d: Not a variable.", t.v_num);
        !            61:        case V_ERR:
        !            62:                t.v_str = 0;
        !            63:                break;
        !            64:        }
        !            65:        ret = p_assign(t.v_str, v, flag);
        !            66:        if (t.v_str != 0)
        !            67:                str_free(t.v_str);
        !            68:        return ret;
        !            69: }
        !            70: 
        !            71: /*
        !            72:  * ? :
        !            73:  */
        !            74: p_expr0(v, flag)
        !            75: register struct value *v;
        !            76: char flag;
        !            77: {
        !            78:        struct value t;
        !            79:        char true;
        !            80: 
        !            81:        if (p_expr1(v, flag) < 0)
        !            82:                return -1;
        !            83:        if (token != T_QUEST)
        !            84:                return 0;
        !            85:        switch (v->v_type) {
        !            86:        case V_NUM:
        !            87:                true = v->v_num != 0;
        !            88:                break;
        !            89:        case V_STR:
        !            90:                p_error("?: Numeric left operand required.");
        !            91:                str_free(v->v_str);
        !            92:                v->v_type = V_ERR;
        !            93:        case V_ERR:
        !            94:                flag = 0;
        !            95:                break;
        !            96:        }
        !            97:        (void) s_gettok();
        !            98:        v->v_type = V_ERR;
        !            99:        if ((flag && true ? p_expr1(v, 1) : p_expr1(&t, 0)) < 0)
        !           100:                return -1;
        !           101:        if (token != T_COLON) {
        !           102:                val_free(*v);
        !           103:                p_synerror();
        !           104:                return -1;
        !           105:        }
        !           106:        (void) s_gettok();
        !           107:        return flag && !true ? p_expr1(v, 1) : p_expr1(&t, 0);
        !           108: }
        !           109: 
        !           110: /*
        !           111:  * ||
        !           112:  */
        !           113: p_expr1(v, flag)
        !           114: register struct value *v;
        !           115: char flag;
        !           116: {
        !           117:        char true = 0;
        !           118: 
        !           119:        if (p_expr2(v, flag) < 0)
        !           120:                return -1;
        !           121:        if (token != T_OROR)
        !           122:                return 0;
        !           123:        for (;;) {
        !           124:                switch (v->v_type) {
        !           125:                case V_NUM:
        !           126:                        v->v_num = true = true || v->v_num != 0;
        !           127:                        break;
        !           128:                case V_STR:
        !           129:                        p_error("||: Numeric operands required.");
        !           130:                        str_free(v->v_str);
        !           131:                        v->v_type = V_ERR;
        !           132:                case V_ERR:
        !           133:                        flag = 0;
        !           134:                        break;
        !           135:                }
        !           136:                if (token != T_OROR)
        !           137:                        return 0;
        !           138:                (void) s_gettok();
        !           139:                if (p_expr2(v, flag && !true) < 0)
        !           140:                        return -1;
        !           141:        }
        !           142: }
        !           143: 
        !           144: /*
        !           145:  * &&
        !           146:  */
        !           147: p_expr2(v, flag)
        !           148: register struct value *v;
        !           149: char flag;
        !           150: {
        !           151:        char true = 1;
        !           152: 
        !           153:        if (p_expr3_10(3, v, flag) < 0)
        !           154:                return -1;
        !           155:        if (token != T_ANDAND)
        !           156:                return 0;
        !           157:        for (;;) {
        !           158:                switch (v->v_type) {
        !           159:                case V_NUM:
        !           160:                        v->v_num = true = true && v->v_num != 0;
        !           161:                        break;
        !           162:                case V_STR:
        !           163:                        p_error("&&: Numeric operands required.");
        !           164:                        str_free(v->v_str);
        !           165:                        v->v_type = V_ERR;
        !           166:                case V_ERR:
        !           167:                        flag = 0;
        !           168:                        break;
        !           169:                }
        !           170:                if (token != T_ANDAND)
        !           171:                        return 0;
        !           172:                (void) s_gettok();
        !           173:                if (p_expr3_10(3, v, flag && true) < 0)
        !           174:                        return -1;
        !           175:        }
        !           176:        /*NOTREACHED*/
        !           177: }

unix.superglobalmegacorp.com

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