BuK/IIm12/BuK-KA-WHILE-COMPILER

Aus ProgrammingWiki

Wiki-Quelltext dieser Seite.

== Aufgabenstellung ==

Entwickeln Sie einen Compiler, der als Eingabesprache $L_{WHILE}\cup L_{GOTO}\cup L_{LOOP}$ verwendet und ein zur Eingabe äquivalentes Programm aus $L_{WHILE}$ (Zielsprache) erzeugt. Die Interpretation des jeweils entstandenen $WHILE$-Programms ist nicht gefordert.

Verwenden Sie AtoCC

== Zielsetzung ==
Die Zielsetzung dieses Compiler ist es ein Programm das aus $WHILE$- $LOOP$- und $GOTO$-Befehelen besteht in ein $WHILE$-Prgramm umzuwandeln. Dabei können die Sprachen beliebig verschachtelt werden.

== Ausgangsgrammatik ==
===Definition===
 G = (N, T, P, s)
 N = {S, P, PNM, Loop_P, While_P, Goto_P, Konstante, Zahl, Ziffer, Variable, Zuweisung, Operationssymbol, Marke, Vergleich}
 T = {:, ;, LOOP, DO, END, WHILE, IF, THEN, GOTO, HALT, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, x, :=, +, -, M, ==}
 P = {
   S                -> P 
   P                -> Marke : PNM | P ; P | PNM 
   PNM              -> While_P | Goto_P | Zuweisung | Loop_P 
   Loop_P           -> LOOP Variable DO P END 
   While_P          -> WHILE Variable DO P END 
   Goto_P           -> IF Vergleich THEN GOTO Marke 
                     | GOTO Marke 
                     | HALT 
   Konstante        -> Zahl 
   Zahl             -> Konstante Ziffer | Ziffer 
   Ziffer           -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 
   Variable         -> x Konstante 
   Zuweisung        -> Variable := Konstante 
                     | Variable := Variable Operationssymbol Konstante 
   Operationssymbol -> + | - 
   Marke            -> M Konstante 
   Vergleich        -> Variable == Konstante 
 }
 s = S
===Beispiel Ableitung===
[[Bild:Fana_Ausgang_ableitung.png|1000px]]

== Scanner-Definition ==
[[Bild:Fana_Token.png]]

== Parser-Definition ==
[[Bild:Fana_Parser.png]]

== Zielgrammatik ==

===Definition===
 G = (N, T, P, s)
 N = {S, P, PNM, While_P, IFVergleich, Konstante, Zahl, Ziffer, Variable, Zuweisung, Operationssymbol, Vergleich}
 T = {;, WHILE, DO, END, IF, THEN, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, x, :=, +, -, ==}
 P = {
   S                -> P 
   P                -> P ; P | PNM 
   PNM              -> IFVergleich | While_P | Zuweisung 
   While_P          -> WHILE Variable DO P END 
   IFVergleich      -> IF Vergleich THEN P 
   Konstante        -> Zahl 
   Zahl             -> Konstante Ziffer | Ziffer 
   Ziffer           -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 
   Variable         -> x Konstante 
   Zuweisung        -> Variable := Konstante 
                     | Variable := Variable Operationssymbol Konstante 
   Operationssymbol -> + | - 
   Vergleich        -> Variable == Konstante 
 }
 s = S
=== Beispiel Ableitung ===
[[Bild:Fana_Ableitung.png|1000px]]