Mercurial > projects > dang
annotate ast/Stmt.d @ 11:642c6a998fd9
Support for while statements and fixed scope for if
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 13:45:39 +0200 |
parents | 2c5a8f4c254a |
children | ce17bea8e9bd |
rev | line source |
---|---|
1 | 1 module ast.Stmt; |
2 | |
3 import ast.Exp, | |
4 ast.Decl; | |
5 | |
6 import sema.SymbolTable; | |
7 | |
8 enum StmtType | |
9 { | |
10 Stmt, | |
11 Decl, | |
12 Exp, | |
13 Return, | |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
14 If, |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
15 While, |
1 | 16 } |
17 | |
18 class Stmt | |
19 { | |
20 this(StmtType stmtType = StmtType.Stmt) | |
21 { | |
22 this.stmtType = stmtType; | |
23 } | |
24 | |
25 StmtType stmtType; | |
26 Scope env; | |
27 } | |
28 | |
29 class ReturnStmt : Stmt | |
30 { | |
31 this() | |
32 { | |
33 super(StmtType.Return); | |
34 } | |
35 | |
36 public Exp exp; | |
37 } | |
38 | |
39 class DeclStmt : Stmt | |
40 { | |
41 this(Decl decl) | |
42 { | |
43 super(StmtType.Decl); | |
44 this.decl = decl; | |
45 } | |
46 | |
47 public Decl decl; | |
48 } | |
49 | |
50 class ExpStmt : Stmt | |
51 { | |
52 this(Exp exp) | |
53 { | |
54 super(StmtType.Exp); | |
55 this.exp = exp; | |
56 } | |
57 | |
58 public Exp exp; | |
59 } | |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
60 |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
61 class IfStmt : Stmt |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
62 { |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
63 this(Exp cond, Stmt[] then, Stmt[] el = null) |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
64 { |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
65 super(StmtType.If); |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
66 this.cond = cond; |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
67 this.then_body = then; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
68 this.else_body = el; |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
69 } |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
70 |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
71 Exp cond; |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
72 Stmt[] then_body; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
73 Stmt[] else_body; |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
74 } |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
75 |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
76 class WhileStmt : Stmt |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
77 { |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
78 this(Exp cond, Stmt[] stmts) |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
79 { |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
80 super(StmtType.While); |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
81 this.cond = cond; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
82 this.stmts = stmts; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
83 } |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
84 |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
85 Exp cond; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
86 Stmt[] stmts; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
87 } |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
88 |