Skip to content

raysuliteanu/rust-lox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implementing Lox in Rust

Based on Crafting Interpreters.

Implement a recursive-descent parser for the made up "Lox" language (made up for the book).

Current Status

Can parse the expression grammar specified below:

expression grammar standalone


expression     → equality ;
equality       → comparison ( ( "!=" | "==" ) comparison )*;
comparison     → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term           → factor ( ( "-" | "+" ) factor )* ;
factor         → unary ( ( "/" | "*" ) unary )* ;
unary          → ( "!" | "-" ) unary
               | primary ;
primary        → NUMBER | STRING | "true" | "false" | "nil"
               | "(" expression ")" ;

Notes on the implementation

Miette

I use the miette crate for pretty-printing errors, since it has specific support for fancy output for text parsing e.g.

  ╭─[3:2]
 2 │ \notok
 3 │ "also not ok
   ·  ▲
   ·  ╰── here
   ╰────

Strum

I use the strum crate for making it easier to display enums. This is partly due to the funky requirements of CodeCrafters but also the book, since CC is just enforcing the book's output.

Thiserror, log and env-logger

I use the thiserror crate combined with the log and env-logger crates for nice log messages rather than dbg! or e/println!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages