Skip to content

Commit c54f5f6

Browse files
committed
primaryexp -> suffixedexp; prefixexp -> primaryexp + more 'syntactical'
way to distinguish between function calls and assignments
1 parent 4cca1a4 commit c54f5f6

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

lparser.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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 $
33
** Lua Parser
44
** See Copyright Notice in lua.h
55
*/
@@ -879,8 +879,8 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
879879
*/
880880

881881

882-
static void prefixexp (LexState *ls, expdesc *v) {
883-
/* prefixexp -> NAME | '(' expr ')' */
882+
static void primaryexp (LexState *ls, expdesc *v) {
883+
/* primaryexp -> NAME | '(' expr ')' */
884884
switch (ls->t.token) {
885885
case '(': {
886886
int line = ls->linenumber;
@@ -901,12 +901,12 @@ static void prefixexp (LexState *ls, expdesc *v) {
901901
}
902902

903903

904-
static void primaryexp (LexState *ls, expdesc *v) {
905-
/* primaryexp ->
906-
prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
904+
static void suffixedexp (LexState *ls, expdesc *v) {
905+
/* suffixedexp ->
906+
primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
907907
FuncState *fs = ls->fs;
908908
int line = ls->linenumber;
909-
prefixexp(ls, v);
909+
primaryexp(ls, v);
910910
for (;;) {
911911
switch (ls->t.token) {
912912
case '.': { /* fieldsel */
@@ -941,7 +941,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
941941

942942
static void simpleexp (LexState *ls, expdesc *v) {
943943
/* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
944-
constructor | FUNCTION body | primaryexp */
944+
constructor | FUNCTION body | suffixedexp */
945945
switch (ls->t.token) {
946946
case TK_NUMBER: {
947947
init_exp(v, VKNUM, 0);
@@ -981,7 +981,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
981981
return;
982982
}
983983
default: {
984-
primaryexp(ls, v);
984+
suffixedexp(ls, v);
985985
return;
986986
}
987987
}
@@ -1141,10 +1141,10 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
11411141
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
11421142
expdesc e;
11431143
check_condition(ls, vkisvar(lh->v.k), "syntax error");
1144-
if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */
1144+
if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
11451145
struct LHS_assign nv;
11461146
nv.prev = lh;
1147-
primaryexp(ls, &nv.v);
1147+
suffixedexp(ls, &nv.v);
11481148
if (nv.v.k != VINDEXED)
11491149
check_conflict(ls, lh, &nv.v);
11501150
checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
@@ -1480,13 +1480,15 @@ static void exprstat (LexState *ls) {
14801480
/* stat -> func | assignment */
14811481
FuncState *fs = ls->fs;
14821482
struct LHS_assign v;
1483-
primaryexp(ls, &v.v);
1484-
if (v.v.k == VCALL) /* stat -> func */
1485-
SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
1486-
else { /* stat -> assignment */
1483+
suffixedexp(ls, &v.v);
1484+
if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
14871485
v.prev = NULL;
14881486
assignment(ls, &v, 1);
14891487
}
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+
}
14901492
}
14911493

14921494

0 commit comments

Comments
 (0)