exit final exam

NAME

1–4 CHARACTERS CODE (if you want your final grade posted)

 
CSE 756: Final Exam
 
Monday, June 2, 1:30—3:28
Open Notes, Open Books
The exam consists of four problems
Answers not appearing in designated spaces WILL NOT be graded

Consider the programming language having the following grammar

prog::=body
body::=body stat
ϵ
stat ::=DO body REPEAT
COPY
EXIT_0

where the following semantics holds.

Example.

EXIT_0  
DO  
  COPY  
  EXIT_0  
  COPY  
  EXIT_0  
  DO  
    EXIT_0  
    COPY  
    EXIT_0  
    COPY  
    EXIT_0  
  REPEAT  
  COPY  
  EXIT_0  
REPEAT  
COPY  
EXIT_0

Problem #1 (10 points)
Write a (J)FLEX program that generates a scanner for the language

Problem #2 (10 points)
Write a Bison/CUP program that provides a translation into MINI MACHINE code.

Problem #3 (10 points)
Provide the parsing table for the following LALR(1)-like transition diagram of the grammar. (The cores of the states are identical to those of the LALR(1) diagram. The lookahead symbols are different.)

                                      |||||||||
      ||||||||||                 ||||||       ||||||
   --|prog→ ⋅body,$||-            --| bopdry→obg→obdoydy⋅s⋅,t$at,$  ||-
   -body→ ⋅body stat,$-----body------stat→ ⋅DO  body REPEAT,$
   -|||  →ϵ⋅,$  ||--            -||    → ⋅COP Y,$     |-----
      ||||I0||||              ----|||→|⋅EXIIT1 _0,$||||---- ----------
                      COP-Y---        ||||||||        ------      ----------
                    ------          ||DO|||||||||    EXIT 0------ stat     ----------
   ||||||||-||||-----      ||||||||||           |||||||||       -----|||||-|||||||| ----------||||||||-|||||||||
-stat→COP  Y⋅,{$,REPEAT|}|-   -stat→DObod⋅by→ody⋅boRdEyP stEatA,RTE,{P$,ERAETPEAT }||   -stat→EXIT _0⋅,{$,REP EAT}|-   --body→body stat⋅,{$,REPEAT|}||
||||||||  I3  ||-||||--   -|||       →ϵ⋅,REPEAT         ||--   ||||||-||  I4  ||||||||-    |---|||||  I5   ||||||||-
       ||||||||  -----       ||||||||||-|I2||-||||||||||       ------ |||-||||    ---------       |||||||||
                     ------       body|      -         EXIT--0--        stat------
                   COP  Y ------ |||||--||||||DO|||| ------    ----------
                           stat→DO| body ⋅REP EAT,{$,REPEAT-}-------
                          --|   body→body ⋅stat,REP EAT     ||-
                          -  stat→ ⋅DO  body REPEAT,REP EAT  --
                          -|||    →→⋅⋅ECXOIPTY_,0R,ERPEEPAETAT     |||-
                              |||||||||||I6||||||||||||
                                          |
                                |REP|EAT|||||||||||||
                          -||||||                   |||||||
                          |stat→DO||body REPIE7AT ⋅,{$,REPEAT|}--
                                  |||||||||||||||||

Problem #4 (10 points)
Determine the LR(0), SLR(1), and LR(1) transition diagrams for the grammar.