예기치 일단이이 이것이 y.tab.h 파일들소 : 구문 오류 파일
IS%{
#include <stdio.h>
#include <string.h>
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yywrap()
{
return 1;
}
main()
{
yyparse();
}
%}
%token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE
내 thermo.y 파일 내 thermo.l 파일
%{
#include <stdio.h>
#include "y.tab.h"
%}
%%
[0-9]+ return NUMBER;
heat return TOKHEAT;
on|off return STATE;
target return TOKTARGET;
temperature return TOKTEMPERATURE;
\n /* ignore end of line */;
[ \t]+ /* ignore whitespace */;
%%
인
commands: /* empty */
| commands command
;
command:
heat_switch
|
target_set
;
heat_switch:
TOKHEAT STATE
{
printf("\tHeat turned on or off\n");
}
;
target_set:
TOKTARGET TOKTEMPERATURE NUMBER
{
printf("\tTemperature set\n");
}
;
내 THERMO.Y 파일을 컴파일하려고했지만 오류가 발생합니다. "오류 : 구문 오류, 예기치 않은 파일 끝" * Bison을 사용하고 있습니다.
flex thermo.l
bison -y -d thermo.y
gcc -g -c lex.yy.c y.tab.c
gcc -g -0 thermo.n lex.yy.o y.tab.0 -ll
아무도 도와 줄 수 있습니까? bison
manual의 예와 같이
thermo.y 파일에 문법이 표시되지 않습니다. 그 중 일부를 나갔나요? 그것이 전체 파일이라면, 들소는 같은 질문을 할 것입니다 : 문법은 어디에 있습니까? :) – rici
명령 :/* empty */ | 명령 명령 ; 명령 : heat_switch | target_set ; heat_switch : 는 { 의 printf는 ("\을 theat가 또는 \ n을 끌") TOKHEAT 상태; } ; target_set : TOKTARGET TOKTEMPERATURE NUMBER { printf ("\ t 온도 세트 \ n"); } ; – user2986415
질문을 편집하십시오. 주석의 코드를 읽을 수 없습니다. 또한 컴파일 단계의 어떤 지점에서 오류 메시지가 나타날지 명확히 알 수 있습니다. (오류 이후 단계를 생략 할 수 있습니다. 실제로는 관련이 없으므로 실제로 적용하지 않습니다.) – rici