I’m working on a Computer Science exercise and need support.
S → E$
F → id
E → T E’
The attribute grammar we discussed in class calculated the value of a given expression. In this question, you are to solve the same problem, but you should take a different approach: • Instead of directly computing the value of the expression, you are to generate C code that computes the value of the expression at runtime. Specifically, if you run the parser generated from the grammar annotated with your action routines, the parser should print C code to evaluate the parsed expression to stdout. • You are to use action routines written in C to generate this C code. The code you generate has access to a stack of doubles that can be manipulated using the following two functions: • A function void push(double) that pushes a double onto a global stack holding values of type double. • A function double pop() that removes the topmost entry from the global stack of doubles and returns it. The code you generate should place the final result of evaluating the arithmetic expression into a variable result of type double.
Requirements: see pdf | .doc fileATTACHMENTSq_semantic_analysis.pdf