簡體   English   中英

野牛錯誤:為 Semi 給出的規則,這是一個令牌?

[英]bison error: rule given for Semi, which is a token?

我的野牛語法遇到了錯誤:

解析器.yy:

%union {
  Ast *ast;
  char *str;
  int tok;
}

%token <tok> NEWLINE SEMICOLON
%type <ast> Semi

%%

Semi: NEWLINE { $$ = new Ast($1); }
    | SEMICOLON { $$ = new Ast($1); }
    ;

Statements: Statement
          | Statement Semi Statements
          ;

Statement: ...
         ;

%% 

它給出了錯誤信息:

Parser.yy:xxx.x-x: error: rule given for Semi, which is a token

有沒有辦法實現這個?

或者我必須這樣寫:?

Statements: Statement
          | Statement NEWLINE Statements
          | Statement SEMICOLON Statements
          ;

Semi是一種代幣。 它不需要定義規則即可返回。 就用它吧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM