Git Product home page Git Product logo

building-a-python-compiler-and-interpreter's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

building-a-python-compiler-and-interpreter's Issues

scope not working 'correctly'

I get the following error when I run 'python -m pytcomp.interpreter "a = b + 3":

(pytcomp) PS E:\Projects\pytcomp> python -m pytcomp.interpreter "a = b + 3"
bc: Bytecode(BytecodeType.LOAD, 'b')
bc.value: b
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "E:\Projects\pytcomp\src\pytcomp\interpreter.py", line 105, in
Interpreter(bytecode).interpret()
File "E:\Projects\pytcomp\src\pytcomp\interpreter.py", line 50, in interpret
interpret_method(bc)
File "E:\Projects\pytcomp\src\pytcomp\interpreter.py", line 88, in interpret_load
self.stack.push(self.scope[bc.value])
~~~~~~~~~~^^^^^^^^^^
KeyError: 'b'

I have looked through the code for 0.6.0, 0.7.0, 0.8.0, and 0.9.0 and have not found anywhere that 'b' (or anything) is added to scope.
HELP! :)
This error occurs when I run your code as well:

(pytcomp) PS E:\Projects\pytcomp\0.6.0\src> python -m python.interpreter "a = b + 3"
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "E:\Projects\pytcomp\0.6.0\src\python\interpreter.py", line 101, in
Interpreter(bytecode).interpret()
File "E:\Projects\pytcomp\0.6.0\src\python\interpreter.py", line 48, in interpret
interpret_method(bc)
File "E:\Projects\pytcomp\0.6.0\src\python\interpreter.py", line 84, in interpret_load
self.stack.push(self.scope[bc.value])
~~~~~~~~~~^^^^^^^^^^
KeyError: 'b'

I am running python 3.12.1 on Windows 11 in a virtual environment.

I am really enjoying this series; brings back pleasant memories of a compiler construction class from grad school a gazillion years ago...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.