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


Groups > comp.lang.javascript > #26340

Re: Optional semicolons - wrong rule or wrong example?

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: Optional semicolons - wrong rule or wrong example?
Date 2014-12-16 23:21 +0100
Organization solani.org
Message-ID <m6qb8p$2bg$1@solani.org> (permalink)
References <4ca7db7d-5a3b-457d-8601-aa9c72afab36@googlegroups.com>

Show all headers | View raw


Peter wrote:

> In the 6th edition of "JavaScript: The Definitive Guide", in chapter
> 2.5 (Optional Semicolons), the following rule can be found:
> 
> "JavaScript treats a line break as a semicolon if the next nonspace
> character cannot be interpreted as a continuation of the current
> statement".
> 
> and the following example is given:
> 
> var a a = 3 console.log(a)
> 
> According to the author, the above shall be treated as:
> 
> var a; a = 3; console.log(a);
> 
> He justifies it as follows:
> 
> "JavaScript does treat the first line break as a semicolon because it
> cannot parse the code var a a without a semicolon.">

The ECMAScript specification, edition 5.1, explains the rule more
clearly[1]:

| When, as the program is parsed from left to right, a token (called
| the offending token) is encountered that is not allowed by any
| production of the grammar, then a semicolon is automatically inserted
| before the offending token if one or more of the following conditions
| is true:
| * The offending token is separated from the previous token by at
| least one LineTerminator.
| * The offending token is }.

Obviously, it is important to clearly distinguish between *tokens* and
*characters* for this rule.

<http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1>

-- 
Christoph M. Becker

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


Thread

Optional semicolons - wrong rule or wrong example? Peter <pilarp@poczta.onet.pl> - 2014-12-16 13:58 -0800
  Re: Optional semicolons - wrong rule or wrong example? "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-16 23:21 +0100
  Re: Optional semicolons - wrong rule or wrong example? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-17 00:10 +0100
    JavaScript: The Definitive Guide (was: Optional semicolons - wrong rule or wrong example?) "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-17 01:29 +0100
      Re: JavaScript: The Definitive Guide Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-20 23:00 +0100
        Re: JavaScript: The Definitive Guide Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-20 23:04 +0100
        Re: JavaScript: The Definitive Guide "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-28 23:52 +0100
          Re: JavaScript: The Definitive Guide Tim Streater <timstreater@greenbee.net> - 2014-12-28 23:52 +0000
            Re: JavaScript: The Definitive Guide Scott Sauyet <scott.sauyet@gmail.com> - 2015-01-01 21:46 -0800
              Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-02 09:32 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-03 07:54 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-02 22:14 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-03 11:46 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-03 11:59 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-03 23:46 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-03 14:57 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-04 09:31 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-04 00:29 +0100
                Re: JavaScript: The Definitive Guide Andrew Poulos <ap_prog@hotmail.com> - 2015-01-04 20:17 +1100
                Re: JavaScript: The Definitive Guide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-01-04 10:57 +0100
                OT: Mass, weight and friction (was: JavaScript: The Definitive Guide) "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-03 02:52 +0100
  Re: Optional semicolons - wrong rule or wrong example? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2014-12-18 14:39 +0100
    Re: Optional semicolons - wrong rule or wrong example? Tim Streater <timstreater@greenbee.net> - 2014-12-18 14:04 +0000

csiph-web