Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ evaler Public

Implements a simple floating point arithmetic expression evaluator in Go (golang).

License

Notifications You must be signed in to change notification settings

soniah/evaler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

evaler

Package evaler implements a simple fp arithmetic expression evaluator.

Evaler uses Dijkstra's Shunting Yard algorithm [1] to convert an infix expression to postfix/RPN format [2], then evaluates the RPN expression. The implementation is adapted from a Java implementation at [3].

This is release 1.0.

Usage

result, err := evaler.Eval("1+2")

Operators

The operators supported are:

+ - * / ** () < >

< (less than) and > (greater than) will get lowest precedence, all other precedence is as expected (BODMAS [4]).

< and > tests will evaluate to 0.0 for false and 1.0 for true, allowing expressions like:

3 * (1 < 2) # returns 3.0
3 * (1 > 2) # returns 0.0

Author

Sonia Hamilton

http://www.snowfrog.net

[email protected]

Links

[1] http://en.wikipedia.org/wiki/Shunting-yard_algorithm

[2] http://en.wikipedia.org/wiki/Reverse_Polish_notation

[3] http://willcode4beer.com/design.jsp?set=evalInfix

[4] http://www.mathsisfun.com/operation-order-bodmas.html

About

Implements a simple floating point arithmetic expression evaluator in Go (golang).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages