1 // An example of using the flex C++ scanner class. 2 3 %option C++ noyywrap 4 5 %{ 6 int mylineno = 0; 7 %} 8 9 string \"[^\n"]+\" 10 11 ws [ \t]+ 12 13 alpha [A-Za-z] 14 dig [0-9] 15 name ({alpha}|{dig}|\$)({alpha}|{dig}|\_|\.|\-|\/|\$)* 16 num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)? 17 num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)? 18 number {num1}|{num2} 19 20 %% 21 22 {ws} /* skip blanks and tabs */ 23 24 "/*" { 25 int c; 26 27 while((c = yyinput()) != 0) 28 { 29 if(c == '\n') 30 ++mylineno; 31 32 else if(c == '*') 33 { 34 if((c = yyinput()) == '/') 35 break; 36 else 37 unput(c); 38 } 39 } 40 } 41 42 {number} cout << "number " << YYText() << '\n'; 43 44 \n mylineno++; 45 46 {name} cout << "name " << YYText() << '\n'; 47 48 {string} cout << "string " << YYText() << '\n'; 49 50 %% 51 52 int main( int /* argc */, char** /* argv */ ) 53 { 54 FlexLexer* lexer = new yyFlexLexer; 55 while(lexer->yylex() != 0) 56 ; 57 return 0; 58 } 59