The erty 3. (30 points) Consider the grammar that represents a stack on integers
ID: 3888267 • Letter: T
Question
The erty 3. (30 points) Consider the grammar that represents a stack on integers: stack-) Empty stack : (num stack);Non-empty stack (a) (10 points) Create an abstract syntax for stack using the define-datatype macro. (b) (10 points) Write the following procedures for stack in Scheme where stack is represented by the abstract syntax of part (a): empty-stack? determines whether a stack is empty ;; returns the val on top of a stack ; report stack underflow error if stack is empty top (stack) pop(stack)returns the stack with the top value popped off ; report stack underflow error if stack is empty push (val stack)i returns the stack vith val pushed on top of stack Here is the error code: (define report-stack-underflow (lambda ) (eopl:error 'empty-stack "Stack underflow")))Explanation / Answer
int main (int argc, char struct ch *charactop; struct integer *integertop; char rd, op; int i = 0, op1, op2; charactop = cclearstack(); integertop = iclearstack(); while(1) { rd = argv[1][i++]; switch(rd) { case '+': case '-': case '/': case '*': case '(': charactop = cpush(charactop, rd); break; case ')': integertop = ipop (integertop, &op2); integertop = ipop (integertop, &op1); charactop = cpop (charactop, &op); while(op != '(') { integertop = ipush (integertop, eval(op, op1, op2)); charactop = cpop (charactop, &op); if (op != '(') { integertop = ipop(integertop, &op2); integertop = ipop(integertop, &op1); } } break; case '