Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[C++] "Omijanie" niektórych czynności

Ostatnio zmodyfikowano 2015-04-09 12:43
Autor Wiadomość
C-Objective
Temat założony przez niniejszego użytkownika
[C++] "Omijanie" niektórych czynności
» 2015-04-03 18:59:36
Witam. Mam taki kodzik mojego pseudo-parsera:
C/C++
void cparse( char * filename ) {
    int im = 0;
    fstream file;
    file.open( filename, ios::in );
    if( file.good() ) {
        do {
            file >> tokens[ im ];
            cout << "Reading token " << im << "(" << tokens[ im ] << ") " << "Please wait." << endl;
            im++;
        } while( !file.eof() );
       
    }
    else {
        cout << " There's exception in interpreter.exe module 3. Closing app..." << endl;
        void pause();
        exit( - 1 );
    }
    int tpos = 0;
    new int[ 100 ];
    new char[ 100 ];
    new char *[ 100 ];
    new string[ 100 ];
    int stop = 2;
    int state = 0;
    string command;
    cout << "Interpreter v 9.0" << endl;
    cout << "by C-Objective" << endl;
    do {
        cout << endl;
        int arg;
        int onearg;
        string args;
        if( print == true ) cout << "SHELL>> ";
       
        command = tokens[ tpos ];
        tpos++;
        for( int i = 0; i < command.length(); i++ ) {
            command[ i ] = toupper( command[ i ] );
        }
        if( command == pol[ 0 ] ) { //DONE
            exit( - 1 );
        }
        else if( command == pol[ 1 ] ) { //DONE
            tpos++;
            onearg = atoi( tokens[ tpos ].c_str() );
            Sleep( arg );
        }
        else if( command == pol[ 2 ] ) { //DONE
            if( print == true ) system( "help.exe" );
           
        }
        else if( command == pol[ 3 ] ) { //DONE
            tpos++;
            onearg = atoi( tokens[ tpos ].c_str() );
            if( print == true ) cout << "Saving on adress " << state << ". Please wait..." << endl;
           
            memory[ state ] = onearg;
            if( print == true ) cout << "Saved!" << endl;
           
            state++;
           
        }
        else if( command == pol[ 4 ] ) { //DONE
            tpos++;
            arg = atoi( tokens[ tpos ].c_str() );
            if( arg > 0 ) memory[ arg ] = 0;
            else cout << "Error. please do not use numbers such as: -1, -2..." << endl;
           
            if( print == true ) cout << "Memory on adress " << arg << " set to NULL." << endl;
           
        }
        else if( command == pol[ 5 ] ) { //DONE
            tpos++;
            args = tokens[ tpos ];
            system( args.c_str() );
        }
        else if( command == pol[ 6 ] ) { //DONE
            system( "CLS" );
        }
        else if( command == pol[ 7 ] ) { //DONE
            system( "start und.exe" );
            exit( - 1 );
        }
        else if( command == pol[ 8 ] ) { //DONE
            tpos++;
            args = tokens[ tpos ];
            string edit = "notepad " + args;
            system( edit.c_str() );
        }
        else if( command == pol[ 9 ] ) { //DONE
            tpos++;
            arg = atoi( tokens[ tpos ].c_str() );
            if( print == true ) cout << "Memory on adress " << arg << " is " << memory[ arg ];
           
        }
        else if( command == pol[ 10 ] ) { //DONE
            if( print == true ) cout << "Interpreter v 9.0 All rights reservied. Experimental build." << endl;
           
        }
        else if( command == pol[ 11 ] ) { //DONE UWAGA TUTAJ ZNAJDUJE SIĘ PRINT! WARNING! a pol[11] = "PRINT"
            tpos++;
            args = tokens[ tpos ];
            string print2 = args;
            for( int i = 0; i < print2.length(); i++ ) {
                print2[ i ] = toupper( print2[ i ] );
            }
            if( print2 == "ON" ) {
                cout << "Printing turned on" << endl;
                print = true;
            }
            else if( print2 == "OFF" ) {
                cout << "Printing turned off" << endl;
                print = false;
            }
            else if( print2 == "\\N" ) {
                cout << endl;
            } else {
                cout << print2;
            }
        }
        else if( command == pol[ 12 ] ) { //DONE
            system( "call calculator.exe" );
        }
        else if( command == pol[ 13 ] ) { //DONE
            tpos++;
            onearg = atoi( tokens[ tpos ].c_str() );
            string compilr = "gcpl.exe " + args;
            system( compilr.c_str() );
        }
        else if( command == pol[ 14 ] ) { //DONE
            cout << "Please use Interpreter to use that command." << endl;
        }
        else {
            cout << "Invaild command. CMDS for more info." << endl;
        }
        cout << "";
    } while( stop == 2 );
   
}
oczywiście wszystkie zmienne są zadeklarowane.
mam teraz "hello.gcp", kod:

print Hello_World!
stop 1000
exit

to polecenie print jest 'omijane' i wykonuje się tylko 'stop'. Możecie mi wskazać błąd?
P-130014
pekfos
» 2015-04-07 20:35:31
A gdzie jest implementacja print? Bez wartości pol[] ciężko się tu w czymkolwiek połapać, powinieneś używać jakichś enumów dla indeksów tej tablicy. I dlaczego implementacja niektórych komend zaczyna się od tpos++..? To już zrobiłeś po przypisaniu wartości do command.

C/C++
void pause();
exit( - 1 );
Co to?

C/C++
new int[ 100 ];
new char[ 100 ];
new char *[ 100 ];
new string[ 100 ];
Co to..?
P-130364
C-Objective
Temat założony przez niniejszego użytkownika
» 2015-04-08 17:45:25
W kodzie odpowiedzi na twoje dwa pytania są. Nie mam zielonego co to enum. Probówałem się dowiedzieć ale ciężko coś mi idzie. tpos++ to pozycja w tablicy komend. "Aby przemieszczać się po tablicy, trzeba przesunąć adres elementu. Jak by tego nie było, to wczytywało by tylko 1 polecenie i 1000 razy może więcej powtarzało.".
Chcę aby wyświetlił się komunikat "Aby kontynuować ..."... No i tak. To new to też mi się zdaje że jakaś durnota bo kolega postanowił mi pomagać, i mi na pomagał. A wcześniej dobrze działało. Nie mam backupu :( EDIT: @up Memory leak ;)
P-130412
pekfos
» 2015-04-08 20:36:40
tpos++ to pozycja w tablicy komend. "Aby przemieszczać się po tablicy, trzeba przesunąć adres elementu. Jak by tego nie było, to wczytywało by tylko 1 polecenie i 1000 razy może więcej powtarzało.".
Ale dalej jest to w złym miejscu.
P-130429
C-Objective
Temat założony przez niniejszego użytkownika
» 2015-04-09 12:43:38
To pokaż gdzie będzie w dobrym.
P-130442
« 1 »
  Strona 1 z 1