-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unterminated ifs and loops execute instead of throwing syntax error #2327
Comments
I've been reading some of the code in sys/Interpreter.cpp, and I suspect some of the error-checking lines aren't actually being hit. For example, this line Line 2407 in f0ee4fa
is guarded by Line 2385 in f0ee4fa
If the for i from 11 to 10
writeInfoLine: 1 to make sure the guard is passed, the Similarly, writing a i = 2
while i < 2
writeInfoLine: 1 seems to hit Line 2645 in f0ee4fa
Umatched 'while' error.
|
I've spent some time looking over how loops are interpreted this afternoon. The general
There is, of course, some loop-depth checking and other error checking (e.g., text after Regardless, the final syntax check for the loop only appears to occur at 2.2.2., after the entire loop has been run and terminated. Ideally, the syntax would be checked at 1. and then would not need to be checked again. I don't see a simple change to suggest to have the syntax check occur earlier; any substantive change would require a change in the parsing strategy. Some thoughts on how the syntax check could be implemented:
As an alternative in strategy 2, the lines could be collected as part of the scan to find |
This is all intentional, and meanwhile many scripts will rely on it, e.g. by freely writing text after We would still break the following trick, for which I don't know how often people use it (can you guess what it outputs?):
We have been thinking about a stricter language, without variable substitution, for some time, the major goal being optimization (by compiling all lines before running the first) rather than syntax checking, but syntax checking would automatically come with it. |
Yes, it is. There are manifold ways a change could be accomplished. The line collection was intended to be as small a modification to the current code as possible since the backward progression is already part of the loop. I personally think it would be preferable to not have to collect the lines, but I am not a dev for this project, so my opinion only matters so much.
It produces the function of a I can only speak for myself (and slightly for some other users I know), but I would have expected that block of code to error out, rather than be an intended programming trick. I also can't think of any programming language I know or have used or studied where such block mixing is possible (even though that lack of imagination is evidence of nothing much but my own lack of exposure). I recognize, ultimately, that there is no "good" solution to constraints of keeping old scripts runnable while also changing the execution model. I have witnessed too much of the Python 2 to 3 debacle for too long to think that would be easy. I will say, though, that I am hesitant to write non-trivial Praat scripts knowing that the syntax of control structures is not rigorously checked. |
The example above cannot indeed be seriously recommended. The only common use of variable substitution in control structures is "computed
This works in Praat, and is used in jump tables, as when you're using the Demo window to create a PowerPoint-like presentation (with Praat capabilities, such as on-the-fly simulations). This run-time computation of where to jump should be kept alive. For
but also
and
or would that be clearer if written as?:
|
I feel a bit more live-and-let-live about For the conditional There is also possibly an option similar to a common shortcut that is written in Julia, where short-circuiting in Boolean evaluation is taken advantage of to write |
Yes, I had written |
When using control structures like
if
andfor
, the scripting language parser is not checking for a terminating symbol for the structure before executing the code.For example, all of the following scripts run without raising a syntax error:
The loops will run the interior code block once. Other programming languages I work with (like Julia, R, and Bash) would raise a syntax error here for not terminating the code block appropriately with equivalents of
endif
,endfor
,endwhile
, oruntil
.This feels like a bug in how the language grammar is parsed, but I'm not sure if this was perhaps intended for some reason. If this was intended in the parser, I would put forth as a feature request that these unterminated control structures throw syntax errors instead of executing.
The text was updated successfully, but these errors were encountered: