** subexpr -> (simpleexp | unop subexpr) { binop subexpr } ** where 'binop' is any binary operator with a priority higher than 'limit' */
| 1079 | ** where 'binop' is any binary operator with a priority higher than 'limit' |
| 1080 | */ |
| 1081 | static BinOpr subexpr(LexState *ls, expdesc *v, int limit) { |
| 1082 | BinOpr op; |
| 1083 | UnOpr uop; |
| 1084 | enterlevel(ls); |
| 1085 | uop = getunopr(ls->t.token); |
| 1086 | if (uop != OPR_NOUNOPR) { |
| 1087 | int line = ls->linenumber; |
| 1088 | luaX_next(ls); |
| 1089 | subexpr(ls, v, UNARY_PRIORITY); |
| 1090 | luaK_prefix(ls->fs, uop, v, line); |
| 1091 | } |
| 1092 | else simpleexp(ls, v); |
| 1093 | /* expand while operators have priorities higher than 'limit' */ |
| 1094 | op = getbinopr(ls->t.token); |
| 1095 | while (op != OPR_NOBINOPR && priority[op].left > limit) { |
| 1096 | expdesc v2; |
| 1097 | BinOpr nextop; |
| 1098 | int line = ls->linenumber; |
| 1099 | luaX_next(ls); |
| 1100 | luaK_infix(ls->fs, op, v); |
| 1101 | /* read sub-expression with higher priority */ |
| 1102 | nextop = subexpr(ls, &v2, priority[op].right); |
| 1103 | luaK_posfix(ls->fs, op, v, &v2, line); |
| 1104 | op = nextop; |
| 1105 | } |
| 1106 | leavelevel(ls); |
| 1107 | return op; /* return first untreated operator */ |
| 1108 | } |
| 1109 | |
| 1110 | |
| 1111 | static void expr(LexState *ls, expdesc *v) { |
no test coverage detected