BSD 4_4_Lite2 development
[unix-history] / usr / src / contrib / flex-2.5.2 / MISC / testxxLexer.l
CommitLineData
715c0496
C
1 // An example of using the flex C++ scanner class.
2
3%option C++ noyywrap
4
5%{
6int mylineno = 0;
7%}
8
9string \"[^\n"]+\"
10
11ws [ \t]+
12
13alpha [A-Za-z]
14dig [0-9]
15name ({alpha}|{dig}|\$)({alpha}|{dig}|\_|\.|\-|\/|\$)*
16num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)?
17num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
18number {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
52int main( int /* argc */, char** /* argv */ )
53 {
54 FlexLexer* lexer = new yyFlexLexer;
55 while(lexer->yylex() != 0)
56 ;
57 return 0;
58 }