However, your lexer rules includes
F: FETCH fields FROM tables Conditions
;
fields: ALL
| ids
;
ids: ID ids_
;
ids_: ',' ID ids_
| { /*empty*/ }
;
tables: ID
;
Conditions: WHERE ConditionList
| { /*empty*/ }
;
ConditionList: Condition ConditionList_
;
ConditionList_: BoolOp Condition ConditionList_
| { /*empty*/ }
;
Condition: Operand RELOP Operand
| NOT Operand RELOP Operand
;
Operand: ID
| NUM
;
BoolOp: AND
| OR
;
Since
FETCH{ printf("fetch "); return FETCH;}
FROM { printf("from "); return UNIQUE; }
ALL { printf("all "); return ALL; }
WHERE { printf("where "); return WHERE; }
AND { printf("and "); return AND; }
OR { printf("or "); return OR; }
NOT { printf("not "); return NOT; }
RelOp { printf("%s", yytext); yylval.string = strdup(yytext); return RELOP; }
[0-9]* {printf("num "); return NUM; }
[_a-zA-Z][_a-zA-Z0-9]* { printf("id "); return ID; }
{symbol} { printf("%c ", yytext[0]); return yytext[0]; }
. { }
is different from RelOp ("<"|"<="|">"|">="|"=")
, the grammar rule won't apply.symbol ("("|")"|",")
to get an accurate view of what is going on. (Bison's trace will tell you which token type is being received by the parser, for example.)
F: FETCH fields FROM tables Conditions
FROM { printf("from "); return UNIQUE; }
我正在为一个SQL解析器写语法,我已经被这个问题卡住了一段时间--。UNIQUE
由于某些原因,当lexer读取FROM标记时,解析器会以一个错误终止。下面是词法代码FROM
RelOp是一个模式-
和符号是一个模式 printf
我正在为一个SQL解析器写一个语法,我一直卡在这个问题上,现在-- F: FETCH fields FROM tables Conditions ; fields: ALL