Skip to content

gequitz/LispExpressionEvaluator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

LispExpressionEvaluator

PJ2 Lisp Expression Evaluator /************************************************************************************ *

  •  	CSC220 Programming Project#2
    
  • Specification:
  • Taken from Project 7, Chapter 5, Page 178
  • I have modified specification and requirements of this project
  • Ref: http://www.gigamonkeys.com/book/ (see chap. 10)
  •  http://joeganley.com/code/jslisp.html   (GUI)
    
  • In the language Lisp, each of the four basic arithmetic operators appears
  • before an arbitrary number of operands, which are separated by spaces.
  • The resulting expression is enclosed in parentheses. The operators behave
  • as follows:
  • (+ a b c ...) returns the sum of all the operands, and (+) returns 0.
  • (- a b c ...) returns a - b - c - ..., and (- a) returns -a.
  • (* a b c ...) returns the product of all the operands, and (*) returns 1.
  • (/ a b c ...) returns a / b / c / ..., and (/ a) returns 1/a.
  • Note: + * may have zero operand
  •   - / must have at least one operand
    
  • You can form larger arithmetic expressions by combining these basic
  • expressions using a fully parenthesized prefix notation.
  • For example, the following is a valid Lisp expression:
  • (+ (- 6) (* 2 3 4) (/ (+ 3) (* 1) (- 2 3 1)) (+))
  • This expression is evaluated successively as follows:
  • (+ (- 6) (* 2 3 4) (/ 3 1 -2) (+))
  • (+ -6 24 -1.5 0.0)
  • 16.5
  • Requirements:
    • Implement the given MyStack class
    • Design and implement an algorithm that uses MyStack class to evaluate a
  • valid Lisp expression composed of the four basic operators and integer values.
    • Valid tokens in an expression are '(',')','+','-','*','/',and positive integers (>=0)
    • Display result as floting point number with at 2 decimal places
    • Negative number is not a valid "input" operand, e.g. (+ -2 3)
  • However, you may create a negative number using parentheses, e.g. (+ (-2)3)
    • There may be any number of blank spaces, >= 0, in between tokens
  • Thus, the following expressions are valid:
  •  (+   (-6)3)
    
  •  (/(+20 30))
    
    • Must use MyStack class in this project. (*** DO NOT USE Java API Stack class ***)
    • Must throw LispExpressionException to indicate errors in LispExpressionEvaluator class
    • Must not add new or modify existing data fields
    • Must implement methods in MyStack class.
    • Must implement these methods in LispExpressionEvaluator class:
  •  public LispExpressionEvaluator()
    
  •  public LispExpressionEvaluator(String inputExpression) 
    
  •  public void reset(String inputExpression) 
    
  •  public double evaluate()
    
  •  private void evaluateCurrentOperation()
    
    • You may add new private methods

*************************************************************************************/

About

Java PJ2 Lisp Expression Evaluator CSC220

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors