diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-04-20 16:20:05 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-04-20 16:20:05 -0300 |
commit | c54f5f64c95d73de8a4b66592e6f033469b07fe4 (patch) | |
tree | 71e3c4cefaece34f12c75bb7cdba39d5d45d4661 | |
parent | 4cca1a436db7b425e28e3ef0bea8216bdcf02fb8 (diff) | |
download | lua-c54f5f64c95d73de8a4b66592e6f033469b07fe4.tar.gz lua-c54f5f64c95d73de8a4b66592e6f033469b07fe4.tar.bz2 lua-c54f5f64c95d73de8a4b66592e6f033469b07fe4.zip |
primaryexp -> suffixedexp; prefixexp -> primaryexp + more 'syntactical'
way to distinguish between function calls and assignments
-rw-r--r-- | lparser.c | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.124 2011/12/02 13:23:56 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.125 2012/01/23 23:05:18 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -879,8 +879,8 @@ static void funcargs (LexState *ls, expdesc *f, int line) { | |||
879 | */ | 879 | */ |
880 | 880 | ||
881 | 881 | ||
882 | static void prefixexp (LexState *ls, expdesc *v) { | 882 | static void primaryexp (LexState *ls, expdesc *v) { |
883 | /* prefixexp -> NAME | '(' expr ')' */ | 883 | /* primaryexp -> NAME | '(' expr ')' */ |
884 | switch (ls->t.token) { | 884 | switch (ls->t.token) { |
885 | case '(': { | 885 | case '(': { |
886 | int line = ls->linenumber; | 886 | int line = ls->linenumber; |
@@ -901,12 +901,12 @@ static void prefixexp (LexState *ls, expdesc *v) { | |||
901 | } | 901 | } |
902 | 902 | ||
903 | 903 | ||
904 | static void primaryexp (LexState *ls, expdesc *v) { | 904 | static void suffixedexp (LexState *ls, expdesc *v) { |
905 | /* primaryexp -> | 905 | /* suffixedexp -> |
906 | prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ | 906 | primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */ |
907 | FuncState *fs = ls->fs; | 907 | FuncState *fs = ls->fs; |
908 | int line = ls->linenumber; | 908 | int line = ls->linenumber; |
909 | prefixexp(ls, v); | 909 | primaryexp(ls, v); |
910 | for (;;) { | 910 | for (;;) { |
911 | switch (ls->t.token) { | 911 | switch (ls->t.token) { |
912 | case '.': { /* fieldsel */ | 912 | case '.': { /* fieldsel */ |
@@ -941,7 +941,7 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
941 | 941 | ||
942 | static void simpleexp (LexState *ls, expdesc *v) { | 942 | static void simpleexp (LexState *ls, expdesc *v) { |
943 | /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... | | 943 | /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... | |
944 | constructor | FUNCTION body | primaryexp */ | 944 | constructor | FUNCTION body | suffixedexp */ |
945 | switch (ls->t.token) { | 945 | switch (ls->t.token) { |
946 | case TK_NUMBER: { | 946 | case TK_NUMBER: { |
947 | init_exp(v, VKNUM, 0); | 947 | init_exp(v, VKNUM, 0); |
@@ -981,7 +981,7 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
981 | return; | 981 | return; |
982 | } | 982 | } |
983 | default: { | 983 | default: { |
984 | primaryexp(ls, v); | 984 | suffixedexp(ls, v); |
985 | return; | 985 | return; |
986 | } | 986 | } |
987 | } | 987 | } |
@@ -1141,10 +1141,10 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { | |||
1141 | static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { | 1141 | static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { |
1142 | expdesc e; | 1142 | expdesc e; |
1143 | check_condition(ls, vkisvar(lh->v.k), "syntax error"); | 1143 | check_condition(ls, vkisvar(lh->v.k), "syntax error"); |
1144 | if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ | 1144 | if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */ |
1145 | struct LHS_assign nv; | 1145 | struct LHS_assign nv; |
1146 | nv.prev = lh; | 1146 | nv.prev = lh; |
1147 | primaryexp(ls, &nv.v); | 1147 | suffixedexp(ls, &nv.v); |
1148 | if (nv.v.k != VINDEXED) | 1148 | if (nv.v.k != VINDEXED) |
1149 | check_conflict(ls, lh, &nv.v); | 1149 | check_conflict(ls, lh, &nv.v); |
1150 | checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS, | 1150 | checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS, |
@@ -1480,13 +1480,15 @@ static void exprstat (LexState *ls) { | |||
1480 | /* stat -> func | assignment */ | 1480 | /* stat -> func | assignment */ |
1481 | FuncState *fs = ls->fs; | 1481 | FuncState *fs = ls->fs; |
1482 | struct LHS_assign v; | 1482 | struct LHS_assign v; |
1483 | primaryexp(ls, &v.v); | 1483 | suffixedexp(ls, &v.v); |
1484 | if (v.v.k == VCALL) /* stat -> func */ | 1484 | if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */ |
1485 | SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ | ||
1486 | else { /* stat -> assignment */ | ||
1487 | v.prev = NULL; | 1485 | v.prev = NULL; |
1488 | assignment(ls, &v, 1); | 1486 | assignment(ls, &v, 1); |
1489 | } | 1487 | } |
1488 | else { /* stat -> func */ | ||
1489 | check_condition(ls, v.v.k == VCALL, "syntax error"); | ||
1490 | SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ | ||
1491 | } | ||
1490 | } | 1492 | } |
1491 | 1493 | ||
1492 | 1494 | ||