next up previous
Next: Über dieses Dokument

M. Sperber, H. Klaeren Wintersemester 1998/99


Compilerbau I


Blatt 5

Abgabe: 24.11.1998

  1. [5 Punkte] Implementieren Sie Attributauswertung für den Parser mit rekursivem Aufstieg -- wenn möglich in einem Parser, der auch Fehlerbehandlung vornimmt.
  2. [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.
  3. [20 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.

\: tex2html_wrap_inline434 \| tex2html_wrap_inline652 `=13

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

type 'ident syntax =
    Nil
  | Int of int
  | String of string
  | Char of char
  | Ident of 'ident
  | Builtin of 'ident
  | Apply of 'ident syntax * 'ident syntax
  | If of 'ident syntax * 'ident syntax * 'ident syntax
  | Sequence of 'ident syntax * 'ident syntax
  | Function of 'ident * 'ident syntax
  | Raise of 'ident syntax
  | Try of 'ident syntax * 'ident * 'ident syntax
  | Let of 'ident binding * 'ident syntax
  | Letrec of 'ident binding list * 'ident syntax
and 'ident binding = 'ident * 'ident syntax

type 'ident definition = 'ident binding list

type 'ident program = 'ident definition list





Michael Sperber [Mr. Preprocessor]
Tue Nov 17 16:20:05 MET 1998