Example #1
0
File: Test.c Project: Laxa/DogeLang
int main(int argc, char ** argv)
{
  FILE  *input;
  FILE  *output;
  Program parse_tree;
  char  *str;
  char  *fileName;

  if (argc > 1)
  {
    input = fopen(argv[1], "r");
    if (!input)
    {
      fprintf(stderr, "Error opening input file.\n");
      exit(1);
    }
  }
  else input = stdin;
  /* The default entry point is used. For other options see Parser.h */
  parse_tree = pProgram(input);
  if (parse_tree)
  {
    printf("\nParse Succesful!\n");
    printf("\n[Abstract Syntax]\n");
    printf("%s\n\n", showProgram(parse_tree));
    printf("Parsing AST for doge now...\n");
    visitProgram(parse_tree);
    printf("Done!\n");
    str = printProgram(parse_tree);
    if (input != stdin)
    {
      fileName = strdup(argv[1]);
      fileName = realloc(fileName, strlen(fileName) + 3);
      strcat(fileName, ".c");
      output = fopen(fileName, "w");
      fwrite(str, strlen(str), 1, output);
      printf("Wrote program to %s\n", fileName);
      free(fileName);
    }
    else
    {
      printf("[Linearized Tree]\n");
      printf("%s\n\n", str);
    }
    if (str)
      free(str);
    return 0;
  }
  return 1;
}
Example #2
0
    // Starts the viewer and executes your Work function
    void Execute(int *argc, char ***argv)
    {
        std::string visitProgram("visit");

        if(viewer != 0)
            return;

        // Let the user override the program we use for VisIt on the command line.
        for(int i = 0; i < *argc; ++i)
        {
            char **argv2 = *argv;
            if(strcmp(argv2[i], "-dir") == 0 && (i+1) < *argc)
            {
                visitProgram = std::string(argv2[i+1]) + "/bin/visit";
                ++i;
            }
        }

        // Create the viewer proxy and launch the viewer.
        viewer = new ViewerProxy;
        viewer->InitializePlugins(PluginManager::Scripting);
        viewer->Create(visitProgram.c_str(), argc, argv);

        // Set up an observer that will call our LoadPlugins method
        // when the plugin manager attributes come from the viewer.
        loadPlugins = new ObserverToCallback(
            viewer->GetViewerState()->GetPluginManagerAttributes(),
            LoadPlugins,
            (void*)this);

        // Wait for synchronization
        Synchronize();

        // Show the viewer windows.
        viewer->GetViewerMethods()->ShowAllWindows();

        // Call the user's Work method.
        Work();
    }