Benutzer:Grey/pss: Unterschied zwischen den Versionen
(→BNF) |
(→BNF) |
||
| Zeile 18: | Zeile 18: | ||
2)Def -> <u>DEF</u> Lhs <u>==</u> Expr <2><br> | 2)Def -> <u>DEF</u> Lhs <u>==</u> Expr <2><br> | ||
3)Def' -> Def Def' | 3)Def' -> Def Def' | ||
| − | + | 4) | e<br> | |
| − | + | 5)Lhs -> <u>MAIN</u> <u>:</u> Type <3> | |
| − | + | 6) | <u>id</u> <u>(</u> Lhs' <u>)</u> <u>:</u> Type <4><br> | |
| − | + | 7)Lhs' -> <u>id</u> <u>:</u> Type Lhs´´ <5> | |
| − | + | 8) | e<br> | |
| − | + | 9)Lhs´´ -> <u>,</u> Lhs' | |
| − | + | 10) | e<br> | |
| − | + | 11)Type -> <u>nat</u> | |
| − | + | 12) | <u>bool</u><br> | |
| − | + | 13)Expr -> <u>number</u> | |
| − | + | 14) | <u>true</u> | |
| − | + | 15) | <u>false</u> | |
| − | + | 16) | <u>id</u> Expr' <6> | |
| − | + | 17) | <u>IF</u> Expr <u>THEN</u> Expr fi' <u>FI</u> <7><br> | |
| − | + | 18)Expr' -> <u>(</u> Expr´´ <u>)</u> | |
| − | + | 19) | e<br> | |
| − | + | 20)Expr´´ -> Expr Expr´´´ <8> | |
| − | + | 21) | e<br> | |
| − | + | 22)Expr´´´ -> <u>,</u> Expr Expr´´´ | |
| − | + | 23) | e<br> | |
| + | 24)fi' -> <u>ELSE</u> Expr | ||
| e<br> | | e<br> | ||
Version vom 9. Dezember 2005, 11:03 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' 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