コード例 #1
0
ファイル: semantics.c プロジェクト: doniexun/compiler-22
void doExtDefList(TreeNode *p) {
	//printf("doExtDefList\n");
	//printf("TreeNode->state:%s\n", p->state);
	//printf("TreeNode->productionRule: %d\n", p->productionRule);
	switch (p->productionRule) {
		case 1:{
			TreeNode *p1 = p->firstChild;
			TreeNode *p2 = p1->rightBrother;
			doExtDef(p1);
			doExtDefList(p2);
			break;
			   }
		case 2:
			break;
	}
}
コード例 #2
0
ファイル: semantics.c プロジェクト: doniexun/compiler-22
void doProgram(TreeNode *p) {
	//printf("---doProgram---\n");
	//printf("root->state:%s\n", p->state);
	out_fp = fopen("out.s", "w");
	if(out_fp == NULL) 
		perror("error in creating out.s\n");

	fprintf(out_fp,".data\n");
	fprintf(out_fp,"_prompt: .asciiz \"Enter an integer:\"\n");
	fprintf(out_fp,"_ret: .asciiz \"\\n\"\n");
	fprintf(out_fp,".globl main\n");
	fprintf(out_fp,".text\n");
	fprintf(out_fp,"read:\n");
	fprintf(out_fp,"\tli $v0,4\n");
	fprintf(out_fp,"\tla $a0,_prompt\n");
	fprintf(out_fp,"\tsyscall\n");
	fprintf(out_fp,"\tli $v0,5\n");
	fprintf(out_fp,"\tsyscall\n");
	fprintf(out_fp,"\tjr $ra\n");
	fprintf(out_fp,"\n");
	fprintf(out_fp,"write:\n");
	fprintf(out_fp,"\tli $v0,1\n");
	fprintf(out_fp,"\tsyscall\n");
	fprintf(out_fp,"\tli $v0,4\n");
	fprintf(out_fp,"\tla $a0,_ret\n");
	fprintf(out_fp,"\tsyscall\n");
	fprintf(out_fp,"\tmove $v0,$0\n");
	fprintf(out_fp,"\tjr $ra\n");
	fprintf(out_fp,"\n");
	fprintf(out_fp,"main:\n");

	TreeNode *p1 = p->firstChild;
	doExtDefList(p1);
	fprintf(out_fp,"\tmove $v0, $0\n");
	fprintf(out_fp,"\tjr $ra\n");//手动添加return 0,后续要进行修改
	fclose(out_fp);
	if(!OUT) 
		remove("out.s");
	else
		printf("Create out.s successfully\n");
}
コード例 #3
0
ファイル: semantics.c プロジェクト: pysherlock/compiler
void doProgram(TreeNode *p) {
	//printf("---doProgram---\n");
	//printf("root->state:%s\n", p->state);
	TreeNode *p1 = p->firstChild;	
	doExtDefList(p1);
}