###################################################################### # Grammaire attribuée ###################################################################### P = Program { D } E(te) Crée une portée pour le programme entier, et l'utilise pour analyser les déclarations {D} et l'expression principale E. D = FunDecl ident { F }({ta}) T(tt) E(te) Analyse les arguments {F} dans une nouvelle portée, imbriquée dans la portée courante. Ajoute un nouveau symbole dans la portée courante, de nom 'ident' et de type 'tf'. Analyse ensuite le corps E dans la portée des arguments. tf = Type.FunType({ta},tt) te <: tt F(t) = Formal ident T(tt) Ajoute un nouveau symbole dans la portée courante, de nom 'ident' et de type 'tt'. t = tt T(t) = UnitType t = Type.UNIT T(t) = IntType t = Type.INT T(t) = ListType T(tt) t = Type.ListType(tt) T(t) = FunType { T }({ts}) T(tt) t = Type.FunType({ts},tt) S = VarDecl ident T(tt) E(te) Analyse l'expression E dans la portée courante. Ajoute un nouveau symbole dans la portée courante, de nom 'ident' et de type 'tt'. te <: tt S = While E(tc) E(te) tc = Type.INT S = Exec E(te) E(t) = If E(tc) E(t1) E(t2) tc = Type.INT t1 <: t2 || t2 <: t1 t = max(t1,t2) E(t) = Assign ident E(t1) sym= lookup(ident) sym.isVariable() t1 <: sym.type t = Type.UNIT E(t) = Operation ( Eq | Ne | Lt | Le | Gt | Ge ) E(t1) E(t2) t1 = Type.INT t2 = Type.INT t = Type.INT E(t) = Operation ( Add | Sub | Mul | Div | Mod ) E(t1) E(t2) t1 = Type.INT t2 = Type.INT t = Type.INT E(t) = Operation Cons E(t1) E(t2) t2 <: Type.ListType(t1) || Type.ListType(t1) <: t2 t = max(Type.ListType(t1),t2) E(t) = Operation Head E(t1) t1 = Type.ListType(t2) t = t2 E(t) = Operation Tail E(t1) t1 = Type.ListType(t2) t = t1 E(t) = Operation IsEmpty E(t1) t1 = Type.ListType(t2) t = Type.INT E(t) = Ident ident sym= lookup(ident) t = sym.type E(t) = UnitLit t = Type.UNIT E(t) = IntLit int t = Type.INT E(t) = NilLit t = Type.ListType(Type.BOTTOM) E(t) = Block { S } E(t1) Analyse {S} et E dans une nouvelle portée, imbriquée dans la portée courante. t = t1 E(t) = FunCall E(tf) { E }({ta}) tf = Type.FunType({ts},tt) {ts}.length = {ta}.length for i in 1..{ts}.length {ta}[i] <: {ts}[i] t = tt ###################################################################### $Id: attribute_grammar.txt,v 1.1 2004/02/24 16:11:58 schinz Exp $