示例#1
0
int
main(int argc, char **argv) {
    char s1[] = "  the \tinternet is a series of tubes  ";
    char s2[] = "   \t\n";
    char s3[] = "  the \tinternet is not a series of tubes  ";
    char s4[] = "   \t\n";
    char s5[] = "8";
    
    removewhitespace(s1);
    removewhitespace(s2);
    printf("Remove whitespace - s1: %s\n", s1);
    printf("Remove whitespace - s2: %s\n", s2);

    printtokens(tokenify(s3));
    printtokens(tokenify(s4));
    printtokens(tokenify(s5));

    return 0;
}
示例#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);
}