Пример #1
0
void Scanner::PopIndentToHere() {
  // are we in flow?
  if (InFlowContext()) {
    return;
  }

  // now pop away
  while (!m_indents.empty()) {
    const IndentMarker& indent = *m_indents.top();
    if (indent.column < INPUT.column()) {
      break;
    }
    if (indent.column == INPUT.column() &&
        !(indent.type == IndentMarker::SEQ &&
          !Exp::BlockEntry().Matches(INPUT))) {
      break;
    }

    PopIndent();
  }

  while (!m_indents.empty() &&
         m_indents.top()->status == IndentMarker::INVALID) {
    PopIndent();
  }
}
Пример #2
0
// PopAllIndents
// . Pops all indentations (except for the base empty one) off the stack,
//   and enqueues the proper token each time.
void Scanner::PopAllIndents() {
  // are we in flow?
  if (InFlowContext())
    return;

  // now pop away
  while (!m_indents.empty()) {
    const IndentMarker& indent = *m_indents.top();
    if (indent.type == IndentMarker::NONE)
      break;

    PopIndent();
  }
}
Пример #3
0
void rbBytecode::Parse()
{
	wxLogMessage(wxT(""));

	// Initialize stack
	// parse until end-script marker
	Root = new rbToken(NULL,-1,wxT("ROOT"),wxT("ROOT"));
	PushIndent();
	PrintOutput(wxT("{\n"));
	PushStack(Root);	
	while( true )
	{
		dword token = LoadToken();
		if( token == 0x53 )
			break;
	}
	PopStack();
	PopIndent();
	//ScriptText.RemoveLast(); // remove tab
	PrintOutput( wxT("}\n") );


}
Пример #4
0
inline vector<BigInt> PollardRho
( const BigInt& n,
  const PollardRhoCtrl& ctrl )
{
    vector<BigInt> factors;
    BigInt nRem = n;

    Timer timer;
    PushIndent();
    while( true )
    {
        // Try Miller-Rabin first
        if( ctrl.time )
            timer.Start();
        Primality primality = PrimalityTest( nRem, ctrl.numReps );
        if( primality == PRIME )
        {
            if( ctrl.time )
                Output(nRem," is prime (",timer.Stop()," seconds)");
            else if( ctrl.progress )
                Output(nRem," is prime");
            factors.push_back( nRem );       
            break;
        }
        else if( primality == PROBABLY_PRIME )
        {
            if( ctrl.time )
                Output(nRem," is probably prime (",timer.Stop()," seconds)");
            else if( ctrl.progress )
                Output(nRem," is probably prime");
            factors.push_back( nRem );
            break;
        }
        else
        {
            if( ctrl.time )
                Output(nRem," is composite (",timer.Stop()," seconds)");
            else if( ctrl.progress )
                Output(nRem," is composite");
        }

        if( ctrl.progress )
            Output("Attempting to factor ",nRem," with a=",ctrl.a0);
        if( ctrl.time )
            timer.Start();
        PushIndent();
        BigInt factor;
        try
        {
            factor = pollard_rho::FindFactor( nRem, ctrl.a0, ctrl );
        }
        catch( const exception& e ) // TODO: Introduce factor exception?
        {
            // Try again with a=ctrl.a1
            if( ctrl.progress )
                Output("Attempting to factor ",nRem," with a=",ctrl.a1);
            factor = pollard_rho::FindFactor( nRem, ctrl.a1, ctrl );
        }
        if( ctrl.time )
            Output("Pollard-rho: ",timer.Stop()," seconds");
        PopIndent();

        factors.push_back( factor );
        nRem /= factor;
    }
    PopIndent();
    sort( factors.begin(), factors.end() );
    return factors;
}
Пример #5
0
inline vector<BigInt> PollardPMinusOne
( const BigInt& n,
        DynamicSieve<SieveUnsigned>& sieve,
  const PollardPMinusOneCtrl<SieveUnsigned>& ctrl )
{
    vector<BigInt> factors;
    BigInt nRem = n;

    Timer timer;
    PushIndent();
    while( true )
    {
        // Try Miller-Rabin first
        if( ctrl.time )
            timer.Start();
        Primality primality = PrimalityTest( nRem, ctrl.numReps );
        if( primality == PRIME )
        {
            if( ctrl.time )
                Output(nRem," is prime (",timer.Stop()," seconds)");
            else if( ctrl.progress )
                Output(nRem," is prime");
            factors.push_back( nRem );       
            break;
        }
        else if( primality == PROBABLY_PRIME )
        {
            if( ctrl.time )
                Output(nRem," is probably prime (",timer.Stop()," seconds)");
            else if( ctrl.progress )
                Output(nRem," is probably prime");
            factors.push_back( nRem );
            break;
        }
        else
        {
            if( ctrl.time )
                Output(nRem," is composite (",timer.Stop()," seconds)");
            else if( ctrl.progress )
                Output(nRem," is composite");
        }

        if( ctrl.progress )
            Output("Attempting to factor ",nRem);
        if( ctrl.time )
            timer.Start();
        PushIndent();
        BigInt factor = pollard_pm1::FindFactor( nRem, sieve, ctrl );
        PopIndent();
        if( ctrl.time )
            Output("Pollard p-1: ",timer.Stop()," seconds");

        // The factor might be composite, so attempt to factor it
        PushIndent();
        auto subfactors = PollardPMinusOne( factor, ctrl );
        PopIndent();
        for( auto subfactor : subfactors )
            factors.push_back( subfactor );
        nRem /= factor;
    }
    PopIndent();
    sort( factors.begin(), factors.end() );
    return factors;
}