Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write in a C program Problem: Write a program that behaves in the manner describe in the usage message listed below, either printing the
Please write in a C program Problem: Write a program that behaves in the manner describe in the "usage" message listed below, either printing the usage message when the first command-line argument is "--help", or upon identifying the "-rpn" command- line argument accepting input from stdin. You must write appropriate error messages to stderr if an error arises, whether an unrecognized command-line argument, a stack underflow or overflow, unrecognized input or any other error condition that may arise in your code. Output: Your program's normal output must be to stdout and of one of the formats following, assuming argc and argv are the usual parameters for main() and where is argv[0]. If argv[1] is "--help", display the following. Usage: " --help" display this usage material. " -postfix" The program accepts input from standard input as a sequence of numbers and operators. The numbers (operands, as integers or floating point numbers) read are pushed on a stack until needed. When an operator is read, the required operands are popped from the stack and used to perform the calculation, with the result placed on the stack. Valid operators are +, -, * and ), are interpreted as addition, subtraction, multiplication and division, respectively, as described below. An additional operator is =, which indicates that the value at the top of the stack is popped from the stack and displayed along with the number of values remaining on the stack, whereupon the program terminates. Stack underflows generate an error message and halt the program, as do a stack overflows. Unrecognized input tokens produce error messages and result in program termination, as do unrecognized command line arguments. The size of the stack is 10. Stack operations are performed so as to produce results identically as indicated here. +: push(pop() + pop(); - : temp = pop(); push(pop() - temp; *: push(pop() * pop(); /: temp = pop(); push(pop() / temp; swap : t1 = pop(); t2 = pop(); push(t1); push(t2); copy : temp = pop(); push(temp); push(temp); = : pop stack top and display it as the result with the number of stack elements remaining. The above describes the majority of the behavior of the program you are to write. To reiterate and expand important points: If the first command-line argument is "--help", subsequent command-line arguments are ignored, the usage message is displayed and the program terminates. If the first command-line argument is -postfix, subsequent command line arguments are ignored and the program proceeds with reading from standard input. Invalid/unrecognized command-line arguments produce a suitable error message, display the usage information above, and terminate the program. If an unrecognized token is read from standard input, a suitable error message for the type of error is to be displayed with the usage text and the program terminated. If all inputs are recognized and no errors arise, print the following to stdout. Result = , values remain on the stack. Please write in a C program Problem: Write a program that behaves in the manner describe in the "usage" message listed below, either printing the usage message when the first command-line argument is "--help", or upon identifying the "-rpn" command- line argument accepting input from stdin. You must write appropriate error messages to stderr if an error arises, whether an unrecognized command-line argument, a stack underflow or overflow, unrecognized input or any other error condition that may arise in your code. Output: Your program's normal output must be to stdout and of one of the formats following, assuming argc and argv are the usual parameters for main() and where is argv[0]. If argv[1] is "--help", display the following. Usage: " --help" display this usage material. " -postfix" The program accepts input from standard input as a sequence of numbers and operators. The numbers (operands, as integers or floating point numbers) read are pushed on a stack until needed. When an operator is read, the required operands are popped from the stack and used to perform the calculation, with the result placed on the stack. Valid operators are +, -, * and ), are interpreted as addition, subtraction, multiplication and division, respectively, as described below. An additional operator is =, which indicates that the value at the top of the stack is popped from the stack and displayed along with the number of values remaining on the stack, whereupon the program terminates. Stack underflows generate an error message and halt the program, as do a stack overflows. Unrecognized input tokens produce error messages and result in program termination, as do unrecognized command line arguments. The size of the stack is 10. Stack operations are performed so as to produce results identically as indicated here. +: push(pop() + pop(); - : temp = pop(); push(pop() - temp; *: push(pop() * pop(); /: temp = pop(); push(pop() / temp; swap : t1 = pop(); t2 = pop(); push(t1); push(t2); copy : temp = pop(); push(temp); push(temp); = : pop stack top and display it as the result with the number of stack elements remaining. The above describes the majority of the behavior of the program you are to write. To reiterate and expand important points: If the first command-line argument is "--help", subsequent command-line arguments are ignored, the usage message is displayed and the program terminates. If the first command-line argument is -postfix, subsequent command line arguments are ignored and the program proceeds with reading from standard input. Invalid/unrecognized command-line arguments produce a suitable error message, display the usage information above, and terminate the program. If an unrecognized token is read from standard input, a suitable error message for the type of error is to be displayed with the usage text and the program terminated. If all inputs are recognized and no errors arise, print the following to stdout. Result = , values remain on the stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started