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

05 Interpreting #10

Merged
merged 4 commits into from
Apr 15, 2022
Merged

05 Interpreting #10

merged 4 commits into from
Apr 15, 2022

Conversation

ngjunsiang
Copy link
Contributor

Let's start changing state by interpreting the code.

@ngjunsiang
Copy link
Contributor Author

Executing statements

Let's execute statements as well, starting with the OUTPUT statement we implemented in the previous notebook.

For now, we only have OUTPUT statements to execute. When we have more kinds of statements, they too will go into the if-else cascade.

[102ed45]

@ngjunsiang
Copy link
Contributor Author

Interpreting

Our interpreter runs the following in a loop:
https://github.com/nyjc-computing/pseudo/blob/9dc3aa28dbfd607def076b19591878d0392045bb/interpreter.py#L22-L28

It takes the list of statements from the parser, and execute()s them to bring about their effects.

We catch any errors that occur, and raise our own custom RuntimeError instead.

@ngjunsiang
Copy link
Contributor Author

Main loop

The main program loop :

  1. passes src to the scanner and gets tokens,
  2. passes tokens to the parser and gets statements,
  3. passes statements to the interpreter,
  4. exits.

[acc19e7]

@ngjunsiang
Copy link
Contributor Author

@ngjunsiang
Copy link
Contributor Author

Testing

if __name__ == "__main__":
    main()

Result:

Hello, everyone!

[39779f8]

@ngjunsiang ngjunsiang merged commit d920ca7 into main Apr 15, 2022
@ngjunsiang ngjunsiang deleted the interpreter branch April 15, 2022 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant