int main() {

  int noRoot = 0;		/* 0 means we will have a root */
  symboltable_t *symtab;
  list = NULL;

  /* Build the tree */
  error_out = stderr;
  noRoot = yyparse();

  if (parseError && (!noRoot))
    fprintf(stderr, "WARNING: There were %d parse errors.\nParse tree may be ill-formed.\n", parseError);

  if (noRoot)
    fprintf(stderr, "Parsing reached fatal error. No AST was constructed\n");

  /* Set up the symbol tree */
  symtab = create_symboltable();
  symtab = build_symboltable(symtab, root, root);
  print_symtab(symtab);
  print_ast(stdout, root, 0);

  code_gen(root, symtab);

  print_quad_list(stdout, list);
  return 0;
}
int main() {
  FILE *ys = fopen("./sample.ys", "w");
  int noRoot = 0;		/* 0 means we will have a root */
  symboltable_t *symtab;
  list = NULL;

  /* Build the tree */
  error_out = stderr;
  noRoot = yyparse();

  if (parseError && (!noRoot))
    fprintf(stderr, "WARNING: There were %d parse errors.\nParse tree may be ill-formed.\n", parseError);

  if (noRoot)
    fprintf(stderr, "Parsing reached fatal error. No AST was constructed\n");

  /* Set up the symbol tree */
  symtab = create_symboltable();
  symtab = build_symboltable(symtab, root, root);
  typecheck_ast(symtab, root);
  int retval = typecheck_ast(symtab, root);
  print_checked_ast(stdout, root, 0);
  if (retval != 0) {
    fprintf(stderr, "There were %d errors encountered in the parse tree. Aborting.\n", retval);
    return 1;
  } 
  print_ast(stdout, root, 0);
  print_symtab(symtab);
  code_gen(root, symtab);
  print_symtab(symtab);

  print_quad_list(stdout, list);
  generate_assembly(ys, list, symtab);
  return 0;
}
Esempio n. 3
0
int main(int argc, char** argv)
{

  int print_t = 0;
  int print_v = 0;
  int print_f = 0;
  int i;
  int rc;

  g_type = (char*) malloc(10);
  symboltable tracking_table = create_symboltable();
  flat_symtab var_table = create_flat_symtab();
  func_table function_table = create_functable();

  
  if (argc < 2){
    printf("usage: scan filename\n");
    return -1;
  }

  FILE* in = fopen(argv[1], "r");
  if (in == NULL){
    printf("file not found\n");
    return -1;
  }

  for(i = 2; i < argc; i++){
    if(strcmp(argv[i], "-t") == 0){
      print_t = 1;
    }else if (strcmp(argv[i], "-v") == 0){
      print_v = 1;
    }else if (strcmp(argv[i], "-f") == 0){
      print_f = 1;
    }else {
      printf("acceptable options are -t, -v and -f\n");
    }
  }

  // set input source
  yyset_in(in);

  // parse input
  rc = yyparse();

  if (rc == 0){
    printf("succeeded parsing input.\n");
  }
  else{
    printf("--- error --- failed parsing input: error at line %d, abort.\n", lineNumber);
    return -1;
  }
  
  // build symbol table
  build_symtab(tracking_table, var_table, function_table, root);
  if (sym_error != 0){
    printf("--- error --- errors found building symboltable, abort. \n");
    return -1;
  }

  // type check
  rc = type_check(var_table, function_table, root);
  if (rc != 0){
    printf("--- error --- errors found in type checking, abort.\n");
    // return -1;
  }

  // print data structures
   if(print_t == 1)
     print_ast(root, 0);	
   if(print_v == 1)
     print_flat_table(var_table);
   if(print_f == 1)
     print_func_table(function_table);
 
  return 0;
}