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; 80ff567c75 2010-11-08 kinaba: import polemy.lex; 423f308350 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: abstract class AST 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: immutable LexPosition pos; 423f308350 2010-11-07 kinaba: mixin SimpleConstructor; 1c01f44f52 2010-11-13 kinaba: mixin SimplePatternMatch; 80ff567c75 2010-11-08 kinaba: } 80ff567c75 2010-11-08 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: class StrLiteral : AST 80ff567c75 2010-11-08 kinaba: { 80ff567c75 2010-11-08 kinaba: string data; 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: class IntLiteral : AST 423f308350 2010-11-07 kinaba: { 80ff567c75 2010-11-08 kinaba: BigInt data; 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; b985f3bf91 2010-11-08 kinaba: this(immutable LexPosition pos, long n) {super(pos); data = n;} b985f3bf91 2010-11-08 kinaba: this(immutable LexPosition pos, BigInt n) {super(pos); data = n;} b985f3bf91 2010-11-08 kinaba: this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n);} 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: class VarExpression : AST 423f308350 2010-11-07 kinaba: { 80ff567c75 2010-11-08 kinaba: string var; b985f3bf91 2010-11-08 kinaba: mixin SimpleClass; b985f3bf91 2010-11-08 kinaba: } b985f3bf91 2010-11-08 kinaba: 38fcc662be 2010-11-10 kinaba: /// dc93ad8cf6 2010-11-09 kinaba: class LayeredExpression : AST dc93ad8cf6 2010-11-09 kinaba: { dc93ad8cf6 2010-11-09 kinaba: string lay; dc93ad8cf6 2010-11-09 kinaba: AST expr; dc93ad8cf6 2010-11-09 kinaba: mixin SimpleClass; dc93ad8cf6 2010-11-09 kinaba: } dc93ad8cf6 2010-11-09 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: class LetExpression : AST 423f308350 2010-11-07 kinaba: { b985f3bf91 2010-11-08 kinaba: string var; aa770610d3 2010-11-08 kinaba: string layer; b985f3bf91 2010-11-08 kinaba: AST init; b985f3bf91 2010-11-08 kinaba: AST expr; 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; 80ff567c75 2010-11-08 kinaba: } 80ff567c75 2010-11-08 kinaba: 38fcc662be 2010-11-10 kinaba: /// b985f3bf91 2010-11-08 kinaba: class FuncallExpression : AST 80ff567c75 2010-11-08 kinaba: { b985f3bf91 2010-11-08 kinaba: AST fun; b985f3bf91 2010-11-08 kinaba: AST[] args; b985f3bf91 2010-11-08 kinaba: this(immutable LexPosition pos, AST fun, AST[] args...) 80ff567c75 2010-11-08 kinaba: { super(pos); this.fun=fun; this.args=args.dup; } 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; 3f5dc76a75 2010-11-07 kinaba: } 3f5dc76a75 2010-11-07 kinaba: 38fcc662be 2010-11-10 kinaba: /// 8e6fa743ee 2010-11-11 kinaba: class Parameter 8e6fa743ee 2010-11-11 kinaba: { 8e6fa743ee 2010-11-11 kinaba: string name; 8e6fa743ee 2010-11-11 kinaba: string[] layers; 8e6fa743ee 2010-11-11 kinaba: mixin SimpleClass; 8e6fa743ee 2010-11-11 kinaba: } 8e6fa743ee 2010-11-11 kinaba: 8e6fa743ee 2010-11-11 kinaba: /// b985f3bf91 2010-11-08 kinaba: class FunLiteral : AST 3f5dc76a75 2010-11-07 kinaba: { 8e6fa743ee 2010-11-11 kinaba: Parameter[] params; 8e6fa743ee 2010-11-11 kinaba: AST funbody; 80ff567c75 2010-11-08 kinaba: mixin SimpleClass; 3f5dc76a75 2010-11-07 kinaba: } 3f5dc76a75 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() 3f5dc76a75 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: 38fcc662be 2010-11-10 kinaba: alias genEast!StrLiteral strl; /// 38fcc662be 2010-11-10 kinaba: alias genEast!IntLiteral intl; /// 8e6fa743ee 2010-11-11 kinaba: auto fun(string[] xs, AST ps) { 8e6fa743ee 2010-11-11 kinaba: return genEast!FunLiteral(array(map!((string x){return new Parameter(x,[]);})(xs)),ps); } 8e6fa743ee 2010-11-11 kinaba: auto funp(Parameter[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } /// 38fcc662be 2010-11-10 kinaba: alias genEast!VarExpression var; /// 38fcc662be 2010-11-10 kinaba: alias genEast!LayeredExpression lay; /// 38fcc662be 2010-11-10 kinaba: alias genEast!LetExpression let; /// 38fcc662be 2010-11-10 kinaba: alias genEast!FuncallExpression call; /// a7b5d1d95a 2010-11-12 kinaba: auto param(string name, string[] lay...) { return new Parameter(name, lay); } /// 423f308350 2010-11-07 kinaba: }