嗨,当我运行以下 Bison 时,我得到 $$ 没有返回类型:
%{
#include <stdio.h>
#include <string.h>
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yywrap()
{
return 1;
}
main()
{
yyparse();
}
%}
%start query
%token AND OR GREATER LESS COLON TO
%union
{
int number;
char *string;
}
%token <number> VALUE
%token <string> WORD
%%
query: /* empty */
| query expression { }
;
expression:
term
|expression AND term {$$=$1}
|expression OR term {}
;
term:
WORD { printf("Term:%s\t",$1);}
| VALUE
;
以下是我的弹性:
%{
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
%}
%%
":" return COLON;
"and"|"&"|"&&" return AND;
"or"|"|"|"||" return OR;
".." return TO;
">" return GREATER;
"<" return LESS;
\n /* ignore end of line */;
\t /* ignore end of line */;
%%
这个错误是什么意思?我怎样才能解决这个问题?