. LISP, or LISt Processing, is a recursive based programming language, used in artificial intelligence processing, and involves the use of lists to process data. Every list is contained within...

1 answer below »
. LISP, or LISt Processing, is a recursive based programming language, used in artificial intelligence processing, and involves the use of lists to process data. Every list is contained within parentheses. For example, (ADD 5 8) is simply 5 + 8, or 13. Write a program that evaluates mathematical LISP expressions. Input from the keyboard an expression involving ADD, SUB, MUL, and DIV, each of which are contained in a list. Each operation will begin with a three-letter abbreviation, followed by a single space, followed by the operands involved, also with single space separation. ADD and MUL may have 2 or more operands, while DIV and SUB will only have 2. Each individual list will have no more than one imbedded list as an operand, and only at the end of that list, but each expression may have multiple imbedded lists, as seen in the sample runs below. Assume proper formation when entered from the keyboard. Output the result of the mathematical expression. For C++ use the string class. Use a stack data structure. Refer to the sample output below. Sample Runs (2): Enter the LISP expression: (SUB 6 3) The result is: 3 Enter the LISP expression: (ADD 4 6 (MUL 4 5 (DIV 8 4))) The result is: 50
Answered 4 days AfterMar 09, 2021

Answer To: . LISP, or LISt Processing, is a recursive based programming language, used in artificial...

Bhagyesh answered on Mar 14 2021
130 Votes
#include
#include
#include
#include
#include
int performInnerOperation(std::stack& operands, const std::string& operatr) {
    int ans = 0;
    if (operatr == "ADD") {
        while (!operands.empty()) {
            ans += operands.top();
            operands.pop();
        }
    }
    else if (operatr == "SUB") {
        ans = operands.top();
        operands.pop();
        while (!operands.empty()) {
            ans -= operands.top();
            operands.pop();
        }
    }
    else if (operatr == "MUL") {
        ans = 1;
        while (!operands.empty()) {
            ans *= operands.top();
            operands.pop();
        }
        return...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here