samedi 27 février 2016

C++ if statement issue in tokenizer

I am writing a tokenizer for a small language called jack in c++ for class. The problem isn't tokenizing itself, but one of the if statements is acting up. In the code below, the line if(jack.characters == "/*") will return false even when jack.characters holds "/*". Is this an error with c++ commenting?

char checkch = ' ';

do
{
    checkch = getc(in_file);     //get next character and add it to token
    jack.characters += checkch;

    if(jack.characters == "")
    {
        jack.characters = checkch;
    }

    if(jack.characters == "//")    //handle comments 
    {
        fgets(ignore, INT_MAX, in_file);  //ignore rest of line when comment is encountered
        jack.characters = getc(in_file);  //set jack.characters to first character of next line
    }

    if(jack.characters == "/*")   //handle multi-line comments
    {
        while(true)               //continue ignoring until end of comment is found
        {
            checkch = getc(in_file);
            if(checkch == '*')
            {
                checkch = getc(in_file);
                if(checkch == '/')
                {
                    checkch = getc(in_file);
                    jack.characters = "";    //reset jack.characters
                    break;
                }
                break;
            }
            break;
        }
    }

List item

List item

Aucun commentaire:

Enregistrer un commentaire