Example #1
0
char Scanner::getChar(char source_buffer[])
{
    /*
     If at the end of the current line (how do you check for that?),
     we should call get source line.  If at the EOF (end of file) we should
     set the character ch to EOF and leave the function.
     */
    char ch;
    
    if (*theLinePtr == '\0')
    {
        if (!getSourceLine(source_buffer))
        {
            ch = EOF_CHAR;
            return ch;
        }
        theLinePtr = source_buffer;
    }
    
    /*
     Write some code to set the character ch to the next character in the buffer
     */
    ch = *theLinePtr;
    if ((ch == '\n') || (ch == '\t') || (ch == '\r'))
    {
        ch = ' ';
    }
    if (ch == '{')
    {
        skipComment(source_buffer);
    }
    return ch;
}
Example #2
0
void getChar(void)
{
	if (*bufferp == nullptr)
	{
		if (!getSourceLine())
		{
			if (NumOpenFiles > 1)
			{
				closeSourceFile();
				return;
			}
			else
			{
				curChar = CHAR_EOF;
				return;
			}
		}
		bufferp		 = sourceBuffer;
		bufferOffset = 0;
	}
	curChar = *bufferp;
	bufferp++;
	if (DumbGetCharOn)
	{
		bufferOffset++;
		return;
	}
	//-------------------
	// Special Characters
	switch (curChar)
	{
	case '\t':
		// TAB
		bufferOffset += TAB_SIZE - bufferOffset % TAB_SIZE;
		curChar = ' ';
		break;
	case '\n':
	case '\r':
		// NEWLINE
		bufferOffset++;
		curChar = ' ';
		break;
	case '/':
		if (*bufferp == '/')
			skipLineComment();
		else if (*bufferp == '*')
			skipBlockComment();
		else
			bufferOffset++;
		break;
	case '#':
		languageDirective();
		break;
	default:
		bufferOffset++;
	}
}