lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


-----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