Diff
Not logged in

Differences From Artifact [9b22488b3393157f]:

To Artifact [f03af1208bc8c434]:


2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 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 : LexPosition; | 9 import polemy.lex; 10 10 11 alias Statement[] Program; 11 alias Statement[] Program; 12 12 13 abstract class Statement 13 abstract class Statement 14 { 14 { 15 immutable LexPosition pos; 15 immutable LexPosition pos; 16 mixin SimpleConstructor; 16 mixin SimpleConstructor; 17 } 17 } 18 18 19 class DeclStatement : Statement 19 class DeclStatement : Statement 20 { 20 { 21 string var; 21 string var; 22 Expression expr; 22 Expression expr; 23 mixin SimpleConstructor; < 24 mixin SimpleCompare; | 23 mixin SimpleClass; 25 } 24 } 26 25 27 class ExprStatement : Statement 26 class ExprStatement : Statement 28 { 27 { 29 Expression expr; 28 Expression expr; 30 mixin SimpleConstructor; < 31 mixin SimpleCompare; | 29 mixin SimpleClass; 32 } 30 } 33 31 34 abstract class Expression 32 abstract class Expression 35 { 33 { 36 immutable LexPosition pos; 34 immutable LexPosition pos; 37 mixin SimpleConstructor; 35 mixin SimpleConstructor; 38 mixin SimpleCompare; < 39 } 36 } 40 37 41 class StrLiteralExpression : Expression 38 class StrLiteralExpression : Expression 42 { 39 { 43 string data; 40 string data; 44 mixin SimpleConstructor; < 45 mixin SimpleCompare; | 41 mixin SimpleClass; 46 } 42 } 47 43 48 class IntLiteralExpression : Expression 44 class IntLiteralExpression : Expression 49 { 45 { 50 BigInt data; 46 BigInt data; 51 mixin SimpleConstructor; < 52 mixin SimpleCompare; | 47 mixin SimpleClass; 53 } 48 } 54 49 55 class VarExpression : Expression 50 class VarExpression : Expression 56 { 51 { 57 string var; 52 string var; 58 mixin SimpleConstructor; < 59 mixin SimpleCompare; | 53 mixin SimpleClass; 60 } 54 } 61 55 62 class AssignExpression : Expression 56 class AssignExpression : Expression 63 { 57 { 64 Expression lhs; 58 Expression lhs; 65 Expression rhs; 59 Expression rhs; 66 mixin SimpleConstructor; < 67 mixin SimpleCompare; | 60 mixin SimpleClass; 68 } 61 } 69 62 70 class FuncallExpression : Expression 63 class FuncallExpression : Expression 71 { 64 { 72 Expression fun; 65 Expression fun; 73 Expression[] args; 66 Expression[] args; 74 this(immutable LexPosition pos, Expression fun, Expression[] args...) 67 this(immutable LexPosition pos, Expression fun, Expression[] args...) 75 { super(pos); this.fun=fun; this.args=args.dup; } 68 { super(pos); this.fun=fun; this.args=args.dup; } 76 mixin SimpleCompare; | 69 mixin SimpleClass; 77 } 70 } 78 71 79 class FunLiteralExpression : Expression 72 class FunLiteralExpression : Expression 80 { 73 { 81 string[] params; 74 string[] params; 82 Program funbody; 75 Program funbody; 83 mixin SimpleConstructor; | 76 mixin SimpleClass; > 77 } > 78 > 79 /// Handy Generator for AST nodes. To use this, mixin EasyAst; > 80 84 mixin SimpleCompare; | 81 /*mixin*/ > 82 template EasyAst() > 83 { > 84 template genEast(T) > 85 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } > 86 > 87 alias genEast!DeclStatement decl; > 88 alias genEast!ExprStatement expr; > 89 alias genEast!VarExpression var; > 90 alias genEast!FuncallExpression funcall; > 91 alias genEast!IntLiteralExpression intl; > 92 alias genEast!StrLiteralExpression strl; > 93 alias genEast!FunLiteralExpression fun; 85 } 94 }