Beispiel #1
0
int isValidLabel(char* str) {
	/* Verify that it is not an opcode */
	if (isOpcode(str) == 1) { return -1; }
	/* Check for other illegal names */
	if (
		strcmp("in", str) == 0 ||
		strcmp("out", str) == 0 ||
		strcmp("getc", str) == 0 ||
		strcmp("puts", str) == 0
		) {
		return -1;
	}
	/* Check that every character is alphanumeric */
	int i;
	for (i = 0; i < strlen(str); i++) {
		if (isalnum(str[i]) == 0) { /* NOT alphanumeric */
			return -1;
		}
	}
	/* Labels cannot begin with 'x' or a number */
	if (str[0] == 'x' || isdigit(str[0])) {
		return -1;
	}
	/* Labels cannot be registers */
	if (getRegister(str) != -1) {
		return -1;
	}
	/* Check for empty label name */
	if (strlen(str) <= 0) {
		return -1;
	}
	return 1;
}
Beispiel #2
0
/*Find any label */
int readLabel(FILE * pInfile, char * pLine, char ** pLabel)
{
	char * lPtr;
	   int i;
	   if( !fgets( pLine, MAX_LINE_LENGTH, pInfile ) )
		return( DONE );
	   for( i = 0; i < (int) strlen( pLine ); i++ )
		pLine[i] = tolower( pLine[i] );
	   
           /* convert entire line to lowercase */
	   *pLabel = pLine + strlen(pLine);

	   /* ignore the comments */
	   lPtr = pLine;

	   while( *lPtr != ';' && *lPtr != '\0' &&
	   *lPtr != '\n' ) 
		lPtr++;

	   *lPtr = '\0';
	   if( !(lPtr = strtok( pLine, "\t\n ," ) ) ) 
		return( EMPTY_LINE );

	   if( isOpcode( lPtr ) == 0 && lPtr[0] != '.' ) /* found a label */
	   {
		*pLabel = lPtr;
		if( !( lPtr = strtok( NULL, "\t\n ," ) ) ) return( OK );
	   }
	   return(OK);
}
Beispiel #3
0
	int readAndParse( FILE * pInfile, char * pLine, char ** pLabel, char ** pOpcode, char ** pArg1, char ** pArg2, char ** pArg3, char ** pArg4)
	{
	   char * lRet ,*lPtr;
	   int i;
	   if( !fgets( pLine, MAX_LINE_LENGTH, pInfile ) )
		return( DONE );
	   for( i = 0; i < strlen( pLine ); i++ )
		pLine[i] = tolower( pLine[i] );
	   
           /* convert entire line to lowercase */
	   *pLabel = *pOpcode = *pArg1 = *pArg2 = *pArg3 = *pArg4 = pLine + strlen(pLine);

	   /* ignore the comments */
	   lPtr = pLine; 

	   while( *lPtr != ';' && *lPtr != '\0' && *lPtr != '\n' )
		lPtr++;

	    *lPtr = '\0';
	   if( !(lPtr = strtok( pLine, "\t\n ," ) ) ) 
		return( EMPTY_LINE );

	   if( isOpcode( lPtr ) == -1 && lPtr[0] != '.' ){ /* found a label */
		*pLabel = lPtr;
		label = 1;
		/*printf("Found a label\n");*/
		if( !( lPtr = strtok( NULL, "\t\n ," )))  return( OK );
		/*return (LABEL);*/
	   } /*null pointer may be specified, in which case the function continues scanning 
	     where a previous successful call to the function ended.*/
	   
           *pOpcode = lPtr;

	   if( !( lPtr = strtok( NULL, "\t\n ," ))) return(OK ); 
	   
           *pArg1 = lPtr;
	   
           if( !( lPtr = strtok( NULL, "\t\n ," ) ) ) return( OK );

	   *pArg2 = lPtr;
	   if( !( lPtr = strtok( NULL, "\t\n ," ) ) ) return( OK );

	   *pArg3 = lPtr;

	   if( !( lPtr = strtok( NULL, "\t\n ," ) ) ) return( OK );

	   *pArg4 = lPtr;

	   return( OK );
	}
