Saturday, August 15, 2015

parsing an arithmetic expression using the shunting-yard algorithm and drawing with javafx


this time I am demonstrating the use of the shunting-yard algorithm for parsing an arithmetic expression. the parser is written in groovy. you can use the following functions :


  • cos
  • sin 
  • tan
  • log
  • log10
  • sqrt
  • abs
  • pow
  • max
  • min 


and the following  operators :

  • +
  • -
  • *
  • /
  • ^ (power not xor).

the parser is from me but for the graphical part, i found an intersting post on stackoverflow :

http://stackoverflow.com/questions/24005247/draw-cartesian-plane-graphi-with-canvas-in-javafx

so i use the awsome piece of code given by jewelsea : http://stackoverflow.com/users/1155209/jewelsea

the code is very concise and easy to ready you extend or fix it with no pain. perhaps it is a foundation for a new open source project what do you think?

any way here is some snapshots :







i also user the library exp4j http://www.objecthunter.net/exp4j/ to test my code.

as usual you can find the code source at github : https://github.com/mooninvader/FunctionPlotter



1 comment: