Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15613
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Semicolons and the do..while statement |
| Date | 2012-08-29 20:02 -0500 |
| Organization | albasani.net |
| Message-ID | <k1me8n$7dr$1@news.albasani.net> (permalink) |
| References | <88f8c6ba-bc50-4695-b442-10f1dc377363@o8g2000yqm.googlegroups.com> <k1lopg$qsm$1@news.albasani.net> <4191624.W6QT1uhmCP@PointedEars.de> |
On 8/29/2012 3:20 PM, Thomas 'PointedEars' Lahn wrote:
> BGB wrote:
>
>> On 8/29/2012 1:56 AM, RobG wrote:
>>> The syntax for the do..while statement (ECMA-262 12.6.1[1]) is:
>>>
>>> do /Statement/ while ( /Expression/ );
>>>
>>> Noting the trailing semicolon, I expected the following to throw an
>>> error:
>>>
>>> do {} while (false) var x = 3;
>>>
>>> since there is no semicolon to separate the two statements. However,
>>> I've tested a number of browsers and no error is thrown. So either the
>>> browsers I tested are all tolerant of the error (possible in one or
>>> two but unlikely in half a dozen) or automatic semicolon insertion is
>>> at work.
>>
>> maybe?... (speculation here, based partly on my own implementation).
>
> Did you mean _interpretation_? If not, your implementation is borken.
>
this particular implementation is in the gray area between being "not
exactly conformant" and "an entirely different language" (it is used
mostly for application-level scripting, currently within a 3D game engine).
>> because some implementations don't actually "insert" semicolons, rather
>> they "eat" them (check for semicolon, and if-seen, it is discarded).
>> (this would be because it is faster and easier to treat the semicolon as
>> a break and then eat it, than it is to figure out how to write logic to
>> accurately figure out where to insert them, the "semicolon insertion"
>> may then be generally interpreted as "if we may see a semicolon here,
>> and see a newline or similar instead, interpret it as if it were a
>> semicolon").
>>
>> but, upon trying to eat the semicolon, there is none there for it to
>> eat, so it continues on as normal (and since the do/while statement is
>> otherwise self-terminating, it does not lead to an ambiguity).
>
> I realize that you said "maybe?" and "speculation", but still…
>
> Utter nonsense.
>
actually, the implementation in question does actually work this way.
it seemed at least possible that other implementations could have worked
in a similar way.
> What actually happens is very simple:
>
> ,-[ECMA-262, 5.1 Edition]
> |
> | 7.9 Automatic Semicolon Insertion
> |
> | Certain ECMAScript statements (empty statement, variable statement,
> | expression statement, do-while statement, continue statement, break
> | statement, return statement, and throw statement) must be terminated with
> | semicolons. Such semicolons may always appear explicitly in the source
> ^^^ ^^^^^^^^^^^^^^^^^
> | text. For convenience, however, such semicolons may be omitted from the
> ^^^^^^^^^^^^^^
> | source text in certain situations. These situations are described by
> | saying that semicolons are automatically inserted into the source code
> ^^^^^^^^^^^^^^^^^^^^^^^^^^ (MUST)
> | token stream in those situations.
> ^^^^^^^^^^^^^^^^^^^
>
in this case, it only behaves as if this were happening, but the actual
logic is instead based on noticing certain patterns, and eating the tokens.
the reason was partly because this could be done directly within the
parser logic, without needing to actually "insert" anything (there is no
separate lexer or parser stages either, FWIW, just a single-pass
recursive descent parser).
<snip rest>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Semicolons and the do..while statement BGB <cr88192@hotmail.com> - 2012-08-29 13:55 -0500
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-29 22:20 +0200
Re: Semicolons and the do..while statement BGB <cr88192@hotmail.com> - 2012-08-29 20:02 -0500
Re: Semicolons and the do..while statement RobG <rgqld@iinet.net.au> - 2012-08-29 18:27 -0700
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-30 12:37 +0200
Re: Semicolons and the do..while statement John G Harris <john@nospam.demon.co.uk> - 2012-08-30 14:24 +0100
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-30 15:59 +0200
Re: Semicolons and the do..while statement John G Harris <john@nospam.demon.co.uk> - 2012-08-30 16:26 +0100
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-30 17:47 +0200
Re: Semicolons and the do..while statement John G Harris <john@nospam.demon.co.uk> - 2012-09-01 11:40 +0100
Re: Semicolons and the do..while statement Dr J R Stockton <reply1235@merlyn.demon.co.uk.invalid> - 2012-09-02 19:54 +0100
Re: Semicolons and the do..while statement BGB <cr88192@hotmail.com> - 2012-08-30 11:17 -0500
Re: Semicolons and the do..while statement Gene Wirchenko <genew@ocis.net> - 2012-08-30 10:25 -0700
Re: Semicolons and the do..while statement Dr J R Stockton <reply1235@merlyn.demon.co.uk.invalid> - 2012-08-31 23:20 +0100
Re: Semicolons and the do..while statement Gene Wirchenko <genew@ocis.net> - 2012-08-31 16:03 -0700
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-29 22:30 +0200
csiph-web