Skip to content

Commit c179483

Browse files
committed
Added example based on WhileLang.
This example is based on the WhileLang example used in SWEN430. Specifically, this is a simple while language interpreter. Currently, it is not complete yet though.
1 parent 6b0762e commit c179483

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

examples/whilelang/WhileLang.wyrl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ====================================================================
2+
// Values
3+
// ====================================================================
4+
term Num(int)
5+
term False
6+
term True
7+
define Bool as True|False
8+
define Value as Num | Bool
9+
10+
// ====================================================================
11+
// Expressions
12+
// ====================================================================
13+
term Var(string)
14+
term Sub[Expr,Expr]
15+
term Add[Expr,Expr]
16+
term Mul[Expr,Expr]
17+
term Div[Expr,Expr]
18+
19+
define Expr as Value | Var | Sub | Add | Mull | Div
20+
21+
// ====================================================================
22+
// Statements
23+
// ====================================================================
24+
term Assign[Var,Expr]
25+
term Return(Expr)
26+
27+
define Stmt as Assign | Return
28+
29+
// ====================================================================
30+
// Semantics
31+
// ====================================================================
32+
term Env{[Var,Value]...}
33+
term Program[Stmt...]
34+
35+
term State[Env,Program]
36+
37+
// R-Return1
38+
reduce State[Env, Program[Return(Value v),Stmt... rest]]:
39+
=> v
40+
41+
// R-Return2 ?
42+
43+
// R-Assign1
44+
reduce State[Env{[Var,Value]... ps}, Program[Assign[Var v, Value n],Stmt... rest]]:
45+
=> let ws = { [p[0],p[1]] | p in ps, p[0] != v }
46+
in State[Env(ws ++ {[v,n]}), rest]
47+
48+
// R-Assign2 ?
49+
50+

examples/whilelang/build.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<project name="wyrl" default="build">
2+
<import file="../../config.xml"/>
3+
4+
<target name="build">
5+
<taskdef name="wyrl" classname="wyrl.util.WyrlAntTask" classpath="../../src/:../../${WYBS_JAR}"/>
6+
<wyrl srcdir="." debug="false" source="WhileLang.wyrl" output="WhileLang.java"/>
7+
<javac debug="true" debuglevel="vars,lines,source" srcdir="." source="1.7" target="1.7" includeantruntime="false" classpath="../../src/">
8+
<include name="*/**"/>
9+
</javac>
10+
</target>
11+
12+
<target name="clean">
13+
<delete failonerror="false">
14+
<fileset dir="." includes="*.class,WhileLang.java"/>
15+
</delete>
16+
</target>
17+
</project>

0 commit comments

Comments
 (0)