|
On 2012-09-17 10:26 AM, "Robert Virding" <robert.virding@erlang-solutions.com> wrote:
>
> My guess is that the lexer works left-to-right with out backtracking, which is the most common and efficient way.
>
> It sees '6' and starts scanning a number,
> it sees '4' and continues scanning the number,
> it sees '.' and is still happy scanning the number,
> and then it sees another '.' which it does not recognise as in a number.
>
> When it gets this far it can't go back and try something different so it generates an error. Having a backtracking scanner would be much slower, and lead to even more strange cases.
>
> Robert
>
> ----- Original Message -----
> > From: "Egor Skriptunoff" <egor.skriptunoff@gmail.com>
> > To: "Lua mailing list" <lua-l@lists.lua.org>
> > Sent: Monday, 17 September, 2012 3:32:51 PM
> > Subject: Probably bug in implementation of numerical constant parsing
> >
> > This string causes "malformed number" error:
> > print(64..'KB')
> > It seems that lexer does not know that two dots are never contained
> > in
> > numerical constant.
> > IMHO, correct parsing of numerical constant should stop before
> > concatenation operator.
> >
> >
>
The parser does do some lookahead though doesn't it? I seen to recall looking at the code and seeing such a trick when parsing for comments. It could do the same for numbers; if this is a dot, then check the next to see whether it's a concat or a decimal.