Esempio n. 1
0
/*
NAME

RecordInstruction - Parse a line from the the file to determine the the type of
					instruction and record all important values.

SYNOPSIS

Instruction::InstructionType Instruction::RecordInstruction(string &a_buff);

a_buff - passed by reference, the line from the file to be parsed.

DESCRIPTION

First parse out all comments from the line.  Then determine whether or not
a label exists on the line.  Perform some error checking and set all important values including
label, opcode, and operand.  Then determine if the opcode is an assembly instruction or 
machine language instruction.  If assembly check to see if it is an end command.

RETURNS

InstructionType ST_Comment if after parsing the line for comments, it is blank.
ST_End if the opcode is determined to be "END".
ST_AssemblerInstr if it is an assembly instruction with no associated numeric opcode.
Otherwise it is a ST_MachineLanguage.

AUTHOR

Charles Snyder
*/
Instruction::InstructionType Instruction::RecordInstruction(string &a_buff)
{
	m_instruction = a_buff;  // Store the original instruction.
	m_Label = "";  // Reset the label.
	m_IsNumericOperand = false; // Reset the numeric operand flag.

	// Parse out any comments
	int pos = (int)a_buff.find_first_of(';');
	string noCommentString = a_buff.substr(0, pos);
	trimBlanks(noCommentString);

	string label, opcode, operand, error;

	// Read in the contents of the line.
	istringstream parseLine(noCommentString);

	// The line was not a comment.
	if (!noCommentString.empty()) {
		// Check to see if a label exists on the line.
		if (noCommentString[0] != ' ' && noCommentString[0] != '\t') {
			parseLine >> label >> opcode >> operand >> error;
			makeUpperCase(opcode);
			SetLabel(label);
			SetOpCode(opcode);
			SetOperand(operand);

			FindBlankAndGarbageValues(opcode, operand, error, true);

			if (opcode == "ORG" || opcode == "HALT" || opcode == "END") {
				string error = "Command should not have label";
				Errors::RecordError(lineCount, error);
			}

			if (m_IsNumericOperand == true) {
				SetNumOperandValue(operand);
			}

			if (isAssemblerInstruction(opcode) == true) {
				AssemblyLabelError();
				m_type = ST_AssemblerInstr;
				return ST_AssemblerInstr;
			}
			else {
				MachineNoSymbolOperandError();
				DetermineNumOpCode(opcode);
				m_type = ST_MachineLanguage;
				return ST_MachineLanguage;
			}
		}
		// Line contained no symbol value.
		else {
int main ()
{
    char buf1[ 100 ], buf2[ 100 ];
    gets( buf1 );
    gets( buf2 );

    makeUpperCase( buf1 );
    makeLowerCase( buf2 );

    printf( "Upper case: %s\n", buf1 );
    printf( "Lower case: %s\n", buf2 );

    return 0;
}
Esempio n. 3
0
static void createAndAppendTransformationsSubMenu(const HitTestResult& result, ContextMenuItem& transformationsMenuItem)
{
    ContextMenu transformationsMenu(result);

    ContextMenuItem makeUpperCase(ActionType, ContextMenuItemTagMakeUpperCase, contextMenuItemTagMakeUpperCase());
    ContextMenuItem makeLowerCase(ActionType, ContextMenuItemTagMakeLowerCase, contextMenuItemTagMakeLowerCase());
    ContextMenuItem capitalize(ActionType, ContextMenuItemTagCapitalize, contextMenuItemTagCapitalize());

    transformationsMenu.appendItem(makeUpperCase);
    transformationsMenu.appendItem(makeLowerCase);
    transformationsMenu.appendItem(capitalize);

    transformationsMenuItem.setSubMenu(&transformationsMenu);
}