Diff
Not logged in

Differences From Artifact [f03af1208bc8c434]:

To Artifact [4e37845b6ce5021a]:


4 4 * 5 5 * Syntax tree for Polemy programming language. 6 6 */ 7 7 module polemy.ast; 8 8 import polemy._common; 9 9 import polemy.lex; 10 10 11 -alias Statement[] Program; 12 - 13 -abstract class Statement 11 +abstract class AST 14 12 { 15 13 immutable LexPosition pos; 16 14 mixin SimpleConstructor; 17 15 } 18 16 19 -class DeclStatement : Statement 20 -{ 21 - string var; 22 - Expression expr; 23 - mixin SimpleClass; 24 -} 25 - 26 -class ExprStatement : Statement 27 -{ 28 - Expression expr; 29 - mixin SimpleClass; 30 -} 31 - 32 -abstract class Expression 33 -{ 34 - immutable LexPosition pos; 35 - mixin SimpleConstructor; 36 -} 37 - 38 -class StrLiteralExpression : Expression 17 +class StrLiteral : AST 39 18 { 40 19 string data; 41 20 mixin SimpleClass; 42 21 } 43 22 44 -class IntLiteralExpression : Expression 23 +class IntLiteral : AST 45 24 { 46 25 BigInt data; 47 26 mixin SimpleClass; 27 + this(immutable LexPosition pos, long n) {super(pos); data = n;} 28 + this(immutable LexPosition pos, BigInt n) {super(pos); data = n;} 29 + this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n);} 48 30 } 49 31 50 -class VarExpression : Expression 32 +class VarExpression : AST 51 33 { 52 34 string var; 53 35 mixin SimpleClass; 54 36 } 55 37 56 -class AssignExpression : Expression 38 +class LetExpression : AST 57 39 { 58 - Expression lhs; 59 - Expression rhs; 40 + string var; 41 + AST init; 42 + AST expr; 60 43 mixin SimpleClass; 61 44 } 62 45 63 -class FuncallExpression : Expression 46 +class FuncallExpression : AST 64 47 { 65 - Expression fun; 66 - Expression[] args; 67 - this(immutable LexPosition pos, Expression fun, Expression[] args...) 48 + AST fun; 49 + AST[] args; 50 + this(immutable LexPosition pos, AST fun, AST[] args...) 68 51 { super(pos); this.fun=fun; this.args=args.dup; } 69 52 mixin SimpleClass; 70 53 } 71 54 72 -class FunLiteralExpression : Expression 55 +class FunLiteral : AST 73 56 { 74 57 string[] params; 75 - Program funbody; 58 + AST funbody; 76 59 mixin SimpleClass; 77 60 } 78 61 79 62 /// Handy Generator for AST nodes. To use this, mixin EasyAst; 80 63 81 64 /*mixin*/ 82 -template EasyAst() 65 +template EasyAST() 83 66 { 84 67 template genEast(T) 85 68 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } } 86 69 87 - alias genEast!DeclStatement decl; 88 - alias genEast!ExprStatement expr; 70 + alias genEast!StrLiteral strl; 71 + alias genEast!IntLiteral intl; 72 + auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } 89 73 alias genEast!VarExpression var; 90 - alias genEast!FuncallExpression funcall; 91 - alias genEast!IntLiteralExpression intl; 92 - alias genEast!StrLiteralExpression strl; 93 - alias genEast!FunLiteralExpression fun; 74 + alias genEast!LetExpression let; 75 + alias genEast!FuncallExpression call; 94 76 }