Esempio n. 1
0
int main (int argc, char **argv)
{
	FILE *stream;
	signed short c;
	char cache_file_ln[256];
	int line_length, line_nr;
	int status;
	
	if (argc != 2)
		fprintf(stderr, "%s: Argc != 2\n", argv[0]);
	
	stream = fopen(argv[1], "r");
	if (stream == NULL)
		fprintf(stderr, "File % cannot be opened\n", argv[1]);
	
	tmp = fopen("tmp", "w");
	if (tmp == NULL)
		fprintf(stderr, "tmp file cannot be opened\n");
	
	
	status = line_length = line_nr = 0;
	memset(cache_file_ln, 0, 256);
	root = (struct symbols *) create_symbol_table();
	printf("root symbol address: %p\n\n", root);
	
	while (status != EOF) {
		c = fgetc(stream);
		if (c != '\n' && c != EOF) {
			cache_file_ln[line_length++] = c;
			if (line_length >= 256)
				fprintf(stderr, "Line (%d) too large!\n", 
					line_nr + 1);
		} else {
			if (c == EOF) 
				status = EOF;
			else if (c == '\n') 
				cache_file_ln[line_length] = c;
			
			if (line_length >= 1) {
				int err = parse_line(cache_file_ln, line_length);
				if (err == OVERFLOW_DETECTED)
					fprintf(stderr, "Overflow!\n");
			}
			
			line_length = 0;
			memset(cache_file_ln, 0, 256);
			line_nr++;
		}		
	}
	puts("\n");
	print_all_symbols(root);
		
	free_symbol_table(root);
	fclose(tmp);
	fclose(stream);
	return 0;
}
Esempio n. 2
0
int
main (void)
{
  int status = parse ();

  if (status == 0 && errcnt == 0)
    {
      printf ("=== The input parse tree (%d nodes) ===\n\n",
	      get_last_node_id ());
      print_node (root);
    }

  free_all_nodes ();

  if (symbol_functions || symbol_variables || symbol_history)
    printf ("\n=== Symbol table ===\n");

  if (symbol_functions)
    {
      printf ("* Functions:\n");
      print_all_symbols (symbol_functions);
      free_all_symbols (&symbol_functions);
    }
  if (symbol_variables)
    {
      printf ("* Variables (present):\n");
      print_all_symbols (symbol_variables);
      free_all_symbols (&symbol_variables);
    }
  if (symbol_history)
    {
      printf ("* Variables (past):\n");
      print_all_symbols (symbol_history);
      free_all_symbols (&symbol_history);
    }

  if (errcnt)
    status = 1;
  printf ("\nCompilation: %s\n", status ? "Failed" : "Passed");
  return status;
}