Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
执行使用lex和yacc工具开发的c文件时出错_C_Compiler Construction_Yacc_Lex - Fatal编程技术网

执行使用lex和yacc工具开发的c文件时出错

执行使用lex和yacc工具开发的c文件时出错,c,compiler-construction,yacc,lex,C,Compiler Construction,Yacc,Lex,我正在尝试开发一个程序,使用lex和yacc工具将中缀表达式转换为后缀表达式 以下是源代码: (Lex计划:ipi.l) (Yacc项目:ipi.y) 请帮我解决这个问题。 提前感谢。您应该提供您自己的yyerror,如下所示: void yyerror (char *s) { fprintf (stderr, "%s\n", s); } 资料来源: %{ #include <stdio.h> #include <stdlib.h> %} %token

我正在尝试开发一个程序,使用lex和yacc工具将中缀表达式转换为后缀表达式

以下是源代码:

(Lex计划:ipi.l)

(Yacc项目:ipi.y)

请帮我解决这个问题。
提前感谢。

您应该提供您自己的
yyerror
,如下所示:

void yyerror (char *s) {
    fprintf (stderr, "%s\n", s);
}
资料来源:

%{
#include <stdio.h>
#include <stdlib.h>
%}
%token    ID
%left    '+' '-'
%left    '*' '/'
%left    UMINUS

%%

S    :    E
E    :    E'+'{A1();}T{A2();}
     |    E'-'{A1();}T{A2();}
     |    T
     ;
T    :    T'*'{A1();}F{A2();}
     |    T'/'{A1();}F{A2();}
     |    F
     ;
F    :    '('E{A2();}')'
     |    '-'{A1();}F{A2();}
     |    ID{A3();}
     ;

%%

#include "lex.yy.c"
char st[100];
int top=0;

main()
{
 printf("Enter infix expression:  ");
 yyparse();
 printf("\n");
}

A1()
{
  st[top++]=yytext[0];
}

A2()
{
 printf("%c",st[--top]);
}

A3()
{
  printf("%c",yytext[0]);
}
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/liby.a(yyerror.o): In function `yyerror':
 (.text+0x1c): undefined reference to `rpl_fprintf'
 collect2: ld returned 1 exit status
void yyerror (char *s) {
    fprintf (stderr, "%s\n", s);
}