Artifact c08643c4271f8f35712cc4cb5eba47ea4bc1aed7
/**
* Authors: k.inaba
* License: NYSL 0.9982 http://www.kmonos.net/nysl/
*
* Syntax tree for Polemy programming language.
*/
module polemy.ast;
import polemy._common;
import polemy.lex;
abstract class AST
{
immutable LexPosition pos;
mixin SimpleConstructor;
}
class StrLiteral : AST
{
string data;
mixin SimpleClass;
}
class IntLiteral : AST
{
BigInt data;
mixin SimpleClass;
this(immutable LexPosition pos, long n) {super(pos); data = n;}
this(immutable LexPosition pos, BigInt n) {super(pos); data = n;}
this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n);}
}
class VarExpression : AST
{
string var;
mixin SimpleClass;
}
class LetExpression : AST
{
string var;
string layer;
AST init;
AST expr;
mixin SimpleClass;
}
class FuncallExpression : AST
{
AST fun;
AST[] args;
this(immutable LexPosition pos, AST fun, AST[] args...)
{ super(pos); this.fun=fun; this.args=args.dup; }
mixin SimpleClass;
}
class FunLiteral : AST
{
string[] params;
AST funbody;
mixin SimpleClass;
}
/// Handy Generator for AST nodes. To use this, mixin EasyAst;
/*mixin*/
template EasyAST()
{
template genEast(T)
{ T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } }
alias genEast!StrLiteral strl;
alias genEast!IntLiteral intl;
auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } // to help type inference of D
alias genEast!VarExpression var;
alias genEast!LetExpression let;
alias genEast!FuncallExpression call;
}