Question: In the programming language Lisp, each of four basic arithmetic operators appears before an arbitrary numbers of operands, which are separated by spaces. The resulting

In the programming language Lisp, each of four basic arithmetic operators appears before an arbitrary numbers 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 operands, and (+) returns 0.(- a b c ) returns a b c , and (-a) returns -a. The minus operator must have at least one operand. (* a b c ) returns the product of all operands, and (*) returns 1.(/ a b c ) returns a / b / c -, and (/ a) returns 1/a. The divide operator 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)(*234)(/(+3)(*)(-231))) This expression is evaluated successively as follows: (+(-6)(*234)(/31-2))(+-624-1.5)16.5 Now, your task is to do the following: 1. Design and implement an algorithm that uses a stack to evaluate a legal Lisp expression composed of the four basic operators and integer values.2. Write a Java program that reads Lisp expression and evaluate it.3. Test your program on a set of valid and invalid Lisp expression.4. Repeat the above tasks to allow operands to be either integer values or variables names that strings of letters. Design and implement an algorithm that uses stack to test whether an expression is legal in the Lisp. Each expression that your program reads can be split across several lines which is the style used by typical Lisp programmers. For example, the following expression is legal in Lisp: (+(- height)(*334)(/3 width length)(* radius radius))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!