Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15615

Re: Semicolons and the do..while statement

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <9690906.pQKyqEuMBg@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Thu, 30 Aug 2012 12:37:51 +0200
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Semicolons and the do..while statement
Newsgroups comp.lang.javascript
References <88f8c6ba-bc50-4695-b442-10f1dc377363@o8g2000yqm.googlegroups.com> <k1lopg$qsm$1@news.albasani.net> <4191624.W6QT1uhmCP@PointedEars.de> <c9183673-3b9b-4c95-adbc-7b8d63da571a@k9g2000pbr.googlegroups.com>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 119
NNTP-Posting-Date 30 Aug 2012 12:37:52 CEST
NNTP-Posting-Host cc8eefe8.newsspool3.arcor-online.net
X-Trace DXC=Q4ZZXMW1jj;^8FBo0_81f>McF=Q^Z^V384Fo<]lROoR18kF<OcfhCO;N7R:9EjSaT?DZm8W4\YJN<b@mF9jNikd5a_\Tedi=oJ98bnkb4WQ?Z;
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:15615

Followups directed to: comp.lang.javascript

Show key headers only | View raw


RobG wrote:

> Thomas 'PointedEars' Lahn wrote:
> 
> [breakdown of ASI]

That appears to be correct.

>> IOW,
>>
>> do {} while (false) var x = 3;
>>
>> *is* equivalent to
>>
>> do {} while (false); var x = 3;
>>
>> because `var' delimits a /VariableStatement/ and the parser is allowed,
>> in order to produce
>>
>> /Program/
>> → /SourceElements_opt/
>> → /SourceElements/     /SourceElement/
>> → /SourceElement/      /SourceElement/
>> → /Statement/          /Statement/
>> → /IterationStatement/ /VariableStatement/
>> → do /Statement/ while ( /Expression/ ); /VariableStatement/
>> → do /Block/ while ( /Expression/ );     /VariableStatement/
>> → …
>> → do {} while ( true );                  var x = 3;
>>
>> to insert the semicolon before the /VariableStatement/.

To be precise, after the closing parenthesis of a supposed do-while 
statement.  Function serialization, although implementation-dependent, can 
show this:

$ js
Rhino 1.7 release 2 2010 02 06
js> (function () { do {} while (true) var x = 3; }).toString()

function () {
    do {
    } while (true);
    var x = 3;
}

>> It's not a bug,>it's a feature, and a standards-compliant feature at
>> that.
> 
> I suppose I'm still missing something because my understanding of this
> explanation is that a semicolon should be inserted for
> 
>      /VariableStatement/ /VariableStatement/
> 
> as it's one of the "certain statements", but it isn't. If the newline
> is removed from the variable statement example above:
> 
>     var x = 3 var y = 4
> 
> then a syntax error is thrown.

ACK:

js> (function () { var x = 3 var y = 4; }).toString()
js: "<stdin>", line 3: missing ; before statement
js: (function () { var x = 3 var y = 4; }).toString()
js: ............................^

> I can't see how the second "var" can be interpreted as anything other than
> the start of a variable statement, and therefore that a semicolon can (or
> should) be inserted before it (per your logic above).

Good "question".  I do not have a good answer to it yet.  However:
 
> The only explanation I can think of is that the "v" at the start of
> the second "var" is interpreted as the start of an identifier, so
> either a semicolon, comma[1] or newline (which would force semicolon
> insertion) is required. Because of the ambiguity, an error results, so
> the whole "var" token is not read and the second variable statement
> isn't identified.

I think we can exclude that possibility.  `var' is a /ReservedWord/, in 
particular a /Keyword/, so explicitly _not_ an /Identifier/:

| 7.6.1 Reserved Words
| 
| A reserved word is an IdentifierName that cannot be used as an Identifier.
| 
| Syntax
| 
| ReservedWord ::
|   Keyword
|   FutureReservedWord
|   NullLiteral
|   BooleanLiteral
| 
| 7.6.1.1 Keywords
| 
| The following tokens are ECMAScript keywords and may not be used as
| Identifiers in ECMAScript programs.
| 
| Syntax
| 
| Keyword :: one of
|   break     do        instanceof  typeof
|   case      else      new         var
|   catch     finally   return      void
|   continue  for       switch      while
|   debugger  function  this        with
|   default   if        throw       delete
|   in        try


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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