public FunctionNode(Node name,Node paraNode,Node func) : base() { this.name = (SymbolNode)name; this.paraNode = (ParametersNode)paraNode; this.func = (BlockNode)func; this.paraNode.SetBlock(this.func); }
//messageを受け取る。 public Node recv_message(Node recv,string message) { if(recv==null){ return GetSlot(message)(null); }else{ return GetSlot(message)(recv); } }
public Node div(Node node) { Node n = node.eval(); if(!(node is NumberNode)){ throw new Exception("Right is not Number"); } return new NumberNode(Value/(((NumberNode)n).Value)); }
public void Set(string str,Node n) { if(existName(str)){ SetSub(str,n); }else{ Name[str] = n; } }
public Node plus(Node node) { Node n = node.eval(); if(!(node is StringNode)){ throw new UmiException("Right is not String"); } return new StringNode(Value+(((StringNode)n).Value)); }
public Node equal(Node node) { if(node is TrueNode){ return new TrueNode(); }else if(node is FalseNode){ return new FalseNode(); }else{ throw new UmiException("Right is not boolean"); } }
public Node call(Node node) { ArgumentsNode argsNode = (ArgumentsNode)node; if(argsNode.Length != paraNode.Length){ throw new UmiException("Call failed because of args'length"); } for(int i=0;i<argsNode.Length;i++){ paraNode[i].assign(argsNode[i].eval()); } return func.eval(); }
public Node greaterequal(Node node) { Node n = node.eval(); if(!(node is NumberNode)){ throw new Exception("Right is not Number"); } if(((NumberNode)n).Value <= this.Value){ return new TrueNode(); }else{ return new FalseNode(); } }
public Node print(Node node) { if(node is ArgumentsNode){ Node s = null; for(int i=0;i<((ArgumentsNode)node).Length;i++){ s = send_message((((ArgumentsNode)node)[i]).eval(),null,"to_s"); Console.WriteLine(((StringNode)s).Value); } return s; }else{ Node s = send_message(node.eval(),null,"to_s"); Console.WriteLine(((StringNode)s).Value); return s; } return null; }
public override Node to_s(Node node) { return new StringNode(Value.ToString()); }
public Node positive(Node node) { return new NumberNode(1*Value); }
private Node ParseAssignment2(Node node) { TokenType op_type = tokenType; GetToken(); Node right = ParseExpression(); Node op = new AssignNode(node,right,op_type); return op; }
public PositiveNode(Node node) { this.node = node; }
public override Node to_s(Node node) { return new StringNode(name); }
public virtual Node to_s(Node node) { return new StringNode("Node"); }
public AssignNode(Node left,Node right,TokenType op_type) { Right = right; Left = left; OPType = op_type; }
public ElifNode(Node boolean,Node TrueBlock) { this.boolean = boolean; this.TrueBlock = TrueBlock; excuted = false; }
public CompareNode(Node left,Node right,TokenType op_type) { Left = left; Right = right; OPType = op_type; }
private Node ParseMethod(Node node) { SymbolNode name = ParseSymbol(); Node argnode = ParseArguments(); return new MethodNode(node,argnode,name.Name); }
private Node ParseComparison2(Node node) { TokenType op_type = tokenType; GetToken(); Node right = ParseAdditiveExpression(); Node compNode = new CompareNode(node,right,op_type); return compNode; }
public Node assign(Node node) { Node n = node.eval(); Block.Set(name,n); return n; }
public void Add(Node n) { ChildNodes.Add(n); }
public Node defineFunc(Node node) { Block.Set(name,node); return node; }
public override Node to_s(Node node) { return new StringNode("true"); }
public MethodNode(Node node,Node x,string message) { this.node = node; this.x = x; this.message = message; }
public Node negative(Node node) { return new NumberNode(-1*Value); }
//send_messageは、senderのGetSlot(message)した関数にrecvを渡して実行する。 //これはSmallTalkのオブジェクト指向。 public Node send_message(Node sender,Node recv,string message) { return sender.recv_message(recv,message); }
public Node not(Node n) { return new TrueNode(); }
//実引数を追加。 public void Add(Node n) { arguments.Add(n); }
public Node not(Node n) { return new FalseNode(); }