GithubHelp home page GithubHelp logo

hbobenicio / lox Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 221 KB

jlox compiler written as an exercise from the totally awesome Crafting Interpreters book

Java 7.30% C 54.90% C++ 34.20% Haskell 1.54% CMake 2.07%

lox's People

Contributors

hbobenicio avatar

Watchers

James Cloos avatar  avatar  avatar

lox's Issues

Embed scanner inside the parser

It doesn't make sense to care about scanner if you just need to use a parser. API would improve if scanner were inside the parser.

Expr refactoring

  • Move files to the ast dir. Refactor include directives
  • Prefix symbols with clox_ast_
  • Separate expr visitor free into its own module
  • Separate expr visitor eval into its own module

Fix memory leak with string concatenation

Whenever a new string value is evaluated by the interpreter, a new string is allocated. So, when setting a new value, the now useless old string must be deallocated.

In the end, after the eval method finish, the caller or the callee (interpreter) must deallocate the resulting string too.

Improve error handling for expressions evaluation

  • Refactor the clox_ast_expr_visitor and all its implementations to return an int
  • Expose and Chain expr evaluation errors in the expr_eval_visitor implementation for the interpreter
  • Implement the synchronize function to handle error recovery in the declarations parsing level (see chapter 8)

Fix scanner line couting

=== Clox REPL - Press CTRL+C or CTRL+D to exit ===
> "a' 
error: unterminated string. expecting token '"'
error: line 2: expecting a primary expression (a literal or an opening parentesis '('), got 'TOKEN_KIND_EOF'
error: parsing failed.

Improve data structures lifecycles

Make the lifecycle of these data independent somehow:

  • Input source file (program) contents
  • Scanner (and its tokens dynamic array)
  • Parser
  • AST
  • Interpreter

It's better to allocate than to depend on old data structures which are not necessarily anymore.

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.