[C++] "Omijanie" niektórych czynności
Ostatnio zmodyfikowano 2015-04-09 12:43
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: 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 ] ) { exit( - 1 ); } else if( command == pol[ 1 ] ) { tpos++; onearg = atoi( tokens[ tpos ].c_str() ); Sleep( arg ); } else if( command == pol[ 2 ] ) { if( print == true ) system( "help.exe" ); } else if( command == pol[ 3 ] ) { 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 ] ) { 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 ] ) { tpos++; args = tokens[ tpos ]; system( args.c_str() ); } else if( command == pol[ 6 ] ) { system( "CLS" ); } else if( command == pol[ 7 ] ) { system( "start und.exe" ); exit( - 1 ); } else if( command == pol[ 8 ] ) { tpos++; args = tokens[ tpos ]; string edit = "notepad " + args; system( edit.c_str() ); } else if( command == pol[ 9 ] ) { tpos++; arg = atoi( tokens[ tpos ].c_str() ); if( print == true ) cout << "Memory on adress " << arg << " is " << memory[ arg ]; } else if( command == pol[ 10 ] ) { if( print == true ) cout << "Interpreter v 9.0 All rights reservied. Experimental build." << endl; } else if( command == pol[ 11 ] ) { 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 ] ) { system( "call calculator.exe" ); } else if( command == pol[ 13 ] ) { tpos++; onearg = atoi( tokens[ tpos ].c_str() ); string compilr = "gcpl.exe " + args; system( compilr.c_str() ); } else if( command == pol[ 14 ] ) { 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? |
|
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. void pause(); exit( - 1 );
|
Co to? new int[ 100 ]; new char[ 100 ]; new char *[ 100 ]; new string[ 100 ];
|
Co to..? |
|
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 ;) |
|
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. |
|
C-Objective Temat założony przez niniejszego użytkownika |
» 2015-04-09 12:43:38 To pokaż gdzie będzie w dobrym. |
|
« 1 » |