Benutzer:Grey/pss: Unterschied zwischen den Versionen
(→Abstrakter Syntaxbaum) |
(→Milstone 1) |
||
Zeile 1: | Zeile 1: | ||
= Milstone 1 = | = Milstone 1 = | ||
* EBNF in BNF Grammatik umwandeln: | * EBNF in BNF Grammatik umwandeln: | ||
− | |||
== EBNF == | == EBNF == | ||
Gegeben ist folgende EBNF Syntax von microOPAL: | Gegeben ist folgende EBNF Syntax von microOPAL: | ||
Zeile 41: | Zeile 40: | ||
23)fi' -> <u>ELSE</u> Expr | 23)fi' -> <u>ELSE</u> Expr | ||
| e<br> | | e<br> | ||
+ | |||
+ | |||
== Directormengen == | == Directormengen == | ||
− | |||
{| border="2" cellspacing="0" cellpadding="4" rules="all" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse; background-color:#F9F9F9; font-size:95%; empty-cells:show;" | {| border="2" cellspacing="0" cellpadding="4" rules="all" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse; background-color:#F9F9F9; font-size:95%; empty-cells:show;" | ||
! {{Highlight1}} |Produktion | ! {{Highlight1}} |Produktion | ||
Zeile 97: | Zeile 97: | ||
|ja | |ja | ||
|} | |} | ||
+ | |||
== Abstrakter Syntaxbaum == | == Abstrakter Syntaxbaum == | ||
http://www.freitagsrunde.org/~grey/pss/absy.jpg | http://www.freitagsrunde.org/~grey/pss/absy.jpg | ||
+ | |||
+ | |||
== Implementation == | == Implementation == |
Version vom 2. Dezember 2005, 16:22 Uhr
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' 3b) | e
4)Lhs -> MAIN : Type <3> 5) | id ( Lhs' ) : Type <4>
6)Lhs' -> id : Type Lhs´´ <5> 7) | e
8)Lhs´´ -> , Lhs' 9) | e
10)Type -> nat 11) | bool
12)Expr -> number 13) | true 14) | false 15) | id Expr' <6> 16) | IF Expr THEN Expr fi' FI <7>
17)Expr' -> ( Expr´´ ) 18) | e
19)Expr´´ -> Expr Expr´´´ <8> 20) | e
21)Expr´´´ -> , Expr 22) | e
23)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