Benutzer:Grey/pss
Inhaltsverzeichnis
Milstone 1
- EBNF in BNF Grammatik umwandeln:
EBNF
Gegeben ist folgende EBNF Syntax von microOPAL:
Prog -> Def Def * # Def -> DEF Lhs == Expr Lhs -> MAIN : Type | id ( [id : Type (, id : Type)*]) : Type Type -> nat | bool Expr -> number | true | false | id [ ( [Expr (, Expr)*] ) ] | IF Expr THEN Expr [ELSE Expr] FI
BNF
Erste Umformung inklusive semantischer Aktionen:
1)Prog -> Def Def' # <1>
2)Def -> DEF Lhs == Expr <2>
3)Def' -> Def Def' 4) | e
5)Lhs -> MAIN : Type <3> 6) | id ( Lhs' ) : Type <4>
7)Lhs' -> id : Type Lhs´´ <5> 8) | e
9)Lhs´´ -> , Lhs' 10) | e
11)Type -> nat 12) | bool
13)Expr -> number 14) | true 15) | false 16) | id Expr' <6> 17) | IF Expr THEN Expr fi' FI <7>
18)Expr' -> ( Expr´´ ) 19) | e
20)Expr´´ -> Expr Expr´´´ <8> 21) | e
22)Expr´´´ -> , Expr Expr´´´ 23) | e
24)fi' -> ELSE Expr | e
Directormengen
Vorlage:Highlight1 |Produktion | Vorlage:Highlight1 |Directormenge | Vorlage:Highlight1 |disjunkt? |
---|---|---|
1) | uninteressant | ja |
2) | uninteressant | ja |
3) 3b) |
{DEF} {#, DEF} |
ja |
4) 5) |
{MAIN} {id} |
ja |
6) 7) |
{id} {)} |
ja |
8) 9) |
{,} {)} |
ja |
10) 11) |
{nat} {bool} |
ja |
12) 13) 14) 15) 16) |
{number} {true} {false} {id} {IF} |
ja |
17) 18) |
{(} {THEN, ELSE, FI, ,, )} |
ja |
19) 20) |
{number, true, false, id, IF} {,, )} |
ja |
21) 22) |
{,} {)} |
ja |
23) 24) |
{ELSE} {FI} |
ja |
Abstrakter Syntaxbaum
http://www.freitagsrunde.org/~grey/pss/absy.jpg
Implementation
Absy.impl
IMPLEMENTATION Absy DATA absy == Prog( defseq:seq[absy]) Def(id:denotation, seq[id:denotation, typ: type], typ:type) Funcall(id: denotation, parref: seq[absy]) ParRef(id:denotation) Cond(ifCond:absy, thenCond:absy) CondElse(ifElse:absy, thenElse:absy, elseElse: absy) NatConst(number:nat) BoolConst(boolean:bool) DATA type == TNat(n:nat) TBool(b:bool) -- Ausgabefunktion vom Absy -- DEF `(Absy) == DEF `(Prog(defseq)) == "Prog(" ++ (printSeqAbsy(defseq)) ++ ")" DEF `(Def(id,seqIdTyp,typ)) == "Def " ++ id ++ "(" ++ (printSeqType(seqIdTyp)) ++ ") :" ++ (printType(typ)) DEF `(Funcall(id,parref)) == "Funcall:" ++ id ++ "(" ++ (printSeqAbsy(parref)) ++ ")" DEF `(ParRef(id)) == "ParRef:" ++ id DEF `(Cond(ifCond,thenCond)) == "Cond(" ++ "IF " ++ (`(ifCond)) ++ " THEN " ++ (`(thenCond)) ++ ")" DEF `(CondElse(ifCondE,thenCondE, elseCondE)) == "Cond(" ++ "IF " ++ (`(ifCondE)) ++ " THEN " ++ (`(thenCondE)) ++ " ELSE " ++ (`(elseCondE)) ++ ")" DEF `(NatConst(natC)) == `(natC) DEF `(BoolConst(boolC)) == `(boolC) DEF printSeqAbsy(<>) == "<>" DEF printSeqAbsy(a::R) == `(a) ++ ";" ++ printSeqAbsy(R) DEF printType(TNat) == "nat" DEF printType(TBool) == "bool" DEF printSeqType(<>) == "<>" DEF printSeqType((id,typ)::R) == id ++ ":" ++ printType(typ) ++ ", " ++ printSeqType(R)
Absy.sign
/* % Die abstrakte Syntax. NOT YET IMPLEMENTED. */ SIGNATURE Absy SORT absy -- Augabefunktion FUN ` : absy -> denotation -- Ausgabefunktionen für Typen inerhalb von Absy FUN printSeqAbsy : seq[absy] -> denotation FUN printType : type -> denotation FUN printSeqType : seq[denotation, type] -> denotation