Text Command Parser Problems

Started by
4 comments, last by MasterInsan0 20 years, 8 months ago
I am writing a sort of Hacker game, where you are a hacker and you...well, hack into things. It is completely text-based so I didn''t bother making it anything fancy, just a console (DOS) program. However, I am having some really bad problems getting my parser to parse something. I keep getting this error, repeated for every command I try to parse: c:\documents and settings\owner\desktop\desktop icons\programming projects\hacker game\commands.h(53) : error C2501: ''ParseWithoutInput'' : missing storage-class or type specifiers c:\documents and settings\owner\desktop\desktop icons\programming projects\hacker game\commands.h(53) : error C2373: ''ParseWithoutInput'' : redefinition; different type modifiers c:\documents and settings\owner\desktop\desktop icons\programming projects\hacker game\parser.h(153) : see declaration of ''ParseWithoutInput'' c:\documents and settings\owner\desktop\desktop icons\programming projects\hacker game\commands.h(53) : error C2078: too many initializers Here is my parsing function: // This function actually parses the line given to it. void ParseLine( Line * pLine ) { // Set the src line to lowercase lcase( pLine->src ); // Reset the command/parameter memory memset(&pLine->cmd,0,4); memset(&pLine->param,0,12*4); pLine->num_params = 0; // Variables for holding info char TempString[32]; // Temporary command segment unsigned int chr = 0; // Current character of the string unsigned int index = 0; // Which command segment we''re on char * pEditStr = NULL; // Always points to the temp string while( (chr < 256) && (pLine->src[chr] != ''\0'') ) { // Reset the temp string memset(&TempString,0,32); // Get a pointer to the temp string pEditStr = TempString; while(true) { // Add the character to the buffer *pEditStr = pLine->src[chr]; // Advance to then next character chr++; pEditStr++; // Check the next character for break if( pLine->src[chr] == '' '' || pLine->src[chr] == '','' ) { chr++; // If we break, advance the char // until the next parameter while( pLine->src[chr] == '' '' ) chr++; break; } if( pLine->src[chr] == ''\0'' ) { break; } } // Convert the parameter into // it''s counterpart if( index == 0 ) { // We''re on the command part of the string long cmd = 0; unsigned int p = 0; while( TempString[p] != ''\0'' ) { if( p % 2 == 0 ) cmd += TempString[p]*(p+1); else cmd -= TempString[p]*(p+1); p++; } pLine->cmd = cmd; } else { // We''re on a parameter long cmd = 0; // Try to find a ''0'' inside of the string. // We do this to make sure that just becase // the user typed in 0, the parser doesn''t // try to make it into a name int i = 0; bool bZeroInside = false; while( TempString != ''\0'' ) { if( TempString == ''0'' ) { bZeroInside = true; break; } i++; } // Try converting the string // into a long-variable cmd = atol( TempString ); // If the atol couldn''t convert the string // and there was no zero inside the string // then it must be a name if( cmd == 0 && bZeroInside == false ) { unsigned int p = 0; while( TempString[p] != ''\0'' ) { if( p % 2 == 0 ) cmd += (long)TempString[p] * (long)(p+1); else cmd -= (long)TempString[p] * (long)(p+1); p++; } } // Set the parameter''s value pLine->param[index-1] = cmd; // Advance the number of parameters found pLine->num_params++; } index++; } } Here is the function I''m trying to use to parse a string and return a storable value: void ParseWithoutInput(Line * pLine, char * szCommand, int cmdnum) { memset( pLine->src, 0, 256 ); memcpy( pLine->src, &szCommand, strlen(szCommand) ); ParseLine( pLine ); CmdArray[cmdnum] = pLine->cmd; return; } And finally, here is the structure for the Line: struct Line { char src[256]; // Allow for a 256-character line long cmd; // The command after parsing long param[12]; // 12 parameters possible unsigned int num_params;// The number of parameters used Line() { memset(src,0,256); memset(&cmd,0,4); memset(&param,0,12*4); num_params = 0; } }; Essentially, ParseLine takes the src string, parses it, and puts it into the cmd variable. I am trying to parse a whole bunch of commands and store their values in an array (parameters will come later). I have no idea why it gives me this error. The friend that developed this parsing function told me to change char szCommand to char * szCommand, but that didn''t make a difference. Anyone know what''s going wrong? Another helpful bit of information: it seems to be &#111;nly ParseWithoutInput() that has problems. Every other time I use the parsing functions it works fine. </i>
Justin O'ConnerProducer, Designer, ProgrammerUnseen Studios
Advertisement
Just after a quick look, I think you need to put the declaration of the Line structure above ParseWithoutInput.
Erm, I should have mentioned this. I didn''t put them in the exact order in which they are in my project. In order, they go: struct Line, ParseLine(), ParseWithoutInput().
Justin O'ConnerProducer, Designer, ProgrammerUnseen Studios
Hmmm...woke up this morning and found my post on page 5. I still can''t figure this annoying little problem out and it''s really aggrivating. Anyone have an idea?
Justin O'ConnerProducer, Designer, ProgrammerUnseen Studios
I will look at it, and try to see what I can do with the code, this may take a while.So far, it is a bit confusing to work with, so I will probably edit it a bit.
EDIT: Ok, first off, you have some stuff missing from the program, for example what header files you included, the main(int,char**) that you made for the game, etc. These are important functions. I would also suggest that for your Line constructor, that you actually have arguments. this way, it makes it possible to parse the command, since at this point, all src that your pLine->src is, would be that of an empty character array, so you would parse nothing. This would lead to a fairly unexciting program.

[edited by - bastard2k5 on August 15, 2003 11:36:15 PM]
I didn't include the function that grabs the user's input and stores it in the src array of the Line struct. It does exist, though, as do the other parts you mentioned that were missing. I simply included all of the program that had to do with parsing text. If you want me to e-mail you all of the program, send me an e-mail telling me so and I'll send the VC6 project files and the source. It's still a little...messy, though.

[edited by - MasterInsan0 on August 17, 2003 10:10:06 PM]
Justin O'ConnerProducer, Designer, ProgrammerUnseen Studios

This topic is closed to new replies.

Advertisement