1997-09-16 23:25:59 +04:00
|
|
|
/*
|
1997-09-26 19:02:26 +04:00
|
|
|
** $Id: llex.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
1997-09-16 23:25:59 +04:00
|
|
|
** Lexical Analizer
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
1996-05-30 18:04:07 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1993-12-28 19:42:29 +03:00
|
|
|
#include <string.h>
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "llex.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lobject.h"
|
|
|
|
#include "lparser.h"
|
|
|
|
#include "lstring.h"
|
|
|
|
#include "ltokens.h"
|
1996-02-07 17:14:40 +03:00
|
|
|
#include "luadebug.h"
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "lzio.h"
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1995-09-16 00:48:26 +04:00
|
|
|
|
1997-06-16 20:50:22 +04:00
|
|
|
static int current; /* look ahead character */
|
|
|
|
static ZIO *lex_z;
|
1996-05-30 18:04:07 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
int luaX_linenumber;
|
|
|
|
int lua_debug=0;
|
|
|
|
|
|
|
|
|
1997-06-16 20:50:22 +04:00
|
|
|
#define next() (current = zgetc(lex_z))
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void addReserved (void)
|
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
char *name;
|
|
|
|
int token;
|
|
|
|
} reserved [] = {
|
|
|
|
{"and", AND}, {"do", DO}, {"else", ELSE}, {"elseif", ELSEIF},
|
|
|
|
{"end", END}, {"function", FUNCTION}, {"if", IF}, {"local", LOCAL},
|
|
|
|
{"nil", NIL}, {"not", NOT}, {"or", OR}, {"repeat", REPEAT},
|
|
|
|
{"return", RETURN}, {"then", THEN}, {"until", UNTIL}, {"while", WHILE}
|
|
|
|
};
|
|
|
|
static int firsttime = 1;
|
|
|
|
if (firsttime) {
|
|
|
|
int i;
|
|
|
|
firsttime = 0;
|
|
|
|
for (i=0; i<(sizeof(reserved)/sizeof(reserved[0])); i++) {
|
|
|
|
TaggedString *ts = luaS_new(reserved[i].name);
|
1997-09-26 19:02:26 +04:00
|
|
|
ts->head.marked = reserved[i].token; /* reserved word (always > 255) */
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
|
|
|
|
|
1997-06-11 22:56:02 +04:00
|
|
|
#define MAX_IFS 5
|
|
|
|
|
|
|
|
/* "ifstate" keeps the state of each nested $if the lexical is dealing with. */
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int elsepart; /* true if its in the $else part */
|
|
|
|
int condition; /* true if $if condition is true */
|
|
|
|
int skip; /* true if part must be skiped */
|
|
|
|
} ifstate[MAX_IFS];
|
|
|
|
|
1997-04-07 18:48:53 +04:00
|
|
|
static int iflevel; /* level of nested $if's */
|
1993-12-23 00:15:16 +03:00
|
|
|
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
static struct textbuff {
|
|
|
|
char *text;
|
|
|
|
int tokensize;
|
|
|
|
int buffsize;
|
|
|
|
} textbuff;
|
|
|
|
|
1997-07-29 17:33:15 +04:00
|
|
|
|
|
|
|
static void firstline (void)
|
|
|
|
{
|
|
|
|
int c = zgetc(lex_z);
|
|
|
|
if (c == '#')
|
|
|
|
while((c=zgetc(lex_z)) != '\n' && c != EOZ) /* skip first line */;
|
|
|
|
zungetc(lex_z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
void luaX_setinput (ZIO *z)
|
1993-12-23 00:15:16 +03:00
|
|
|
{
|
1997-09-16 23:25:59 +04:00
|
|
|
addReserved();
|
1996-09-26 01:52:00 +04:00
|
|
|
current = '\n';
|
1997-09-16 23:25:59 +04:00
|
|
|
luaX_linenumber = 0;
|
1997-04-07 18:48:53 +04:00
|
|
|
iflevel = 0;
|
1997-06-11 22:56:02 +04:00
|
|
|
ifstate[0].skip = 0;
|
|
|
|
ifstate[0].elsepart = 1; /* to avoid a free $else */
|
1997-06-16 20:50:22 +04:00
|
|
|
lex_z = z;
|
1997-07-29 17:33:15 +04:00
|
|
|
firstline();
|
1997-09-16 23:25:59 +04:00
|
|
|
textbuff.buffsize = 20;
|
|
|
|
textbuff.text = luaM_buffer(textbuff.buffsize);
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
|
1997-04-07 18:48:53 +04:00
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
/*
|
1997-09-16 23:25:59 +04:00
|
|
|
** =======================================================
|
|
|
|
** PRAGMAS
|
|
|
|
** =======================================================
|
1997-04-12 19:01:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define PRAGMASIZE 20
|
|
|
|
|
|
|
|
static void skipspace (void)
|
|
|
|
{
|
|
|
|
while (current == ' ' || current == '\t') next();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int checkcond (char *buff)
|
|
|
|
{
|
1997-06-11 22:56:02 +04:00
|
|
|
static char *opts[] = {"nil", "1"};
|
1997-09-16 23:25:59 +04:00
|
|
|
int i = luaO_findstring(buff, opts);
|
1997-06-11 22:56:02 +04:00
|
|
|
if (i >= 0) return i;
|
1997-04-14 19:30:29 +04:00
|
|
|
else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
|
1997-09-26 19:02:26 +04:00
|
|
|
return luaS_globaldefined(buff);
|
1997-04-12 19:01:49 +04:00
|
|
|
else {
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("invalid $if condition", buff);
|
1997-04-12 19:01:49 +04:00
|
|
|
return 0; /* to avoid warnings */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-07 18:48:53 +04:00
|
|
|
static void readname (char *buff)
|
1996-09-26 01:52:00 +04:00
|
|
|
{
|
1997-04-07 18:48:53 +04:00
|
|
|
int i = 0;
|
1997-04-12 19:01:49 +04:00
|
|
|
skipspace();
|
1997-09-16 23:25:59 +04:00
|
|
|
while (isalnum(current) || current == '_') {
|
1997-04-12 19:01:49 +04:00
|
|
|
if (i >= PRAGMASIZE) {
|
|
|
|
buff[PRAGMASIZE] = 0;
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("pragma too long", buff);
|
1997-04-12 19:01:49 +04:00
|
|
|
}
|
1997-04-07 18:48:53 +04:00
|
|
|
buff[i++] = current;
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
buff[i] = 0;
|
|
|
|
}
|
|
|
|
|
1997-04-12 19:01:49 +04:00
|
|
|
|
|
|
|
static void inclinenumber (void);
|
|
|
|
|
|
|
|
|
1997-06-11 22:56:02 +04:00
|
|
|
static void ifskip (void)
|
1997-04-12 19:01:49 +04:00
|
|
|
{
|
1997-06-11 22:56:02 +04:00
|
|
|
while (ifstate[iflevel].skip) {
|
1997-04-12 19:01:49 +04:00
|
|
|
if (current == '\n')
|
|
|
|
inclinenumber();
|
1997-06-16 20:50:22 +04:00
|
|
|
else if (current == EOZ)
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("input ends inside a $if", "");
|
1997-04-12 19:01:49 +04:00
|
|
|
else next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void inclinenumber (void)
|
1997-04-07 18:48:53 +04:00
|
|
|
{
|
1997-09-16 23:25:59 +04:00
|
|
|
static char *pragmas [] =
|
1997-06-11 22:56:02 +04:00
|
|
|
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
|
1997-04-12 19:01:49 +04:00
|
|
|
next(); /* skip '\n' */
|
1997-09-16 23:25:59 +04:00
|
|
|
++luaX_linenumber;
|
1997-04-07 18:48:53 +04:00
|
|
|
if (current == '$') { /* is a pragma? */
|
1997-04-12 19:01:49 +04:00
|
|
|
char buff[PRAGMASIZE+1];
|
|
|
|
int ifnot = 0;
|
1997-06-11 22:56:02 +04:00
|
|
|
int skip = ifstate[iflevel].skip;
|
1996-09-26 01:52:00 +04:00
|
|
|
next(); /* skip $ */
|
1997-04-07 18:48:53 +04:00
|
|
|
readname(buff);
|
1997-09-16 23:25:59 +04:00
|
|
|
switch (luaO_findstring(buff, pragmas)) {
|
1997-04-07 18:48:53 +04:00
|
|
|
case 0: /* debug */
|
1997-06-11 22:56:02 +04:00
|
|
|
if (!skip) lua_debug = 1;
|
1997-04-07 18:48:53 +04:00
|
|
|
break;
|
|
|
|
case 1: /* nodebug */
|
1997-06-11 22:56:02 +04:00
|
|
|
if (!skip) lua_debug = 0;
|
|
|
|
break;
|
|
|
|
case 2: /* endinput */
|
|
|
|
if (!skip) {
|
1997-06-16 20:50:22 +04:00
|
|
|
current = EOZ;
|
1997-06-11 22:56:02 +04:00
|
|
|
iflevel = 0; /* to allow $endinput inside a $if */
|
|
|
|
}
|
1997-04-07 18:48:53 +04:00
|
|
|
break;
|
1997-06-11 22:56:02 +04:00
|
|
|
case 3: /* end */
|
|
|
|
if (iflevel-- == 0)
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("unmatched $end", "$end");
|
1997-04-07 18:48:53 +04:00
|
|
|
break;
|
1997-06-11 22:56:02 +04:00
|
|
|
case 4: /* ifnot */
|
1997-04-12 19:01:49 +04:00
|
|
|
ifnot = 1;
|
1997-04-07 18:48:53 +04:00
|
|
|
/* go through */
|
1997-06-11 22:56:02 +04:00
|
|
|
case 5: /* if */
|
|
|
|
if (iflevel == MAX_IFS-1)
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("too many nested `$ifs'", "$if");
|
1997-04-07 18:48:53 +04:00
|
|
|
readname(buff);
|
1997-06-11 22:56:02 +04:00
|
|
|
iflevel++;
|
|
|
|
ifstate[iflevel].elsepart = 0;
|
|
|
|
ifstate[iflevel].condition = checkcond(buff) ? !ifnot : ifnot;
|
|
|
|
ifstate[iflevel].skip = skip || !ifstate[iflevel].condition;
|
1997-04-12 19:01:49 +04:00
|
|
|
break;
|
1997-06-11 22:56:02 +04:00
|
|
|
case 6: /* else */
|
|
|
|
if (ifstate[iflevel].elsepart)
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("unmatched $else", "$else");
|
1997-06-11 22:56:02 +04:00
|
|
|
ifstate[iflevel].elsepart = 1;
|
|
|
|
ifstate[iflevel].skip =
|
|
|
|
ifstate[iflevel-1].skip || ifstate[iflevel].condition;
|
1997-04-14 23:08:09 +04:00
|
|
|
break;
|
1997-04-12 19:01:49 +04:00
|
|
|
default:
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("invalid pragma", buff);
|
1996-09-26 01:52:00 +04:00
|
|
|
}
|
1997-04-12 19:01:49 +04:00
|
|
|
skipspace();
|
1997-06-11 22:56:02 +04:00
|
|
|
if (current == '\n') /* pragma must end with a '\n' ... */
|
1997-04-12 19:01:49 +04:00
|
|
|
inclinenumber();
|
1997-06-16 20:50:22 +04:00
|
|
|
else if (current != EOZ) /* or eof */
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_syntaxerror("invalid pragma format", buff);
|
1997-06-11 22:56:02 +04:00
|
|
|
ifskip();
|
1996-09-26 01:52:00 +04:00
|
|
|
}
|
|
|
|
}
|
1993-12-23 00:15:16 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** =======================================================
|
|
|
|
** LEXICAL ANALIZER
|
|
|
|
** =======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void save (int c)
|
|
|
|
{
|
|
|
|
if (textbuff.tokensize >= textbuff.buffsize)
|
|
|
|
textbuff.text = luaM_buffer(textbuff.buffsize *= 2);
|
|
|
|
textbuff.text[textbuff.tokensize++] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *luaX_lasttoken (void)
|
|
|
|
{
|
|
|
|
save(0);
|
|
|
|
return textbuff.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define save_and_next() (save(current), next())
|
|
|
|
|
|
|
|
|
|
|
|
static int read_long_string (void)
|
1995-07-06 21:47:08 +04:00
|
|
|
{
|
|
|
|
int cont = 0;
|
1997-09-16 23:25:59 +04:00
|
|
|
while (1) {
|
|
|
|
switch (current) {
|
1997-06-16 20:50:22 +04:00
|
|
|
case EOZ:
|
1996-05-30 18:04:07 +04:00
|
|
|
save(0);
|
1995-07-06 21:47:08 +04:00
|
|
|
return WRONGTOKEN;
|
|
|
|
case '[':
|
1996-05-30 18:04:07 +04:00
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
if (current == '[') {
|
1995-07-06 21:47:08 +04:00
|
|
|
cont++;
|
1996-05-30 18:04:07 +04:00
|
|
|
save_and_next();
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
continue;
|
1995-07-06 21:47:08 +04:00
|
|
|
case ']':
|
1996-05-30 18:04:07 +04:00
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
if (current == ']') {
|
1996-05-30 18:04:07 +04:00
|
|
|
if (cont == 0) goto endloop;
|
1995-07-06 21:47:08 +04:00
|
|
|
cont--;
|
1996-05-30 18:04:07 +04:00
|
|
|
save_and_next();
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
continue;
|
1995-09-16 00:48:26 +04:00
|
|
|
case '\n':
|
1997-04-12 19:01:49 +04:00
|
|
|
save('\n');
|
1997-04-07 18:48:53 +04:00
|
|
|
inclinenumber();
|
1996-09-26 01:52:00 +04:00
|
|
|
continue;
|
1995-07-06 21:47:08 +04:00
|
|
|
default:
|
1996-05-30 18:04:07 +04:00
|
|
|
save_and_next();
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
} endloop:
|
|
|
|
save_and_next(); /* pass the second ']' */
|
1997-09-16 23:25:59 +04:00
|
|
|
textbuff.text[textbuff.tokensize-2] = 0; /* erases ']]' */
|
|
|
|
luaY_lval.pTStr = luaS_new(textbuff.text+2);
|
|
|
|
textbuff.text[textbuff.tokensize-2] = ']'; /* restores ']]' */
|
1996-05-30 18:04:07 +04:00
|
|
|
return STRING;
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1995-12-21 19:14:04 +03:00
|
|
|
int luaY_lex (void)
|
1993-12-23 00:15:16 +03:00
|
|
|
{
|
1995-10-25 16:05:51 +03:00
|
|
|
static int linelasttoken = 0;
|
1996-05-30 18:04:07 +04:00
|
|
|
double a;
|
1997-09-16 23:25:59 +04:00
|
|
|
textbuff.tokensize = 0;
|
1995-10-25 16:05:51 +03:00
|
|
|
if (lua_debug)
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_codedebugline(linelasttoken);
|
|
|
|
linelasttoken = luaX_linenumber;
|
1997-07-01 23:32:41 +04:00
|
|
|
while (1) {
|
|
|
|
switch (current) {
|
1996-09-26 01:52:00 +04:00
|
|
|
case '\n':
|
1997-04-12 19:01:49 +04:00
|
|
|
inclinenumber();
|
1997-09-16 23:25:59 +04:00
|
|
|
linelasttoken = luaX_linenumber;
|
1993-12-23 00:15:16 +03:00
|
|
|
continue;
|
1993-12-23 00:39:15 +03:00
|
|
|
|
1996-09-26 01:52:00 +04:00
|
|
|
case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
|
|
|
|
next();
|
|
|
|
continue;
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '-':
|
|
|
|
save_and_next();
|
1996-03-14 18:17:28 +03:00
|
|
|
if (current != '-') return '-';
|
1997-06-16 20:50:22 +04:00
|
|
|
do { next(); } while (current != '\n' && current != EOZ);
|
1997-09-16 23:25:59 +04:00
|
|
|
textbuff.tokensize = 0;
|
1993-12-23 00:15:16 +03:00
|
|
|
continue;
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1995-07-06 21:47:08 +04:00
|
|
|
case '[':
|
|
|
|
save_and_next();
|
|
|
|
if (current != '[') return '[';
|
1997-09-16 23:25:59 +04:00
|
|
|
else {
|
1995-07-06 21:47:08 +04:00
|
|
|
save_and_next(); /* pass the second '[' */
|
1997-09-16 23:25:59 +04:00
|
|
|
return read_long_string();
|
1995-07-06 21:47:08 +04:00
|
|
|
}
|
|
|
|
|
1994-09-26 19:21:52 +03:00
|
|
|
case '=':
|
|
|
|
save_and_next();
|
|
|
|
if (current != '=') return '=';
|
|
|
|
else { save_and_next(); return EQ; }
|
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '<':
|
|
|
|
save_and_next();
|
|
|
|
if (current != '=') return '<';
|
|
|
|
else { save_and_next(); return LE; }
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '>':
|
|
|
|
save_and_next();
|
|
|
|
if (current != '=') return '>';
|
|
|
|
else { save_and_next(); return GE; }
|
1994-09-22 16:44:00 +04:00
|
|
|
|
1993-12-23 00:15:16 +03:00
|
|
|
case '~':
|
|
|
|
save_and_next();
|
|
|
|
if (current != '=') return '~';
|
|
|
|
else { save_and_next(); return NE; }
|
|
|
|
|
|
|
|
case '"':
|
1997-09-16 23:25:59 +04:00
|
|
|
case '\'': {
|
1993-12-23 00:15:16 +03:00
|
|
|
int del = current;
|
1996-05-30 18:04:07 +04:00
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
while (current != del) {
|
|
|
|
switch (current) {
|
1997-06-16 20:50:22 +04:00
|
|
|
case EOZ:
|
1994-09-22 16:44:00 +04:00
|
|
|
case '\n':
|
1996-05-30 18:04:07 +04:00
|
|
|
save(0);
|
1993-12-23 00:15:16 +03:00
|
|
|
return WRONGTOKEN;
|
|
|
|
case '\\':
|
|
|
|
next(); /* do not save the '\' */
|
1997-09-16 23:25:59 +04:00
|
|
|
switch (current) {
|
1993-12-23 00:15:16 +03:00
|
|
|
case 'n': save('\n'); next(); break;
|
|
|
|
case 't': save('\t'); next(); break;
|
|
|
|
case 'r': save('\r'); next(); break;
|
1997-04-12 19:01:49 +04:00
|
|
|
case '\n': save('\n'); inclinenumber(); break;
|
1996-09-26 01:52:00 +04:00
|
|
|
default : save_and_next(); break;
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
break;
|
1994-09-22 16:44:00 +04:00
|
|
|
default:
|
1993-12-23 00:15:16 +03:00
|
|
|
save_and_next();
|
|
|
|
}
|
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
next(); /* skip delimiter */
|
|
|
|
save(0);
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_lval.pTStr = luaS_new(textbuff.text+1);
|
|
|
|
textbuff.text[textbuff.tokensize-1] = del; /* restore delimiter */
|
1993-12-23 00:15:16 +03:00
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '.':
|
|
|
|
save_and_next();
|
1994-09-22 16:44:00 +04:00
|
|
|
if (current == '.')
|
|
|
|
{
|
|
|
|
save_and_next();
|
1996-05-29 01:07:32 +04:00
|
|
|
if (current == '.')
|
|
|
|
{
|
|
|
|
save_and_next();
|
|
|
|
return DOTS; /* ... */
|
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
else return CONC; /* .. */
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
1997-09-16 23:25:59 +04:00
|
|
|
else if (!isdigit(current)) return '.';
|
1993-12-23 00:15:16 +03:00
|
|
|
/* current is a digit: goes through to number */
|
1994-10-17 22:01:53 +03:00
|
|
|
a=0.0;
|
1993-12-23 00:15:16 +03:00
|
|
|
goto fraction;
|
|
|
|
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
1994-10-17 22:01:53 +03:00
|
|
|
a=0.0;
|
1996-05-30 18:04:07 +04:00
|
|
|
do {
|
|
|
|
a=10.0*a+(current-'0');
|
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
} while (isdigit(current));
|
1996-11-08 15:49:35 +03:00
|
|
|
if (current == '.') {
|
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
if (current == '.') {
|
|
|
|
save(0);
|
|
|
|
luaY_error(
|
1996-11-08 15:49:35 +03:00
|
|
|
"ambiguous syntax (decimal point x string concatenation)");
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
1996-11-08 15:49:35 +03:00
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
fraction:
|
1996-02-27 01:35:51 +03:00
|
|
|
{ double da=0.1;
|
1997-09-16 23:25:59 +04:00
|
|
|
while (isdigit(current))
|
1996-05-30 18:04:07 +04:00
|
|
|
{
|
|
|
|
a+=(current-'0')*da;
|
|
|
|
da/=10.0;
|
|
|
|
save_and_next();
|
|
|
|
}
|
1997-09-16 23:25:59 +04:00
|
|
|
if (toupper(current) == 'E') {
|
1994-10-17 22:01:53 +03:00
|
|
|
int e=0;
|
|
|
|
int neg;
|
1996-02-27 01:35:51 +03:00
|
|
|
double ea;
|
1994-10-17 22:01:53 +03:00
|
|
|
save_and_next();
|
|
|
|
neg=(current=='-');
|
|
|
|
if (current == '+' || current == '-') save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
if (!isdigit(current)) {
|
1996-11-22 16:08:02 +03:00
|
|
|
save(0); return WRONGTOKEN; }
|
1996-05-30 18:04:07 +04:00
|
|
|
do {
|
|
|
|
e=10.0*e+(current-'0');
|
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
} while (isdigit(current));
|
1996-05-30 18:04:07 +04:00
|
|
|
for (ea=neg?0.1:10.0; e>0; e>>=1)
|
1994-10-17 22:01:53 +03:00
|
|
|
{
|
|
|
|
if (e & 1) a*=ea;
|
|
|
|
ea*=ea;
|
|
|
|
}
|
|
|
|
}
|
1997-07-31 23:37:37 +04:00
|
|
|
luaY_lval.vReal = a;
|
1994-10-17 22:01:53 +03:00
|
|
|
return NUMBER;
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
1994-11-13 17:39:04 +03:00
|
|
|
|
1997-06-16 20:50:22 +04:00
|
|
|
case EOZ:
|
1997-04-02 01:23:20 +04:00
|
|
|
save(0);
|
1997-04-07 18:48:53 +04:00
|
|
|
if (iflevel > 0)
|
1997-09-16 23:25:59 +04:00
|
|
|
luaY_error("missing $endif");
|
1997-04-02 01:23:20 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
1997-09-16 23:25:59 +04:00
|
|
|
if (current != '_' && !isalpha(current)) {
|
1997-07-01 23:32:41 +04:00
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
return textbuff.text[0];
|
1997-07-01 23:32:41 +04:00
|
|
|
}
|
|
|
|
else { /* identifier or reserved word */
|
|
|
|
TaggedString *ts;
|
|
|
|
do {
|
|
|
|
save_and_next();
|
1997-09-16 23:25:59 +04:00
|
|
|
} while (isalnum(current) || current == '_');
|
1997-07-01 23:32:41 +04:00
|
|
|
save(0);
|
1997-09-16 23:25:59 +04:00
|
|
|
ts = luaS_new(textbuff.text);
|
1997-09-26 19:02:26 +04:00
|
|
|
if (ts->head.marked > 255)
|
|
|
|
return ts->head.marked; /* reserved word */
|
1997-07-01 23:32:41 +04:00
|
|
|
luaY_lval.pTStr = ts;
|
|
|
|
return NAME;
|
|
|
|
}
|
1993-12-23 00:15:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-05-30 18:04:07 +04:00
|
|
|
|