(all) Add support for postfix increment and decrement #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is not ready yet, will complete another day.Reasonably complete now.Things currently missing:
Support for decrement also, not just increment
Ensure that we put this at a reasonable level of precedence. (The way I did it now was just a slightly lame approximation)
Maybe we can live with this as it is now after all. Right now I put it between "assignment" and "logical or". I would love to detect invalid usages such as
foo(c++)
which I consider very bad practice, but we can perhaps live without that at this stage. Note: even though these are postfix operators at the moment, they work like prefix operators do in other languages. I.e.var c = 0; some_function(c++);
will use1
as the value of the the parameter passed to the function.I tried to document this now in the syntax grammar, which is btw again heavily inspired by the Lox specification: (docs) Add syntax-grammar.md document #18.
Properly handle cases when the user tries to do things like
var a = "foo"; a++;
and similar folly. This is clearly an area where a static type checker would make things immensely much better; then interpreter/compiler in the future will then have to take much less precautions in ensuring that things are of the expected types all the time.