[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with c++ sample in flex 2.5.11
From: |
Bernd Prager |
Subject: |
Re: help with c++ sample in flex 2.5.11 |
Date: |
Tue, 13 Aug 2002 17:11:58 -0400 |
----- Original Message -----
From: "W. L. Estes" <address@hidden>
...
> On Tuesday, 13 August 2002,13:53 -0400, Bernd Prager wrote:
>
> > I'm trying to make the c++ example from the doc working.
>
> You have put the @samp{*} in your code. that is not what you
> want. See the compiler's reference to line 28.
>
> --Will
Sorry, you're right. I missed that.
But I'm still not successful.
Corrected the code to:
---------- test.l --------------------------
%{
#include <iostream>
using std::cout;
using std::endl;
int mylineno = 0;
%}
string \"[^\n"]+\"
ws [ \t]+
alpha [A-Za-z]
dig [0-9]
name ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)?
num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
number {num1}|{num2}
%%
{ws} /* skip blanks and tabs */
"/*" {
int c;
while((c = yyinput()) != 0)
{
if(c == '\n')
++mylineno;
else if(c == '*')
{
if((c = yyinput()) == '/')
break;
else
unput(c);
}
}
}
{number} cout << "number " << YYText() << endl;
\n mylineno++;
{name} cout << "name " << YYText() << endl;
{string} cout << "string " << YYText() << endl;
%%
int main( int /* argc */, char** /* argv */ )
{
FlexLexer* lexer = new yyFlexLexer;
while(lexer->yylex() != 0)
;
return 0;
}
------ end test.l --------------------------
and end up with the error code:
-------- snip -----------------------------
g++ -o test test.tab.cc -lfl
test.l: In function `int yylex()':
test.l:42: `YYText' undeclared (first use this function)
test.l:42: (Each undeclared identifier is reported only once for each
function
it appears in.)
test.tab.cc: At global scope:
test.tab.cc:2033: `c' was not declared in this scope
test.tab.cc:2033: `yy_bp' was not declared in this scope
test.tab.cc:2034: variable or field `yyunput' declared void
test.tab.cc:2034: `int yyunput' redeclared as different kind of symbol
test.tab.cc:1335: previous declaration of `void yyunput(int, char*)'
test.tab.cc:2034: initializer list being treated as compound expression
test.tab.cc:2034: syntax error before `int'
test.tab.cc:2035: register name not specified for `char*yy_bp'
test.tab.cc:2039: parse error before `{' token
test.tab.cc:2043: ISO C++ forbids declaration of `yy_cp' with no type
test.tab.cc:2043: invalid conversion from `char' to `int*'
test.tab.cc:2045: parse error before `if'
test.tab.cc:2049: register name not specified for `char*dest'
test.tab.cc:2052: `number_to_move' was not declared in this scope
test.tab.cc:2051: register name not specified for `char*source'
test.tab.cc:2054: parse error before `while'
test.tab.cc:2057: syntax error before `+=' token
-------- snip -----------------------------
Any help is really appreciated.
Thanks,
-- Bernd