CSE 428 : Solution of Assignment #1


Question 1

  1.  
       S ::= lambda | aSa | bSb
       

  2.  
       S ::= AB
       A ::= lambda | aAb
       B ::= lambda | bSa
       

  3.  
       S ::= AAAAAB
       A ::= a | b
       B ::= lambda | aB | bB
       

Question 2

Question 3

  1. There are various ambiguities, due to An example of the last kind of ambiguity is the following:
              BExp                  BExp
            /  |  \                /   |  
        BExp  and  BExp         not   BExp
        /  |        |               /  |  \ 
      not BExp    false         BExp  and  BExp
           |                      |         |
         false                  false     false    
    
    
  2.    BExp  ::= BTerm -> BExp | BTerm
    
       BTerm ::= BTerm and Literal | Literal
    
       Literal ::= not Literal | Atom
     
       Atom  ::= true | false
    

Question 4

   Exp  ::= Exp + Term | Exp - Term | Term	

   Term ::= Term * Factor | Term / Factor | Factor

   Factor ::= Base ^ Factor | Base

   Base ::= (Exp) | Num

   Num ::= 0 | Non_Zero_Digit Seq

   Seq ::= lambda | Digit Seq 

   Non_Zero_Digit ::= 1 | 2 | ... | 9

   Digit ::= 0 | Non_Zero_Digit