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); }
//関数呼び出し。 private Node CallFunction(SymbolNode symbol) { Node f = symbol.eval(); if(!(f is FunctionNode)){ throw new UnexpectedException(tokenType,"not paren"); } FunctionNode func = (FunctionNode)f; ArgumentsNode args = (ArgumentsNode)ParseArguments(); return func.call(args); }
private SymbolNode ParseSymbol() { SymbolNode node = new SymbolNode((string)lex.Value); node.Block = Block; GetToken(); return node; }
//数値とか、文字列とか、一番最初にパースされるもの //もしくはカッコの中。 private Node ParseFirst() { ShowDebugMessage("ParseFirst"); Node node = null; switch(tokenType){ case TokenType.Number: node = new NumberNode((decimal)lex.Value); GetToken(); break; case TokenType.String: node = new StringNode((string)lex.Value); GetToken(); break; case TokenType.Symbol: node = new SymbolNode((string)lex.Value); node.Block = Block; GetToken(); if(tokenType == TokenType.OpenParen){ node = CallFunction((SymbolNode)node); } break; case TokenType.Define: GetToken (); node = DefineFunction(); break; case TokenType.If: GetToken(); node = ParseIf(); break; case TokenType.While: GetToken(); node = ParseWhile(); break; case TokenType.OpenBrace: GetToken(); node = ParseBlock(); break; case TokenType.OpenParen: GetToken(); node = ParseParentheses(); break; default: break; } if(tokenType==TokenType.Dot){ GetToken(); node = ParseMethod(node); } return node; }