Assignment 4

4.1
Consider the following grammar for postfix expressions.

E ::= E E + | E E - |  id 
  1. Eliminate left-recursion from the grammar.
  2. The resulting grammar after (1) is still not suitable for top-down parsing since there are common left factors in the right-hand sides of productions. Transform the grammar further to make it suitable for top-down parsing.
  3. For each non-terminal A and each terminal a, show the entry M[A,a] in the table for top-down parsing.
4.2
Construct the SLR(1) parsing table for the grammar in 4.1.
4.3
Implement a parser (either LL(1) or SLR) for the language defined by the following CFG:
Program:
	Assignment*

Assignment:
	Identifier = Exp;

Exp: 
	Exp + Term | Exp - Term | Term

Term:
	Term * Fact  | Fact

Fact:
	( Exp ) | - Fact | + Fact | Literal | Identifier

Identifier:
     	Letter [Letter | Digit]*

Letter:
	a|...|z|A|...|Z|_

Literal:
	0 | NonZeroDigit Digit*
		
NonZeroDigit:
	1|...|9

Digit:
	0|1|...|9