Esempio n. 1
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++;
	}
}
Esempio n. 2
0
int main(){

	tSymTablePtr symTable;


	symtableInit(&symTable);


	tData symTableData = symtableInsert(&symTable,"c");

	printf("%s\n",symTable->key);



	symtableInsert(&symTable,"a");
	symtableInsert(&symTable,"e");

	printf("%s\n",symTable->LPtr->key);
	printf("%s\n",symTable->RPtr->key);
	


	//tData symTableData = symtableSearch(symTable,"c");


	symTableData->value->i=0;
	printf("%d\n",symTable->data->value->i);


	symTableData->type=INT;
	printf("%d\n",symTable->data->type);


	symTableData->scope=(char*) malloc(sizeof(5));
	strcpy(symTableData->scope,"main");
	printf("%s\n",symTable->data->scope);




	symTableData = symtableSearch(symTable,"a");

	symTableData->value->f=1.54;
	printf("%f\n",symTableData->value->f);


	symTableData->type=DBL;
	printf("%d\n",symTableData->type);


	symtableScopeInsert(symtableSearch(symTable,"a"),"globalna");
	printf("%s\n",symTable->LPtr->data->scope);



	symtableDispose(&symTable);

	printf("-----------------------------\n");


	loadSourceFile("test.txt");

	Ttoken* token = getNextToken();

	while(!(token->type==END_OF_FILE)){
	
		if ((token->type==1)||(token->type==2)||(token->type==3)||(token->type==4)){
			printf("LINE%d: %s\n",token->lineNum,token->attr->str);
		}
		else{
			printf("LINE%d: %d\n",token->lineNum,token->type);
		}

		destroyToken(token);
		token=getNextToken();
	}
	
	destroyToken(token);
	closeSourceFile();

return 0;
}