new way to handle pragmas (at the lexical level, instead of parsing).
This commit is contained in:
58
lex.c
58
lex.c
@@ -1,4 +1,4 @@
|
|||||||
char *rcs_lex = "$Id: lex.c,v 2.34 1996/05/30 14:04:07 roberto Exp roberto $";
|
char *rcs_lex = "$Id: lex.c,v 2.35 1996/09/09 14:11:11 roberto Exp roberto $";
|
||||||
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -25,7 +25,8 @@ static Input input; /* input function */
|
|||||||
|
|
||||||
void lua_setinput (Input fn)
|
void lua_setinput (Input fn)
|
||||||
{
|
{
|
||||||
current = ' ';
|
current = '\n';
|
||||||
|
lua_linenumber = 0;
|
||||||
input = fn;
|
input = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +72,26 @@ void luaI_addReserved (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int inclinenumber (void)
|
||||||
|
{
|
||||||
|
if (current == '$') { /* is a pragma? */
|
||||||
|
char buff[MINBUFF];
|
||||||
|
int i = 0;
|
||||||
|
next(); /* skip $ */
|
||||||
|
while (isalnum(current)) {
|
||||||
|
if (i >= MINBUFF) lua_error("pragma too long");
|
||||||
|
buff[i++] = current;
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
buff[i] = 0;
|
||||||
|
if (strcmp(buff, "debug") == 0)
|
||||||
|
lua_debug = 1;
|
||||||
|
else if (strcmp(buff, "nodebug") == 0)
|
||||||
|
lua_debug = 0;
|
||||||
|
else lua_error("invalid pragma");
|
||||||
|
}
|
||||||
|
return ++lua_linenumber;
|
||||||
|
}
|
||||||
|
|
||||||
static int read_long_string (char *yytext, int buffsize)
|
static int read_long_string (char *yytext, int buffsize)
|
||||||
{
|
{
|
||||||
@@ -103,7 +124,9 @@ static int read_long_string (char *yytext, int buffsize)
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
case '\n':
|
case '\n':
|
||||||
lua_linenumber++; /* goes through */
|
save_and_next();
|
||||||
|
inclinenumber();
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
save_and_next();
|
save_and_next();
|
||||||
}
|
}
|
||||||
@@ -131,29 +154,14 @@ int luaY_lex (void)
|
|||||||
int tokensize = 0;
|
int tokensize = 0;
|
||||||
switch (current)
|
switch (current)
|
||||||
{
|
{
|
||||||
case '\n': linelasttoken = ++lua_linenumber;
|
case '\n':
|
||||||
case ' ':
|
|
||||||
case '\r': /* CR: to avoid problems with DOS/Windows */
|
|
||||||
case '\t':
|
|
||||||
next();
|
next();
|
||||||
|
linelasttoken = inclinenumber();
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '$':
|
case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
|
||||||
save_and_next();
|
next();
|
||||||
while (isalnum(current) || current == '_')
|
continue;
|
||||||
save_and_next();
|
|
||||||
save(0);
|
|
||||||
if (strcmp(yytext+1, "debug") == 0)
|
|
||||||
{
|
|
||||||
luaY_lval.vInt = 1;
|
|
||||||
return DEBUG;
|
|
||||||
}
|
|
||||||
else if (strcmp(yytext+1, "nodebug") == 0)
|
|
||||||
{
|
|
||||||
luaY_lval.vInt = 0;
|
|
||||||
return DEBUG;
|
|
||||||
}
|
|
||||||
return WRONGTOKEN;
|
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
save_and_next();
|
save_and_next();
|
||||||
@@ -212,8 +220,8 @@ int luaY_lex (void)
|
|||||||
case 'n': save('\n'); next(); break;
|
case 'n': save('\n'); next(); break;
|
||||||
case 't': save('\t'); next(); break;
|
case 't': save('\t'); next(); break;
|
||||||
case 'r': save('\r'); next(); break;
|
case 'r': save('\r'); next(); break;
|
||||||
case '\n': lua_linenumber++; /* goes through */
|
case '\n': save_and_next(); inclinenumber(); break;
|
||||||
default : save(current); next(); break;
|
default : save_and_next(); break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
12
lua.stx
12
lua.stx
@@ -1,6 +1,6 @@
|
|||||||
%{
|
%{
|
||||||
|
|
||||||
char *rcs_luastx = "$Id: lua.stx,v 3.38 1996/07/24 14:38:12 roberto Exp roberto $";
|
char *rcs_luastx = "$Id: lua.stx,v 3.39 1996/09/24 17:29:50 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -440,7 +440,6 @@ void lua_parse (TFunc *tf)
|
|||||||
%token <vFloat> NUMBER
|
%token <vFloat> NUMBER
|
||||||
%token <vWord> STRING
|
%token <vWord> STRING
|
||||||
%token <pTStr> NAME
|
%token <pTStr> NAME
|
||||||
%token <vInt> DEBUG
|
|
||||||
|
|
||||||
%type <vLong> PrepJump
|
%type <vLong> PrepJump
|
||||||
%type <vLong> exprlist, exprlist1 /* if > 0, points to function return
|
%type <vLong> exprlist, exprlist1 /* if > 0, points to function return
|
||||||
@@ -469,14 +468,10 @@ void lua_parse (TFunc *tf)
|
|||||||
chunk : chunklist ret
|
chunk : chunklist ret
|
||||||
|
|
||||||
chunklist : /* empty */
|
chunklist : /* empty */
|
||||||
| chunklist globalstat
|
| chunklist stat sc
|
||||||
| chunklist function
|
| chunklist function
|
||||||
;
|
;
|
||||||
|
|
||||||
globalstat : stat sc
|
|
||||||
| setdebug
|
|
||||||
;
|
|
||||||
|
|
||||||
function : FUNCTION funcname body
|
function : FUNCTION funcname body
|
||||||
{
|
{
|
||||||
code_byte(PUSHFUNCTION);
|
code_byte(PUSHFUNCTION);
|
||||||
@@ -804,7 +799,4 @@ decinit : /* empty */ { $$ = 0; }
|
|||||||
| '=' exprlist1 { $$ = $2; }
|
| '=' exprlist1 { $$ = $2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
setdebug : DEBUG { lua_debug = $1; }
|
|
||||||
;
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|||||||
Reference in New Issue
Block a user