Prepare a lisp program to evaluate the arithmetic


You need to prepare a Lisp program to evaluate the arithmetic expressions.

Write a Lisp program to evaluate Lisp arithmetic expressions. Assume four operators may be used in expressions and they are +, -, *, and /. All these operators are binary, i.e., they are applied in an expression in this format: (operator operand1 operand2), where "operator" can be +, -, *, or /, and each operand can be either a single number, or another expression.

For case, the subsequent are all legal input:

(+ 1 2)

(- 6 (/ 7 0.5))

(* (/ 78 (- 67 3.5)) (+ 4 9.0))

But the following are not:

(+ 1) ; missing operand

(6 - 7) ; every expression must start with an operator

(/ + 4 5) ; every expression can only have one operator

(* 6 7 8) ; every expression must have exactly two operands

(% 6 7 ) ; unrecognizable operator

(- 6 A) ; illegal operator

Name the main function of your program "main". The given should be the way to run your program:

? (main '(+ 1 2))

3

where '(+ 1 2) is the input. If the input is legal, your program should output the final result of the expression evaluation, as given in the above case. If the input is illegal, the result is undefined, i.e., your program assumes the input is legal.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Prepare a lisp program to evaluate the arithmetic
Reference No:- TGS0960599

Expected delivery within 24 Hours