Skip to content

A simple Rust parser to parse mathematical expressions (e.g "1+(3*6)+20-4") and evaluate them.

Notifications You must be signed in to change notification settings

farhat-nawaz/expression_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Expression Parser

This is a simple implementation of a parser that takes a string and computes its numerical value using the given rules. Operators are applied in order of precedence from left to right. An exception to this is brackets which are used to explicitly denote precedence by grouping parts of an expression that should be evaluated first.

Rules:

Instead of using mathematical operators directly, following alphabatical mapping can also be used:

  • a => +
  • b => -
  • c => *
  • d => /
  • e => (
  • f => )

Usage

let input = "3c4d2aee2a4c41fc4f";
let expression = Expression::parse(input).unwrap();

let result = expression.evaluate().unwrap();

Running Tests

Tests can be run using the following command:

$ cargo t

About

A simple Rust parser to parse mathematical expressions (e.g "1+(3*6)+20-4") and evaluate them.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages