Artifact f03af1208bc8c4340244f99c7e3f6f054dc2fcc5
/**
* 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;
alias Statement[] Program;
abstract class Statement
{
immutable LexPosition pos;
mixin SimpleConstructor;
}
class DeclStatement : Statement
{
string var;
Expression expr;
mixin SimpleClass;
}
class ExprStatement : Statement
{
Expression expr;
mixin SimpleClass;
}
abstract class Expression
{
immutable LexPosition pos;
mixin SimpleConstructor;
}
class StrLiteralExpression : Expression
{
string data;
mixin SimpleClass;
}
class IntLiteralExpression : Expression
{
BigInt data;
mixin SimpleClass;
}
class VarExpression : Expression
{
string var;
mixin SimpleClass;
}
class AssignExpression : Expression
{
Expression lhs;
Expression rhs;
mixin SimpleClass;
}
class FuncallExpression : Expression
{
Expression fun;
Expression[] args;
this(immutable LexPosition pos, Expression fun, Expression[] args...)
{ super(pos); this.fun=fun; this.args=args.dup; }
mixin SimpleClass;
}
class FunLiteralExpression : Expression
{
string[] params;
Program 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!DeclStatement decl;
alias genEast!ExprStatement expr;
alias genEast!VarExpression var;
alias genEast!FuncallExpression funcall;
alias genEast!IntLiteralExpression intl;
alias genEast!StrLiteralExpression strl;
alias genEast!FunLiteralExpression fun;
}