예제 #1
0
파일: driver.c 프로젝트: oyzh/tiger
int main(int argc, char **argv) {
 string fname; int tok;
 if (argc!=2) {
   fprintf(stderr,"usage: a.out filename\n");
   exit(1);
 }
 fname=argv[1];
 EM_reset(fname);
 for(;;) {
   tok=yylex();
   if (tok==0) break;
   switch(tok) {
   case ID: case STRING:
     printf("%10s %4d %s\n",tokname(tok),EM_tokPos,yylval.sval);
     //   printf("%10s %4d\n",tokname(tok),EM_tokPos);
     break;
   case INT:
     printf("%10s %4d %d\n",tokname(tok),EM_tokPos,yylval.ival);
     break;
   default:
     printf("%10s %4d\n",tokname(tok),EM_tokPos);
   }
 }
 return 0;
}
예제 #2
0
파일: parse.c 프로젝트: JackWyj/Tiger
A_exp parse(string fname) 
{
	EM_reset(fname);
	if (yyparse() == 0) return absyn_root;
	else printf("f**k! not pass syntax!\n"); 
	return NULL;
}
예제 #3
0
파일: driver.c 프로젝트: JackWyj/Tiger
int main(int argc, char **argv) {
	string fname; int tok;
	if (argc!=2) {
		fprintf(stderr,"usage: a.out filename\n"); 
		exit(1);
	}
	fname=argv[1];
	EM_reset(fname);
	for(;;) {
		tok=yylex();
		if (tok==0) break;
		
		if(strcmp("BAD_TOKEN", tokname(tok)) == 0) assert("Invalid Token");
		 
		// here is unit-test i'm lazy --
		if(strcmp("WHILE", tokname(tok)) != 0) assert("Program failed");
		
		switch (tok) {
		case ID: case STRING:
			printf("%10s %4d %s\n",tokname(tok),EM_tokPos,yylval.sval);
			break;
		case INT:
			printf("%10s %4d %d\n",tokname(tok),EM_tokPos,yylval.ival);
			break;
		default:
			printf("%10s %4d\n",tokname(tok),EM_tokPos);
		}
	}
	return 0;
}
void parse(string fname) 
{
  EM_reset(fname);
  if (yyparse() == 0) /* parsing worked */
    fprintf(stderr,"Parsing successful!\n");
  else
    fprintf(stderr,"Parsing failed\n");
}
예제 #5
0
A_program parse(string file_name)
{
    EM_reset(file_name);
    if (yyparse() == 0)
        return root;
    else
        printf("syntax error!\n");
    return 0;
}
예제 #6
0
파일: parse.c 프로젝트: geeeeeeeeek/tiger
/* parse source file fname; 
   return abstract syntax data structure */
A_exp parse(string fname) 
{EM_reset(fname);
 if (yyparse() == 0) /* parsing worked */
   return absyn_root;
 else{ 
 	exit(123);
 	return NULL;
 }

}
예제 #7
0
/* parse source file fname; 
   return abstract syntax data structure */
A_exp parse(string fname) 
{EM_reset(fname);
 if (yyparse() == 0) /* parsing worked */
   return absyn_root;
 else{
	 printf("not pass!\n");
	 return NULL;
	} 
	 
}
예제 #8
0
int main(int argc, char **argv) {
 FILE* outfile;
 A_exp ast;
 
 yydebug = 1;
 
 if (argc!=3) {fprintf(stderr,"usage: parser tigfile outfile\n"); exit(1);}
 if (! (outfile=fopen(argv[2], "w"))) exit(1);
 EM_reset(argv[1]);
 ast = parse(argv[1]);
 if (ast)
   pr_exp(outfile, ast, 0);
 return 0;
}