1: #ifndef lint
   2: static char sccsid[] = "@(#)parser3.c	3.5 4/24/85";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1983 Regents of the University of California,
   7:  * All rights reserved.  Redistribution permitted subject to
   8:  * the terms of the Berkeley Software License Agreement.
   9:  */
  10: 
  11: #include "parser.h"
  12: 
  13: /*
  14:  * =
  15:  * ? :
  16:  * ||
  17:  * &&
  18:  * |
  19:  * ^
  20:  * &
  21:  * == !=
  22:  * <= >=
  23:  * << >>
  24:  * + -
  25:  * * / %
  26:  * unary - + ~ !
  27:  */
  28: p_expr(v, flag)
  29: register struct value *v;
  30: char flag;
  31: {
  32:     struct value t;
  33:     int ret;
  34: 
  35:     if (p_expr0(&t, flag) < 0)
  36:         return -1;
  37: 
  38:     if (token != T_ASSIGN) {
  39:         *v = t;
  40:         return 0;
  41:     }
  42:     switch (t.v_type) {
  43:     case V_NUM:
  44:         p_error("%d: Not a variable.", t.v_num);
  45:     case V_ERR:
  46:         t.v_str = 0;
  47:         break;
  48:     }
  49:     ret = p_assign(t.v_str, v, flag);
  50:     if (t.v_str != 0)
  51:         str_free(t.v_str);
  52:     return ret;
  53: }
  54: 
  55: /*
  56:  * ? :
  57:  */
  58: p_expr0(v, flag)
  59: register struct value *v;
  60: char flag;
  61: {
  62:     struct value t;
  63:     char true;
  64: 
  65:     if (p_expr1(v, flag) < 0)
  66:         return -1;
  67:     if (token != T_QUEST)
  68:         return 0;
  69:     switch (v->v_type) {
  70:     case V_NUM:
  71:         true = v->v_num != 0;
  72:         break;
  73:     case V_STR:
  74:         p_error("?: Numeric left operand required.");
  75:         str_free(v->v_str);
  76:         v->v_type = V_ERR;
  77:     case V_ERR:
  78:         flag = 0;
  79:         break;
  80:     }
  81:     (void) s_gettok();
  82:     v->v_type = V_ERR;
  83:     if ((flag && true ? p_expr1(v, 1) : p_expr1(&t, 0)) < 0)
  84:         return -1;
  85:     if (token != T_COLON) {
  86:         val_free(*v);
  87:         p_synerror();
  88:         return -1;
  89:     }
  90:     (void) s_gettok();
  91:     return flag && !true ? p_expr1(v, 1) : p_expr1(&t, 0);
  92: }
  93: 
  94: /*
  95:  * ||
  96:  */
  97: p_expr1(v, flag)
  98: register struct value *v;
  99: char flag;
 100: {
 101:     char true = 0;
 102: 
 103:     if (p_expr2(v, flag) < 0)
 104:         return -1;
 105:     if (token != T_OROR)
 106:         return 0;
 107:     for (;;) {
 108:         switch (v->v_type) {
 109:         case V_NUM:
 110:             v->v_num = true = true || v->v_num != 0;
 111:             break;
 112:         case V_STR:
 113:             p_error("||: Numeric operands required.");
 114:             str_free(v->v_str);
 115:             v->v_type = V_ERR;
 116:         case V_ERR:
 117:             flag = 0;
 118:             break;
 119:         }
 120:         if (token != T_OROR)
 121:             return 0;
 122:         (void) s_gettok();
 123:         if (p_expr2(v, flag && !true) < 0)
 124:             return -1;
 125:     }
 126: }
 127: 
 128: /*
 129:  * &&
 130:  */
 131: p_expr2(v, flag)
 132: register struct value *v;
 133: char flag;
 134: {
 135:     char true = 1;
 136: 
 137:     if (p_expr3_10(3, v, flag) < 0)
 138:         return -1;
 139:     if (token != T_ANDAND)
 140:         return 0;
 141:     for (;;) {
 142:         switch (v->v_type) {
 143:         case V_NUM:
 144:             v->v_num = true = true && v->v_num != 0;
 145:             break;
 146:         case V_STR:
 147:             p_error("&&: Numeric operands required.");
 148:             str_free(v->v_str);
 149:             v->v_type = V_ERR;
 150:         case V_ERR:
 151:             flag = 0;
 152:             break;
 153:         }
 154:         if (token != T_ANDAND)
 155:             return 0;
 156:         (void) s_gettok();
 157:         if (p_expr3_10(3, v, flag && true) < 0)
 158:             return -1;
 159:     }
 160:     /*NOTREACHED*/
 161: }

Defined functions

p_expr0 defined in line 58; used 2 times
p_expr1 defined in line 97; used 5 times
p_expr2 defined in line 131; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2220
Valid CSS Valid XHTML 1.0 Strict