Skip to content

jfalameda/rust-math-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple interpreter written in rust

A parser implemented using top-down operator precedence parsing.

How it works:

  1. The input is sent to the lexer for lexical analysis
  2. The returned tokens are then passed to the parser. The parser creates an AST tree that can be evaluated.

How to use it

# cargo run program.rmp

Syntax example

// Asign result to variable a
let main_expr  = (2-3)*4+3^5+4+(-3+4^4)+5+6+2-1;
let sin_result = sin(10/5+(main_expr+2));
let cos_result = cos(30);

let value = to_number(readln("Insert value: "));

// Print variable a
println("Result main: ", main_expr);

// Concatenation using + symbol
println("Result sin(x): " + sin_result);

println(str_concat("This ", "is ", "an ", "example"));

TODO

  • Write tests
  • Implement mechanism on the interpreter to check for mandatory function arguments
  • Exponential binary operations should be right-hand associative
  • Check for undefined variables
  • Add line number to errors
  • Improve syntax errors
  • Use peekabe iterable https://doc.rust-lang.org/stable/std/iter/struct.Peekable.html

About

A simple interpreter written in rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages