Files
otyaSMILEBASIC/SMILEBASIC/node.d
T

87 lines
1.5 KiB
D
Raw Normal View History

2015-06-03 19:51:42 +09:00
module otya.smilebasic.node;
import otya.smilebasic.type;
import otya.smilebasic.token;
2015-06-03 21:52:09 +09:00
import std.container;
2015-06-03 19:51:42 +09:00
enum NodeType
{
Node,
2015-06-03 19:51:42 +09:00
Expression,
Constant,
BinaryOperator,
2015-06-03 21:52:09 +09:00
Variable,
CallFunction,
VoidExpression,
2015-06-03 19:51:42 +09:00
}
abstract class Node
{
NodeType type;
}
abstract class Expression : Node
{
}
class Constant : Expression
{
Value value;
this(Value v)
{
this.type = NodeType.Constant;
2015-06-03 19:51:42 +09:00
this.value = v;
}
}
class BinaryOperator : Expression
{
Expression item1;
TokenType operator;
Expression item2;
2015-06-03 21:12:00 +09:00
this(BinaryOperator bop)
{
this.type = NodeType.BinaryOperator;
this.item1 = bop.item1;
this.operator = bop.operator;
this.item2 = bop.item2;
}
this(Expression i1)
{
this.type = NodeType.BinaryOperator;
this.item1 = i1;
}
2015-06-03 19:51:42 +09:00
this(Expression i1, TokenType o, Expression i2)
{
this.type = NodeType.BinaryOperator;
this.item1 = i1;
this.operator = o;
this.item2 = i2;
}
}
2015-06-03 21:52:09 +09:00
class Variable : Expression
{
wstring name;
this(wstring n)
{
this.type = NodeType.Variable;
this.name = n;
}
}
class CallFunction : Expression
{
wstring name;
Expression[] args;
this(wstring n)
{
this.type = NodeType.CallFunction;
this.name = n;
args = new Expression[0];
}
void addArg(Expression arg)
{
args ~= arg;
}
}
class VoidExpression : Expression
{
this()
{
this.type = NodeType.VoidExpression;
}
}