/// <summary> /// INCLUDEのチェックとINCLUDEの実行。 /// </summary> private void Include() { // INCLUDEのチェック tokens.MoveTop(); NakoToken previousToken = tokens.CurrentToken; for (; !tokens.IsEOF(); tokens.MoveNext()) { // TOKENを挿入 if (tokens.CurrentTokenType == NakoTokenType.INCLUDE) { string filename = previousToken.Value; string source = File.ReadAllText(filename); NakoToken currentToken = tokens.CurrentToken; int index = tokens.IndexOf(currentToken); NakoTokenList includedTokens = new NakoTokenizer().Tokenize(source, this.tokenDic); int insertIndex = index; foreach (NakoToken tok in includedTokens) { insertIndex++; tokens.Insert(insertIndex, tok); } tokens.Remove(previousToken); tokens.Remove(currentToken); } previousToken = tokens.CurrentToken; } }
/// <summary> /// 予約語のチェックと代入文への変換作業を行います。 /// </summary> private void CheckWord() { // 予約語句のチェックなど tokens.MoveTop(); for (; !tokens.IsEOF(); tokens.MoveNext()) { // 予約語句の置き換え if (tokens.CurrentTokenType == NakoTokenType.WORD) { var token = tokens.CurrentToken; string key = token.GetValueAsName(); if (tokenDic.ContainsKey(token.GetValueAsName())) { token.Type = tokenDic [key]; } else if (tokenDic.MayBeFunction(token.Value)) { tokens.Save(); StringBuilder tmp = new StringBuilder(); int indexFrom = tokens.IndexOf(token); while (!tokens.IsEOF()) { token = tokens.CurrentToken; tmp.Append(token.Value); if (tokenDic.IsFunction(tmp.ToString())) { NakoToken funcToken = new NakoToken(NakoTokenType.FUNCTION_NAME); funcToken.Josi = token.Josi; funcToken.Value = tmp.ToString(); int indexTo = tokens.IndexOf(token); for (int i = indexTo; i >= indexFrom; i--) { tokens.RemoveAt(i); } tokens.Insert(indexFrom, funcToken); break; } else if (!tokenDic.MayBeFunction(tmp.ToString())) { tokens.Restore(); break; } tmp.Append(token.Josi); tokens.MoveNext(); } if (tokens.IsEOF()) { return; } } } // 助詞が「は」ならば、代入文に変える if (tokens.CurrentToken.Josi == "は") { tokens.CurrentToken.Josi = ""; tokens.InsertAfterCurrentToken(new NakoToken(NakoTokenType.EQ)); } // コメントならばトークンから取り除く if (tokens.CurrentTokenType == NakoTokenType.COMMENT) { tokens.RemoveCurrentToken(); continue; } } }