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

Add global scope assignments #18

Merged
merged 8 commits into from
Jan 15, 2018
Merged

Conversation

sjbarag
Copy link
Owner

@sjbarag sjbarag commented Jan 15, 2018

This PR allows users of BRS to create globally-scoped variables, assign values to them, and reference their stored values in other expressions and statements. It makes brs significantly more useful, because it can remember things!

Global variables currently take a copy-value approach, e.g.:

a = 10
b = a
a = 1000

print a     ' 1000
print b     ' 10
print a = b ' false

This will likely need to change once we implement associative arrays in BRS, but IIRC "copy-value" is correct for primitive values.

Since assignments in BrightScript take the place of declarations in most
other languages, they need to be lower precedence (i.e. appear in the
top-down grammar before statements).

Since this grammar isn't being validated or used anywhere this is quite
likely wrong and quite likely a moot effort, but I'm sticking with it
for now gosh darnit!
This includes assignment *and* retrieval from global scope!  BRS is now
stateful.
Global variables currently take a copy-value approach, e.g.:

```brightscript
a = 10
b = a
a = "foo"

print a     ' "foo"
print b     ' 10
print a = b ' false
```

This will likely need to change once we implement associative arrays in
BRS, but IIRC "copy-value" is correct for primitive values.
This language isn't very useful if you only get a REPL!
Rather than infinitely reporting an error at the same location (not very
helpful), we should move on to the next statement boundary (only a
':' or newline so far) and continue parsing.
@sjbarag sjbarag added enhancement Any addition to this project's existing capabilities parser Affects this project's token parser interpreter Affects this project's tree-walking interpreter labels Jan 15, 2018
@sjbarag sjbarag merged commit 6cd68e7 into master Jan 15, 2018
@sjbarag sjbarag deleted the add-global-scope-assignments branch January 15, 2018 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any addition to this project's existing capabilities interpreter Affects this project's tree-walking interpreter parser Affects this project's token parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant