MCPcopy Create free account
hub / github.com/DFHack/dfhack / subexpr

Function subexpr

depends/lua/src/lparser.c:1049–1076  ·  view source on GitHub ↗

** subexpr -> (simpleexp | unop subexpr) { binop subexpr } ** where 'binop' is any binary operator with a priority higher than 'limit' */

Source from the content-addressed store, hash-verified

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

Callers 1

exprFunction · 0.85

Calls 8

enterlevelFunction · 0.85
getunoprFunction · 0.85
luaX_nextFunction · 0.85
luaK_prefixFunction · 0.85
simpleexpFunction · 0.85
getbinoprFunction · 0.85
luaK_infixFunction · 0.85
luaK_posfixFunction · 0.85

Tested by

no test coverage detected