8de5b49cdf 2010-11-09 kinaba: /** 4198578702 2010-11-07 kinaba: * Authors: k.inaba 4198578702 2010-11-07 kinaba: * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4198578702 2010-11-07 kinaba: * 4198578702 2010-11-07 kinaba: * Syntax tree for Polemy programming language. 423f308350 2010-11-07 kinaba: */ 4198578702 2010-11-07 kinaba: module polemy.ast; 4198578702 2010-11-07 kinaba: import polemy._common; 3464a035ec 2010-11-20 kinaba: import polemy.failure; 3995a5eb6a 2010-11-21 kinaba: import polemy.layer; 423f308350 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: abstract class AST 423f308350 2010-11-07 kinaba: { 2bdfb8a182 2010-11-21 kinaba: LexPosition pos; b97bd4f713 2010-11-23 kinaba: 423f308350 2010-11-07 kinaba: mixin SimpleConstructor; 3995a5eb6a 2010-11-21 kinaba: } 3995a5eb6a 2010-11-21 kinaba: 3995a5eb6a 2010-11-21 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class Int : AST 3995a5eb6a 2010-11-21 kinaba: { 3995a5eb6a 2010-11-21 kinaba: BigInt data; b97bd4f713 2010-11-23 kinaba: 3995a5eb6a 2010-11-21 kinaba: mixin SimpleClass; 3995a5eb6a 2010-11-21 kinaba: this(LexPosition pos, int n) {super(pos); data = n;} 3995a5eb6a 2010-11-21 kinaba: this(LexPosition pos, long n) {super(pos); data = n;} 3995a5eb6a 2010-11-21 kinaba: this(LexPosition pos, BigInt n) {super(pos); data = n;} 3995a5eb6a 2010-11-21 kinaba: this(LexPosition pos, string n) {super(pos); data = BigInt(n);} 3995a5eb6a 2010-11-21 kinaba: } 3995a5eb6a 2010-11-21 kinaba: 3995a5eb6a 2010-11-21 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class Str : AST 3995a5eb6a 2010-11-21 kinaba: { 3995a5eb6a 2010-11-21 kinaba: string data; b97bd4f713 2010-11-23 kinaba: 6ac127ddd0 2010-11-23 kinaba: mixin SimpleClass; 6ac127ddd0 2010-11-23 kinaba: } 6ac127ddd0 2010-11-23 kinaba: 6ac127ddd0 2010-11-23 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class Var : AST 6ac127ddd0 2010-11-23 kinaba: { 6ac127ddd0 2010-11-23 kinaba: string name; b97bd4f713 2010-11-23 kinaba: 2bdfb8a182 2010-11-21 kinaba: mixin SimpleClass; 8e6fa743ee 2010-11-11 kinaba: } 8e6fa743ee 2010-11-11 kinaba: 8e6fa743ee 2010-11-11 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class Lay : AST 8e6fa743ee 2010-11-11 kinaba: { 6ac127ddd0 2010-11-23 kinaba: Layer layer; 6ac127ddd0 2010-11-23 kinaba: AST expr; b97bd4f713 2010-11-23 kinaba: aa770610d3 2010-11-08 kinaba: mixin SimpleClass; 8e6fa743ee 2010-11-11 kinaba: } 8e6fa743ee 2010-11-11 kinaba: 8e6fa743ee 2010-11-11 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class Let : AST 8e6fa743ee 2010-11-11 kinaba: { 3995a5eb6a 2010-11-21 kinaba: string name; 3995a5eb6a 2010-11-21 kinaba: Layer layer; 3995a5eb6a 2010-11-21 kinaba: AST init; 2bdfb8a182 2010-11-21 kinaba: AST expr; b97bd4f713 2010-11-23 kinaba: 8e6fa743ee 2010-11-11 kinaba: mixin SimpleClass; 3f5dc76a75 2010-11-07 kinaba: } 3f5dc76a75 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class App : AST 3f5dc76a75 2010-11-07 kinaba: { 8e6fa743ee 2010-11-11 kinaba: AST fun; 8e6fa743ee 2010-11-11 kinaba: AST[] args; b97bd4f713 2010-11-23 kinaba: 38fcc662be 2010-11-10 kinaba: mixin SimpleClass; b97bd4f713 2010-11-23 kinaba: this(LexPosition pos, AST fun, AST[] args...) { super(pos); this.fun=fun; this.args=args.dup; } 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: /// 8e6fa743ee 2010-11-11 kinaba: class Parameter 38fcc662be 2010-11-10 kinaba: { 3995a5eb6a 2010-11-21 kinaba: string name; 3995a5eb6a 2010-11-21 kinaba: Layer[] layers; b97bd4f713 2010-11-23 kinaba: 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// 6ac127ddd0 2010-11-23 kinaba: class Fun : AST 423f308350 2010-11-07 kinaba: { 8e6fa743ee 2010-11-11 kinaba: Parameter[] params; 8e6fa743ee 2010-11-11 kinaba: AST funbody; b97bd4f713 2010-11-23 kinaba: 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 80ff567c75 2010-11-08 kinaba: /// Handy Generator for AST nodes. To use this, mixin EasyAst; 80ff567c75 2010-11-08 kinaba: 80ff567c75 2010-11-08 kinaba: /*mixin*/ b985f3bf91 2010-11-08 kinaba: template EasyAST() 423f308350 2010-11-07 kinaba: { 38fcc662be 2010-11-10 kinaba: /// 80ff567c75 2010-11-08 kinaba: template genEast(T) 80ff567c75 2010-11-08 kinaba: { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } } 80ff567c75 2010-11-08 kinaba: 6ac127ddd0 2010-11-23 kinaba: alias genEast!Str strl; /// 6ac127ddd0 2010-11-23 kinaba: alias genEast!Int intl; /// 8e6fa743ee 2010-11-11 kinaba: auto fun(string[] xs, AST ps) { 6ac127ddd0 2010-11-23 kinaba: return genEast!Fun(array(map!((string x){return new Parameter(x,[]);})(xs)),ps); } 6ac127ddd0 2010-11-23 kinaba: auto funp(Parameter[] xs, AST ps) { return genEast!Fun(xs,ps); } /// 6ac127ddd0 2010-11-23 kinaba: alias genEast!Var var; /// 6ac127ddd0 2010-11-23 kinaba: alias genEast!Lay lay; /// 6ac127ddd0 2010-11-23 kinaba: alias genEast!Let let; /// 6ac127ddd0 2010-11-23 kinaba: alias genEast!App call; /// a7b5d1d95a 2010-11-12 kinaba: auto param(string name, string[] lay...) { return new Parameter(name, lay); } /// 423f308350 2010-11-07 kinaba: }