作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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/
我正在尝试使用 FLEX 和 BISON 进行一些练习。 这是我写的代码: calc_pol.y %{ #define YYSTYPE double #include "calc_pol.tab.h"
我是一名优秀的程序员,十分优秀!