Exemplo n.º 1
0
Arquivo: astree.c Projeto: mtnash/oc
void freeast (astree root) {
   astree child = NULL;
   if (root == NULL) return;
   assert (is_astree (root));
   for (child = root->first; child != NULL;) {
      astree asttofree = child;
      assert (is_astree (asttofree));
      child = child->next;
      freeast (asttofree);
   }
   DEBUGF ('f', "free [%X]-> %d:%d.%d: %s: %p->\"%s\")\n",
           (uintptr_t) root, root->filenr, root->linenr, root->offset,
            get_yytname (root->symbol), root->lexinfo, root->lexinfo);
   memset (root, 0, sizeof (struct astree_rep));
   free (root);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	char *filenamein = NULL;
	char *filenameout = NULL;
	char *inputstr = NULL;
	token *tokenlist = NULL;
	term *ast = NULL;
	int numtokens = 0;

	/* If argc < 3, we don't have 2 files at least as arguments */
	if(argc < 3)
	{
		/* Show usage for the uninformed. */
		help(argv[0]);
		exit(-1);
	}
	else if(argc > 3) /* If we have more than 3, there's probably flags specified */
	{
		getargs(argc, argv);
	} /* If args >= 3, the last two must be the input file and the output file. */ 
	filenamein = argv[argc - 2];
	filenameout = argv[argc - 1];
	inputstr = getfile(filenamein);
	/* Lex the input string. If numtokens < 0, there's an issue. */
	numtokens = lex(inputstr, &tokenlist);
	free(inputstr);
	if(numtokens == -1 || (tokenlist == NULL && numtokens > 0))
	{
		puts("A lexing error occured.");
		exit(-1);
	}
	/* If -l is specified (currently default) show the result of the lex */
	if(FLAGS & SHOWLEX)
	{
		printtokens(tokenlist, numtokens);
	}

	/*parse(tokenlist, numtokens, &ast);*/
	
	int perr = prog(tokenlist, numtokens, &ast);
	if(perr)
		puts("parsing error");
	
	if(FLAGS & SHOWPARSE)
	{
		printast(ast, numtokens);
	}

	codegen(ast, filenameout);
	
	if(tokenlist != NULL)
	{
		freetokens(&tokenlist, numtokens);
	}
	
	if(ast != NULL)
	{
		freeast(&ast);
	}

	exit(0);
}