Differences From Artifact [dd714695d64176f9]:
- File
polemy/ast.d
- 2010-11-09 10:28:08 - part of checkin [dc93ad8cf6] on branch trunk - layered exec expression @lay(...) added (user: kinaba) [annotate]
To Artifact [b8324439b8512940]:
- File
polemy/ast.d
- 2010-11-10 12:38:54 - part of checkin [38fcc662be] on branch trunk - cleaned up documentation comments (user: kinaba) [annotate]
4 * 4 *
5 * Syntax tree for Polemy programming language. 5 * Syntax tree for Polemy programming language.
6 */ 6 */
7 module polemy.ast; 7 module polemy.ast;
8 import polemy._common; 8 import polemy._common;
9 import polemy.lex; 9 import polemy.lex;
10 10
> 11 ///
11 abstract class AST 12 abstract class AST
12 { 13 {
13 immutable LexPosition pos; 14 immutable LexPosition pos;
14 mixin SimpleConstructor; 15 mixin SimpleConstructor;
15 } 16 }
16 17
> 18 ///
17 class StrLiteral : AST 19 class StrLiteral : AST
18 { 20 {
19 string data; 21 string data;
20 mixin SimpleClass; 22 mixin SimpleClass;
21 } 23 }
22 24
> 25 ///
23 class IntLiteral : AST 26 class IntLiteral : AST
24 { 27 {
25 BigInt data; 28 BigInt data;
26 mixin SimpleClass; 29 mixin SimpleClass;
27 this(immutable LexPosition pos, long n) {super(pos); data = n;} 30 this(immutable LexPosition pos, long n) {super(pos); data = n;}
28 this(immutable LexPosition pos, BigInt n) {super(pos); data = n;} 31 this(immutable LexPosition pos, BigInt n) {super(pos); data = n;}
29 this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n); 32 this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n);
30 } 33 }
31 34
> 35 ///
32 class VarExpression : AST 36 class VarExpression : AST
33 { 37 {
34 string var; 38 string var;
35 mixin SimpleClass; 39 mixin SimpleClass;
36 } 40 }
37 41
> 42 ///
38 class LayeredExpression : AST 43 class LayeredExpression : AST
39 { 44 {
40 string lay; 45 string lay;
41 AST expr; 46 AST expr;
42 mixin SimpleClass; 47 mixin SimpleClass;
43 } 48 }
44 49
> 50 ///
45 class LetExpression : AST 51 class LetExpression : AST
46 { 52 {
47 string var; 53 string var;
48 string layer; 54 string layer;
49 AST init; 55 AST init;
50 AST expr; 56 AST expr;
51 mixin SimpleClass; 57 mixin SimpleClass;
52 } 58 }
53 59
> 60 ///
54 class FuncallExpression : AST 61 class FuncallExpression : AST
55 { 62 {
56 AST fun; 63 AST fun;
57 AST[] args; 64 AST[] args;
58 this(immutable LexPosition pos, AST fun, AST[] args...) 65 this(immutable LexPosition pos, AST fun, AST[] args...)
59 { super(pos); this.fun=fun; this.args=args.dup; } 66 { super(pos); this.fun=fun; this.args=args.dup; }
60 mixin SimpleClass; 67 mixin SimpleClass;
61 } 68 }
62 69
> 70 ///
63 class FunLiteral : AST 71 class FunLiteral : AST
64 { 72 {
65 string[] params; 73 string[] params;
66 AST funbody; 74 AST funbody;
67 mixin SimpleClass; 75 mixin SimpleClass;
68 } 76 }
69 77
70 /// Handy Generator for AST nodes. To use this, mixin EasyAst; 78 /// Handy Generator for AST nodes. To use this, mixin EasyAst;
71 79
72 /*mixin*/ 80 /*mixin*/
73 template EasyAST() 81 template EasyAST()
74 { 82 {
> 83 ///
75 template genEast(T) 84 template genEast(T)
76 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } 85 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); }
77 86
78 alias genEast!StrLiteral strl; | 87 alias genEast!StrLiteral strl; ///
79 alias genEast!IntLiteral intl; | 88 alias genEast!IntLiteral intl; ///
80 auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } // t | 89 auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } ///
81 alias genEast!VarExpression var; | 90 alias genEast!VarExpression var; ///
82 alias genEast!LayeredExpression lay; | 91 alias genEast!LayeredExpression lay; ///
83 alias genEast!LetExpression let; | 92 alias genEast!LetExpression let; ///
84 alias genEast!FuncallExpression call; | 93 alias genEast!FuncallExpression call; ///
85 } 94 }