作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在编译野牛代码时遇到问题,尝试编译此代码:
%{
#include <stdio.h>
#include <stdlib.h>
#include <stdstring.h>
//#include "list.h"
int yylex();
int errore = 0;
void yyerror(char const *s);
%}
%union{
char *stringa;
double reale;
int intero;
}
%start Input
%token <stringa> MATR
%token <reale> CFU COD_M
%token <intero> ANNO_C VOTO
%token AA DATA MATERIA SEP1 SEP2 VIR LANC PEV PAR_I PAR_F TRAT NOME
%define parse.error verbose
%%
Input : AA DATA SEP1 Corsi SEP2 Studenti
;
Corsi : El_Materie
;
El_Materie : Materie
El_Materie Materie
;
Materie : PAR_I COD_M VIR MATERIA VIR ANNO_C VIR CFU PAR_F
;
Studenti : El_Studenti
;
El_Studenti : Studente Lista_M
El_Studenti Studente Lista_M
;
Studente : MATR LANC NOME PEV ANNO_C PEV
;
Lista_M : Esame
Lista_M Esame
;
Esame : COD_M VIR VOTO TRAT
;
%%
void yyerror(char const *s){
fprintf(stderr, "Errore: %s\n", s);
}
int main(void){
if(yyparse() == 0){
print();
}
return 0;
}
它给了我这个错误:
Carriera1.y: warning: 10 nonterminals useless in grammar [-Wother]
Carriera1.y: warning: 10 rules useless in grammar [-Wother]
Carriera1.y:16.8-13: fatal error: no phrase is derived from the initial symbol Start
16 | %start Input
我该如何解决该错误?
Carriera.fl: In function ‘yylex’:
Carriera.fl:38:17: error: assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast [-Werror=int-conversion]
38 | {Matr} {yylval.stringa = strdup(yytext); return(MATR);}
| ^
At top level:
lex.yy.c:1251:16: error: ‘input’ defined but not used [-Werror=unused-function]
1251 | static int input (void)
| ^~~~~
lex.yy.c:1208:17: error: ‘yyunput’ defined but not used [-Werror=unused-function]
1208 | static void yyunput (int c, char * yy_bp )
| ^~~~~~~
谢谢
最佳答案
要定义具有多个替代项的规则,请使用|
运算符(而不是换行符)分隔替代项。您当然可以保留换行符以提高可读性,但是|
运算符实际上是分隔替代项的地方。
Lista_M : Esame
Lista_M Esame
Lista_M : Esame Lista_M Esame
相同,因此是无限递归的,这就是规则无法匹配任何内容的原因。
关于compiler-errors - 如何在 Bison 码中解决此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62478843/
我是一名优秀的程序员,十分优秀!