README
...tumbleweed...
runs on python
python plox/plox.py
Lox from Crafting Interpreters but in Python
README
...tumbleweed...
runs on python
python plox/plox.py
on commit bf4507b
trying the command in the readme is erroring
% python --version
Python 3.11.3
% python plox/plox.py
Traceback (most recent call last):
File "/home/janus/flipstone/craftinginterpreters-plox/plox/plox.py", line 3, in <module>
from scanner import Scanner, Token, TokenType
File "/home/janus/flipstone/craftinginterpreters-plox/plox/scanner.py", line 12, in <module>
@unique
^^^^^^
File "/home/janus/.pyenv/versions/3.11.3/lib/python3.11/enum.py", line 1561, in unique
raise ValueError('duplicate values found in %r: %s' %
ValueError: duplicate values found in <enum 'TokenType'>: NUMBER -> STRING, EOF -> STRING
Changing Enum to StrEnum seems to work.
% python plox/plox.py ../crafting-interpreters/closure-bind.lox
readin ../crafting-interpreters/closure-bind.lox
global
block
% cat ../crafting-interpreters/closure-bind.lox
var a = "global";
{
fun showA() {
print a;
}
showA();
var a = "block";
showA();
}
The error from resolving and binding seems to be present. You probably know, but now you know i know :P
applying the StrEnum fix i proposed in #1 , nested ternaries are not working:
% rlwrap python plox/plox.py
1?2?3:4:5
TOKENS
[ '1' `1.0`]
[ '?' `None`]
[ '2' `2.0`]
[ '?' `None`]
[ '3' `3.0`]
[ ':' `None`]
[ '4' `4.0`]
[ ':' `None`]
[ '5' `5.0`]
[ '' `None`]
STATEMENTS
Error at line 1 at end. expected a ';' after expressionStmt. where is my ; !?
none stmt
INTERPRETATION
skip none stmt `None`
1?2:3?4:5
TOKENS
[ '1' `1.0`]
[ '?' `None`]
[ '2' `2.0`]
[ ':' `None`]
[ '3' `3.0`]
[ '?' `None`]
[ '4' `4.0`]
[ ':' `None`]
[ '5' `5.0`]
[ '' `None`]
STATEMENTS
Error at line 1 at end. expected a ';' after expressionStmt. where is my ; !?
none stmt
INTERPRETATION
skip none stmt `None`
According to the book, zero should not be truthy, but when I do (0?1:2)==(1?1:2);
I get False, implying that zero is special.
The book:
Lox follows Ruby’s simple rule: false and nil are falsey, and everything else is truthy. We implement that like so:
private boolean isTruthy(Object object) {
if (object == null) return false;
if (object instanceof Boolean) return (boolean)object;
return true;
}
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.