Re: Isn't this wrong?
- Posted by DerekParnell (admin) Jul 25, 2010
- 1081 views
This runs fine using Eu 3.1:
atom retry
but fails using 4.0:
<0025>:: a name is expected here atom retry
The word retry is a reserved word in Eu 4. It can be used inside loops to repeat the current iteration.
Hmm. Ok, i rename it to retry2, and this runs fine on Eu v4a3 and v4b2:
atom retry2 retry2 = 0 with trace trace(1) while 1 do if retry2 then end if end while
Ok, that is interesting, what with that dangling "if" there, it runs with no errors using 3 Eu interpreters. Well, ok. So i add a few lines...
The 'dangling' if is not really dangling. The IF statement must end with the two words 'end' and 'if' and they do not have to be on the same line.
eg.
-- First statement if 1 then ? 1 end if -- Second statement if 1 then ? 1 end if
Both statements above are identical as far as Eu is concerned.
sequence TheWebPage TheWebPage = "" atom retry2 retry2 = 0 with trace trace(1) while 1 do if match(upper("<title>404 - Page Not Found</title>"),upper(TheWebPage)) then TheWebPage = "404" exit end if retry2 then end if end while
Eu v4a2 says:
Syntax error - expected to see =, +=, -=, *=, /= or &=\\ if retry2 then end\\ ^\\
implying i should start a expression of some sort between "then" and "end", starting with a boolean or math of some sort? Suddenly, the line that ran fine before needs an assigment in it?
Eu v4b2 says:
<0076>:: expected to see an assignment after 'retry2', such as =, +=, -=, *=, /= or &= if retry2 then end ^
but again, pointing to between "then" and "end". Even tho retry2 has been assigned. And why does an assignment after an "if" ? Plus, " if retry2 then end" ran with no errors before i added the code about TheWebPage.
Ok, the error pointer could be improved. Currently the scanner has gotten to the end of the word 'then' and the parser has by now realized that an assignment is required so the error message is correct "expecting to see an assignment" and the '^' pointer is showing you where the scanner is up to. It is sort of saying, "Hey I got 'then' but was expecting some sort of assignment there instead".
Now it was expecting an assignment because the previous IF statement actually uses the 'if' preceding the 'retry2' word as marking the end of the IF statement. Thus 'retry2' is the start of a new statement and the only type of statements that start with a variable are assignment statements.
It seems that you have mistakenly thought that the IF statement was completed by the 'end' word alone, but that is not the case. Look at it laid out differently ...
sequence TheWebPage TheWebPage = "" atom retry2 retry2 = 0 with trace trace(1) while 1 do if match(upper("<title>404 - Page Not Found</title>"),upper(TheWebPage)) then TheWebPage = "404" exit end if retry2 then end if end while
Now is the syntax error obvious?
...
it complained about the dangling "if"....
Just to restate, statements such as IF, WHILE, FOR etc are terminated by a two word combination, and those words do not have to be on the same line. The terminator is 'end' followed by 'if', while', 'for' etc that may or may not be on the same line.