The document provides instructions for three compiler construction exercises. The first exercise asks students to write a predictive parser in C that parses infix notation for single-digit addition and subtraction and prints the equivalent postfix notation. The second exercise asks students to simplify the predictive parser to use a single expr() function instead of separate functions. The third exercise asks students to write a recursive descent parser for a grammar involving addition, subtraction, and terminals.
The document provides instructions for three compiler construction exercises. The first exercise asks students to write a predictive parser in C that parses infix notation for single-digit addition and subtraction and prints the equivalent postfix notation. The second exercise asks students to simplify the predictive parser to use a single expr() function instead of separate functions. The third exercise asks students to write a recursive descent parser for a grammar involving addition, subtraction, and terminals.
The document provides instructions for three compiler construction exercises. The first exercise asks students to write a predictive parser in C that parses infix notation for single-digit addition and subtraction and prints the equivalent postfix notation. The second exercise asks students to simplify the predictive parser to use a single expr() function instead of separate functions. The third exercise asks students to write a recursive descent parser for a grammar involving addition, subtraction, and terminals.
On Moodle, you can find a zipped project archive as a
stepping stone for the next exercises. 1. The lecture of introduces a small compiler that translates addition and subtraction of single-digit numbers in infix notation to the corresponding postfix notation according to the following translation scheme: expr → expr + term {printf("+");} | expr – term {printf("-");} | term term → 0 {printf("0");} | ... | 9 {printf("9");} Write a predictive parser in C that parses infix notation and prints out postfix notation. The download for this exercise already includes a solution (for the case that none has been created during the lecture) – however, you should try to write your own parser from scratch. Note: 1. The first step should be eliminating the left recursion in the grammar defiinition. 2. The finished program parser.c can be compiled on a UNIX system simply by typing "make parser" in a terminal – the needed compilation steps can be resolved by the make tool via implicit rules. 2. Simplify your predictive parser from above so that the function R() (or rest()) introduced during elimination of left recursion is removed in favour of a single expr() function. 3. Construct a recursive-descent parser for the following grammar: S→+SS |-SS |a