예제 #1
0
 internal void Step(Stmt st)
 {
     /* switch ( CurrentToken.TokenName )
      * {
      *   case Lexer.Tokens.Function:
      *       //skip to end return;
      *
      *       break;
      *   case Lexer.Tokens.NewLine:
      *       break;
      *   case Lexer.Tokens.Set:
      *       Set();
      *       break;
      *   case Lexer.Tokens.Label:
      *
      *       break;
      *   case Lexer.Tokens.Goto: // todo scan forward for labels.
      *       CurrentIndex++;
      *       if ( CurrentToken.TokenName == Lexer.Tokens.StringLiteral )
      *           CurrentIndex = Labels[CurrentToken.TokenValue.ToLowerInvariant()];
      *       else
      *           throw new Exception( "Unhandled goto " + CurrentToken.TokenValue + " on line " + CurrentLine );
      *       break;
      *   case Lexer.Tokens.Event:
      *       CurrentIndex++;
      *       if ( CurrentToken.TokenValue == "macro" )
      *       {
      *           CurrentIndex++;
      *           EventMacro();
      *       }
      *       break;
      *   case Lexer.Tokens.Target:
      *       CurrentIndex++;
      *       if ( CurrentToken.TokenName == Lexer.Tokens.IntLiteral )
      *       {
      *           CurrentIndex++;
      *       }
      *       else
      *           while ( !Targeting.HasTarget ) Thread.Sleep( 55 );
      *
      *       break;
      *
      *   case Lexer.Tokens.Wait:
      *       CurrentIndex++;
      *       if ( CurrentToken.TokenName == Lexer.Tokens.IntLiteral )
      *       {
      *           Thread.Sleep( int.Parse( CurrentToken.TokenValue ) * 50 );
      *           CurrentIndex++;
      *       }
      *       else if ( CurrentToken.TokenName == Lexer.Tokens.StringLiteral )
      *       {
      *           Thread.Sleep( int.Parse( CurrentToken.TokenValue.TrimEnd( new char[] { 's' } ) ) * 1000 );
      *           CurrentIndex++;
      *       }
      *       else
      *       {
      *           Thread.Sleep( 1000 );
      *       }
      *
      *       break;
      *
      *   case Lexer.Tokens.If:
      *       ParseIF();
      *       break;
      *   case Lexer.Tokens.Else:
      *       ParseElse();
      *       break;
      *   case Lexer.Tokens.FindItem:
      *       ParseFindItem();
      *       break;
      *   case Lexer.Tokens.For:
      *       ParseFor();
      *       break;
      *   case Lexer.Tokens.Comment:
      *       break;
      *   default:
      *       Console.WriteLine( "Unhandled Token: " + CurrentToken.TokenName );
      *       break;
      * }
      * CurrentIndex++;*/
 }
예제 #2
0
        public void Statement()
        {
            if (CurrentBlock == null && CurrentStack == null)
            {
                CurrentBlock    = m_Statements[0] as Block;
                CurrentStack    = CurrentBlock.GetStack();
                CurrentStatment = CurrentStack.Pop();
            }


            if (CurrentStatment is Goto go)
            {
                HandleGoto(go);
            }
            else if (CurrentStatment is Call call)
            {
                HandleCall(call);
            }
            else if (CurrentStatment is Break)
            {
                //pop till we leave a loop TODO

                CurrentBlock    = BlockStack.Pop();
                CurrentStack    = OldStacks.Pop();
                CurrentStatment = CurrentStack.Pop();
            }
            else if (CurrentStatment is Return ret)
            {
                if (ret.expr != null)
                {
                    Setvariable("#result", ret.expr.GetValue());
                }
                //pop till we leave a Func TODO
                CurrentBlock    = BlockStack.Pop();
                CurrentStack    = OldStacks.Pop();
                CurrentStatment = CurrentStack.Pop();
            }
            else if (CurrentStatment is Continue)
            {
                CurrentStack    = CurrentBlock.GetStack();
                CurrentStatment = CurrentStack.Pop();
            }
            else if (CurrentStatment is Block block)
            {
                if (CurrentStatment.Execute())
                {
                    if (block is BaseLoopBlock loop)
                    {
                        CurrentStack.Push(block);
                    }
                    OldStacks.Push(CurrentStack);

                    BlockStack.Push(CurrentBlock);
                    CurrentBlock    = block;
                    CurrentStack    = CurrentBlock.GetStack();
                    CurrentStatment = CurrentStack.Pop();
                    //foreach ( var s in CurrentBlock.statements )
                    //    CurrentStack.Push( s );
                }
                else
                {
                    if (CurrentStack.Count > 0)
                    {
                        CurrentStatment = CurrentStack.Pop();
                    }
                    else
                    {
                        CurrentStatment = null;
                    }
                }
            }
            //DEBUG DONT EXECUTE STATEMENTS
            else if (CurrentStatment != null && CurrentStatment.Execute())
            {
                if (CurrentStack.Count > 0)
                {
                    CurrentStatment = CurrentStack.Pop();
                }
                else
                {
                    CurrentStatment = null;
                }
            }
            //
            if (CurrentStatment == null)
            {
                if (BlockStack.Count > 0)
                {
                    CurrentBlock = BlockStack.Pop();
                    CurrentStack = OldStacks.Pop();
                    if (CurrentStack.Count > 0)
                    {
                        CurrentStatment = CurrentStack.Pop();
                    }
                }
                else
                {
                    CurrentBlock = null;
                    CurrentStack = null;
                }
            }
        }
예제 #3
0
 public void AddStmt(Stmt stmt)
 {
     statements.Add(stmt);
 }