yacc에 대한 다음 코드를 참조하십시오. 생산 요소를 제거하면 '!' expr, 구문 분석 충돌이 사라집니다. 여기에 무슨 일이 일어 났습니까? 파서가 볼 때 때문에 충돌이 아마 발생과 같은shift/reduce 충돌 yacc
%{
#include <stdio.h>
#include <ctype.h>
%}
%token TRUE
%token FALSE
%%
line : line expr '\n' { printf("%d\n", $2); }
| line '\n'
|
;
expr : expr "or" term { printf("expr : expr or term\n"); $$ = $1 | $3; }
| term { printf("expr : term\n"); }
;
term : term "and" factor { printf("term : term and factor\n"); $$ = $1 & $3; }
| factor { printf("term : factor\n"); }
;
factor : '(' expr ')' { printf("factor : (expr)\n"); $$ = $2; }
| '!' expr { printf("factor : !expr\n"); $$ = !$2; }
| TRUE { printf("factor : TRUE\n"); }
| FALSE { printf("factor : FALSE\n"); }
;
%%
#include "lex.yy.c"
int main(int argc, char** argv)
{
while (yyparse() == 0) {
}
return 0;
}