• Keine Ergebnisse gefunden

// Art des Objekts: Con, Var, Typ,

N/A
N/A
Protected

Academic year: 2022

Aktie "// Art des Objekts: Con, Var, Typ,"

Copied!
14
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

UE zu ÜbersetzerbauSymbolliste

Deklarierte Name in MicroJava • K lasse – K onstanten – g lobale Variablen – innere Klassen • F elder – M ethoden • formale Parameter • lokale Variablen • W o werden die Namen deklariert = wo werden sie in die Symbolliste eingefügt

Æ Program () Æ ConstDecl () Æ VarDecl ()

(level == 0)

Æ ClassDecl () Æ VarDecl () Æ MethDecl () Æ FormPars () Æ VarDecl ()

(level > 0)

(2)

UE zu ÜbersetzerbauSymbolliste

Knotenarten der Symbolliste

(1) class Obj{ staticfinalintCon=0, Var=1, Type=2, Fld=3, Meth int kind;

// Art des Objekts: Con, Var, Typ,

Stringname;

Struct type; Obj next;

// Zeiger auf nächstes Objekt

int adr;

//

Con

: Wert;

Meth

,

Var

,

Fld

: Adresse

int level;

//

Var

: Deklarations stufe;

Meth

: Anzahl der Parameter

Obj locals;

//

Meth

: Referenz auf lokale Variablen der Methode

}

(3)

UE zu ÜbersetzerbauSymbolliste

Knotenarten der Symbolliste

(2) class Struct{ staticfinalint None=0, Int=1, Char=2, Arr=3, Class=4; int kind;

// Art des Typs: N one, Int ,Char, Arr, Class

Struct elemType;

//

Arr

: Elementtyp

intn;

//

Class

: Anzahl der Felder

Obj fields;

//

Class

: Liste der Felder

} class Scope{ Scope outer;

// Referenz auf äußeren Gültigkeitsbereich

Obj locals;

// Symbolliste dieses Gültigkeitsbereichs

int nVars;

// Anzahl d. Variablen dieses Gültigkeitsbereichs

}

(4)

UE zu ÜbersetzerbauSymbolliste

Symbollisten-Klasse Tab

class Tab{ static final Struct noType, intType, charType, nullType;

// predefined types

static final Obj noObj;

// predefined objects

static Obj chrObj, ordObj, lenObj;

// predefined objects

static Scope topScope;

// current scope

static intlevel;

// nesting level of current scope

static void init(); static void openScope(); static void closeScope(); static Objinsert(intkind, String name, Structtype); static Objfind(String name); static Obj findField(Stringname,Struct type); }

(5)

UE zu ÜbersetzerbauSymbolliste

Einbau von semantischen Aktionen zum Füllen der Symbolliste /** VarDecl = Type ident { "," ident } ";" . */

private static void VarDecl() {

Type(); check(ident); while

(sym== comma) { scan(); check(ident); } check(semicolon); } private static void VarDecl() { Structtype =Type(); check(ident); Tab.insert(Obj.Var, t.string, type); while (sym == comma) { scan(); check(ident); Tab.insert(Obj.Var, t.string, type);

} check(semicolon);

}

(6)

UE zu ÜbersetzerbauSymbolliste

Einbau von semantischen Aktionen, die Infos aus Symbolliste verwenden /** Type = ident [ "[" "]" ] . */

private static voidType() {

check(ident); if(sym== lbrack) { scan(); check(rbrack); } } private static StructType() { Struct type = Tab.noType; check(ident); Objo = Tab.find(t.string); if (o.kind != Obj.Type) Parser.Errors.semError("type expected"); type = o.type; if(sym== lbrack) { scan(); check(rbrack); type = new Struct(Struct.Arr, type); } return type; }

(7)

UE zu ÜbersetzerbauSymbolliste

Innere Klassen

Beispiel aus VO-Skript (Folie 5.16):class int x, y, z; } C v;

/** ClassDecl = "class" ident "{" { VarDecl } "}" . */

private static void ClassDecl(){

scan(); check(ident); Obj c = Tab.insert(Obj.Type, t.string,new Struct(Struct.Class)); check(lbrace); Tab.openScope(); while(sym==ident)VarDecl(); check(rbrace); c.type.fields= Tab.topScope.locals; c.type.n = Tab.topScope.nVars; for(Obj cur= c.type.fields;cur!= null;cur=cur.next) cur.kind=Obj.Fld;

// change from Obj.Var to O bj.Fld

Tab.closeScope(); }

(8)

UE zu ÜbersetzerbauSymbolliste

Beispiel: Symbollistenaufbau

classABC

(** 1 **)

char[] c; int

max; char npp; { intput

(** 2 **)

(intx) {

(** 3 **)

x++; print(x, 5); npp= 'C'; returnx; }

(** 4 **)

}

(** 5 **)

(9)

UE zu ÜbersetzerbauSymbolliste

Bsp: Bei Punkt (** 1 **)

Vordefinierte Typen und Objekte:Strukturder 3 Knotenarten:

(10)

UE zu ÜbersetzerbauSymbolliste

Bsp: Bei Punkt (** 2 **)

(11)

UE zu ÜbersetzerbauSymbolliste

Bsp: Bei Punkt (** 3 **)

(12)

UE zu ÜbersetzerbauSymbolliste

Bsp: Bei Punkt (** 4 **)

(13)

UE zu ÜbersetzerbauSymbolliste

Bsp: Bei Punkt (** 5 **)

(14)

UE zu ÜbersetzerbauSymbolliste

UE 4: Symbolliste & Fehlerbehandlung UB-UE4-Angabe.zip • Implementierung:

–Token.java: toString()gibt nun ALLE Felder aus! –Scanner.java

: Gerüst verwendet nun

Parser.Errors –Parser.java

: Gerüst + innere Klasse

Errors –Compiler.java

: verwendet nun

Parser.Errors

– S ymbollistenklassen:

•Obj.java

,

Struct.java

,

Scope.java

: vollständige Implementierungen (müssen nicht mehr verändert werden)

•Tab.java

: Gerüst für Symbollistenverwaltungsklasse • T estfälle:

–SymTabTest.java

: spezielle Tests für Symbolliste

–ParserTest.java

: zusätzliche Symbollistentests & semantische Checks

Referenzen

ÄHNLICHE DOKUMENTE

Nachricht beim Anklicken: BN_CLICKED Beschriftung

The software verification tools use many techniques for automated proving, in particular:. • Superposition provers (e.g.,

The basic problem of static program analysis: virtually all interesting program properties are

Produces the same results for all possible invocations of M independent of possible callers and parameter values.

This grammar is formalized using annotated state diagrams, and the verification analysis is based on static control flow, data flow and alias analyses.. The paper illustrates the

It is illustrated how fun- damental methods of static analysis, in particular abstract interpretation by interval analysis, contribute to the solution of problems typically

Seiko Epson does not assume any liability of any kind arising out of any inaccuracies contained in this material or due to its application or use in any product or circuit and,

Seiko Epson does not assume any liability of any kind arising out of any inaccuracies contained in this material or due to its application or use in any product or circuit and,