[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (beta-rc1) GOTO
- From: "Michael Rose" <michael.h.rose@...>
- Date: Thu, 16 Jun 2011 10:10:21 +0200 (CEST)
-----Ursprüngliche Nachricht-----
Von: "Pierre-Yves Gérardy" <pygy79@gmail.com>
Gesendet: 15.06.2011 20:04:12
An: "Lua mailing list" <lua-l@lists.lua.org>
Betreff: Re: [ANN] Lua 5.2.0 (beta-rc1) GOTO
>On Wed, Jun 15, 2011 at 17:32, Michael Rose <michael.h.rose@web.de> wrote:
>...
>
>How do you discriminate between a label or a goto before reaching
>either the column or the right angled bracket?
>
>Not that it matters much, but it increments the cyclomatic complexity
>of the "@" clause.
I don't think so. But because sometimes code might be more comprehensive then
describing it in discussion I attached the relevant part of 'llex.c' to the bottom of
this e-mail, showing the scanning of the '@' syntax by the lexer.
>
>> @123.name> or
>> @123$name!> or even
>> @12-34-5123>
>
>I understand the purpose of a terminator, but none of your examples
>are valid goto labels. I assume that the first two would jump to
>"name", but what about the third one?
We have to distinguish the current Lua beta and my suggestion.
In my '@' extension, such labels are perfectly legitim. They need not be
of identifier form to allow compiler generated labels being safely different
from user generated ones.
>
>Also, these examples create more convoluted clauses for the parser,
>and duplicated code unless you use a goto. Here's the simplfied code
>flow:
>
> name ? ( ":" ? label : goto )
> number ? ( "." ? label with info : line number )
>
>@!name,info> is clean and would allow the "@" section of the parser to
>have only one conditional level. More straightforward, easier to read
>and understand, and thus to maintain.
>
> name ? label (with or without debug info)
> number ? line number
> "!" ? goto
>
>-- Pierre-Yves
>
Just have a look in given code snipped. It is short and there is no issue
with maintainance. It covers scanning of labels, gotos, line number annotations
and statement block delimiters.
Regards,
Michael Rose
Extract from modified 'llex.c':
====================
static int llex (LexState *ls, SemInfo *seminfo) {
luaZ_resetbuffer(ls->buff);
for (;;) {
switch (ls->current) {
...
...
case '@': {
save_and_next(ls);
switch (ls->current) {
case '@': next(ls); return '@';
case '[': next(ls); return TK_STATBEG;
case '|': next(ls); return TK_STATEXP;
case ']': next(ls); return TK_STATEND;
}
if (lisdigit(ls->current)) {
/* This could be a line number annotation: */
do save_and_next(ls); while (lisdigit(ls->current));
if (lisspace(ls->current) || ls->current == EOZ) {
save(ls, '\0');
if (!luaO_str2d(luaZ_buffer(ls->buff) + 1, &seminfo->r) ||
seminfo->r >= (lua_Number)(MAX_INT))
luaX_syntaxerror(ls, "line number annotation too high");
lua_number2int(ls->linenumber, seminfo->r);
luaZ_resetbuffer(ls->buff);
ls->linenumber -= currIsNewline(ls);
break;
}
}
for (;;) {
int cur = ls->current;
if (cur == ':' || cur == '>' || cur == '@') {
save_and_next(ls);
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff)+1,
luaZ_bufflen(ls->buff)-2);
switch (cur) {
case ':': return TK_LABEL;
case '>': return TK_GOTO;
default: return TK_NAME;
}
}
if (!lisprint(ls->current) || lisspace(ls->current))
lexerror(ls, "illegal character in '@' statement", 0);
save_and_next(ls);
}
break;
}
...
...
}
}
...
...
___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar