Ejemplo n.º 1
0
void Parser::Cleanup()
{
	size_t i;


	// delete all symbols first
	for(i = 0; i < globalIdentifierList.size(); i++)
	{
		Symbol *s = globalIdentifierList[i];
//		delete s;
	}

	for(i = globalTagSymbolList.size(); i > 0; i--)
	{
		Symbol *s = globalTagSymbolList[i - 1];
		
		if(s->type)
		{
			if(s->type->ty == typeENUM)
				delete s->type->eptr;
			else						
				delete s->type->sptr;
		}
		
//		delete s;
	}

	for(i = 0; i < globalTypeDeclList.size(); i++)
	{
		delete globalTypeDeclList[i];
	}


	lex_cleanup();

	/*for(i = 0; i < 100; i++)
	{
		Type *type = smegHead[i];
		if(type)
		{
			printf("[%d] %s", i, ::inenglish(type->ty));

			if(type->ty == typeIDENTIFIER || type->ty == typeTYPEDEF)
			{
				printf("   %s\n", type->sym->name);
			}
			else
			{
				printf("\n");
			}
		}
	}*/

}
Ejemplo n.º 2
0
void do_whole_file(const char *filename)
{
  // Do not set current_filename.
  FILE *fp;
  if (strcmp(filename, "-") == 0)
    fp = stdin;
  else {
    errno = 0;
    fp = fopen(filename, "r");
    if (fp == 0)
      fatal("can't open `%1': %2", filename, strerror(errno));
  }
  lex_init(new file_input(fp, filename));
  if (yyparse())
    had_parse_error = 1;
  parse_cleanup();
  lex_cleanup();
}
Ejemplo n.º 3
0
void do_picture(FILE *fp)
{
  flyback_flag = 0;
  int c;
  a_delete graphname;
  graphname = strsave("graph");		// default picture name in TeX mode
  while ((c = getc(fp)) == ' ')
    ;
  if (c == '<') {
    string filename;
    while ((c = getc(fp)) == ' ')
      ;
    while (c != EOF && c != ' ' && c != '\n') {
      filename += char(c);
      c = getc(fp);
    }
    if (c == ' ') {
      do {
	c = getc(fp);
      } while (c != EOF && c != '\n');
    }
    if (c == '\n') 
      current_lineno++;
    if (filename.length() == 0)
      error("missing filename after `<'");
    else {
      filename += '\0';
      const char *old_filename = current_filename;
      int old_lineno = current_lineno;
      // filenames must be permanent
      do_file(strsave(filename.contents()));
      current_filename = old_filename;
      current_lineno = old_lineno;
    }
    out->set_location(current_filename, current_lineno);
  }
  else {
    out->set_location(current_filename, current_lineno);
    string start_line;
    while (c != EOF) {
      if (c == '\n') {
	current_lineno++;
	break;
      }
      start_line += c;
      c = getc(fp);
    }
    if (c == EOF)
      return;
    start_line += '\0';
    double wid, ht;
    switch (sscanf(&start_line[0], "%lf %lf", &wid, &ht)) {
    case 1:
      ht = 0.0;
      break;
    case 2:
      break;
    default:
      ht = wid = 0.0;
      break;
    }
    out->set_desired_width_height(wid, ht);
    out->set_args(start_line.contents());
    lex_init(new top_input(fp));
    if (yyparse()) {
      had_parse_error = 1;
      lex_error("giving up on this picture");
    }
    parse_cleanup();
    lex_cleanup();

    // skip the rest of the .PF/.PE line
    while ((c = getc(fp)) != EOF && c != '\n')
      ;
    if (c == '\n')
      current_lineno++;
    out->set_location(current_filename, current_lineno);
  }
}