【发布时间】:2012-10-25 12:02:29
【问题描述】:
您好,我刚刚开始在 bison/yacc 中进行一些解析。现在我的第一个程序已经失败了。什么地方出了错?我正在使用以下示例: original source of tutorial
%{
#include <stdio.h>
int yylex(void);
void yyerror(char *);
%}
%token INTEGER
%%
program:
program expr '\n' { printf("%d\n", $2); }
|
;
expr:
INTEGER { $$ = $1; }
| expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
;
%%
void yyerror(char *s) {
fprintf(stderr, "%s\n", s);
}
int main(void) {
yyparse();
return 0;
}
使用 2.4.1 版的 bison 我收到此错误:
conflicts: 4 shift/reduce
【问题讨论】:
-
AIX Documentation of yacc 解释了我的问题。我的语法模棱两可