aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-28 18:13:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-28 18:13:13 -0200
commit72659a06050632da1a9b4c492302be46ac283f6b (patch)
treebac06b4ea523ba5443564d0869e392180d4b7b77 /lparser.c
parentdfaf8c5291fa8aef5bedbfa375853475364ac76e (diff)
downloadlua-72659a06050632da1a9b4c492302be46ac283f6b.tar.gz
lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.bz2
lua-72659a06050632da1a9b4c492302be46ac283f6b.zip
no more explicit support for wide-chars; too much troble...
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c167
1 files changed, 83 insertions, 84 deletions
diff --git a/lparser.c b/lparser.c
index 744c9ce6..f5d722c4 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.159 2001/10/02 16:41:36 roberto Exp $ 2** $Id: lparser.c,v 1.160 2001/10/25 19:14:14 roberto Exp $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,7 +8,6 @@
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
10 10
11#define LUA_PRIVATE
12#include "lua.h" 11#include "lua.h"
13 12
14#include "lcode.h" 13#include "lcode.h"
@@ -76,9 +75,9 @@ static void lookahead (LexState *ls) {
76 75
77 76
78static void error_expected (LexState *ls, int token) { 77static void error_expected (LexState *ls, int token) {
79 l_char buff[30], t[TOKEN_LEN]; 78 char buff[30], t[TOKEN_LEN];
80 luaX_token2str(token, t); 79 luaX_token2str(token, t);
81 sprintf(buff, l_s("`%.10s' expected"), t); 80 sprintf(buff, "`%.10s' expected", t);
82 luaK_error(ls, buff); 81 luaK_error(ls, buff);
83} 82}
84 83
@@ -90,7 +89,7 @@ static void check (LexState *ls, int c) {
90} 89}
91 90
92 91
93static void check_condition (LexState *ls, int c, const l_char *msg) { 92static void check_condition (LexState *ls, int c, const char *msg) {
94 if (!c) luaK_error(ls, msg); 93 if (!c) luaK_error(ls, msg);
95} 94}
96 95
@@ -109,11 +108,11 @@ static void check_match (LexState *ls, int what, int who, int where) {
109 if (where == ls->linenumber) 108 if (where == ls->linenumber)
110 error_expected(ls, what); 109 error_expected(ls, what);
111 else { 110 else {
112 l_char buff[70]; 111 char buff[70];
113 l_char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; 112 char t_what[TOKEN_LEN], t_who[TOKEN_LEN];
114 luaX_token2str(what, t_what); 113 luaX_token2str(what, t_what);
115 luaX_token2str(who, t_who); 114 luaX_token2str(who, t_who);
116 sprintf(buff, l_s("`%.10s' expected (to close `%.10s' at line %d)"), 115 sprintf(buff, "`%.10s' expected (to close `%.10s' at line %d)",
117 t_what, t_who, where); 116 t_what, t_who, where);
118 luaK_error(ls, buff); 117 luaK_error(ls, buff);
119 } 118 }
@@ -123,7 +122,7 @@ static void check_match (LexState *ls, int what, int who, int where) {
123 122
124 123
125static TString *str_checkname (LexState *ls) { 124static TString *str_checkname (LexState *ls) {
126 check_condition(ls, (ls->t.token == TK_NAME), l_s("<name> expected")); 125 check_condition(ls, (ls->t.token == TK_NAME), "<name> expected");
127 return ls->t.seminfo.ts; 126 return ls->t.seminfo.ts;
128} 127}
129 128
@@ -150,7 +149,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
150 FuncState *fs = ls->fs; 149 FuncState *fs = ls->fs;
151 Proto *f = fs->f; 150 Proto *f = fs->f;
152 luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, 151 luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
153 LocVar, MAX_INT, l_s("")); 152 LocVar, MAX_INT, "");
154 f->locvars[fs->nlocvars].varname = varname; 153 f->locvars[fs->nlocvars].varname = varname;
155 return fs->nlocvars++; 154 return fs->nlocvars++;
156} 155}
@@ -158,7 +157,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
158 157
159static void new_localvar (LexState *ls, TString *name, int n) { 158static void new_localvar (LexState *ls, TString *name, int n) {
160 FuncState *fs = ls->fs; 159 FuncState *fs = ls->fs;
161 luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, l_s("local variables")); 160 luaX_checklimit(ls, fs->nactloc+n+1, MAXLOCALS, "local variables");
162 fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name); 161 fs->actloc[fs->nactloc+n] = luaI_registerlocalvar(ls, name);
163} 162}
164 163
@@ -194,7 +193,7 @@ static void removelocalvars (LexState *ls, int nvars, int toclose) {
194} 193}
195 194
196 195
197static void new_localvarstr (LexState *ls, const l_char *name, int n) { 196static void new_localvarstr (LexState *ls, const char *name, int n) {
198 new_localvar(ls, luaS_new(ls->L, name), n); 197 new_localvar(ls, luaS_new(ls->L, name), n);
199} 198}
200 199
@@ -206,7 +205,7 @@ static int indexupvalue (FuncState *fs, expdesc *v) {
206 return i; 205 return i;
207 } 206 }
208 /* new one */ 207 /* new one */
209 luaX_checklimit(fs->ls, fs->f->nupvalues+1, MAXUPVALUES, l_s("upvalues")); 208 luaX_checklimit(fs->ls, fs->f->nupvalues+1, MAXUPVALUES, "upvalues");
210 fs->upvalues[fs->f->nupvalues] = *v; 209 fs->upvalues[fs->f->nupvalues] = *v;
211 return fs->f->nupvalues++; 210 return fs->f->nupvalues++;
212} 211}
@@ -263,11 +262,11 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
263static void code_params (LexState *ls, int nparams, short dots) { 262static void code_params (LexState *ls, int nparams, short dots) {
264 FuncState *fs = ls->fs; 263 FuncState *fs = ls->fs;
265 adjustlocalvars(ls, nparams); 264 adjustlocalvars(ls, nparams);
266 luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters")); 265 luaX_checklimit(ls, fs->nactloc, MAXPARAMS, "parameters");
267 fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */ 266 fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */
268 fs->f->is_vararg = dots; 267 fs->f->is_vararg = dots;
269 if (dots) { 268 if (dots) {
270 new_localvarstr(ls, l_s("arg"), 0); 269 new_localvarstr(ls, "arg", 0);
271 adjustlocalvars(ls, 1); 270 adjustlocalvars(ls, 1);
272 } 271 }
273 luaK_reserveregs(fs, fs->nactloc); /* reserve register for parameters */ 272 luaK_reserveregs(fs, fs->nactloc); /* reserve register for parameters */
@@ -294,7 +293,7 @@ static void pushclosure (LexState *ls, FuncState *func, expdesc *v) {
294 Proto *f = fs->f; 293 Proto *f = fs->f;
295 int i; 294 int i;
296 luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, 295 luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
297 MAXARG_Bc, l_s("constant table overflow")); 296 MAXARG_Bc, "constant table overflow");
298 f->p[fs->np++] = func->f; 297 f->p[fs->np++] = func->f;
299 init_exp(v, VRELOCABLE, luaK_codeABc(fs, OP_CLOSURE, 0, fs->np-1)); 298 init_exp(v, VRELOCABLE, luaK_codeABc(fs, OP_CLOSURE, 0, fs->np-1));
300 for (i=0; i<func->f->nupvalues; i++) { 299 for (i=0; i<func->f->nupvalues; i++) {
@@ -366,7 +365,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z) {
366 next(&lexstate); /* read first token */ 365 next(&lexstate); /* read first token */
367 chunk(&lexstate); 366 chunk(&lexstate);
368 check_condition(&lexstate, (lexstate.t.token == TK_EOS), 367 check_condition(&lexstate, (lexstate.t.token == TK_EOS),
369 l_s("<eof> expected")); 368 "<eof> expected");
370 close_func(&lexstate); 369 close_func(&lexstate);
371 lua_assert(funcstate.prev == NULL); 370 lua_assert(funcstate.prev == NULL);
372 lua_assert(funcstate.f->nupvalues == 0); 371 lua_assert(funcstate.f->nupvalues == 0);
@@ -396,7 +395,7 @@ static void luaY_index (LexState *ls, expdesc *v) {
396 next(ls); /* skip the '[' */ 395 next(ls); /* skip the '[' */
397 expr(ls, v); 396 expr(ls, v);
398 luaK_exp2val(ls->fs, v); 397 luaK_exp2val(ls->fs, v);
399 check(ls, l_c(']')); 398 check(ls, ']');
400} 399}
401 400
402 401
@@ -404,7 +403,7 @@ static int explist1 (LexState *ls, expdesc *v) {
404 /* explist1 -> expr { `,' expr } */ 403 /* explist1 -> expr { `,' expr } */
405 int n = 1; /* at least one expression */ 404 int n = 1; /* at least one expression */
406 expr(ls, v); 405 expr(ls, v);
407 while (ls->t.token == l_c(',')) { 406 while (ls->t.token == ',') {
408 next(ls); /* skip comma */ 407 next(ls); /* skip comma */
409 luaK_exp2nextreg(ls->fs, v); 408 luaK_exp2nextreg(ls->fs, v);
410 expr(ls, v); 409 expr(ls, v);
@@ -419,21 +418,21 @@ static void funcargs (LexState *ls, expdesc *f) {
419 expdesc args; 418 expdesc args;
420 int base, nparams; 419 int base, nparams;
421 switch (ls->t.token) { 420 switch (ls->t.token) {
422 case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */ 421 case '(': { /* funcargs -> `(' [ explist1 ] `)' */
423 int line = ls->linenumber; 422 int line = ls->linenumber;
424 if (line != ls->lastline) 423 if (line != ls->lastline)
425 luaK_error(ls, l_s("ambiguous syntax (function call x new statement)")); 424 luaK_error(ls, "ambiguous syntax (function call x new statement)");
426 next(ls); 425 next(ls);
427 if (ls->t.token == l_c(')')) /* arg list is empty? */ 426 if (ls->t.token == ')') /* arg list is empty? */
428 args.k = VVOID; 427 args.k = VVOID;
429 else { 428 else {
430 explist1(ls, &args); 429 explist1(ls, &args);
431 luaK_setcallreturns(fs, &args, LUA_MULTRET); 430 luaK_setcallreturns(fs, &args, LUA_MULTRET);
432 } 431 }
433 check_match(ls, l_c(')'), l_c('('), line); 432 check_match(ls, ')', '(', line);
434 break; 433 break;
435 } 434 }
436 case l_c('{'): { /* funcargs -> constructor */ 435 case '{': { /* funcargs -> constructor */
437 constructor(ls, &args); 436 constructor(ls, &args);
438 break; 437 break;
439 } 438 }
@@ -443,7 +442,7 @@ static void funcargs (LexState *ls, expdesc *f) {
443 break; 442 break;
444 } 443 }
445 default: { 444 default: {
446 luaK_error(ls, l_s("function arguments expected")); 445 luaK_error(ls, "function arguments expected");
447 break; 446 break;
448 } 447 }
449 } 448 }
@@ -480,13 +479,13 @@ static void recfield (LexState *ls, expdesc *t) {
480 checkname(ls, &key); 479 checkname(ls, &key);
481 break; 480 break;
482 } 481 }
483 case l_c('['): { 482 case '[': {
484 luaY_index(ls, &key); 483 luaY_index(ls, &key);
485 break; 484 break;
486 } 485 }
487 default: luaK_error(ls, l_s("<name> or `[' expected")); 486 default: luaK_error(ls, "<name> or `[' expected");
488 } 487 }
489 check(ls, l_c('=')); 488 check(ls, '=');
490 luaK_exp2RK(fs, &key); 489 luaK_exp2RK(fs, &key);
491 expr(ls, &val); 490 expr(ls, &val);
492 luaK_exp2anyreg(fs, &val); 491 luaK_exp2anyreg(fs, &val);
@@ -497,9 +496,9 @@ static void recfield (LexState *ls, expdesc *t) {
497 496
498 497
499static int anotherfield (LexState *ls) { 498static int anotherfield (LexState *ls) {
500 if (ls->t.token != l_c(',')) return 0; 499 if (ls->t.token != ',') return 0;
501 next(ls); /* skip the comma */ 500 next(ls); /* skip the comma */
502 return (ls->t.token != l_c(';') && ls->t.token != l_c('}')); 501 return (ls->t.token != ';' && ls->t.token != '}');
503} 502}
504 503
505 504
@@ -508,7 +507,7 @@ static int recfields (LexState *ls, expdesc *t) {
508 int n = 0; 507 int n = 0;
509 do { /* at least one element */ 508 do { /* at least one element */
510 recfield(ls, t); 509 recfield(ls, t);
511 luaX_checklimit(ls, n, MAX_INT, l_s("items in a constructor")); 510 luaX_checklimit(ls, n, MAX_INT, "items in a constructor");
512 n++; 511 n++;
513 } while (anotherfield(ls)); 512 } while (anotherfield(ls));
514 return n; 513 return n;
@@ -525,7 +524,7 @@ static int listfields (LexState *ls, expdesc *t) {
525 expr(ls, &v); 524 expr(ls, &v);
526 while (anotherfield(ls)) { 525 while (anotherfield(ls)) {
527 luaK_exp2nextreg(fs, &v); 526 luaK_exp2nextreg(fs, &v);
528 luaX_checklimit(ls, n, MAXARG_Bc, l_s("items in a constructor")); 527 luaX_checklimit(ls, n, MAXARG_Bc, "items in a constructor");
529 if (n%LFIELDS_PER_FLUSH == 0) { 528 if (n%LFIELDS_PER_FLUSH == 0) {
530 luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */ 529 luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */
531 fs->freereg = reg; /* free registers */ 530 fs->freereg = reg; /* free registers */
@@ -548,18 +547,18 @@ static int listfields (LexState *ls, expdesc *t) {
548 547
549static void constructor_part (LexState *ls, expdesc *t, Constdesc *cd) { 548static void constructor_part (LexState *ls, expdesc *t, Constdesc *cd) {
550 switch (ls->t.token) { 549 switch (ls->t.token) {
551 case l_c(';'): case l_c('}'): { /* constructor_part -> empty */ 550 case ';': case '}': { /* constructor_part -> empty */
552 cd->narray = cd->nhash = 0; 551 cd->narray = cd->nhash = 0;
553 cd->k = ls->t.token; 552 cd->k = ls->t.token;
554 break; 553 break;
555 } 554 }
556 case TK_NAME: { /* may be listfields or recfields */ 555 case TK_NAME: { /* may be listfields or recfields */
557 lookahead(ls); 556 lookahead(ls);
558 if (ls->lookahead.token != l_c('=')) /* expression? */ 557 if (ls->lookahead.token != '=') /* expression? */
559 goto case_default; 558 goto case_default;
560 /* else go through to recfields */ 559 /* else go through to recfields */
561 } 560 }
562 case l_c('['): { /* constructor_part -> recfields */ 561 case '[': { /* constructor_part -> recfields */
563 cd->nhash = recfields(ls, t); 562 cd->nhash = recfields(ls, t);
564 cd->narray = 0; 563 cd->narray = 0;
565 cd->k = 1; /* record */ 564 cd->k = 1; /* record */
@@ -586,18 +585,18 @@ static void constructor (LexState *ls, expdesc *t) {
586 pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); 585 pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
587 init_exp(t, VRELOCABLE, pc); 586 init_exp(t, VRELOCABLE, pc);
588 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ 587 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */
589 check(ls, l_c('{')); 588 check(ls, '{');
590 constructor_part(ls, t, &cd); 589 constructor_part(ls, t, &cd);
591 na = cd.narray; 590 na = cd.narray;
592 nh = cd.nhash; 591 nh = cd.nhash;
593 if (optional(ls, l_c(';'))) { 592 if (optional(ls, ';')) {
594 Constdesc other_cd; 593 Constdesc other_cd;
595 constructor_part(ls, t, &other_cd); 594 constructor_part(ls, t, &other_cd);
596 check_condition(ls,(cd.k != other_cd.k), l_s("invalid constructor syntax")); 595 check_condition(ls,(cd.k != other_cd.k), "invalid constructor syntax");
597 na += other_cd.narray; 596 na += other_cd.narray;
598 nh += other_cd.nhash; 597 nh += other_cd.nhash;
599 } 598 }
600 check_match(ls, l_c('}'), l_c('{'), line); 599 check_match(ls, '}', '{', line);
601 if (na > 0) 600 if (na > 0)
602 SETARG_B(fs->f->code[pc], luaO_log2(na-1)+2); /* set initial table size */ 601 SETARG_B(fs->f->code[pc], luaO_log2(na-1)+2); /* set initial table size */
603 SETARG_C(fs->f->code[pc], luaO_log2(nh)+1); /* set initial table size */ 602 SETARG_C(fs->f->code[pc], luaO_log2(nh)+1); /* set initial table size */
@@ -618,10 +617,10 @@ static void constructor (LexState *ls, expdesc *t) {
618static void prefixexp (LexState *ls, expdesc *v) { 617static void prefixexp (LexState *ls, expdesc *v) {
619 /* prefixexp -> NAME | '(' expr ')' */ 618 /* prefixexp -> NAME | '(' expr ')' */
620 switch (ls->t.token) { 619 switch (ls->t.token) {
621 case l_c('('): { 620 case '(': {
622 next(ls); 621 next(ls);
623 expr(ls, v); 622 expr(ls, v);
624 check(ls, l_c(')')); 623 check(ls, ')');
625 luaK_dischargevars(ls->fs, v); 624 luaK_dischargevars(ls->fs, v);
626 return; 625 return;
627 } 626 }
@@ -630,15 +629,15 @@ static void prefixexp (LexState *ls, expdesc *v) {
630 next(ls); 629 next(ls);
631 return; 630 return;
632 } 631 }
633 case l_c('%'): { /* for compatibility only */ 632 case '%': { /* for compatibility only */
634 next(ls); /* skip `%' */ 633 next(ls); /* skip `%' */
635 singlevar(ls->fs, str_checkname(ls), v, 1); 634 singlevar(ls->fs, str_checkname(ls), v, 1);
636 check_condition(ls, v->k == VUPVAL, l_s("global upvalues are obsolete")); 635 check_condition(ls, v->k == VUPVAL, "global upvalues are obsolete");
637 next(ls); 636 next(ls);
638 return; 637 return;
639 } 638 }
640 default: { 639 default: {
641 luaK_error(ls, l_s("unexpected symbol")); 640 luaK_error(ls, "unexpected symbol");
642 return; 641 return;
643 } 642 }
644 } 643 }
@@ -652,18 +651,18 @@ static void primaryexp (LexState *ls, expdesc *v) {
652 prefixexp(ls, v); 651 prefixexp(ls, v);
653 for (;;) { 652 for (;;) {
654 switch (ls->t.token) { 653 switch (ls->t.token) {
655 case l_c('.'): { /* field */ 654 case '.': { /* field */
656 luaY_field(ls, v); 655 luaY_field(ls, v);
657 break; 656 break;
658 } 657 }
659 case l_c('['): { /* `[' exp1 `]' */ 658 case '[': { /* `[' exp1 `]' */
660 expdesc key; 659 expdesc key;
661 luaK_exp2anyreg(fs, v); 660 luaK_exp2anyreg(fs, v);
662 luaY_index(ls, &key); 661 luaY_index(ls, &key);
663 luaK_indexed(fs, v, &key); 662 luaK_indexed(fs, v, &key);
664 break; 663 break;
665 } 664 }
666 case l_c(':'): { /* `:' NAME funcargs */ 665 case ':': { /* `:' NAME funcargs */
667 expdesc key; 666 expdesc key;
668 next(ls); 667 next(ls);
669 checkname(ls, &key); 668 checkname(ls, &key);
@@ -671,7 +670,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
671 funcargs(ls, v); 670 funcargs(ls, v);
672 break; 671 break;
673 } 672 }
674 case l_c('('): case TK_STRING: case l_c('{'): { /* funcargs */ 673 case '(': case TK_STRING: case '{': { /* funcargs */
675 luaK_exp2nextreg(fs, v); 674 luaK_exp2nextreg(fs, v);
676 funcargs(ls, v); 675 funcargs(ls, v);
677 break; 676 break;
@@ -702,7 +701,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
702 next(ls); 701 next(ls);
703 break; 702 break;
704 } 703 }
705 case l_c('{'): { /* constructor */ 704 case '{': { /* constructor */
706 constructor(ls, v); 705 constructor(ls, v);
707 break; 706 break;
708 } 707 }
@@ -724,7 +723,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
724static UnOpr getunopr (int op) { 723static UnOpr getunopr (int op) {
725 switch (op) { 724 switch (op) {
726 case TK_NOT: return OPR_NOT; 725 case TK_NOT: return OPR_NOT;
727 case l_c('-'): return OPR_MINUS; 726 case '-': return OPR_MINUS;
728 default: return OPR_NOUNOPR; 727 default: return OPR_NOUNOPR;
729 } 728 }
730} 729}
@@ -732,17 +731,17 @@ static UnOpr getunopr (int op) {
732 731
733static BinOpr getbinopr (int op) { 732static BinOpr getbinopr (int op) {
734 switch (op) { 733 switch (op) {
735 case l_c('+'): return OPR_ADD; 734 case '+': return OPR_ADD;
736 case l_c('-'): return OPR_SUB; 735 case '-': return OPR_SUB;
737 case l_c('*'): return OPR_MULT; 736 case '*': return OPR_MULT;
738 case l_c('/'): return OPR_DIV; 737 case '/': return OPR_DIV;
739 case l_c('^'): return OPR_POW; 738 case '^': return OPR_POW;
740 case TK_CONCAT: return OPR_CONCAT; 739 case TK_CONCAT: return OPR_CONCAT;
741 case TK_NE: return OPR_NE; 740 case TK_NE: return OPR_NE;
742 case TK_EQ: return OPR_EQ; 741 case TK_EQ: return OPR_EQ;
743 case l_c('<'): return OPR_LT; 742 case '<': return OPR_LT;
744 case TK_LE: return OPR_LE; 743 case TK_LE: return OPR_LE;
745 case l_c('>'): return OPR_GT; 744 case '>': return OPR_GT;
746 case TK_GE: return OPR_GE; 745 case TK_GE: return OPR_GE;
747 case TK_AND: return OPR_AND; 746 case TK_AND: return OPR_AND;
748 case TK_OR: return OPR_OR; 747 case TK_OR: return OPR_OR;
@@ -870,8 +869,8 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
870static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { 869static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
871 expdesc e; 870 expdesc e;
872 check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, 871 check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
873 l_s("syntax error!")); 872 "syntax error!");
874 if (ls->t.token == l_c(',')) { /* assignment -> `,' primaryexp assignment */ 873 if (ls->t.token == ',') { /* assignment -> `,' primaryexp assignment */
875 struct LHS_assign nv; 874 struct LHS_assign nv;
876 nv.prev = lh; 875 nv.prev = lh;
877 next(ls); 876 next(ls);
@@ -882,7 +881,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
882 } 881 }
883 else { /* assignment -> `=' explist1 */ 882 else { /* assignment -> `=' explist1 */
884 int nexps; 883 int nexps;
885 check(ls, l_c('=')); 884 check(ls, '=');
886 nexps = explist1(ls, &e); 885 nexps = explist1(ls, &e);
887 if (nexps != nvars) { 886 if (nexps != nvars) {
888 adjust_assign(ls, nvars, nexps, &e); 887 adjust_assign(ls, nvars, nexps, &e);
@@ -965,19 +964,19 @@ static void forbody (LexState *ls, int nvar, OpCode prepfor, OpCode loopfor) {
965static void fornum (LexState *ls, TString *varname) { 964static void fornum (LexState *ls, TString *varname) {
966 /* fornum -> NAME = exp1,exp1[,exp1] forbody */ 965 /* fornum -> NAME = exp1,exp1[,exp1] forbody */
967 FuncState *fs = ls->fs; 966 FuncState *fs = ls->fs;
968 check(ls, l_c('=')); 967 check(ls, '=');
969 exp1(ls); /* initial value */ 968 exp1(ls); /* initial value */
970 check(ls, l_c(',')); 969 check(ls, ',');
971 exp1(ls); /* limit */ 970 exp1(ls); /* limit */
972 if (optional(ls, l_c(','))) 971 if (optional(ls, ','))
973 exp1(ls); /* optional step */ 972 exp1(ls); /* optional step */
974 else { 973 else {
975 luaK_codeAsBc(fs, OP_LOADINT, fs->freereg, 1); /* default step */ 974 luaK_codeAsBc(fs, OP_LOADINT, fs->freereg, 1); /* default step */
976 luaK_reserveregs(fs, 1); 975 luaK_reserveregs(fs, 1);
977 } 976 }
978 new_localvar(ls, varname, 0); 977 new_localvar(ls, varname, 0);
979 new_localvarstr(ls, l_s("(limit)"), 1); 978 new_localvarstr(ls, "(limit)", 1);
980 new_localvarstr(ls, l_s("(step)"), 2); 979 new_localvarstr(ls, "(step)", 2);
981 forbody(ls, 3, OP_FORPREP, OP_FORLOOP); 980 forbody(ls, 3, OP_FORPREP, OP_FORLOOP);
982} 981}
983 982
@@ -985,13 +984,13 @@ static void fornum (LexState *ls, TString *varname) {
985static void forlist (LexState *ls, TString *indexname) { 984static void forlist (LexState *ls, TString *indexname) {
986 /* forlist -> NAME,NAME IN exp1 forbody */ 985 /* forlist -> NAME,NAME IN exp1 forbody */
987 TString *valname; 986 TString *valname;
988 check(ls, l_c(',')); 987 check(ls, ',');
989 valname = str_checkname(ls); 988 valname = str_checkname(ls);
990 next(ls); /* skip var name */ 989 next(ls); /* skip var name */
991 check(ls, TK_IN); 990 check(ls, TK_IN);
992 exp1(ls); /* table */ 991 exp1(ls); /* table */
993 new_localvarstr(ls, l_s("(table)"), 0); 992 new_localvarstr(ls, "(table)", 0);
994 new_localvarstr(ls, l_s("(index)"), 1); 993 new_localvarstr(ls, "(index)", 1);
995 new_localvar(ls, indexname, 2); 994 new_localvar(ls, indexname, 2);
996 new_localvar(ls, valname, 3); 995 new_localvar(ls, valname, 3);
997 luaK_reserveregs(ls->fs, 3); /* registers for control, index and val */ 996 luaK_reserveregs(ls->fs, 3); /* registers for control, index and val */
@@ -1009,9 +1008,9 @@ static void forstat (LexState *ls, int line) {
1009 varname = str_checkname(ls); /* first variable name */ 1008 varname = str_checkname(ls); /* first variable name */
1010 next(ls); /* skip var name */ 1009 next(ls); /* skip var name */
1011 switch (ls->t.token) { 1010 switch (ls->t.token) {
1012 case l_c('='): fornum(ls, varname); break; 1011 case '=': fornum(ls, varname); break;
1013 case l_c(','): forlist(ls, varname); break; 1012 case ',': forlist(ls, varname); break;
1014 default: luaK_error(ls, l_s("`=' or `,' expected")); 1013 default: luaK_error(ls, "`=' or `,' expected");
1015 } 1014 }
1016 check_match(ls, TK_END, TK_FOR, line); 1015 check_match(ls, TK_END, TK_FOR, line);
1017 leavebreak(fs, &bl); 1016 leavebreak(fs, &bl);
@@ -1060,8 +1059,8 @@ static void localstat (LexState *ls) {
1060 next(ls); /* skip LOCAL or `,' */ 1059 next(ls); /* skip LOCAL or `,' */
1061 new_localvar(ls, str_checkname(ls), nvars++); 1060 new_localvar(ls, str_checkname(ls), nvars++);
1062 next(ls); /* skip var name */ 1061 next(ls); /* skip var name */
1063 } while (ls->t.token == l_c(',')); 1062 } while (ls->t.token == ',');
1064 if (optional(ls, l_c('='))) 1063 if (optional(ls, '='))
1065 nexps = explist1(ls, &e); 1064 nexps = explist1(ls, &e);
1066 else { 1065 else {
1067 e.k = VVOID; 1066 e.k = VVOID;
@@ -1077,10 +1076,10 @@ static int funcname (LexState *ls, expdesc *v) {
1077 int needself = 0; 1076 int needself = 0;
1078 singlevar(ls->fs, str_checkname(ls), v, 1); 1077 singlevar(ls->fs, str_checkname(ls), v, 1);
1079 next(ls); /* skip var name */ 1078 next(ls); /* skip var name */
1080 while (ls->t.token == l_c('.')) { 1079 while (ls->t.token == '.') {
1081 luaY_field(ls, v); 1080 luaY_field(ls, v);
1082 } 1081 }
1083 if (ls->t.token == l_c(':')) { 1082 if (ls->t.token == ':') {
1084 needself = 1; 1083 needself = 1;
1085 luaY_field(ls, v); 1084 luaY_field(ls, v);
1086 } 1085 }
@@ -1120,7 +1119,7 @@ static void retstat (LexState *ls) {
1120 expdesc e; 1119 expdesc e;
1121 int first, nret; /* registers with returned values */ 1120 int first, nret; /* registers with returned values */
1122 next(ls); /* skip RETURN */ 1121 next(ls); /* skip RETURN */
1123 if (block_follow(ls->t.token) || ls->t.token == l_c(';')) 1122 if (block_follow(ls->t.token) || ls->t.token == ';')
1124 first = nret = 0; /* return no values */ 1123 first = nret = 0; /* return no values */
1125 else { 1124 else {
1126 explist1(ls, &e); /* optional return values */ 1125 explist1(ls, &e); /* optional return values */
@@ -1145,7 +1144,7 @@ static void breakstat (LexState *ls) {
1145 FuncState *fs = ls->fs; 1144 FuncState *fs = ls->fs;
1146 Breaklabel *bl = fs->bl; 1145 Breaklabel *bl = fs->bl;
1147 if (!bl) 1146 if (!bl)
1148 luaK_error(ls, l_s("no loop to break")); 1147 luaK_error(ls, "no loop to break");
1149 next(ls); /* skip BREAK */ 1148 next(ls); /* skip BREAK */
1150 closelevel(ls, bl->nactloc); 1149 closelevel(ls, bl->nactloc);
1151 luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); 1150 luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
@@ -1205,15 +1204,15 @@ static void parlist (LexState *ls) {
1205 /* parlist -> [ param { `,' param } ] */ 1204 /* parlist -> [ param { `,' param } ] */
1206 int nparams = 0; 1205 int nparams = 0;
1207 short dots = 0; 1206 short dots = 0;
1208 if (ls->t.token != l_c(')')) { /* is `parlist' not empty? */ 1207 if (ls->t.token != ')') { /* is `parlist' not empty? */
1209 do { 1208 do {
1210 switch (ls->t.token) { 1209 switch (ls->t.token) {
1211 case TK_DOTS: dots = 1; break; 1210 case TK_DOTS: dots = 1; break;
1212 case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; 1211 case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break;
1213 default: luaK_error(ls, l_s("<name> or `...' expected")); 1212 default: luaK_error(ls, "<name> or `...' expected");
1214 } 1213 }
1215 next(ls); 1214 next(ls);
1216 } while (!dots && optional(ls, l_c(','))); 1215 } while (!dots && optional(ls, ','));
1217 } 1216 }
1218 code_params(ls, nparams, dots); 1217 code_params(ls, nparams, dots);
1219} 1218}
@@ -1224,13 +1223,13 @@ static void body (LexState *ls, expdesc *e, int needself, int line) {
1224 FuncState new_fs; 1223 FuncState new_fs;
1225 open_func(ls, &new_fs); 1224 open_func(ls, &new_fs);
1226 new_fs.f->lineDefined = line; 1225 new_fs.f->lineDefined = line;
1227 check(ls, l_c('(')); 1226 check(ls, '(');
1228 if (needself) { 1227 if (needself) {
1229 new_localvarstr(ls, l_s("self"), 0); 1228 new_localvarstr(ls, "self", 0);
1230 adjustlocalvars(ls, 1); 1229 adjustlocalvars(ls, 1);
1231 } 1230 }
1232 parlist(ls); 1231 parlist(ls);
1233 check(ls, l_c(')')); 1232 check(ls, ')');
1234 chunk(ls); 1233 chunk(ls);
1235 check_match(ls, TK_END, TK_FUNCTION, line); 1234 check_match(ls, TK_END, TK_FUNCTION, line);
1236 close_func(ls); 1235 close_func(ls);
@@ -1246,7 +1245,7 @@ static void chunk (LexState *ls) {
1246 int islast = 0; 1245 int islast = 0;
1247 while (!islast && !block_follow(ls->t.token)) { 1246 while (!islast && !block_follow(ls->t.token)) {
1248 islast = statement(ls); 1247 islast = statement(ls);
1249 optional(ls, l_c(';')); 1248 optional(ls, ';');
1250 lua_assert(ls->fs->freereg >= ls->fs->nactloc); 1249 lua_assert(ls->fs->freereg >= ls->fs->nactloc);
1251 ls->fs->freereg = ls->fs->nactloc; /* free registers */ 1250 ls->fs->freereg = ls->fs->nactloc; /* free registers */
1252 } 1251 }