简体   繁体   English

野牛错误:为 Semi 给出的规则,这是一个令牌?

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

my bison grammar met an error:我的野牛语法遇到了错误:

parser.yy:解析器.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: ...
         ;

%% 

It gives error message:它给出了错误信息:

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

Is there a way to implement this?有没有办法实现这个?

Or I have to write it like this: ?或者我必须这样写:?

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

Semi is a token. Semi是一种代币。 It doesn't need define rule to return.它不需要定义规则即可返回。 Just use it.就用它吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM