lua-users home
lua-l archive

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


Peter Hill:

> As far as homogenising changes go, I'd move all atomic items (not just
> "function") out of "exp" and into "prefixexp" where they belong.

Björn De Meyer:
> Interesting. Could you or anyone else modify the existing parser to accept
> your definition of the syntax, so we could test the effects?

Eero Pajarre:
> I did a quick test, and the change seems trivial.
>
> Modified Lua seems to be able to run in my application, and now
> print(3(3)) is an "attempt to call a number value" error instead of syntax
> error.
>
> Saying this does not mean that I like or recommend this change ;-)

I'm writing a Lua parser in Visual Basic so I'll try tinkering with the
syntax in that first, and report back any suggestions / problems.

Some syntax possibilities (generally of a homogenising nature) that I intend
to try are:

(a) ["x"] = 123
Assigns to the global x, or in general to a global whose index is specified
by an expression.

(b) f x
Apply function "f" to value "x". Note that no "( )" is needed. Currently
functions can be applied to a variety of "atomic" elements... (exp),
{table}, "string". There seems to be no reason not to extend that to the
remaining atomics... 123, function() ... end, nil, true, false.

(c) = a,b,c
Variable assignment assigns N values to N variables. Current syntax has N>=1
but there is no reason why N couldn't be 0. Not very useful, I admit, but
probably valid (and an alternate to the procedure call syntax).

(d) a,b,... = 1,2,3,4,5
Allowing "arg" for normal assignment as well as parameter passing. So "arg"
becomes {3,4,5,n=3}.

(e) Hmm. It seems that, in principle, an assignment like:
    a,b,c,d,... = 1,2
should have "arg" become {n=-2}. Ie, we were two return values short. Ditto
for parameter passing (though I would have expected an error!).

(f) The comma "," operator becomes simply a binary operator of lower
precedence than "+".

(g) "and" and "or" will return all return-values, not just one. So:
    return t[i] and (i,t[i]) or nil
will work.

(h) Completed statements stop parsing at a newline. "return" and "break"
will no longer need to be terminal.


As an aside, if one allows "t[exp]" then we have the interesting question of
how we should interpret:
    t["a","b","c"] = 5

Should it be:
    t["a"] = 5
or
    t["a"],t["b"],t["c] = 5,5,5


*cheers*
Peter Hill.