Skip to content
/ simL Public

A tiny Rust REPL that parses and evaluates arithmetic expressions.

Notifications You must be signed in to change notification settings

naamanu/simL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpL (sim-l)

A tiny Rust REPL that parses and evaluates arithmetic expressions.

Features

  • Supports +, -, *, / with standard precedence
  • Parentheses for grouping
  • Floating-point numbers
  • Simple interactive REPL

Getting started

Build and run:

cargo run

You should see a prompt like:

========== SimpL: Simple expression evaluator ===========
Enter arithmetic expressions like: 2 + 3 * 4
Type 'quit' or 'q' to exit

>>

Example

>> (2 + 3) * 4
 Parsed: ((2 + 3) * 4)
 = 20

More examples are in examples/ with sample inputs and expected outputs.

Notes

  • Whitespace is optional around operators.
  • Unary minus (e.g. -3) is not supported yet; use 0 - 3 instead.
  • Division by zero returns an error.

Project layout

  • src/main.rs - REPL loop and I/O
  • src/parser.rs - tokenizer and recursive-descent parser
  • src/expr.rs - expression tree and evaluator

About

A tiny Rust REPL that parses and evaluates arithmetic expressions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages