shengyushen
shengyushen

Reputation: 289

class name is not declared in flex c++ scanner

I am trying to generate a c++ scanner with flex, below is the message printed out by flex and g++.

|| flex -o step1_noinc.cpp --c++ --yyclass=step1_noinc  step1_noinc.lex
|| g++  -c step1_noinc.cpp
step1_noinc.cpp|345 col 21| error: ‘step1_noinc’ has not been declared                                                                                                                                              
||  #define YY_DECL int step1_noinc::yylex()

It says that the class name have not been declared, So what is going on?

I simplify my lex code as much as possible like below to ease debug :

%%

<*>\n {
}

%%

Upvotes: 0

Views: 434

Answers (1)

rici
rici

Reputation: 241751

Yes, it is up to you to define that class.

From the flex manual:

--yyclass=NAME, %option yyclass="NAME"

only applies when generating a C++ scanner (the --c++ option). It informs flex that you have derived NAME as a subclass of yyFlexLexer… (emphasis added)

Note the use of the word "you" in that sentence. Flex always defines the yyFlexLexer class (possibly changing the yy prefix), but it also allows you to subclass, in case you have several different similar scanners in a project.

Aside from changing the prefix yy, as far as I know you cannot modify the name of the class flex generates.

Upvotes: 1

Related Questions