aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/lparser.c b/lparser.c
index e98aab69..603998da 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.142 2014/07/21 16:02:10 roberto Exp roberto $ 2** $Id: lparser.c,v 2.143 2014/10/17 16:28:21 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*/
@@ -49,7 +49,7 @@ typedef struct BlockCnt {
49 short firstgoto; /* index of first pending goto in this block */ 49 short firstgoto; /* index of first pending goto in this block */
50 lu_byte nactvar; /* # active locals outside the block */ 50 lu_byte nactvar; /* # active locals outside the block */
51 lu_byte upval; /* true if some variable in the block is an upvalue */ 51 lu_byte upval; /* true if some variable in the block is an upvalue */
52 lu_byte isloop; /* true if `block' is a loop */ 52 lu_byte isloop; /* true if 'block' is a loop */
53} BlockCnt; 53} BlockCnt;
54 54
55 55
@@ -63,7 +63,7 @@ static void expr (LexState *ls, expdesc *v);
63 63
64/* semantic error */ 64/* semantic error */
65static l_noret semerror (LexState *ls, const char *msg) { 65static l_noret semerror (LexState *ls, const char *msg) {
66 ls->t.token = 0; /* remove 'near to' from final message */ 66 ls->t.token = 0; /* remove "near <token>" from final message */
67 luaX_syntaxerror(ls, msg); 67 luaX_syntaxerror(ls, msg);
68} 68}
69 69
@@ -406,7 +406,7 @@ static void findgotos (LexState *ls, Labeldesc *lb) {
406 406
407 407
408/* 408/*
409** "export" pending gotos to outer level, to check them against 409** export pending gotos to outer level, to check them against
410** outer labels; if the block being exited has upvalues, and 410** outer labels; if the block being exited has upvalues, and
411** the goto exits the scope of any variable (which can be the 411** the goto exits the scope of any variable (which can be the
412** upvalue), close those variables being exited. 412** upvalue), close those variables being exited.
@@ -442,7 +442,7 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
442 442
443 443
444/* 444/*
445** create a label named "break" to resolve break statements 445** create a label named 'break' to resolve break statements
446*/ 446*/
447static void breaklabel (LexState *ls) { 447static void breaklabel (LexState *ls) {
448 TString *n = luaS_new(ls->L, "break"); 448 TString *n = luaS_new(ls->L, "break");
@@ -574,7 +574,7 @@ static void close_func (LexState *ls) {
574/* 574/*
575** check whether current token is in the follow set of a block. 575** check whether current token is in the follow set of a block.
576** 'until' closes syntactical blocks, but do not close scope, 576** 'until' closes syntactical blocks, but do not close scope,
577** so it handled in separate. 577** so it is handled in separate.
578*/ 578*/
579static int block_follow (LexState *ls, int withuntil) { 579static int block_follow (LexState *ls, int withuntil) {
580 switch (ls->t.token) { 580 switch (ls->t.token) {
@@ -588,7 +588,7 @@ static int block_follow (LexState *ls, int withuntil) {
588 588
589 589
590static void statlist (LexState *ls) { 590static void statlist (LexState *ls) {
591 /* statlist -> { stat [`;'] } */ 591 /* statlist -> { stat [';'] } */
592 while (!block_follow(ls, 1)) { 592 while (!block_follow(ls, 1)) {
593 if (ls->t.token == TK_RETURN) { 593 if (ls->t.token == TK_RETURN) {
594 statement(ls); 594 statement(ls);
@@ -629,14 +629,14 @@ static void yindex (LexState *ls, expdesc *v) {
629struct ConsControl { 629struct ConsControl {
630 expdesc v; /* last list item read */ 630 expdesc v; /* last list item read */
631 expdesc *t; /* table descriptor */ 631 expdesc *t; /* table descriptor */
632 int nh; /* total number of `record' elements */ 632 int nh; /* total number of 'record' elements */
633 int na; /* total number of array elements */ 633 int na; /* total number of array elements */
634 int tostore; /* number of array elements pending to be stored */ 634 int tostore; /* number of array elements pending to be stored */
635}; 635};
636 636
637 637
638static void recfield (LexState *ls, struct ConsControl *cc) { 638static void recfield (LexState *ls, struct ConsControl *cc) {
639 /* recfield -> (NAME | `['exp1`]') = exp1 */ 639 /* recfield -> (NAME | '['exp1']') = exp1 */
640 FuncState *fs = ls->fs; 640 FuncState *fs = ls->fs;
641 int reg = ls->fs->freereg; 641 int reg = ls->fs->freereg;
642 expdesc key, val; 642 expdesc key, val;
@@ -743,12 +743,12 @@ static void constructor (LexState *ls, expdesc *t) {
743 743
744 744
745static void parlist (LexState *ls) { 745static void parlist (LexState *ls) {
746 /* parlist -> [ param { `,' param } ] */ 746 /* parlist -> [ param { ',' param } ] */
747 FuncState *fs = ls->fs; 747 FuncState *fs = ls->fs;
748 Proto *f = fs->f; 748 Proto *f = fs->f;
749 int nparams = 0; 749 int nparams = 0;
750 f->is_vararg = 0; 750 f->is_vararg = 0;
751 if (ls->t.token != ')') { /* is `parlist' not empty? */ 751 if (ls->t.token != ')') { /* is 'parlist' not empty? */
752 do { 752 do {
753 switch (ls->t.token) { 753 switch (ls->t.token) {
754 case TK_NAME: { /* param -> NAME */ 754 case TK_NAME: { /* param -> NAME */
@@ -756,7 +756,7 @@ static void parlist (LexState *ls) {
756 nparams++; 756 nparams++;
757 break; 757 break;
758 } 758 }
759 case TK_DOTS: { /* param -> `...' */ 759 case TK_DOTS: { /* param -> '...' */
760 luaX_next(ls); 760 luaX_next(ls);
761 f->is_vararg = 1; 761 f->is_vararg = 1;
762 break; 762 break;
@@ -772,7 +772,7 @@ static void parlist (LexState *ls) {
772 772
773 773
774static void body (LexState *ls, expdesc *e, int ismethod, int line) { 774static void body (LexState *ls, expdesc *e, int ismethod, int line) {
775 /* body -> `(' parlist `)' block END */ 775 /* body -> '(' parlist ')' block END */
776 FuncState new_fs; 776 FuncState new_fs;
777 BlockCnt bl; 777 BlockCnt bl;
778 new_fs.f = addprototype(ls); 778 new_fs.f = addprototype(ls);
@@ -794,7 +794,7 @@ static void body (LexState *ls, expdesc *e, int ismethod, int line) {
794 794
795 795
796static int explist (LexState *ls, expdesc *v) { 796static int explist (LexState *ls, expdesc *v) {
797 /* explist -> expr { `,' expr } */ 797 /* explist -> expr { ',' expr } */
798 int n = 1; /* at least one expression */ 798 int n = 1; /* at least one expression */
799 expr(ls, v); 799 expr(ls, v);
800 while (testnext(ls, ',')) { 800 while (testnext(ls, ',')) {
@@ -811,7 +811,7 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
811 expdesc args; 811 expdesc args;
812 int base, nparams; 812 int base, nparams;
813 switch (ls->t.token) { 813 switch (ls->t.token) {
814 case '(': { /* funcargs -> `(' [ explist ] `)' */ 814 case '(': { /* funcargs -> '(' [ explist ] ')' */
815 luaX_next(ls); 815 luaX_next(ls);
816 if (ls->t.token == ')') /* arg list is empty? */ 816 if (ls->t.token == ')') /* arg list is empty? */
817 args.k = VVOID; 817 args.k = VVOID;
@@ -828,7 +828,7 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
828 } 828 }
829 case TK_STRING: { /* funcargs -> STRING */ 829 case TK_STRING: { /* funcargs -> STRING */
830 codestring(ls, &args, ls->t.seminfo.ts); 830 codestring(ls, &args, ls->t.seminfo.ts);
831 luaX_next(ls); /* must use `seminfo' before `next' */ 831 luaX_next(ls); /* must use 'seminfo' before 'next' */
832 break; 832 break;
833 } 833 }
834 default: { 834 default: {
@@ -894,14 +894,14 @@ static void suffixedexp (LexState *ls, expdesc *v) {
894 fieldsel(ls, v); 894 fieldsel(ls, v);
895 break; 895 break;
896 } 896 }
897 case '[': { /* `[' exp1 `]' */ 897 case '[': { /* '[' exp1 ']' */
898 expdesc key; 898 expdesc key;
899 luaK_exp2anyregup(fs, v); 899 luaK_exp2anyregup(fs, v);
900 yindex(ls, &key); 900 yindex(ls, &key);
901 luaK_indexed(fs, v, &key); 901 luaK_indexed(fs, v, &key);
902 break; 902 break;
903 } 903 }
904 case ':': { /* `:' NAME funcargs */ 904 case ':': { /* ':' NAME funcargs */
905 expdesc key; 905 expdesc key;
906 luaX_next(ls); 906 luaX_next(ls);
907 checkname(ls, &key); 907 checkname(ls, &key);
@@ -1035,7 +1035,7 @@ static const struct {
1035 1035
1036/* 1036/*
1037** subexpr -> (simpleexp | unop subexpr) { binop subexpr } 1037** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
1038** where `binop' is any binary operator with a priority higher than `limit' 1038** where 'binop' is any binary operator with a priority higher than 'limit'
1039*/ 1039*/
1040static BinOpr subexpr (LexState *ls, expdesc *v, int limit) { 1040static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
1041 BinOpr op; 1041 BinOpr op;
@@ -1049,7 +1049,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
1049 luaK_prefix(ls->fs, uop, v, line); 1049 luaK_prefix(ls->fs, uop, v, line);
1050 } 1050 }
1051 else simpleexp(ls, v); 1051 else simpleexp(ls, v);
1052 /* expand while operators have priorities higher than `limit' */ 1052 /* expand while operators have priorities higher than 'limit' */
1053 op = getbinopr(ls->t.token); 1053 op = getbinopr(ls->t.token);
1054 while (op != OPR_NOBINOPR && priority[op].left > limit) { 1054 while (op != OPR_NOBINOPR && priority[op].left > limit) {
1055 expdesc v2; 1055 expdesc v2;
@@ -1149,7 +1149,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
1149 "C levels"); 1149 "C levels");
1150 assignment(ls, &nv, nvars+1); 1150 assignment(ls, &nv, nvars+1);
1151 } 1151 }
1152 else { /* assignment -> `=' explist */ 1152 else { /* assignment -> '=' explist */
1153 int nexps; 1153 int nexps;
1154 checknext(ls, '='); 1154 checknext(ls, '=');
1155 nexps = explist(ls, &e); 1155 nexps = explist(ls, &e);
@@ -1173,7 +1173,7 @@ static int cond (LexState *ls) {
1173 /* cond -> exp */ 1173 /* cond -> exp */
1174 expdesc v; 1174 expdesc v;
1175 expr(ls, &v); /* read condition */ 1175 expr(ls, &v); /* read condition */
1176 if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ 1176 if (v.k == VNIL) v.k = VFALSE; /* 'falses' are all equal here */
1177 luaK_goiftrue(ls->fs, &v); 1177 luaK_goiftrue(ls->fs, &v);
1178 return v.f; 1178 return v.f;
1179} 1179}
@@ -1362,7 +1362,7 @@ static void forstat (LexState *ls, int line) {
1362 TString *varname; 1362 TString *varname;
1363 BlockCnt bl; 1363 BlockCnt bl;
1364 enterblock(fs, &bl, 1); /* scope for loop and control variables */ 1364 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1365 luaX_next(ls); /* skip `for' */ 1365 luaX_next(ls); /* skip 'for' */
1366 varname = str_checkname(ls); /* first variable name */ 1366 varname = str_checkname(ls); /* first variable name */
1367 switch (ls->t.token) { 1367 switch (ls->t.token) {
1368 case '=': fornum(ls, varname, line); break; 1368 case '=': fornum(ls, varname, line); break;
@@ -1370,7 +1370,7 @@ static void forstat (LexState *ls, int line) {
1370 default: luaX_syntaxerror(ls, "'=' or 'in' expected"); 1370 default: luaX_syntaxerror(ls, "'=' or 'in' expected");
1371 } 1371 }
1372 check_match(ls, TK_END, TK_FOR, line); 1372 check_match(ls, TK_END, TK_FOR, line);
1373 leaveblock(fs); /* loop scope (`break' jumps to this point) */ 1373 leaveblock(fs); /* loop scope ('break' jumps to this point) */
1374} 1374}
1375 1375
1376 1376
@@ -1400,7 +1400,7 @@ static void test_then_block (LexState *ls, int *escapelist) {
1400 enterblock(fs, &bl, 0); 1400 enterblock(fs, &bl, 0);
1401 jf = v.f; 1401 jf = v.f;
1402 } 1402 }
1403 statlist(ls); /* `then' part */ 1403 statlist(ls); /* 'then' part */
1404 leaveblock(fs); 1404 leaveblock(fs);
1405 if (ls->t.token == TK_ELSE || 1405 if (ls->t.token == TK_ELSE ||
1406 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ 1406 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
@@ -1417,7 +1417,7 @@ static void ifstat (LexState *ls, int line) {
1417 while (ls->t.token == TK_ELSEIF) 1417 while (ls->t.token == TK_ELSEIF)
1418 test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */ 1418 test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
1419 if (testnext(ls, TK_ELSE)) 1419 if (testnext(ls, TK_ELSE))
1420 block(ls); /* `else' part */ 1420 block(ls); /* 'else' part */
1421 check_match(ls, TK_END, TK_IF, line); 1421 check_match(ls, TK_END, TK_IF, line);
1422 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */ 1422 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
1423} 1423}
@@ -1435,7 +1435,7 @@ static void localfunc (LexState *ls) {
1435 1435
1436 1436
1437static void localstat (LexState *ls) { 1437static void localstat (LexState *ls) {
1438 /* stat -> LOCAL NAME {`,' NAME} [`=' explist] */ 1438 /* stat -> LOCAL NAME {',' NAME} ['=' explist] */
1439 int nvars = 0; 1439 int nvars = 0;
1440 int nexps; 1440 int nexps;
1441 expdesc e; 1441 expdesc e;
@@ -1455,7 +1455,7 @@ static void localstat (LexState *ls) {
1455 1455
1456 1456
1457static int funcname (LexState *ls, expdesc *v) { 1457static int funcname (LexState *ls, expdesc *v) {
1458 /* funcname -> NAME {fieldsel} [`:' NAME] */ 1458 /* funcname -> NAME {fieldsel} [':' NAME] */
1459 int ismethod = 0; 1459 int ismethod = 0;
1460 singlevar(ls, v); 1460 singlevar(ls, v);
1461 while (ls->t.token == '.') 1461 while (ls->t.token == '.')
@@ -1476,7 +1476,7 @@ static void funcstat (LexState *ls, int line) {
1476 ismethod = funcname(ls, &v); 1476 ismethod = funcname(ls, &v);
1477 body(ls, &b, ismethod, line); 1477 body(ls, &b, ismethod, line);
1478 luaK_storevar(ls->fs, &v, &b); 1478 luaK_storevar(ls->fs, &v, &b);
1479 luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ 1479 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */
1480} 1480}
1481 1481
1482 1482
@@ -1518,8 +1518,8 @@ static void retstat (LexState *ls) {
1518 if (nret == 1) /* only one single value? */ 1518 if (nret == 1) /* only one single value? */
1519 first = luaK_exp2anyreg(fs, &e); 1519 first = luaK_exp2anyreg(fs, &e);
1520 else { 1520 else {
1521 luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ 1521 luaK_exp2nextreg(fs, &e); /* values must go to the stack */
1522 first = fs->nactvar; /* return all `active' values */ 1522 first = fs->nactvar; /* return all active values */
1523 lua_assert(nret == fs->freereg - first); 1523 lua_assert(nret == fs->freereg - first);
1524 } 1524 }
1525 } 1525 }