Compute the value of an expression in parentheses

Assignment Help Computer Engineering
Reference no: EM132213276

Question :

Write a recursive MARS program that can compute the value of an expression in parentheses.

The program should accept an input string, sequentially examine each character, invoke the procedure calc_expr every time it sees a new open parenthesis, return from that procedure when the parenthesis is closed, and print the answer when the outermost parenthesis is closed.

We will only test with valid inputs including decimal integers, spaces, and +, -, *, / operators.

The program runs until the user enters a string starting with "e". Within parentheses, the expression is evaluated from left to right, i.e., (6/2+7/5) does 6/2 (which is 3), 3+7 (which is 10), 10/5 (which is 2). Here's an example run of the program:

Enter the expression you want evaluated:

((4+3)-((27/9)*2))

The answer is: 1

Enter the expression you want evaluated:

(1*(2 * (3 * (4 * 5))))

The answer is: 120

Enter the expression you want evaluated:
exit

Reference no: EM132213276

Questions Cloud

Simulate a simple four function calculator without a memory : Write a Ruby Script that simulates a simple four function calculator without a memory.
Write a regular expression to pass to grep to determine : Write a regular expression to pass to grep to determine if a Chicago area (773 or 312) phone number, in the form (312) 281-3303, is present in a given file.
Write a research about the importance of servers rooms : Write a research about the importance of servers rooms or (network devices rooms) in any organization or institutions.
Write a recursive method search stack which returns true : Write a recursive method search Stack(LinkedStack S, E x) which returns true if the stack S contains the element x, otherwise it returns false.
Compute the value of an expression in parentheses : Write a recursive MARS program that can compute the value of an expression in parentheses.
Calculate the 2s complement of a number : Write and run the following simple ARM assembly language programs using ARMSIM. Debug each program and view the content of different registers.
Which of the given is a taxable activity : Which of the following is a taxable activity? (a) Renting out a small commercial building in Napier for $52,000 per annum.
Write a recursive function that takes an array of characters : Write a recursive function that takes an array of characters as input and prints it content to the standard
Write and test a prolog predicate abc which succeeds : Write, run, and test a Prolog predicate abc(L) which succeeds if list L somewhere contains an a, followed directly by a b, followed directly by a c;

Reviews

Write a Review

Computer Engineering Questions & Answers

  Modify the inventory program by adding a button to the gui

modify the inventory program by adding a button to the gui that allows the user to move to the first item the previous

  Examine the available data and present it in a set

Your job is to examine the available data and present it in a set ofinformative graphs and text.

  Provide again a polynomial time algorithm

Suppose we are given a directed graph G = (V, E), a set of nodes A V (denoted as people) and a set of nodes B V (denoted as exit).

  Mobile and satellite communication systems

BE302 - Prepare a table showing how to add In-phase and Quadrature components for each state - Calculate how many bits per each state

  Why problem of learning tbn structure is considerably easier

Explain, using the argument of asymptotic complexity, why the problem of learning the 2-TBN structure is considerably easier if we assume that there are no intr

  List all crimes that do not have a hearing date scheduled

List all crimes that don't have a hearing date scheduled. List the crime ID, criminal ID, date charged, and hearing date.

  Write loop that prints elements that are in both set s and t

How can you correctly implement the test of Self Check 12? Write a loop that prints all elements that are in both Set s and Set t.

  The aim of performing an audiometry test at matlab

Write a program with the aim of performing an audiometry test at MATLAB. The program should be as interactive as possible.

  State the strengths and weaknesses of each tool

Risk management software is a critical application that businesses use to gain insight on how risk drivers can impact a project and business.

  Write a program to read the scores recieved

A programmming contest was organised between two universities, Elm and Oak. There were n participants from Elma and m participants from Oak.

  Provide one field and method that compellingly differentiate

Provide at least one field and one method that compellingly differentiates each class from the others.

  What are ldaps major strengths and weaknesses

What are its major strengths and weaknesses? Consider a company like PPI, which has several offices, subsidiaries, and vendors around the world.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd