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