我的野牛代码中包含以下一些语法规则:
funDeclaration: typeSpecifier ID NUM OPEN_PAR params CLOSE_PAR compoundStmt
{char *temp=strcat($1,$2);
char *number=(char *)(__intptr_t)$3;
char *temp0=strcat(temp,number);
char *temp1=strcat($4,$5);
char *temp2=strcat(temp0,temp1);
char *temp3=strcat(temp2,$6);
$$=strcat(temp3,$7);}
params: paramList {$$=$1;}
|VOID {$$=$1;}
paramList: paramList SEMICOLON param
{char *temp=strcat($1,$2); $$=strcat(temp,$3);}
|param {$$=$1;}
param: typeSpecifier ID {$$=strcat($1,$2);}
|typeSpecifier ID OPEN_BRAC CLOSE_BRAC
{char *temp=strcat($1,$2);
char *temp1=strcat(temp,$3);
$$=strcat(temp1,$4);}
现在我在C文件上运行语法分析,我想识别以下行:
int foo (int a){
那么,它应该被上述规则所认可,对吗?但是,在OPEN_PAR之后的funDeclaration的第一条规则中(“(”)它识别出“int”并且它移动到状态1而不是识别“params”并移动到状态19。
这两个州如下:
State 1
8 typeSpecifier: INT .
$default reduce using rule 8 (typeSpecifier)
State 15
10 funDeclaration: typeSpecifier ID NUM OPEN_PAR . params CLOSE_PAR compoundStmt
INT shift, and go to state 1
VOID shift, and go to state 17
typeSpecifier go to state 18
params go to state 19
paramList go to state 20
param go to state 21
有谁知道问题可能是什么?