ids ; ids: ID ids_ ; ids_:...

问题描述 投票:-1回答:1
Your grammar starts with

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 ("("|")"|",")

If those
parsing compiler-construction yacc
1个回答
2
投票

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标记时,解析器会以一个错误终止。下面是词法代码FROMRelOp是一个模式-

和符号是一个模式 printf 我正在为一个SQL解析器写一个语法,我一直卡在这个问题上,现在-- F: FETCH fields FROM tables Conditions ; fields: ALL

© www.soinside.com 2019 - 2024. All rights reserved.