Didn't you want to quote those statements of yours that I was replying
to? I cannot say I am suppressed, but it is not like you to be that
embarrassed by being that wrong. Editing without marking your edits is
disingenuous regardless of your reasons for doing it.
You know my highly skeptical attitude to the Books Of ECMA
wording and statements ("statements" in the common human
language use sense).
I know that you have difficulty understanding the spec, and would
rather construct an elaborate fiction of your own rather than
attempting to understand it.
Yet if we decided to quote the Books then let's us quote them
right. Chapter 12 Song 4
has nothing to do with the issue
because in
if (cond) a=1
a=1 is not an ExpressionStatement.
The - a=1 - in if (cond) a=1 - absolutely is an ExpressionStatement.
I am leaving on you the necessary
reductio ad absurdum steps with the starting rules:
1) "an ExpressionStatement cannot start with an opening curly
brace" (Books of ECMA, Chapter 12, Song 4)
Fine, - a=1 - does not start with either an opening curly brace or the
- function - keyword, so it is not precluded from being an
ExpressionStatement by that.
2) if (cond) {a=1} is a grammatically correct valid language
instruction
Yes, in that case the closing parenthesis after the - if - condition
expression is followed by a Block expression (ECMA 262 3rd Ed. Section
12.1). The StatmentList inside that Block statement is a single
ExpressionStatement consisting of - a=1- but that has no relevance for
an - if - statement that does not include any Block statements.
The relevant to the topic part would be Chapter 12, Song 5 ("The
if Statement") but it is so badly written that not really usable
in the practical sense yet still good for meditations
Section 12.5 is entirely understandable. The two productions for - if
- are:-
if ( Expression ) Statement else Statement
- and:-
if ( Expression ) Statement
- which means that the conditional expression can be anything that
qualifies as an Expression, but it must be parenthesised, and you can
substitute anything that qualifies as a Statement where the words
"Statement" appear. Which could be a Block statement, a
SwitchStatement or an ExpressionStatement, or any of the others
available in the language, including another IfStatement.
Here comes the 'made up off the top of your head' fiction.
is that if-else statement has implied {block}
part after each part of the statement.
Well, no.
And besides auto-insertion of
semicolons the tokenizer has other error-correction mechanics
in it,
There are no other error correcting mechanisms specified, and while
syntax extensions are possible they are not needed to explain anything
that is occurring here.
and among it - an auto block wrapping
"Auto block wrapping" being your fiction of the day.
for *simple* if-else cases.
Other words when meeting
"if (cond) a=1 LINE_TERMINATOR else a=0 LINE_TERMINATOR"
tokenizer brings it to the form
if (cond) {a=1;} else {a=0;}"
Then why is:-
if (cond) a=1 else a=0
-(without line terminators) - a syntax error when:-
if (cond) { a=1 } else { a=0}
- is not? If some sort of implied Block insertion was going on why
does it not happen in the first case. I suppose your next fabrication
would be the suggestion that this can only happen if the - if -
statement is spread across multiple lines, but going back to John G
Harris' original example, why is:-
if (a == 2)
switch (a) { case 2: b = 5; break; } ;
else
b = 6;
- a syntax error when:-
if (a == 2) {
switch (a) { case 2: b = 5; break; } ;
} else {
b = 6;
}
- is not?
This "auto block wrapping" does not appear to be doing a very good job
of explaining what is going on here. Unsurprising as you made it up on
the spot.
and this goes to the parser. You seem to relay on Firefox
back-to-source reverse tools such as toSource:
No, I just observed that they do show the automatically inserted
semicolons, which makes them useful if debating when and were
semicolons are automatically inserted.
which is a very dangerous thing as it is merely a debugging
tool left by Gecko developers - and it outputs what they
wanted for their internal code tracking needs.
That does not stop what it outputs from corresponding with the
specified behaviour.
Yet one may try this as it is pretty close to what the actual
bytecode does:
function demo() {
if (false) window.alert(arguments.callee.toSource()+'\n1');
else window.alert(arguments.callee.toSource()+'\n2');}
demo();
To what end? All that shows is that the complier is smart enough to
recognise that - if (false ) - is the condition there is no point in
having anything but the contents of the - else - branch and the other
code is unreachable. A reasonable optimisation.
I do understand the excitement of purists around if-else case
as it produces so much wanted "missing ; before statement" error
message to show to everyone.
You are becoming incoherent again.
As a side note I want to state that personally I
never rely on error correction mechanics and I always use explicit
block syntax even for single statement:
if (cond) {a=1;} else {a=0;}
and I strongly encourage anyone to do the same. Yet let do not
mix the actual look-ahead mechanics with badly written
descriptions of this mechanics and some misleading error messages.
All we have seen here is the application of the rules for automatic
semicolon insertion, as specified. Yet you have dreamt up "error
correction mechanics", " look-ahead mechanics" and "misleading error
messages" as part of your bullshit explanation.
Where the missing semicolon is the one that should terminate the
ExpressionStatement - IF ( true) -, which is a function call.
Where the missing semicolon is the one that should terminate the
ExpressionStatement - true -, which is worthless but legal.
etc. are still "missing ; before statement" but it proves nothing
(nor does it mean a lot)
It means that your code contains syntax errors, and probably points
you to where those errors are located.
As it was explained earlier it is not,
It is. That code fully stratifies the ECMA 262 rules. The ability to
load that code into any javascript environment without error or
complaint pretty much guarantees that it is free of syntax errors.
because there is not stay alone operator or expression "else",
only "else" as a part of if-else block.
You asserted that in:-
if (cond )
a=1
else
a=2
- the parser (though you actually incorrectly attributed the behaviour
to the tokenise (see the opening sentence of Section 7.9.1)) could not
add a semicolon after the - a=1 -. However, as I said, no only can a
semicolon be automatically added, but it must be automatically added.
That addition corrects the first Statement in;-
if ( Expression ) Statement else Statement
- so it really has nothing to do with - else - being part of the
structure that contains that Statement.
But the semicolon helps the tokenizer look-ahead mechanics to decrypt
the possible author's intentions
"Look-ahead mechanics", "decrypt", "possible author's intentions". I
would suggest that you couldn't make this stuff up, except that you
clearly have.
so it produces grammatically correct
if (cond) {a=1;} else {a=2;}
Why would it do that when:-
if (cond )
a=1;
else
a=2;
- is all that is necessary, and achievable only by the applying of the
automatic semi-colon insertion rules.
Sorry, but it is a complete nonsense.
How could you possibly tell?
Are you implying that any {prop:
f()} is interpreted as
label:
function call
No, I am saying that in isolation such a construct is interpreted in
exactly that way. You mentioned yourself earlier that an Expression
Statement cannot start with an opening curly brace. That is to prevent
object literals being ambiguous with Block statements, so in a context
where statements are expected (which will always be the case when the
construct is in isolation) the opening curly brace can only be
interpreted as starting a Block statement.
When you asserted that - {property: f()} - would be interpreted as an
object literal you provided no context that would force such an
interpretation, and the 'default' interpretation certainly is not as
an object literal.
and 99.99% of existing code is in rewrite emergency? You cannot
be serious.
I can be serious, but it tends to go right over your head when I am.
function f() {
return 'bar';}
window.alert({foo:f()}.foo); // 'bar'
The items in an ArgumentsList are AssignmentExpressions (and it makes
no sense to try to use a Statement as an argument anyway), so in that
context - {foo:f()} - has to be interpreted as an object literal. When
you were asserting that - {property: f()} - had to interpreted as an
object literal you provided no context, but instead asserted that the
alternative, Block containing label statement, was not "grammatical".
While in reality, without context, the interpretation is going to be
as a Block, and the contract is completely legal under that
interpretation.
Richard.