Skip to content
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

Increment and decrement operators result in parse error #190

Closed
TwitchBronBron opened this issue Mar 9, 2019 · 0 comments · Fixed by #222
Closed

Increment and decrement operators result in parse error #190

TwitchBronBron opened this issue Mar 9, 2019 · 0 comments · Fixed by #222
Labels
bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior interpreter Affects this project's tree-walking interpreter lexer Affects this project's lexer (aka scanner) parser Affects this project's token parser

Comments

@TwitchBronBron
Copy link
Contributor

The increment and decrement operators do not seem to be supported, and result in a parse error.
image


sub Main()
    age = 1
    age++
    age--
    person = {
        age: 10
    }
    person.age++
    person.age--
end sub

Roku docs

@sjbarag sjbarag added bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior lexer Affects this project's lexer (aka scanner) parser Affects this project's token parser interpreter Affects this project's tree-walking interpreter labels Mar 9, 2019
sjbarag added a commit that referenced this issue Apr 29, 2019
It's finally here: support for `++` and `--`!

A few things to note for anyone reading this:

1. This is still mostly a nights-and-weekends project, in which I work
   on it when I have some free time.  I haven't had much lately, hence
   the delay in getting this out to the world.
2. This could have been implemented as syntactic sugar, in that a
   `foo++` statement is expanded to `foo = foo + 1`, and I in fact
   started that way!  Eventually I chose to make `++`/`--` top-level
   statements.  This allows for much more clear error messaging, and
   makes the parsing rules a bit more explicit as well.  It seems better
   for everyone this way :)
3. The Reference BrightScript Implementation only allows `++` and `--`
   to exist as a statement — *not* as an expression!  That means the
   following contrived uses are not syntactically valid:

```brightscript
sub countToFive()
    i = 0
    while i++ < 5
'         ~~~
'         ++ can't be used as part of the binary expression `A < B`
        print i
    end while

    print "Stopped at " i++
'                       ~~~
'                       print statements accept a list of expressions,
'                       not statements
end sub
```

Compare this to JavaScript, Java, C, etc., in which the `++` and `--`
operators can be used basically anywhere an expression is used, e.g.:

```javascript
function countToFive() {
    let i = 0;
    while (i++ < 5) {
        console.log(i);
    }

    console.log(`Stopped at ${i++}`);
}
```

fixes #190
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior interpreter Affects this project's tree-walking interpreter lexer Affects this project's lexer (aka scanner) parser Affects this project's token parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants