Artifact Content
Not logged in

Artifact c08643c4271f8f35712cc4cb5eba47ea4bc1aed7


     1  /**
     2   * Authors: k.inaba
     3   * License: NYSL 0.9982 http://www.kmonos.net/nysl/
     4   *
     5   * Syntax tree for Polemy programming language.
     6   */
     7  module polemy.ast;
     8  import polemy._common;
     9  import polemy.lex;
    10  
    11  abstract class AST
    12  {
    13  	immutable LexPosition pos;
    14  	mixin SimpleConstructor;
    15  }
    16  
    17  class StrLiteral : AST
    18  {
    19  	string data;
    20  	mixin SimpleClass;
    21  }
    22  
    23  class IntLiteral : AST
    24  {
    25  	BigInt data;
    26  	mixin SimpleClass;
    27  	this(immutable LexPosition pos, long n) {super(pos); data = n;}
    28  	this(immutable LexPosition pos, BigInt n) {super(pos); data = n;}
    29  	this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n);}
    30  }
    31  
    32  class VarExpression : AST
    33  {
    34  	string var;
    35  	mixin SimpleClass;
    36  }
    37  
    38  class LetExpression : AST
    39  {
    40  	string var;
    41  	string layer;
    42  	AST    init;
    43  	AST    expr;
    44  	mixin SimpleClass;
    45  }
    46  
    47  class FuncallExpression : AST
    48  {
    49  	AST   fun;
    50  	AST[] args;
    51  	this(immutable LexPosition pos, AST fun, AST[] args...)
    52  		{ super(pos); this.fun=fun; this.args=args.dup; }
    53  	mixin SimpleClass;
    54  }
    55  
    56  class FunLiteral : AST
    57  {
    58  	string[] params;
    59  	AST      funbody;
    60  	mixin SimpleClass;
    61  }
    62  
    63  /// Handy Generator for AST nodes. To use this, mixin EasyAst;
    64  
    65  /*mixin*/
    66  template EasyAST()
    67  {
    68  	template genEast(T)
    69  		{ T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } }
    70  
    71  	alias genEast!StrLiteral strl;
    72  	alias genEast!IntLiteral intl;
    73  	auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } // to help type inference of D
    74  	alias genEast!VarExpression var;
    75  	alias genEast!LetExpression let;
    76  	alias genEast!FuncallExpression call;
    77  }