/// <summary> /// コンストラクタ /// </summary> /// <param name="scope"></param> public NakoVariableManager(NakoVariableScope scope) { list = new List<NakoVariable>(); names = new Dictionary<string, int>(); if (scope == NakoVariableScope.Global) { // 変数「それ」を登録 NakoVariable sore = new NakoVariable(); sore.SetBody(0, NakoVarType.Int); list.Add(sore); names[NakoReservedWord.SORE] = 0; } }
//> _def_function : DEF_FUNCTION _def_function_args _scope //> ; private bool _def_function() { if (!Accept(NakoTokenType.DEF_FUNCTION)) return false; NakoToken t = tok.CurrentToken; tok.MoveNext(); // '*' NakoFunc userFunc = new NakoFunc(); userFunc.funcType = NakoFuncType.UserCall; // 引数 + 関数名の取得 _def_function_args(userFunc); // ブロックの取得 PushFrame(); NakoNodeDefFunction funcNode = new NakoNodeDefFunction(); funcNode.func = userFunc; parentNode = funcNode.funcBody = new NakoNode(); funcNode.RegistArgsToLocalVar(); localVar = funcNode.localVar; if (!_scope()) { throw new NakoParserException("関数定義中のエラー。", t); } PopFrame(); // グローバル変数に登録 NakoVariable v = new NakoVariable(); v.SetBody(funcNode, NakoVarType.UserFunc); globalVar.CreateVar(userFunc.name, v); // 関数の宣言は、ノードのトップ直下に追加する if (!this.topNode.hasChildren()) { this.topNode.AddChild(new NakoNode()); } this.topNode.Children.Insert(0, funcNode); return true; }
/// <summary> /// システムに登録する /// </summary> /// <param name="dic"></param> /// <param name="globalVar"></param> public void RegisterToSystem(NakoTokenDic dic, NakoVariableManager globalVar) { // --- 関数 // Tokenizer に登録 for (int i = 0; i < FuncList.Count; i++) { NakoAPIFunc call = FuncList[i]; if (!dic.ContainsKey(call.name)) { dic.Add(call.name, NakoTokenType.FUNCTION_NAME); } else { dic[call.name] = NakoTokenType.FUNCTION_NAME; } } // NakoVariables に登録 for (int i = 0; i < FuncList.Count; i++) { NakoVariable var = new NakoVariable(); var.SetBody(i, NakoVarType.SystemFunc); NakoAPIFunc call = FuncList[i]; globalVar.SetVar(call.name, var); } // --- 変数 foreach (string name in VarList.Keys) { NakoVariable var = new NakoVariable(); var.SetBodyAutoType(VarList[name]); globalVar.SetVar(name, var); } }