aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-22 15:24:11 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-22 15:24:11 -0200
commit22439a7511f45c4180e532857a4f831046460778 (patch)
tree6ff083c0418079e2e5f264a9e941360d8918791e
parent7ecc3ce82700b931be0a2cc4a2feacb674c9854f (diff)
downloadlua-22439a7511f45c4180e532857a4f831046460778.tar.gz
lua-22439a7511f45c4180e532857a4f831046460778.tar.bz2
lua-22439a7511f45c4180e532857a4f831046460778.zip
new syntax for constructors (a={n=3;1,2,3}).
-rw-r--r--lua.stx51
1 files changed, 28 insertions, 23 deletions
diff --git a/lua.stx b/lua.stx
index 8bf40d6c..6dbaf32b 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2/* 2/*
3** $Id: lua.stx,v 1.22 1997/12/09 16:01:08 roberto Exp roberto $ 3** $Id: lua.stx,v 1.23 1997/12/15 16:17:20 roberto Exp roberto $
4** Syntax analizer and code generator 4** Syntax analizer and code generator
5** See Copyright Notice in lua.h 5** See Copyright Notice in lua.h
6*/ 6*/
@@ -664,8 +664,7 @@ TProtoFunc *luaY_parser (ZIO *z, char *chunkname)
664 counter */ 664 counter */
665%type <vInt> varlist1, funcParams, funcvalue 665%type <vInt> varlist1, funcParams, funcvalue
666%type <vInt> fieldlist, localnamelist, decinit 666%type <vInt> fieldlist, localnamelist, decinit
667%type <vInt> ffieldlist, ffieldlist1, semicolonpart 667%type <vInt> ffieldlist1, lfieldlist1, ffieldlist, lfieldlist, part
668%type <vInt> lfieldlist, lfieldlist1
669%type <vLong> var, funcname /* vardesc */ 668%type <vLong> var, funcname /* vardesc */
670%type <pFunc> body 669%type <pFunc> body
671 670
@@ -861,25 +860,35 @@ parlist : /* empty */ { code_args(0, 0); }
861 | localnamelist ',' DOTS { code_args($1, 1); } 860 | localnamelist ',' DOTS { code_args($1, 1); }
862 ; 861 ;
863 862
864fieldlist : lfieldlist 863fieldlist : part { $$ = abs($1); }
865 { flush_list($1/LFIELDS_PER_FLUSH, $1%LFIELDS_PER_FLUSH); } 864 | part ';' part
866 semicolonpart 865 {
867 { $$ = $1+$3; } 866 if ($1*$3 > 0) /* repeated parts? */
868 | ffieldlist1 lastcomma 867 luaY_error("invalid constructor syntax");
869 { $$ = $1; flush_record($1%RFIELDS_PER_FLUSH); } 868 $$ = abs($1)+abs($3);
870 ; 869 }
870 ;
871 871
872semicolonpart : /* empty */ { $$ = 0; } 872part : /* empty */ { $$ = 0; }
873 | ';' ffieldlist { $$ = $2; flush_record($2%RFIELDS_PER_FLUSH); } 873 | ffieldlist { $$ = $1; }
874 ; 874 | lfieldlist { $$ = $1; }
875 ;
875 876
876lastcomma : /* empty */ 877lastcomma : /* empty */ | ',' ;
877 | ','
878 ;
879 878
880ffieldlist : /* empty */ { $$ = 0; } 879ffieldlist : ffieldlist1 lastcomma
881 | ffieldlist1 lastcomma { $$ = $1; } 880 {
882 ; 881 flush_record($1%RFIELDS_PER_FLUSH);
882 $$ = -$1; /* negative signals a "record" part */
883 }
884 ;
885
886lfieldlist : lfieldlist1 lastcomma
887 {
888 flush_list($1/LFIELDS_PER_FLUSH, $1%LFIELDS_PER_FLUSH);
889 $$ = $1;
890 }
891 ;
883 892
884ffieldlist1 : ffield {$$=1;} 893ffieldlist1 : ffield {$$=1;}
885 | ffieldlist1 ',' ffield 894 | ffieldlist1 ',' ffield
@@ -897,10 +906,6 @@ ffieldkey : '[' expr1 ']'
897 | NAME { code_string($1); } 906 | NAME { code_string($1); }
898 ; 907 ;
899 908
900lfieldlist : /* empty */ { $$ = 0; }
901 | lfieldlist1 lastcomma { $$ = $1; }
902 ;
903
904lfieldlist1 : expr1 {$$=1;} 909lfieldlist1 : expr1 {$$=1;}
905 | lfieldlist1 ',' expr1 910 | lfieldlist1 ',' expr1
906 { 911 {