mathspp / building-a-python-compiler-and-interpreter Goto Github PK
View Code? Open in Web Editor NEWCode for the article series on building a Python compiler and interpreter
Home Page: https://mathspp.com/blog/tag:bpci
Code for the article series on building a Python compiler and interpreter
Home Page: https://mathspp.com/blog/tag:bpci
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...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.