我想在FLEX和BISON中做一点练习。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]; }
%%
的Makefile
你知道什么是错吗? 感谢
编辑: 的错误消息是
flex calc_pol.l: calc_pol.l:18: règle non reconnue
第18行是{reel}
开头的行,和错误信息翻译成英文为“无法识别的规则”。
症状?...... – 2010-03-09 16:07:12
要回答这个问题,我不知道什么是错的。你有任何实际证据表明有什么问题吗?如诊断输出,还是来自calc_pol的测试结果? – 2010-03-09 16:10:21
'flex calc_pol.l':calc_pol.l:18:règlenon reconnue – Natim 2010-03-09 16:16:51