mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
Mudancas na sintaxe para a versao 2.0. Igual relacional passa
a ser ==, tiramos o colchete na criacao de tabelas usando apenas chaves (podendo fazer inicializacao mista). O caracter @ so' deve estar presente quando se tem construtores associados. /
This commit is contained in:
parent
d107d5bfd2
commit
87dded9363
94
lua.stx
94
lua.stx
@ -1,6 +1,6 @@
|
|||||||
%{
|
%{
|
||||||
|
|
||||||
char *rcs_luastx = "$Id: lua.stx,v 2.6 1994/08/03 14:15:46 celes Exp celes $";
|
char *rcs_luastx = "$Id: lua.stx,v 2.7 1994/08/05 19:31:09 celes Exp celes $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -232,21 +232,21 @@ static void init_function (void)
|
|||||||
%token LOCAL
|
%token LOCAL
|
||||||
%token FUNCTION
|
%token FUNCTION
|
||||||
%token <vFloat> NUMBER
|
%token <vFloat> NUMBER
|
||||||
%token <vWord> STRING
|
%token <pChar> STRING
|
||||||
%token <pChar> NAME
|
%token <pChar> NAME
|
||||||
%token <vInt> DEBUG
|
%token <vInt> DEBUG
|
||||||
|
|
||||||
%type <vLong> PrepJump
|
%type <vLong> PrepJump
|
||||||
%type <vInt> expr, exprlist, exprlist1, varlist1, typeconstructor
|
%type <vInt> expr, exprlist, exprlist1, varlist1
|
||||||
%type <vInt> fieldlist, localdeclist
|
%type <vInt> fieldlist, localdeclist
|
||||||
%type <vInt> ffieldlist, ffieldlist1
|
%type <vInt> ffieldlist1
|
||||||
%type <vInt> lfieldlist, lfieldlist1
|
%type <vInt> lfieldlist1
|
||||||
%type <vInt> functionvalue
|
%type <vInt> functionvalue
|
||||||
%type <vLong> var, singlevar, objectname
|
%type <vLong> var, singlevar
|
||||||
|
|
||||||
|
|
||||||
%left AND OR
|
%left AND OR
|
||||||
%left '=' NE '>' '<' LE GE
|
%left EQ NE '>' '<' LE GE
|
||||||
%left CONC
|
%left CONC
|
||||||
%left '+' '-'
|
%left '+' '-'
|
||||||
%left '*' '/'
|
%left '*' '/'
|
||||||
@ -425,7 +425,7 @@ stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
| functioncall { lua_codeadjust (0); }
|
| functioncall { lua_codeadjust (0); }
|
||||||
| typeconstructor { lua_codeadjust (0); }
|
| constructor { lua_codeadjust (0); }
|
||||||
| LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
|
| LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}}
|
|||||||
;
|
;
|
||||||
|
|
||||||
expr : '(' expr ')' { $$ = $2; }
|
expr : '(' expr ')' { $$ = $2; }
|
||||||
| expr1 '=' expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
|
| expr1 EQ expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
|
||||||
| expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
|
| expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
|
||||||
| expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
| expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
||||||
| expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
| expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
|
||||||
@ -494,18 +494,14 @@ expr : '(' expr ')' { $$ = $2; }
|
|||||||
| expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
|
| expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
|
||||||
| '+' expr1 %prec UNARY { $$ = 1; }
|
| '+' expr1 %prec UNARY { $$ = 1; }
|
||||||
| '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
|
| '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
|
||||||
| typeconstructor { $$ = $1; }
|
| constructor { $$ = 0; }
|
||||||
| '@' '(' dimension ')'
|
| table { $$ = 1; }
|
||||||
{
|
|
||||||
code_byte(CREATEARRAY);
|
|
||||||
$$ = 1;
|
|
||||||
}
|
|
||||||
| var { lua_pushvar ($1); $$ = 1;}
|
| var { lua_pushvar ($1); $$ = 1;}
|
||||||
| NUMBER { code_number($1); $$ = 1; }
|
| NUMBER { code_number($1); $$ = 1; }
|
||||||
| STRING
|
| STRING
|
||||||
{
|
{
|
||||||
code_byte(PUSHSTRING);
|
code_byte(PUSHSTRING);
|
||||||
code_word($1);
|
code_word(lua_findconstant($1));
|
||||||
$$ = 1;
|
$$ = 1;
|
||||||
incr_ntemp();
|
incr_ntemp();
|
||||||
}
|
}
|
||||||
@ -533,40 +529,32 @@ expr : '(' expr ')' { $$ = $2; }
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
typeconstructor: '@'
|
constructor : '@' singlevar table
|
||||||
{
|
{
|
||||||
code_byte(PUSHWORD);
|
lua_pushvar ($2);
|
||||||
$<vLong>$ = pc; code_word(0);
|
|
||||||
incr_ntemp();
|
|
||||||
code_byte(CREATEARRAY);
|
|
||||||
}
|
|
||||||
objectname fieldlist
|
|
||||||
{
|
|
||||||
code_word_at(basepc+$<vLong>2, $4);
|
|
||||||
if ($3 < 0) /* there is no function to be called */
|
|
||||||
{
|
|
||||||
$$ = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lua_pushvar ($3+1);
|
|
||||||
code_byte(PUSHMARK);
|
code_byte(PUSHMARK);
|
||||||
incr_ntemp();
|
incr_ntemp();
|
||||||
code_byte(PUSHOBJECT);
|
code_byte(PUSHOBJECT);
|
||||||
incr_ntemp();
|
incr_ntemp();
|
||||||
code_byte(CALLFUNC);
|
code_byte(CALLFUNC);
|
||||||
ntemp -= 4;
|
ntemp -= 4;
|
||||||
$$ = 0;
|
|
||||||
if (lua_debug)
|
if (lua_debug)
|
||||||
{
|
{
|
||||||
code_byte(SETLINE); code_word(lua_linenumber);
|
code_byte(SETLINE); code_word(lua_linenumber);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
table :
|
||||||
dimension : /* empty */ { code_byte(PUSHNIL); incr_ntemp();}
|
{
|
||||||
| expr1
|
code_byte(PUSHWORD);
|
||||||
|
$<vLong>$ = pc; code_word(0);
|
||||||
|
incr_ntemp();
|
||||||
|
code_byte(CREATEARRAY);
|
||||||
|
}
|
||||||
|
'{' fieldlist '}'
|
||||||
|
{
|
||||||
|
code_word_at(basepc+$<vLong>1, $3);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
functioncall : functionvalue
|
functioncall : functionvalue
|
||||||
@ -575,6 +563,7 @@ functioncall : functionvalue
|
|||||||
if ($1 != 0) lua_pushvar($1);
|
if ($1 != 0) lua_pushvar($1);
|
||||||
}
|
}
|
||||||
'(' exprlist ')' { code_byte(CALLFUNC); ntemp = $<vInt>2-1;}
|
'(' exprlist ')' { code_byte(CALLFUNC); ntemp = $<vInt>2-1;}
|
||||||
|
;
|
||||||
|
|
||||||
functionvalue : var {lua_pushvar ($1); $$ = 0; }
|
functionvalue : var {lua_pushvar ($1); $$ = 0; }
|
||||||
| singlevar ':' NAME
|
| singlevar ':' NAME
|
||||||
@ -613,24 +602,19 @@ parlist1 : NAME
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
objectname : /* empty */ {$$=-1;}
|
fieldlist : /* empty */ { $$ = 0; }
|
||||||
| NAME {$$=lua_findsymbol($1);}
|
| lfieldlist1 lastcomma
|
||||||
|
{ $$ = $1; flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); }
|
||||||
|
| ffieldlist1 lastcomma
|
||||||
|
{ $$ = $1; flush_record($1%FIELDS_PER_FLUSH); }
|
||||||
|
| lfieldlist1 ';'
|
||||||
|
{ flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); }
|
||||||
|
ffieldlist1 lastcomma
|
||||||
|
{ $$ = $1+$4; flush_record($4%FIELDS_PER_FLUSH); }
|
||||||
;
|
;
|
||||||
|
|
||||||
fieldlist : '{' ffieldlist '}'
|
lastcomma : /* empty */
|
||||||
{
|
| ','
|
||||||
flush_record($2%FIELDS_PER_FLUSH);
|
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
| '[' lfieldlist ']'
|
|
||||||
{
|
|
||||||
flush_list($2/FIELDS_PER_FLUSH, $2%FIELDS_PER_FLUSH);
|
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
ffieldlist : /* empty */ { $$ = 0; }
|
|
||||||
| ffieldlist1 { $$ = $1; }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
ffieldlist1 : ffield {$$=1;}
|
ffieldlist1 : ffield {$$=1;}
|
||||||
@ -647,10 +631,6 @@ ffield : NAME {$<vWord>$ = lua_findconstant($1);} '=' expr1
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
lfieldlist : /* empty */ { $$ = 0; }
|
|
||||||
| lfieldlist1 { $$ = $1; }
|
|
||||||
;
|
|
||||||
|
|
||||||
lfieldlist1 : expr1 {$$=1;}
|
lfieldlist1 : expr1 {$$=1;}
|
||||||
| lfieldlist1 ',' expr1
|
| lfieldlist1 ',' expr1
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user