示例#1
0
Token TokenCreator::identifyTokenType(Token token, assembly_language language) {
	std::string type;
	this->language = language;
	if (isLabel(token))
		type = "LABEL";
	else if (isInstruction(token))
		type = "INSTRUCTION";
	else if(isDirective(token))
		type = "DIRECTIVE";
	else
		type = "OPERAND";
	return Token(token.name, token.line_number, type);
}
示例#2
0
/* 
	Description- parses a line, and exit when setect error.
	GET-
		line: struct that whlie hold info about this line.
		lineStr: the line that we parse.
		lineNum: line number in the file.
		(IC, DC). 
*/
bool parseLine(lineInfo *line, char *lineStr, int lineNum, int *IC, int *DC)
{
	char *startOfNextPart = lineStr;

	line->lineNum = lineNum;
	line->address = FIRST_ADDRESS + *IC;
	line->originalString = allocString(lineStr);
	line->lineStr = line->originalString;
	line->label = NULL;
	line->commandStr = NULL;
	line->cmd = NULL;

	if (!line->originalString)
	{
		printf("ERR:\tNot enough memory - malloc falied.\n");
		return TRUE;
	}

	/* Check if the line is a comment */
	if (isCommentOrEmpty(line))
	{	
		return FALSE;
	}

	/* Find label and add it to the label list */
	startOfNextPart = findLabel(line, *IC);

	/* Update the line if startOfNextPart isn't NULL */
	if (startOfNextPart)
	{
		line->lineStr = startOfNextPart;
	}

	/* Find the command token */
	line->commandStr = getFirstTok(line->lineStr, &startOfNextPart);
	line->lineStr = startOfNextPart;
	/* Parse the command / directive */
	if (isDirective(line->commandStr))
	{
		line->commandStr++; /* Remove the '.' from the command */
		parseDirective(line, IC, DC);
	}
	else
	{
		parseCommand(line, IC, DC);
	}
	return TRUE;
}
inputType identifyType (char input[]) {

    if (isDirective(input)) {

        return DIRECTIVE;
    } else if (isLabel(input)) {
        return LABEL;
    } else if (isComment(input)) {
        return COMMENT;
    } else  if(isInstruction(input)) {
        return INSTRUCTION;
    }

    return ERROR;

}