Beispiel #1
0
        public override GrassFunc Clone()
        {
            GrassFunc newFunc = new GrassMyFunc(_ArgNumberMax, _CurrentArgNumber, _SentenceList);

            newFunc.CopyFuncStack(_FuncStack);
            return(newFunc);
        }
Beispiel #2
0
        protected override GrassFunc Curry(GrassFunc func)
        {
            GrassMyFunc newFunc = new GrassMyFunc(_ArgNumberMax, _CurrentArgNumber + 1, _SentenceList);

            newFunc.CopyFuncStack(_FuncStack);
            newFunc.Push(func);
            return(newFunc);
        }
Beispiel #3
0
 protected override GrassFunc Curry(GrassFunc func)
 {
     GrassMyFunc newFunc = new GrassMyFunc(_ArgNumberMax, _CurrentArgNumber + 1, _SentenceList);
     newFunc.CopyFuncStack(_FuncStack);
     newFunc.Push(func);
     return newFunc;
 }
Beispiel #4
0
 public override GrassFunc Clone()
 {
     GrassFunc newFunc = new GrassMyFunc(_ArgNumberMax, _CurrentArgNumber, _SentenceList);
     newFunc.CopyFuncStack(_FuncStack);
     return newFunc;
 }
Beispiel #5
0
 /// <summary>
 /// 連続トークンを読み取り、解釈し、関数を定義/適用する
 /// </summary>
 /// <param name="tokenWithCountList"></param>
 /// <returns>関数の定義/適用結果リスト</returns>
 /// <exception cref="GllException">パースに失敗</exception>
 private static InterpretResult InterpretFromTokenWithCounts(Stack<GrassFunc> initStack, 
     IEnumerable<TokenWithCount> tokenWithCountList)
 {
     bool isLoopEnd = false;
     var localFuncStack = new Stack<GrassFunc>();
     try
     {
         //残りのトークンリスト
         var tokenWithCounts = tokenWithCountList.Where(twc => twc.Token != Token.None).ToArray();
         for(int index = 0; !isLoopEnd && index < tokenWithCounts.Length; index++)
         {
             //行の先頭トークン
             var headTokenCount = tokenWithCounts[index];
             switch (headTokenCount.Token)
             {
                 case Token.LCW:
                     {
                         #region 関数定義部(ww..WW..ww..)
                         GrassMyFunc currentFunc = new GrassMyFunc(headTokenCount.Count);
                         while (true)
                         {
                             //2つ取り出す
                             index++;
                             var firstTokenCount = tokenWithCounts[index];
                             if (firstTokenCount.Token == Token.UCW)
                             {
                                 index++;
                                 var secondTokenCount = tokenWithCounts[index];
                                 if (secondTokenCount.Token == Token.LCW)
                                 {
                                     currentFunc.AddSentence(new Sentence()
                                     {
                                         CountUpperCaseW = firstTokenCount.Count,
                                         CountLowerCaseW = secondTokenCount.Count,
                                     });
                                 }
                                 else
                                 {
                                     throw new GllArgumentNotFoundException("関数定義じゃねーの?");
                                 }
                             }
                             else if (firstTokenCount.Token == Token.V || firstTokenCount.Token == Token.EOS)
                             {
                                 currentFunc.CopyFuncStack(initStack);
                                 currentFunc.CopyFuncStack(localFuncStack);
                                 localFuncStack.Push(currentFunc);
                                 break;
                             }
                             else // Token.LCW
                             {
                                 throw new GllDisableTokenException(
                                     "ヤダナー。LCWの後にLCWとか、そんな入力来るわけないじゃないですかー。そんなん引数が悪いっすわー");
                             }
                         }
                         #endregion
                         break;
                     }
                 case Token.UCW:
                     {
                         #region 関数適用部(WW..ww..)
                         //1つ取り出す
                         index++;
                         var firstTokenCount = tokenWithCounts[index];
                         if (firstTokenCount.Token == Token.LCW)
                         {
                             int funcCount = headTokenCount.Count - 1;
                             GrassFunc func = localFuncStack.Count > funcCount ?
                                 localFuncStack.Get(funcCount) :
                                 initStack.Get(funcCount - localFuncStack.Count);
                             int argCount = firstTokenCount.Count - 1;
                             GrassFunc arg = localFuncStack.Count > argCount ?
                                 localFuncStack.Get(argCount) :
                                 initStack.Get(argCount - localFuncStack.Count);
                             localFuncStack.Push(func.Apply(arg));
                         }
                         else
                         {
                             throw new GllArgumentNotFoundException("関数適用じゃねーの?");
                         }
                         #endregion
                         break;
                     }
                 case Token.V:
                     break;
                 case Token.EOS:
                     isLoopEnd = true;
                     break;
                 case Token.None:
                 default:
                     throw new GllDisableTokenException("バカな・・・そのトークンは存在しないはずだ・・・");
             }
         }
         return new InterpretResult(true, localFuncStack.Reverse());//関数のリスト
     }
     catch (GllException)
     {
         return new InterpretResult(false, localFuncStack.Reverse());//致命的でない場合、失敗しても途中経過の関数リストを返す
     }
 }