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: 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; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 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; 80ff567c75 2010-11-08 kinaba: } 80ff567c75 2010-11-08 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: b985f3bf91 2010-11-08 kinaba: class VarExpression : AST 423f308350 2010-11-07 kinaba: { 80ff567c75 2010-11-08 kinaba: string var; 8de5b49cdf 2010-11-09 kinaba: mixin SimpleClass; 8de5b49cdf 2010-11-09 kinaba: } 8de5b49cdf 2010-11-09 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: 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; 3f5dc76a75 2010-11-07 kinaba: } 3f5dc76a75 2010-11-07 kinaba: b985f3bf91 2010-11-08 kinaba: class FuncallExpression : AST 3f5dc76a75 2010-11-07 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: b985f3bf91 2010-11-08 kinaba: class FunLiteral : AST 3f5dc76a75 2010-11-07 kinaba: { 80ff567c75 2010-11-08 kinaba: string[] params; b985f3bf91 2010-11-08 kinaba: AST funbody; 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: { 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: b985f3bf91 2010-11-08 kinaba: alias genEast!StrLiteral strl; b985f3bf91 2010-11-08 kinaba: alias genEast!IntLiteral intl; aa770610d3 2010-11-08 kinaba: auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } // to help type inference of D 80ff567c75 2010-11-08 kinaba: alias genEast!VarExpression var; dc93ad8cf6 2010-11-09 kinaba: alias genEast!LayeredExpression lay; b985f3bf91 2010-11-08 kinaba: alias genEast!LetExpression let; b985f3bf91 2010-11-08 kinaba: alias genEast!FuncallExpression call; 423f308350 2010-11-07 kinaba: }