O token NAME deixa de estar associado a um indice da tabela de

simbolos e passa a conter o ponteiro da string yytext.
Recebido o token NAME, decide-se entre um simbolo ou uma constante.
This commit is contained in:
Waldemar Celes 1994-04-15 16:02:04 -03:00
parent dd704b8fe4
commit c77d27afa2
1 changed files with 51 additions and 23 deletions

64
lua.stx
View File

@ -1,6 +1,6 @@
%{ %{
char *rcs_luastx = "$Id: lua.stx,v 1.5 1994/03/28 15:14:54 celes Exp celes $"; char *rcs_luastx = "$Id: lua.stx,v 1.6 1994/04/13 21:37:20 celes Exp celes $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -96,7 +96,7 @@ static void flush_record (int n)
code_byte(STORERECORD); code_byte(STORERECORD);
code_byte(n); code_byte(n);
for (i=0; i<n; i++) for (i=0; i<n; i++)
code_word(lua_findconstant(s_name(fields[--nfields]))); code_word(fields[--nfields]);
ntemp -= n; ntemp -= n;
} }
@ -179,6 +179,7 @@ static void code_number (float f)
int vInt; int vInt;
long vLong; long vLong;
float vFloat; float vFloat;
char *pChar;
Word vWord; Word vWord;
Byte *pByte; Byte *pByte;
} }
@ -191,7 +192,8 @@ static void code_number (float f)
%token RETURN %token RETURN
%token LOCAL %token LOCAL
%token <vFloat> NUMBER %token <vFloat> NUMBER
%token <vWord> FUNCTION NAME STRING %token <vWord> FUNCTION STRING
%token <pChar> NAME
%token <vInt> DEBUG %token <vInt> DEBUG
%type <pByte> PrepJump %type <pByte> PrepJump
@ -225,13 +227,19 @@ functionlist : /* empty */
| functionlist setdebug | functionlist setdebug
; ;
function : FUNCTION NAME {pc=basepc=code; nlocalvar=0;} '(' parlist ')' function : FUNCTION NAME
{
$<vWord>$ = lua_findsymbol($2);
pc=basepc=code;
nlocalvar=0;
}
'(' parlist ')'
{ {
if (lua_debug) if (lua_debug)
{ {
code_byte(SETFUNCTION); code_byte(SETFUNCTION);
code_word(lua_nfile-1); code_word(lua_nfile-1);
code_word($2); code_word($<vWord>3);
} }
lua_codeadjust (0); lua_codeadjust (0);
} }
@ -240,9 +248,9 @@ function : FUNCTION NAME {pc=basepc=code; nlocalvar=0;} '(' parlist ')'
{ {
if (lua_debug) code_byte(RESET); if (lua_debug) code_byte(RESET);
code_byte(RETCODE); code_byte(nlocalvar); code_byte(RETCODE); code_byte(nlocalvar);
s_tag($2) = T_FUNCTION; s_tag($<vWord>3) = T_FUNCTION;
s_bvalue($2) = calloc (pc-code, sizeof(Byte)); s_bvalue($<vWord>3) = calloc (pc-code, sizeof(Byte));
memcpy (s_bvalue($2), code, (pc-code)*sizeof(Byte)); memcpy (s_bvalue($<vWord>3), code, (pc-code)*sizeof(Byte));
#if LISTING #if LISTING
PrintCode(code,pc,(Byte*)buffer); PrintCode(code,pc,(Byte*)buffer);
#endif #endif
@ -479,15 +487,27 @@ parlist : /* empty */
| parlist1 | parlist1
; ;
parlist1 : NAME {localvar[nlocalvar]=$1; add_nlocalvar(1);} parlist1 : NAME
| parlist1 ',' NAME {localvar[nlocalvar]=$3; add_nlocalvar(1);} {
localvar[nlocalvar]=lua_findsymbol($1);
add_nlocalvar(1);
}
| parlist1 ',' NAME
{
localvar[nlocalvar]=lua_findsymbol($3);
add_nlocalvar(1);
}
; ;
objectname : /* empty */ {$$=-1;} objectname : /* empty */ {$$=-1;}
| NAME {$$=$1;} | NAME {$$=lua_findsymbol($1);}
; ;
fieldlist : '{' ffieldlist '}' { flush_record($2%FIELDS_PER_FLUSH); $$ = $2; } fieldlist : '{' ffieldlist '}'
{
flush_record($2%FIELDS_PER_FLUSH);
$$ = $2;
}
| '[' lfieldlist ']' | '[' lfieldlist ']'
{ {
flush_list($2/FIELDS_PER_FLUSH, $2%FIELDS_PER_FLUSH); flush_list($2/FIELDS_PER_FLUSH, $2%FIELDS_PER_FLUSH);
@ -507,7 +527,10 @@ ffieldlist1 : ffield {$$=1;}
} }
; ;
ffield : NAME '=' expr1 { push_field($1); } ffield : NAME {$<vWord>$ = lua_findconstant($1);} '=' expr1
{
push_field($<vWord>2);
}
; ;
lfieldlist : /* empty */ { $$ = 0; } lfieldlist : /* empty */ { $$ = 0; }
@ -538,9 +561,10 @@ varlist1 : var
var : NAME var : NAME
{ {
int local = lua_localname ($1); Word s = lua_findsymbol($1);
int local = lua_localname (s);
if (local == -1) /* global var */ if (local == -1) /* global var */
$$ = $1 + 1; /* return positive value */ $$ = s + 1; /* return positive value */
else else
$$ = -(local+1); /* return negative value */ $$ = -(local+1); /* return negative value */
} }
@ -552,13 +576,17 @@ var : NAME
| var {lua_pushvar ($1);} '.' NAME | var {lua_pushvar ($1);} '.' NAME
{ {
code_byte(PUSHSTRING); code_byte(PUSHSTRING);
code_word(lua_findconstant (s_name($4))); incr_ntemp(); code_word(lua_findconstant($4)); incr_ntemp();
$$ = 0; /* indexed variable */ $$ = 0; /* indexed variable */
} }
; ;
localdeclist : NAME {localvar[nlocalvar]=$1; $$ = 1;} localdeclist : NAME {localvar[nlocalvar]=lua_findsymbol($1); $$ = 1;}
| localdeclist ',' NAME {localvar[nlocalvar+$1]=$3; $$ = $1+1;} | localdeclist ',' NAME
{
localvar[nlocalvar+$1]=lua_findsymbol($3);
$$ = $1+1;
}
; ;
decinit : /* empty */ decinit : /* empty */