ΜOpal: Unterschied zwischen den Versionen
K (wikipedia-link) |
K |
||
Zeile 4: | Zeile 4: | ||
<pre> | <pre> | ||
DEF fac(X:nat):nat == | DEF fac(X:nat):nat == | ||
− | + | IF eq(X,0) THEN | |
− | + | 1 | |
− | + | ELSE | |
− | + | mul(X, fac(sub(X, 1))) | |
+ | FI | ||
+ | |||
DEF MAIN:nat == | DEF MAIN:nat == | ||
− | + | fac(8) | |
</pre> | </pre> | ||
Version vom 21. Februar 2006, 02:53 Uhr
Eine simple Programmiersprache zu der in der Lehrveranstaltung PSS ein Compiler geschrieben wird.
Beispielprogramm:
DEF fac(X:nat):nat == IF eq(X,0) THEN 1 ELSE mul(X, fac(sub(X, 1))) FI DEF MAIN:nat == fac(8)
EBNF:
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"