Code Monkey home page Code Monkey logo

craftinginterpreters-plox's Introduction

README

...tumbleweed...

runs on python

python plox/plox.py

craftinginterpreters-plox's People

Watchers

b s avatar

craftinginterpreters-plox's Issues

`@unique` errors

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.

closure scoping bug present

 % 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

nested ternary doesn't work

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`

0 is not truthy, but should be

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;
  }

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.