0
최근 lex와 yacc (및 flex와 bison)을 발견했으며 프로그램에 문장이 있는지 알려면 오류가 발생합니다.Lex와 Yacc/Flex와 bison 구문 오류
%{
#include <stdio.h>
#include "1.tab.h"
%}
%%
tweety|sylvester return NP;
a|the return AR;
cat|bird return NC;
run|fly return VI;
eat|hate return VT;
"." return POINT;
.|\n
%%
과 .yacc :
lex file.lex
bison -d file.yacc
gcc lex.yy.c 1.tab.c -o test -lfl
I를 : 여기에
%{
#include <stdio.h>
%}
%token NP AR NC VI VT POINT
%%
S: PH POINT {printf("Sentence found !\n");}
PH: GN VT GN|GN VI
GN: NP|AR NC
%%
main(){
yyparse();
}
yyerror(char *s)
{
fprintf(stderr, "error: %s\n", s);
}
내가 프로그램을 컴파일하는 데 사용하는 명령입니다 여기
는 .lex이다 파일입니다 프로그램을 실행하려고하면 첫 번째 입력에 대해서는 잘 작동하지만 이후에는 오류가 발생합니다. 여기에 예를 엉 : 당신이 어떤 생각을 가지고 있습니까
./test
tweety fly.
Sentence found !
tweety hate sylvester.
error: syntax error
?
감사합니다.
대단히 감사합니다. – eli0T