my bison grammar met an error:
parser.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. It doesn't need define rule to return. Just use it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.