Quantcast
Channel: Java, Database, Web And Mobile Apps - cs2it
Viewing all articles
Browse latest Browse all 191

Simple parser-like program for math operations using syntax tree in Java

$
0
0

Requirements:

operators supported: ( ) * / + - ^
trigonometric functions: sine, cosine, tangent, cotangent, secant, cosecant
variables from set of a - z, A - Z, 0 - 9, and _ of arbitrary length


  1. must parse "code-like input" and create tokens from it
  2. must build a syntax tree using PEMDAS (http://www.purplemath.com/modules/orderops.htm) order of operations. Feel free to use code from http://castingrays.blogspot.com/2014/10/mathematical-expression-parsing-and.html for reference
  3. Ability to store variables, and variables must be usable in equations
  4. Numeric values supported is the set of ints and doubles
  5. Ability to support user-defined and evaluation of functionsExample: the user inputs “defn square(x) = x * x”square(5) returns 25
  6. Support for basic graphing: e.g. graph( 3 * X ^ 2 + 7) 
  7. Support for trigonometric functions (implemented in the code – do not reference trig functions of the standard library). e.g. sin(30) outputs 0.5
  8. Please include meaningful/informative comments


Additional examples:

takes in arithmetic expressions of arbitrary length in standard infix notation (e.g. 7 + 8 * 9) and returns the result (output in this example 79)
assignment to variables (e.g. b = 7 + 8 * 9 would assign the value of 79 to variable b)
evaluation with variables (e.g. c = 5 * b would assign 395 to c)
 order now


Viewing all articles
Browse latest Browse all 191

Trending Articles