C++ lex和yacc中没有来自lexer的输出

C++ lex和yacc中没有来自lexer的输出,c++,token,flex-lexer,lex,C++,Token,Flex Lexer,Lex,我在使用lex和yacc时观察到一种奇怪的行为 这是我的lex文件--ex.l %option noyywrap %option yylineno %{ #include <iostream> using namespace std; #include "y.tab.h" void yyerror(char *); // to get the token types that we return %} %% [ \t] ; [0-9]+\.[0-9

我在使用lex和yacc时观察到一种奇怪的行为

这是我的lex文件--ex.l

%option noyywrap
%option yylineno
%{
#include <iostream>
using namespace std; 

#include "y.tab.h" 
 
void yyerror(char *);  // to get the token types that we return
%}

%%
[ \t] ;

[0-9]+\.[0-9]+ { yylval.fval = atof(yytext); //this is not working 
                 cout << "lex found an float: "; return FLOATS; }
[0-9]+  { cout << "lex found an int: "; yylval.ival = atoi(yytext); return INTS; }
[a-zA-Z0-9]+ {
     
    char *res = new char[strlen(yytext) + 1];
    strcpy(res, yytext);
    yylval.sval = res;
    return STRINGS;
}

. ;

%%
%选项noyywrap
%选项yylineno
%{
#包括
使用名称空间std;
#包括“y.tab.h”
void yyerror(char*);//获取返回的令牌类型
%}
%%
[\t];
[0-9]+\[0-9]+{yylval.fval=atof(yytext);//这不起作用

问题是我认为以下代码在ex.y

%token <ival> INTS
%token <fval> FLOATS
%token <sval> STRINGS
希望这有帮助


注意:我没有测试代码。因此,在执行此操作后,您可能会出现其他错误。

据我所知,您没有输入任何浮点数。;)ex.l中的cout语句后面没有任何值-如果您将
cout@codebeard:为什么如此???现在它正在工作??我不完全清楚您希望看到的输出是什么…与原始我得到的代码:
/a.out/34/lex找到了一个int:/56/lex找到了一个int:/78/lex找到了一个int:/yacc找到了一个int:78/yacc找到了一个int:56/yacc找到了一个int:34
在我做那个更改之前它对我有效。
%token <ival> INTS
%token <fval> FLOATS
%token <sval> STRINGS
%token INTS
%token FLOATS
%token STRINGS