当前位置: 首页>>代码示例>>C#>>正文


C# Stack.Get方法代码示例

本文整理汇总了C#中Stack.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Get方法的具体用法?C# Stack.Get怎么用?C# Stack.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stack的用法示例。


在下文中一共展示了Stack.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Perform

 /// <summary>
 /// 実行
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 protected override GrassFunc Perform(GrassFunc arg)
 {
     //追加のローカルスタック
     Stack<GrassFunc> localStack = new Stack<GrassFunc>();
     localStack.Push(arg);
     foreach (var tuple in _SentenceList.Select((sentence, index) => new { sentence, index }))
     {
         if (tuple.sentence.CountUpperCaseW > tuple.index + 1 + _FuncStack.Count ||
             tuple.sentence.CountLowerCaseW > tuple.index + 1 + _FuncStack.Count)
         {
             System.Diagnostics.Debug.WriteLine("スタック内関数の指定は正常??");
         }
         GrassFunc funcApp = (tuple.sentence.CountUpperCaseW > tuple.index + 1) ?
             _FuncStack.Get(tuple.sentence.CountUpperCaseW - tuple.index - 2) :
             localStack.Get(tuple.sentence.CountUpperCaseW - 1);
         GrassFunc argApp = (tuple.sentence.CountLowerCaseW > tuple.index + 1) ?
             _FuncStack.Get(tuple.sentence.CountLowerCaseW - tuple.index - 2) :
             localStack.Get(tuple.sentence.CountLowerCaseW - 1);
         //GrassFunc func2 = (funcApp == argApp) ? funcApp.Clone() : funcApp;
         //localStack.Push(func2.Apply(argApp));
         localStack.Push(funcApp.Apply(argApp));
     }
     return localStack.Peek();
 }
开发者ID:nanayaT,项目名称:GllEditor,代码行数:29,代码来源:Function.cs

示例2: InterpretFromTokenWithCounts

 /// <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());//関数のリスト
     }
//.........这里部分代码省略.........
开发者ID:nanayaT,项目名称:GllEditor,代码行数:101,代码来源:Runner.cs


注:本文中的Stack.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。