[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: boolean operators
- From: Nick Gammon <nick@...>
- Date: Fri, 29 Sep 2006 12:46:51 +1000
On 29/09/2006, at 10:40 AM, Luiz Henrique de Figueiredo wrote:
Unfortunately, the lexer can't do that because x+10 would be two
tokens,
x and +10, not three, x + 10.
The lexer can be told whether or not to consider a sign as a separate
token, I have written ones that do that.
For example, after getting a symbol (x in your example), it is not
syntactically correct for it to be followed by a number (eg. x 5) so
the next "+" must be an operator token, not the start of a number.
However after getting an operator (eg. x + ) then the next token must
*not* be another operator, so it can consider another + as part of a
number. Thus you can correctly parse: x++5.
Right now Lua does not correctly parse: 7--5 (should be 12)
It works if you write 7- -5, which suggests that whitespace is more
important than you might expect.
With my suggestion it could, and also then: x++10
I haven't looked at the lexer in detail, but I suspect that if you
altered the handling of the '-' case to look forwards to a digit (in
the correct context), then a number (like -5) can be parsed as a
single "number" token, rather than a sign and a separate number.
- Nick
- References:
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, Rici Lake
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, Rici Lake
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, David Jones
- Re: boolean operators, Nick Gammon
- Re: boolean operators, David Given
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, Rici Lake
- Re: boolean operators, Luiz Henrique de Figueiredo