-
Notifications
You must be signed in to change notification settings - Fork 13
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
New Mindcode syntax #148
Comments
I planned to make semicolons compulsory to make the grammar more rigid in the hope it will improve error messages. However, the true nature of wrong error messages turned out to be something different (see #156). According to some of my experiments it doesn't seem that optional semicolons make the error messages less focused. Nevertheless, I'm still going to make semicolons compulsory to remove harmful ambiguities in the syntax:
Another issue is this loop:
can be (and was) parsed identically to
That was unexpected, to say the least. 😳 Making semicolons compulsory, as well as the |
Suggestion: After mandatory |
You're right about Edit: unfortunately, removing the I plan to rewrite the grammar from scratch, which might help avoid some pitfalls in the current grammar, especially as I'd love to remove all the ambiguities from the grammar. Maybe I'll be able to avoid the |
For the next release, I plan to push the syntax towards compulsory semicolons and do/then keywords in some way. There's a problem with existing code not compiling under the new syntax. Let's consider this code as an example:
When compiled using the new syntax, it produces the following list of errors (note the error reporting got way better thanks to fixing #156):
The missing semicolons are reported at the beginning of the next statement. That's unfortunate and the third error report looks very strange - there's no To make the transition easier, I can support two versions of the syntax for a while, which I'm calling
The errors are reported at the same positions, but the error messages aren't very descriptive. I could intercept them and reword them into some other message - maybe "Cannot parse source file, check for missing ';' or keyword in the previous expression", but I'm not sure it is optimal. I was, however, able to add explicit handling for missing semicolons, which produces the following output:
It has two problems, though: firstly, it makes parsing slower. It appears we'll just get to the times that were usual prior to the #156 fix, so maybe it wouldn't be a problem. Secondly, the missing semicolon will be reported absolutely everywhere where adding a semicolon would allow the parser to resolve the last token encountered:
Despite the disadvantages, I'd probably go with the last solution, as it seems to help most in making the necessary changes to existing Mindcode - it is now possible to integrate the compiler output with an IDE and obtain clickable links from the error output. In the future, support for the relaxed syntax will be certainly removed and I'll see whether keeping the special semicolon handling would still be worth the downsides. I'd love to hear what y'all think. |
This makes Mindcode more like Pascal, which I think is funny :)
Will it be mandatory to declare functions before the main code block?
It looks a little weird, but not terrible. Anyway, the error report is much better now.
This is amazing! To think that a project with one error message for all situations has grown so much now. This is very inspiring, especially remembering your words 9 months ago: "These syntax error messages are not very intuitive, but I have no idea how to improve them". |
Pascal was one of the first programming languages I learned, so perhaps I'm unconsciously pushing Mindcode in that direction... Seriously, though, Mindcode now really needs one-liner if statements. Currently we have
and that sucks, because the I'm considering two (well, three) possibilities:
Function declarations will be still allowed in any order, before or after the main block (or both).
That's still true, except that I stumbled upon a strange construct in the grammar definition and simplifying it fixed the issue. Relatively small changes to the grammar definition can alter error resolution in ways I don't understand. I plan to rewrite the grammar from the start, which should bring new insights, but I need to prepare some test suite before that to see that I'm not breaking the error reporting on the go. By the way, the web app will have clickable error messages too, which should help a lot. |
A little reminder of how this is implemented in Pascal. Here is an example of one-line if-else expressions:
Since there is no
This is what it looks like if there is more than one operation to perform:
What can be seen here? The operations are inside
The single line expression is not as pretty as in Pascal, but the multiline one looks a little better to me.
Adding a ternary operator would definitely be a nice addition
|
That's right about Pascal. As far as I recall, I used to format the source code like this:
I do like the current Mindcode version better - it eliminates typing quite a few
Mindcode already has the ternary operator and both of your examples compile. You don't even need the parentheses around the condition. They work just like What I propose is supporting the ternary operator without the false branch (well, it wouldn't be ternary anymore), e.g.
to use as a conditional one-liner. Rewriting a snippet of my code using this I get:
I don't like it much. What about
It feels confusing and quirky. Sometimes I wish we had C/C#/Java code blocks - Looks like the current syntax for conditions may be better than any of the alternatives. |
I've updated the main comment to reflect features that were already implemented, plus advances in planning the new syntax. |
Some of the planned changes have already been implemented as of release 2.4.0:
/* this is a block comment that can span several lines */
///
) for generating remarks.param
keyword. Global variables are no longer suitable for program parametrization.getBlock(x, y, , floor)
- the third parameter is optional and the argument may be omitted. Output-only parameters are optional.void
keyword.@coal
) will always be specified including the@
sign, e.g.vault1.@coal
. The non-prefixed variant will be deprecated (see Kebab-case identifiers and the@
sign in mlog identifiers #160).Currently, there are two version of the syntax: strict and relaxed. The relaxed syntax is mostly compatible with Mindcode version 2.2.0 and earlier. Furthermore, there's a lot of deprecated language features. These deprecations, as well as the differences between the strict and relaxed syntax are described here.
The deprecated features and the relaxed version of the syntax will be eventually removed, probably no sooner than January 2025.
The Strict/Relaxed syntax modes will be probably supported even in the future to make adapting to the changes in the syntax easier, and/or to support a lighter variant of the syntax more suited for short, simple scripts.
Additional planned changes
getlink(n).enabled = false
.++
,--
) will be supported in both prefix and postfix forms.var
-->:var
Strict syntax
$
prefix in external variable names will not be supported.begin ... end;
).wave1
), will be allowed for regular variables, as they'll be mangled to:wave1
, not colliding with block names.Relaxed syntax
$
prefix. Additionally, it will be possible to declare external variables without the prefix.Example of the planned syntax
An example of a code rewritten to the strict variant of the new syntax:
The text was updated successfully, but these errors were encountered: