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: { 16abe21957 2010-11-24 kinaba: LexPosition pos; /// b97bd4f713 2010-11-23 kinaba: 423f308350 2010-11-07 kinaba: mixin SimpleConstructor; f9c31f3cd8 2010-11-24 kinaba: invariant(){ assert(pos !is null);} 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 16abe21957 2010-11-24 kinaba: /// AST node for integer literal 6ac127ddd0 2010-11-23 kinaba: class Int : AST 3995a5eb6a 2010-11-21 kinaba: { 16abe21957 2010-11-24 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: 16abe21957 2010-11-24 kinaba: /// AST node for string literal 6ac127ddd0 2010-11-23 kinaba: class Str : AST 6ac127ddd0 2010-11-23 kinaba: { 16abe21957 2010-11-24 kinaba: string data; /// 16abe21957 2010-11-24 kinaba: 16abe21957 2010-11-24 kinaba: mixin SimpleClass; 16abe21957 2010-11-24 kinaba: } 16abe21957 2010-11-24 kinaba: 16abe21957 2010-11-24 kinaba: /// AST node for variable reference 16abe21957 2010-11-24 kinaba: class Var : AST 16abe21957 2010-11-24 kinaba: { 16abe21957 2010-11-24 kinaba: string name; /// b97bd4f713 2010-11-23 kinaba: 1c01f44f52 2010-11-13 kinaba: mixin SimpleClass; 1c01f44f52 2010-11-13 kinaba: } 1c01f44f52 2010-11-13 kinaba: 16abe21957 2010-11-24 kinaba: /// AST node for @layered(expression) 16abe21957 2010-11-24 kinaba: class Lay : AST 8e6fa743ee 2010-11-11 kinaba: { 16abe21957 2010-11-24 kinaba: Layer layer; /// 16abe21957 2010-11-24 kinaba: AST expr; /// b97bd4f713 2010-11-23 kinaba: 8e6fa743ee 2010-11-11 kinaba: mixin SimpleClass; 8e6fa743ee 2010-11-11 kinaba: } 8e6fa743ee 2010-11-11 kinaba: 16abe21957 2010-11-24 kinaba: /// AST node for variable declaration 16abe21957 2010-11-24 kinaba: class Let : AST aa770610d3 2010-11-08 kinaba: { 16abe21957 2010-11-24 kinaba: string name; /// 16abe21957 2010-11-24 kinaba: Layer layer; /// 16abe21957 2010-11-24 kinaba: AST init; /// 16abe21957 2010-11-24 kinaba: AST expr; /// b97bd4f713 2010-11-23 kinaba: aa770610d3 2010-11-08 kinaba: mixin SimpleClass; aa770610d3 2010-11-08 kinaba: } aa770610d3 2010-11-08 kinaba: 16abe21957 2010-11-24 kinaba: /// AST node for function application 6ac127ddd0 2010-11-23 kinaba: class App : AST aa770610d3 2010-11-08 kinaba: { 16abe21957 2010-11-24 kinaba: AST fun; /// 16abe21957 2010-11-24 kinaba: AST[] args; /// b97bd4f713 2010-11-23 kinaba: aa770610d3 2010-11-08 kinaba: mixin SimpleClass; b97bd4f713 2010-11-23 kinaba: this(LexPosition pos, AST fun, AST[] args...) { super(pos); this.fun=fun; this.args=args.dup; } aa770610d3 2010-11-08 kinaba: } aa770610d3 2010-11-08 kinaba: 38fcc662be 2010-11-10 kinaba: /// 8e6fa743ee 2010-11-11 kinaba: class Parameter 8e6fa743ee 2010-11-11 kinaba: { 16abe21957 2010-11-24 kinaba: string name; /// 16abe21957 2010-11-24 kinaba: Layer[] layers; /// 16abe21957 2010-11-24 kinaba: 16abe21957 2010-11-24 kinaba: mixin SimpleClass; 16abe21957 2010-11-24 kinaba: } 16abe21957 2010-11-24 kinaba: 16abe21957 2010-11-24 kinaba: /// AST node for function literal 16abe21957 2010-11-24 kinaba: class Fun : AST 16abe21957 2010-11-24 kinaba: { 16abe21957 2010-11-24 kinaba: Parameter[] params; /// 16abe21957 2010-11-24 kinaba: AST funbody; /// 2134cd44cc 2010-11-23 kinaba: 2134cd44cc 2010-11-23 kinaba: mixin SimpleClass; 2134cd44cc 2010-11-23 kinaba: } b97bd4f713 2010-11-23 kinaba: f7e9e77316 2010-11-26 kinaba: /// AST node for deadend f7e9e77316 2010-11-26 kinaba: class Die : AST f7e9e77316 2010-11-26 kinaba: { f7e9e77316 2010-11-26 kinaba: mixin SimpleClass; f7e9e77316 2010-11-26 kinaba: } f7e9e77316 2010-11-26 kinaba: 2134cd44cc 2010-11-23 kinaba: /// List of AST Types b97bd4f713 2010-11-23 kinaba: f7e9e77316 2010-11-26 kinaba: alias TypeTuple!(Int,Str,Var,Lay,Let,App,Fun,Die) ListOfASTTypes; 80ff567c75 2010-11-08 kinaba: 80ff567c75 2010-11-08 kinaba: /// Handy Generator for AST nodes. To use this, mixin EasyAst; 3f5dc76a75 2010-11-07 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); } } 3f5dc76a75 2010-11-07 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); } /// f7e9e77316 2010-11-26 kinaba: alias genEast!Die dieast; /// 423f308350 2010-11-07 kinaba: }