-
Notifications
You must be signed in to change notification settings - Fork 0
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
06c Retrieving variables #13
Conversation
get() takes in a frame and a name. It returns the value mapped to name in the frame.
Get expressionsWe need a new kind of Handcrafting a get exprSo far we have been treating A
That's promising; |
Parsing namesWe add a new parser for |
DECLARE and Assign statements call identifier() instead of value() to get a name.
Our declare and assignment statements also need updating so they get a |
Get parsing precedenceWhere should we slot this We are likely to be writing code like This is tricky: our scanner just recognises words, and doesn't know what Also we need to wrap our |
Frame insertionFor now we will insert the |
Don't forget to update the |
BugIt's not working:
Suspect the line in With a breakpoint there:
|
FixAdd Result:
Instead of printing out only the value of |
Result:
Now our program can declare variables, assign values to variables, and subsequently retrieve (evaluate) them. |
RefactorWe have an And we have an We don't need both: [58e5ded] |
Testing
Let's see how our program handles variables being used in place of values:
https://github.com/nyjc-computing/pseudo/blob/ecc694bbfabc210fd9c85bb336278320f9061780/main.py#L10-L14
Result:
This is because
evaluate()
handlesname
tokens by returning theirword
value:https://github.com/nyjc-computing/pseudo/blob/ecc694bbfabc210fd9c85bb336278320f9061780/interpreter.py#L5-L9