1 / 14

ALP II: Objektorientierte Programmierung Sommersemester 2006

ALP II: Objektorientierte Programmierung Sommersemester 2006. Elfriede Fehr, Mohammad Al Saad. WHILE-Anweisungen: x := 0; x := x + 1; x := x – 1; while x  y do <Anweisungen> end. Befehlssatz der Registermaschine: zero i succ i pred i je i, j, m goto m.

hogan
Télécharger la présentation

ALP II: Objektorientierte Programmierung Sommersemester 2006

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ALP II: Objektorientierte ProgrammierungSommersemester 2006 Elfriede Fehr, Mohammad Al Saad

  2. WHILE-Anweisungen: x := 0; x := x + 1; x := x – 1; while x  y do <Anweisungen> end Befehlssatz der Registermaschine: zero i succ i pred i je i, j, m goto m Teil I: Grundlagen der BerechenbarkeitDie Programmiersprache WHILE unddie universelle Registermaschine

  3. Übersetzung von WHILE-Programmen in Registermaschinenprogramme:Erster Schritt: Erzeugen der Symboltabelle stBeispiel für eine Symboltabelle

  4. Zweiter Schritt: Anwendung des Übersetzungsschemas (Ü) Achtung:m ist die Adresse des ersten Befehls, der zur While-Schleife gehört und k ist die Adresse des ersten Befehls, der nicht mehr zur While-Schleife gehört.

  5. Beispiel: Fakultätsfunktion Funktionales Programm (Haskell): f 0 = 1 f x = x * f (x - 1) Imperatives Programm (in der Sprache WHILE): y := 1; h:= 0; while x ≠ h do y := x * y; x := x - 1; end

  6. Übersetzung des WHILE-Programms in ein Registermaschinenprogramm

  7. Übersetzung von WHILE nach Java Übersetzung von Java in Bytecode analog zur Übersetzung von WHLIE in Registermaschinenprogramme. Illustration unter http://www.artima.com/insidejvm/applets/EternalMath.html

  8. Ein vollständiges Java-Programm public class Fak { //Aufruf: Fak x , Ausgabe: Fakultät von x = Ergebnis //Hauptprogramm public static void main (String[] args) { // Deklaration aller benötigter Variablen int x, y, h; // Eingabe von x x = Integer.parseInt (args[0]); // Berechne y := Fakultät von x y = 1; h = x; while (h != 0) { y = h * y; h = h - 1; } // Ausgabe des kommentierten Ergebnisses System.out.println("Fakultät von " + x + " = " + y); } }

  9. Type: PrimitiveType ReferenceType PrimitiveType: NumericType boolean NumericType: IntegralType FloatingPointType IntegralType: one of byte short int long char FloatingPointType: one of float double James Gosling et al.: The Java Language Specification, sun microsystems 2005 Datentyp: PrimitiverTyp VerweisTyp PrimitiverTyp: NumerischerTyp boolean NumerischerTyp: GanzzahligerTyp GleitkommaTyp GanzzahligerTyp: einer von byte short int long char GleitkommaTyp: einer von float double Teil II: Datentypen in Java Syntax

  10. Primitive Datentypen

  11. Arithmetische Operationenerklärt auf allen numerischen Typen

  12. Vergleichsoperationen erklärt auf allen numerischen Typen, die beiden letzten auch auf boolean

  13. Typanpassung • Implizit von engeren zu weiteren Typen • Explizit in beide Richtungen Definition der Relation „enger“ (  ): byte  short  int  long  float  double char  int Bemerkung: Die Relation  ist transitiv. Explizite Typanpassung des Wertes eines Ausdrucks A an einen Typ t durch Anwendung des einstelligen Operators (t) auf den Ausdruck A. Beispiele: byte b = 9; b = b + 1; ist illegal! byte b = 9; b = (byte) (b+1); ist legal. int x = 6, y = 10; double q = x / y; der Wert von q ist 0.0 double q = (double)x / y; der Wert von q ist 0.6

  14. Syntaxregeln für Bedingte Anweisungen und Schleifen CondStmt: if (Exp) Stmt [ else Stmt ] WhileStmt: while (Exp) Stmt ForStmt: for ( [Init]; [Exp]; [Update]) Stmt

More Related