next up previous
Next: Über dieses Dokument

M. Sperber, H. Klaeren Wintersemester 1997/98


Compilerbau I


Blatt 5

Abgabe: 27.11.1997

  1. [5 Punkte] Die in der Vorlesung angegebene Grammatik für Mini-Caml ist mehrdeutig -- es gibt z.B. mehrere Syntaxbäume für den Ausdruck 1 + 1 + 1. Geben Sie -- gemäß der Angaben über Präzedenz und Assoziativität im Caml-Handbuch -- eine äquivalente eindeutige Grammatik an.
  2. [10 Punkte] Implementieren Sie einen Parser für Mini-Caml, der abstrakte Syntax wie in der Vorlesung beschrieben erzeugt. Benutzen Sie (vorzugsweise) Ihren eigenen Scanner und Parser oder den Scanner in der Struktur Camllex und den Parser aus der Struktur Lr.
  3. [10 Punkte] Die Grammatik von Mini-Caml erfaßt nicht alle Korrektheitseigenschaften eines Programms, die für eine weitere Übersetzung notwendig sind. Insbesondere wird nicht überprüft, ob alle verwendeten Bezeichner auch tatsächlich gebunden sind. Implementieren Sie eine entsprechende Analyse mit folgender Signatur:
    val analyze_bound :
          'ident Camlsyn.program
             -> 'ident list
               -> ('ident Camlsyn.program * 'ident list)
    Für analyze_bound e l ist e ein Mini-Caml-Programm und l eine Liste eingebauter Bezeichner. Der Rückgabewert ist ein Tupel aus einem Mini-Caml-Programm, in dem Referenzen Ident i auf eingebaute Bezeichner durch Builtin i ersetzt worden sind, und einer Liste im Programm verwendeter aber nicht gebundener Bezeichner.
  4. [5 Punkte] Geben Sie einen ``Un-Parser'' für Mini-Caml an, der aus der abstrakten Syntax wieder ein konkretes Programm produziert. Testen Sie den Un-Parser an einigen repräsentativen Beispielen.

\: tex2html_wrap_inline667 \| tex2html_wrap_inline669 `=13

 ¯ tex2html_wrap_inline669  ¯ tex2html_wrap_inline439 exp tex2html_wrap_inline441  \:  tex2html_wrap_inline439 literal tex2html_wrap_inline441 
		 \|  tex2html_wrap_inline439 ident tex2html_wrap_inline441 
		 \| (  tex2html_wrap_inline439 operator-name tex2html_wrap_inline441  )
		 \| (  tex2html_wrap_inline439 exp tex2html_wrap_inline441  )
		 \|  tex2html_wrap_inline439 exp tex2html_wrap_inline441   tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \|  tex2html_wrap_inline439 prefix-symbol tex2html_wrap_inline441   tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \|  tex2html_wrap_inline439 exp tex2html_wrap_inline441   tex2html_wrap_inline439 infix-symbol tex2html_wrap_inline441   tex2html_wrap_inline439 exp tex2html_wrap_inline441  
		 \| if  tex2html_wrap_inline439 exp tex2html_wrap_inline441  then  tex2html_wrap_inline439 exp tex2html_wrap_inline441  else  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \|  tex2html_wrap_inline439 exp tex2html_wrap_inline441  or  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \|  tex2html_wrap_inline439 exp tex2html_wrap_inline441  &  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \|  tex2html_wrap_inline439 exp tex2html_wrap_inline441  ;  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \| function  tex2html_wrap_inline439 ident tex2html_wrap_inline441  ->  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \| raise  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \| try  tex2html_wrap_inline439 exp tex2html_wrap_inline441  with  tex2html_wrap_inline439 ident tex2html_wrap_inline441  ->  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \| let rec tex2html_wrap_inline673   tex2html_wrap_inline439 let-binding tex2html_wrap_inline441   tex2html_wrap_inline439 more-bindings tex2html_wrap_inline441  in  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
		 \| [  tex2html_wrap_inline439 sequence tex2html_wrap_inline441  ]
 tex2html_wrap_inline439 literal tex2html_wrap_inline441  \: ( ) \|  tex2html_wrap_inline439 integer-literal tex2html_wrap_inline441  \|  tex2html_wrap_inline439 character-literal tex2html_wrap_inline441  \|  tex2html_wrap_inline439 string-literal tex2html_wrap_inline441 
 tex2html_wrap_inline439 operator-name tex2html_wrap_inline441  \:  tex2html_wrap_inline439 infix-symbol tex2html_wrap_inline441  \|  tex2html_wrap_inline439 prefix-symbol tex2html_wrap_inline441 
 tex2html_wrap_inline439 sequence tex2html_wrap_inline441  \:  tex2html_wrap_inline439 empty tex2html_wrap_inline441  \|  tex2html_wrap_inline439 exp tex2html_wrap_inline441   tex2html_wrap_inline439 sequence-rest tex2html_wrap_inline441 
 tex2html_wrap_inline439 sequence-rest tex2html_wrap_inline441  \: ;  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
 tex2html_wrap_inline439 let-binding tex2html_wrap_inline441  \:  tex2html_wrap_inline439 ident tex2html_wrap_inline441  tex2html_wrap_inline675  =  tex2html_wrap_inline439 exp tex2html_wrap_inline441 
 tex2html_wrap_inline439 more-bindings tex2html_wrap_inline441  \: and  tex2html_wrap_inline439 let-binding tex2html_wrap_inline441 
 tex2html_wrap_inline439 definition tex2html_wrap_inline441  \: let rec tex2html_wrap_inline673   tex2html_wrap_inline439 let-binding tex2html_wrap_inline441   tex2html_wrap_inline439 more-bindings tex2html_wrap_inline441 
 tex2html_wrap_inline439 program tex2html_wrap_inline441  \:  tex2html_wrap_inline439 definition tex2html_wrap_inline441 





Michael Sperber [Mr. Preprocessor]
Thu Nov 20 14:59:13 MET 1997