lua-users home
lua-l archive

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



On 30/09/2006, at 4:48 AM, David Jones wrote:

Actually I think NG was suggesting an approach where the parser, having eaten an 'x' say, changes the lexer state so that the next '+' is tokenised as part of a number, not as the token '+'.

To demonstrate my point, I have modified the Lua 5.1.1 source to do exactly that. It seems to work, but I haven't extensively tested it. The change is a 54-line diff, which I am not sure is appropriate to post here, but will if requested.

Example output:

Lua 5.1.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> = 2+2
4
> = 2+-2
0
> = 2++2
4
> t = { +2, -3, -4, 5*-6++7 }
> table.foreach (t, print)
1       2
2       -3
3       -4
4       -23
> print (-3, +2)
-3      2


You can see that it still handles things like 2+2, however it also handles 2++2 where the +2 is a single token now. You can also use +2 in table constructors, etc.


- Nick