[Error] C:\PROGRA~2\C-FREE~1\mingw\include\stdio.h:430: error: called object is not a function
[Error] C:\PROGRA~2\C-FREE~1\mingw\include\stdio.h:431: error: syntax error before "return"
[Error] \mingw32\share\bison.simple:288: error: called object is not a function
[Error] \mingw32\share\bison.simple:289: error: syntax error before '{' token
[Error] \mingw32\share\bison.simple:325: error: called object is not a function
[Error] \mingw32\share\bison.simple:326: error: syntax error before '{' token
[Error] \mingw32\share\bison.simple:334: error: syntax error before '*=' token
[Error] \mingw32\share\bison.simple:337: error: `yystacksize' undeclared here (not in a function)
[Error] \mingw32\share\bison.simple:337: error: `yyssp' undeclared here (not in a function)
[Warning] \mingw32\share\bison.simple:337: warning: initialization makes integer from pointer without a cast
[Error] \mingw32\share\bison.simple:337: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:337: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:338: error: syntax error before '(' token
[Error] \mingw32\share\bison.simple:338: error: syntax error before "char"
[Error] \mingw32\share\bison.simple:339: error: `yyvsp' undeclared here (not in a function)
[Warning] \mingw32\share\bison.simple:339: warning: initialization makes integer from pointer without a cast
[Error] \mingw32\share\bison.simple:339: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:339: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:340: error: syntax error before '(' token
[Error] \mingw32\share\bison.simple:340: error: syntax error before "char"
[Error] \mingw32\share\bison.simple:347: error: `size' undeclared here (not in a function)
[Warning] \mingw32\share\bison.simple:347: warning: data definition has no type or storage class
[Warning] \mingw32\share\bison.simple:348: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:358: error: syntax error before numeric constant
[Warning] \mingw32\share\bison.simple:399: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:405: error: syntax error before '}' token
[Error] \mingw32\share\bison.simple:428: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:428: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:437: error: syntax error before numeric constant
[Error] \mingw32\share\bison.simple:441: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:428: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:441: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:441: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:442: error: syntax error before "goto"
[Error] \mingw32\share\bison.simple:469: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:469: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:470: error: syntax error before "goto"
[Error] \mingw32\share\bison.simple:540: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:441: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:540: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:441: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:540: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:540: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:542: error: redefinition of 'yystate'
[Error] \mingw32\share\bison.simple:469: error: previous definition of 'yystate' was here
[Error] \mingw32\share\bison.simple:542: error: invalid type argument of `unary *'
[Warning] \mingw32\share\bison.simple:542: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:543: error: syntax error before numeric constant
[Error] \mingw32\share\bison.simple:601: error: syntax error before string constant
[Warning] \mingw32\share\bison.simple:601: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:621: error: redefinition of 'yychar'
[Error] \mingw32\share\bison.simple:399: error: previous definition of 'yychar' was here
[Warning] \mingw32\share\bison.simple:621: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:622: error: syntax error before '}' token
[Warning] \mingw32\share\bison.simple:627: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:629: error: syntax error before "goto"
[Error] \mingw32\share\bison.simple:644: error: redefinition of 'yystate'
[Error] \mingw32\share\bison.simple:542: error: previous definition of 'yystate' was here
[Error] \mingw32\share\bison.simple:644: error: redefinition of 'yystate'
[Error] \mingw32\share\bison.simple:542: error: previous definition of 'yystate' was here
[Error] \mingw32\share\bison.simple:644: error: invalid type argument of `unary *'
[Warning] \mingw32\share\bison.simple:644: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:660: error: syntax error before ':' token
[Error] \mingw32\share\bison.simple:670: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:540: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:670: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:441: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:670: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:670: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:671: error: syntax error before numeric constant
[Error] \mingw32\share\bison.simple:675: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:670: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:675: error: redefinition of 'yyn'
[Error] \mingw32\share\bison.simple:441: error: previous definition of 'yyn' was here
[Error] \mingw32\share\bison.simple:675: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:675: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:676: error: syntax error before "goto"
[Error] \mingw32\share\bison.simple:694: error: redefinition of 'yystate'
[Error] \mingw32\share\bison.simple:644: error: previous definition of 'yystate' was here
[Error] \mingw32\share\bison.simple:694: error: redefinition of 'yystate'
[Error] \mingw32\share\bison.simple:542: error: previous definition of 'yystate' was here
[Error] \mingw32\share\bison.simple:694: error: initializer element is not constant
[Warning] \mingw32\share\bison.simple:694: warning: data definition has no type or storage class
[Error] \mingw32\share\bison.simple:695: error: syntax error before "goto"
构建中止 y.tab: 65 个错误, 19 个警告
%{
#include
#include
extern char* yylval;
%}
delim "ε"
whitespace {delim}+
plus \+
minus -
star \*
div \/
relop1 <=
relop2 <
relop3 >
relop4 >=
relop5 ==
relop6 !=
constant ([0-9])+
identfier [A-Za-z]
semi [;]
eq [=]
le [\(]
re [\)]
lm [\{]
rm [\}]
ll [\[]
rl [\]]
if "if"
else "else"
while "while"
Main "main"
%%
{identfier} {return ID;}
{constant} {return NUM;}
{relop1} {return relop1;}
{relop2} {return relop2;}
{relop3} {return relop3;}
{relop4} {return relop4;}
{relop5} {return relop5;}
{relop6} {return relop6;}
{if} {return if;}
{else} {return else;}
{while} {return while;}
{Main} {return Main;}
{semi} {return semi;}
{eq} {return eq;}
{le} {return le;}
{re} {return re;}
{lm} {return lm;}
{rm} {return rm;}
{ll} {return ll;}
{rl} {return rl;}
{plus} {return plus;}
{minus} {return minus;}
{star} {return star;}
{div} {return div;}
{delim} { return delim;}
%%
int main()
{
yylex(); /* start the analysis*/
return 0;
}
int yywrap()
{
return 1;
}
%{
#include
#include
%}
%union {
int i;
float f;
char* id;
}
%token plus minus
%token star div
%token relop1 relop2 relop3 relop4 relop5 relop6
%token ID NUM if else while Main semi eq le re lm rm ll rl delim
%nonassoc lower_than_else
%nonassoc else
%%
program : Main le re lm statement_list rm{ printf("program-->main() { statement_list }\n"); }
;
statement_list : statement_list statement { printf("statement_list -->statement_list statement \n"); }
|delim {printf("statement_list --> ε \n");}
;
statement : expression_stmt { printf("statement -->expression_stmt \n"); }
| if_stmt { printf("statement -->if_stmt\n"); }
| while_stmt{ printf("statement -->while_stmt\n"); }
;
expression_stmt: expression semi { printf("expression_stmt --> expression ; \n"); }
|semi { printf("expression_stmt -->; \n"); }
;
if_stmt : if le expression re statement %prec lower_than_else{ printf("if_stmt -->if ( expression ) statement \n"); }
| if le expression re statement else statement { printf("if_stmt -->if ( expression ) statement else statement\n"); }
;
while_stmt: while le expression re statement { printf("while_stmt-->while ( expression ) statement\n"); }
;
expression: var eq expression { printf("expression--> var = expression \n"); }
| simple_expression { printf("expression-- simple-expression\n"); }
;
var : ID { printf("var -->ID\n"); }
| ID ll expression rl { printf("var --> ID [ expression ]\n"); }
;
simple_expression: additive_expression relop additive_expression { printf("simple-expression--> additive-expression relop additive-expression \n"); }
| additive_expression { printf("simple-expression-->additive-expression\n"); }
;
relop : relop1 { printf("relop --> <= | < | > | >= | == |!= \n"); }
|relop2 { printf("relop --> < | > | >= | == |!= \n"); }
|relop3 { printf("relop --> <= | < | > | >= | == |!= \n"); }
|relop4 { printf("relop --> <= | < | > | >= | == |!= \n"); }
|relop5 { printf("relop --> <= | < | > | >= | == |!= \n"); }
|relop6 { printf("relop --> <= | < | > | >= | == |!= \n"); }
;
additive_expression: additive_expression addop term { printf("additive-expression-->additive-expression addop term\n"); }
| term { printf("additive-expression-->term\n"); }
;
addop : plus { printf("addop --> + \n"); }
|minus { printf("addop --> - \n"); }
;
term : term mulop factor { printf("term --> term mulop factor \n"); }
| factor{ printf("term --> factor \n"); }
;
mulop : star { printf("mulop --> * | / \n"); }
|div { printf("mulop --> * | / \n"); }
;
factor: le expression re { printf("factor-->( expression ) \n"); }
| var { printf("factor-->var \n"); }
| NUM { printf("factor-->NUM\n"); }
;
%%
int main()
{
freopen("input.c","r",stdin);
freopen("output.c","w",stdout);
yyparse();
return 0;
}
int yyerror(char *s)
{
fprintf(stderr,"...%s\n",s);
}
代码中的错误消息表明 stdio.h 头文件和 bison.simple 文件中存在语法错误。 这些错误可能是由 stdio.h 和 bison.simple 文件的损坏或过时版本引起的,或者是由这些文件中的函数和关键字的不正确使用引起的。
要修复这些错误,您可以尝试将 stdio.h 和 bison.simple 文件更新到最新版本,或者用信誉良好的来源的新副本替换它们。 您还可以检查您的代码是否对这些文件中的函数和关键字有任何不正确的使用,并确保根据 C 语言的语法和语义正确使用它们。
如果在更新文件和检查代码后错误仍然存在,您可能需要向熟悉 stdio.h 和 bison.simple 文件的开发人员或支持团队寻求进一步的帮助,他们可以帮助您诊断和修复特定问题 导致代码错误的原因。