** subexpr -> (simpleexp | unop subexpr) { binop subexpr } ** where 'binop' is any binary operator with a priority higher than 'limit' */
| 1044 | ** where 'binop' is any binary operator with a priority higher than 'limit' |
| 1045 | */ |
| 1046 | static BinOpr subexpr (LexState *ls, expdesc *v, int limit) { |
| 1047 | BinOpr op; |
| 1048 | UnOpr uop; |
| 1049 | enterlevel(ls); |
| 1050 | uop = getunopr(ls->t.token); |
| 1051 | if (uop != OPR_NOUNOPR) { |
| 1052 | int line = ls->linenumber; |
| 1053 | luaX_next(ls); |
| 1054 | subexpr(ls, v, UNARY_PRIORITY); |
| 1055 | luaK_prefix(ls->fs, uop, v, line); |
| 1056 | } |
| 1057 | else simpleexp(ls, v); |
| 1058 | /* expand while operators have priorities higher than 'limit' */ |
| 1059 | op = getbinopr(ls->t.token); |
| 1060 | while (op != OPR_NOBINOPR && priority[op].left > limit) { |
| 1061 | expdesc v2; |
| 1062 | BinOpr nextop; |
| 1063 | int line = ls->linenumber; |
| 1064 | luaX_next(ls); |
| 1065 | luaK_infix(ls->fs, op, v); |
| 1066 | /* read sub-expression with higher priority */ |
| 1067 | nextop = subexpr(ls, &v2, priority[op].right); |
| 1068 | luaK_posfix(ls->fs, op, v, &v2, line); |
| 1069 | op = nextop; |
| 1070 | } |
| 1071 | leavelevel(ls); |
| 1072 | return op; /* return first untreated operator */ |
| 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | static void expr (LexState *ls, expdesc *v) { |
no test coverage detected