Beispiel #4
0
int readAndParse(FILE * pInfile, char * pLine, char ** pLabel, char ** pOpcode, char ** pArg1,
       char ** pArg2, char ** pArg3, char ** pArg4)
{
   char * lRet, * lPtr;
   int i;
   if(!fgets(pLine,MAX_LINE_LENGTH,pInfile))
       return(DONE);
   for(i=0;i< strlen(pLine); i++)
       pLine[i] = tolower(pLine[i]);

   /*convert entire line to lowercase/ What does this line do?*/
   *pLabel = *pOpcode = *pArg1 = *pArg2 = *pArg3 = *pArg4 = pLine + strlen(pLine);
   
   lPtr = pLine;

   while(*lPtr != ';' && *lPtr != '\0' && *lPtr != '\n')
      lPtr++;

   *lPtr = '\0';
   if(!(lPtr = strtok(pLine,"\t\n ,")))
      return(EMPTY_LINE);

   if(isOpcode(lPtr) == -1 && lPtr[0] != '.') /* found a label */
   {
      *pLabel = lPtr;
      if(!(lPtr = strtok(NULL,"\t\n ," ))) return(OK);
   }

   *pOpcode = lPtr;

   if(!(lPtr = strtok(NULL,"\t\n ,"))) return(OK);

   *pArg1 = lPtr;

   if(!(lPtr = strtok(NULL,"\t\n ,"))) return(OK);

   *pArg2 = lPtr;
   
   if(!(lPtr = strtok(NULL,"\t\n ,"))) return(OK);

   *pArg3 = lPtr;

   if(!(lPtr = strtok(NULL,"\t\n ,"))) return(OK);

   *pArg4 = lPtr;

   return (OK);
}
Beispiel #5
0
int readAndParse(FILE * pInfile, char * pLine, Instruction* inst) {
	char * lRet, *lPtr;
	int i;
	if (!fgets(pLine, MAX_LINE_LENGTH, pInfile))
		return(DONE);
	for (i = 0; i < strlen(pLine); i++)
		pLine[i] = tolower(pLine[i]);

	/* convert entire line to lowercase */
	inst->pLabel = inst->pOpcode = inst->pArg1 = inst->pArg2 = inst->pArg3 = inst->pArg4 = pLine + strlen(pLine);

	/* ignore the comments */
	lPtr = pLine;

	while (*lPtr != ';' && *lPtr != '\0' &&
		*lPtr != '\n')
		lPtr++;

	*lPtr = '\0';
	if (!(lPtr = strtok(pLine, "\t\n ,")))
		return(EMPTY_LINE);

	if (isOpcode(lPtr) == -1 && lPtr[0] != '.') /* found a label */
	{
		inst->pLabel = lPtr;
		if (!(lPtr = strtok(NULL, "\t\n ,"))) return(OK);
	}

	inst->pOpcode = lPtr;

	if (!(lPtr = strtok(NULL, "\t\n ,"))) return(OK);

	inst->pArg1 = lPtr;

	if (!(lPtr = strtok(NULL, "\t\n ,"))) return(OK);

	inst->pArg2 = lPtr;
	if (!(lPtr = strtok(NULL, "\t\n ,"))) return(OK);

	inst->pArg3 = lPtr;

	if (!(lPtr = strtok(NULL, "\t\n ,"))) return(OK);

	inst->pArg4 = lPtr;

	return(OK);
}
Beispiel #6
0
	String Object::getReadableString() const
	{
		String result;

		switch (this->getNativeType())
		{
		default:
			throw ObjectConversionException(FORMAT("Unknown DataType %u", this->getNativeType()));

		case NIL:
			result = "nil";
			break;

		case BOOLEAN:
		case NUMBER:
		case USERDATA:
			result = getString();
			break;

		case ADDRESS:
		{
			String op = isOpcode(getAddress()) ? opcodeToString((Opcode)getAddress()) : "?";

			result = FORMAT("%u[%s]", getAddress(), op.c_str());
			break;
		}

		case STRING:
			result = "\"" + getString() + "\"";
			break;
		}

		if (this->debug != 0)
		{
			result.append(FORMAT(" %%%s", this->debug->string.c_str()));
		}

		return result;
	}