Beispiel #1
0
bool
CVML::
decode(CFile *file)
{
  reset();

  if (! readHeader(file)) {
    std::cerr << "Not a valid VML file" << std::endl;
    return false;
  }

  if (! readStringTable(file)) {
    std::cerr << "Bad String Table" << std::endl;
    return false;
  }

  if (! readDebug(file)) {
    std::cerr << "Bad Debug Section" << std::endl;
    return false;
  }

  if (! readData(file)) {
    std::cerr << "Bad Data Section" << std::endl;
    return false;
  }

  if (! readInstructions(file)) {
    std::cerr << "Bad Code Section" << std::endl;
    return false;
  }

  return true;
}
Beispiel #2
0
main( int argc, char * argv[] )
{ if (argc != 2)
  { printf("usage: %s <filename>\n",argv[0]);
    exit(1);
  }
  strcpy(pgmName,argv[1]) ;
  if (strchr (pgmName, '.') == NULL)
     strcat(pgmName,".tm");
  pgm = fopen(pgmName,"r");
  if (pgm == NULL)
  { printf("file '%s' not found\n",pgmName);
    exit(1);
  }

  /* read the program */
  if ( ! readInstructions ())
         exit(1) ;
  /* switch input file to terminal */
  /* reset( input ); */
  /* read-eval-print */
  printf("TM  simulation (enter h for help)...\n");
  do
     done = ! doCommand ();
  while (! done );
  printf("Simulation done.\n");
  return 0;
}
Beispiel #3
0
int main(int argc, char * argv[]){
    //First things first. Open the input file.
    FILE *fp;
    int i = 0;
        
    if (argc != 2 || (fp = fopen(argv[1], "r")) == NULL) {
      printf("File open failed.\nUsage: %s <input file>\n",argv[0]);
      exit(1);
    }

    // initialize the symbol table, jump table and stack to 0
    // method will be in instructions.c
    initialize();

    // read the input file and prepare structures
    readInstructions(fp);

    // Close the file.
    fclose(fp); 

    // Begin to interpret
    execute();
    
    // debugging purposes...
    printTables();

    printf("\nProgram halted\n");
}
Beispiel #4
0
int main(int argc, const char * argv[])
{
    if (argc != 2) {
        printf("Usage: %s <filename>\n", argv[0]);
        exit(1);
    }
    
    strcpy(pgmName, argv[1]);
    if (strchr(pgmName, '.') == NULL) {
        strcat(pgmName, ".tm");
    }
    pgm = fopen(pgmName, "r");
    if (pgm == NULL) {
        printf("File %s Not Found\n", pgmName);
        exit(1);
    }
    
    if (!readInstructions()) {
        exit(1);
    }
    
    printf("TM Simulation (Enter h for Help)...\n");
    
    do
    {
        done = ! doCommand();
        
    } while (!done);
    printf("Simulation Done.\n");
    
    return 0;

}
Beispiel #5
0
main(int argc, char * argv[])
{
	if (argc != 2)
	{
		printf("usage: %s <filename>\n", argv[0]);
		exit(1);
	}
	strcpy(pgmName, argv[1]);
	if (strchr(pgmName, '.') == NULL)
		strcat(pgmName, ".tm");
	char *pgmName1;
	pgmName1 = "D:\\code\\cplusplus\\tiny\\sample.tm";//"D:\\code\\Visual Studio\\visual studio 2015\\Projects\\TINY\\tm\\Debug\\sample.tm";
	printf("%s\n", pgmName1);
	pgm = fopen(pgmName1, "r");
	if (pgm == NULL)
	{
		printf("file '%s' not found\n", pgmName);
		exit(1);
	}

	/* read the program 把指令加载到指令区*/
	if (!readInstructions())
		exit(1);
	/* switch input file to terminal */
	/* reset( input ); */
	/* read-eval-print */
	printf("TM  simulation (enter h for help)...\n");
	do
		done = !doCommand();//把指令加载到指令区
	while (!done);
	printf("Simulation done.\n");
	return 0;
}