我试图使用flex和yacc实现编译器。当我使用yyparse()控制台返回"分段错误时,核心转储"。如何解决这个问题?
int main(int argc, char *argv[])
{
char *sourcefile = (char *) calloc(strlen(argv[1]), sizeof(char));
strcpy(sourcefile, argv[1]);
yyin = fopen(sourcefile, "r");
listing = stdout; /* send listing to screen */
yyrestart(yyin);
yyparse();
fclose(yyin);
return 0;
}
编译中的警告:
parse.y: In function ‘yyparse’:
parse.y:103:19: warning: assignment makes pointer from integer without a cast [enabled by default]
| OP_SREDNIK {$$ = OP_SREDNIK;}
^
parse.y:104:19: warning: assignment makes pointer from integer without a cast [enabled by default]
| READ ID OP_SREDNIK {$$ = READ;}
^
parse.y:107:19: warning: assignment makes pointer from integer without a cast [enabled by default]
| ZWROC OP_SREDNIK {$$ = ZWROC;}
^
parse.y:114:19: warning: assignment makes pointer from integer without a cast [enabled by default]
| THIS {$$ = THIS;}
^
parse.y:115:19: warning: assignment makes pointer from integer without a cast [enabled by default]
| SUPER {$$ = SUPER;}
^
parse.y:121:19: warning: assignment from incompatible pointer type [enabled by default]
| WyrazeniePostfiksowe OP_KROPKA ID {$$ = $3;}
parse.y(yacc)
Instrukcja : Wyrazenie OP_SREDNIK {$$ = $1;}
| ZlozonaInstrukcja OP_SREDNIK {$$ = $1;}
| WyrazeniePostfiksowe OP_PRZYPISANIA Wyrazenie OP_SREDNIK {$$ = $3;}
| Blok {$$ = $1;}
| DELETE Wyrazenie OP_SREDNIK {$$ = $2;}
| OP_SREDNIK {$$ = OP_SREDNIK;}
| READ ID OP_SREDNIK {$$ = READ;}
| WRITE Wyrazenie OP_SREDNIK {$$ = $2;}
| ZWROC Wyrazenie OP_SREDNIK {$$ = $2;}
| ZWROC OP_SREDNIK {$$ = ZWROC;}
;