gpt4 book ai didi

bison - 柔性/Bison : Why my rule is not regonized?

转载 作者:行者123 更新时间:2023-12-01 14:01:44 24 4
gpt4 key购买 nike

我正在尝试使用 FLEX 和 BISON 进行一些练习。

这是我写的代码:

calc_pol.y

%{
#define YYSTYPE double
#include "calc_pol.tab.h"
#include <math.h>
#include <stdlib.h>
%}
%start line
%token NOMBRE
%token FIN
%%
line: exp '\n' { printf("\t%.2lf\n", $1); };
exp: exp exp '+' { $$ = $1 + $2 ;}
| exp exp '-' { $$ = $1 - $2 ;}
| exp exp '*' { $$ = $1 * $2 ;}
| exp exp '/' { $$ = $1 / $2 ;}
| exp exp '^' { $$ = pow($1, $2) ;}
| NOMBRE;
%%

calc_pol.l

%{
#include "calc_pol.tab.h"
#include <stdlib.h>
#include <stdio.h>
extern YYSTYPE yylval;
%}

blancs [ \t]+

chiffre [0-9]
entier [+-]?[1-9][0-9]* | 0
reel {entier}('.'{entier})?

%%

{blancs}
{reel} { yylval = atof(yytext); return NOMBRE; }
\n { return FIN; }
. { return yytext[0]; }
%%

生成文件

all: calc_pol.tab.c lex.yy.c
gcc -o calc_pol $< -ly -lfl -lm

calc_pol.tab.c: calc_pol.y
bison -d calc_pol.y

lex.yy.c: calc_pol.l
flex calc_pol.l

你知道哪里出了问题吗?谢谢

编辑:错误信息是
flex calc_pol.l: calc_pol.l:18: règle non reconnue
第 18 行是以 {reel} 开头的行,错误消息翻译成英文为“unrecognized rule”。

最佳答案

我不想打破灵感闪现的快感,所以才提示:两者有什么区别

1 2

12

关于bison - 柔性/Bison : Why my rule is not regonized?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2410431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com