#ifndef __DefaultLex_RECURSIVE_INTERNAL__ #define __DefaultLex_RECURSIVE_INTERNAL__ // recurisvely include this source file to include state definitions #include __FILE__ #include "sample.hh" ///////////////////////////////////////////////////////// // // macros for compatibility with lex/flex // ///////////////////////////////////////////////////////// #ifndef ECHO #define ECHO yoogroup::operator<< (*_yyOS, _yyText) #endif // ECHO #define BEGIN(s) yyBegin (YYSTATE_##s) #define yyleng _yyText.size () #define yyless(n) yyUnput ((int)_yyText.size () - n) #define yyterminate() return YYSType (-1) ///////////////////////////////////////////////////////// // // Now user's code in section 1 of input // ///////////////////////////////////////////////////////// #line 2 "sample.l" // // sample.l // // A simple demonstration of features in YooLex // // This part is put in the beginning of the generated C++ source file. // using namespace std; #line 42 "sample.cc" ///////////////////////////////////////////////////////// // // the main case switch of the scanner // ///////////////////////////////////////////////////////// yoogroup::YooLex::YYSType DefaultLex::yyLexCase (int yySwitch) { _yyReturnValue = true; // // some of user defined code are here // #line 17 "sample.l" // // This part is put in the beginning of the yycase functions, which // is used for switching the accepted states when a string is accepted. // Since in C++ variables can be declared anywhere, the significance of // region is to basically setup certain variables each time upon the // entry of the lex class // #line 69 "sample.cc" switch (yySwitch) { case 1: // in case some regex is not specified by the user ECHO; #line 74 "sample.cc" break; case 5: #line 28 "sample.l" { ECHO; cout << endl << "switching to IDENT" << endl; BEGIN (IDENT); } #line 84 "sample.cc" break; case 6: #line 33 "sample.l" { ECHO; cout << endl << "switching to NUMBER" << endl; BEGIN (NUMBER); } #line 94 "sample.cc" break; case 7: #line 38 "sample.l" ++_lineNumber; #line 100 "sample.cc" break; case 8: #line 39 "sample.l" ; #line 106 "sample.cc" break; case 3: // EOF for IDENT case 2: // EOF for INITIAL { cout << "Total lines: " << _lineNumber << endl; // do not have to call yyterminate } #line 116 "sample.cc" break; case 9: #line 46 "sample.l" { ECHO; cout << endl << "switching to INITIAL" << endl; BEGIN (INITIAL); } #line 126 "sample.cc" break; case 10: #line 51 "sample.l" cout << "."; #line 132 "sample.cc" break; case 11: #line 52 "sample.l" ++_lineNumber; #line 138 "sample.cc" break; case 12: #line 53 "sample.l" ; #line 146 "sample.cc" break; case 13: #line 57 "sample.l" { ECHO; cout << endl << "switching to INITIAL" << endl; BEGIN (INITIAL); } #line 156 "sample.cc" break; case 4: // EOF for NUMBER { cerr << "Unexpected end of file" << endl; // // return a non-negative value to force the // scanner to generate a <> token again // not possible if the yylex calling routine // takes seriously the return value :) // BEGIN (INITIAL); return 0; } #line 171 "sample.cc" break; case 14: #line 73 "sample.l" ECHO; #line 177 "sample.cc" break; case 15: #line 74 "sample.l" ++_lineNumber; #line 183 "sample.cc" break; case 16: #line 75 "sample.l" ; #line 190 "sample.cc" break; yyterminate (); } _yyReturnValue = false; return YYSType(-1); } static unsigned char _yylex_ecs[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #define YYLEX_TRANSLATE(a) _yylex_ecs[a] static int _yylex_accept[18] = { 2, 0, 8, 7, 6, 5, 3, 0, 12, 11, 9, 10, 4, 0, 16, 15, 13, 14 }; static char _yylex_default[21] = { 20, 0, 20, 20, 20, 20, 20, 6, 20, 20, 20, 20, 18, 19, 20, 20, 20, 20, 20, 20, 20 }; static char _yylex_base[21] = { 0, 0, 0, 0, 2, 2, 6, 0, 0, 0, 8, 8, 11, 13, 0, 0, 14, 0, 17, 18, 19 }; static char _yylex_next[20] = { 2, 3, 4, 5, 4, 5, 8, 9, 10, 11, 10, 11, 15, 16, 15, 16, 16, 14, 17, 0 }; static char _yylex_check[20] = { 0, 0, 0, 0, 4, 5, 6, 6, 6, 6, 10, 11, 12, 12, 13, 13, 16, 18, 19, 20 }; ///////////////////////////////////////////////////////// // // DFA state lookup macro // ///////////////////////////////////////////////////////// #define YYLEX_DFA(outstate,instate,a) register int e = a; \ outstate = instate; \ while (_yylex_check[e + _yylex_base[outstate]] != outstate) \ { \ outstate = _yylex_default[outstate]; \ if (outstate >= 18) \ e = 0; \ } \ outstate = _yylex_next[e + _yylex_base[outstate]]; ///////////////////////////////////////////////////////// // // string matching function // ///////////////////////////////////////////////////////// yoogroup::YooLex::YYSType DefaultLex::yyLex () { while (true) { // initiate variables necessary for lookup _yyIsBOL = _yyIsNextBOL; _yyIsNextBOL = false; size_t matchedState = _yyBaseState + (_yyIsBOL ? 1 : 0); size_t matchedLength = 0; #if defined(__GNUC__) && (__GNUC__ < 3) _yyText.erase (_yyText.begin (), _yyText.end ()); #else _yyText.clear (); #endif YYInternalBuffer::iterator internalBufferEnd = _yyInternalBuffer.end (); YYInternalBuffer::iterator lookahead = _yyLastMatchStart; // the DFA lookup while (true) { // check buffer status if (lookahead < internalBufferEnd) { // now okay to process the character register size_t currentState; YYLEX_DFA (currentState, matchedState, YYLEX_TRANSLATE (static_cast(*lookahead))); if (currentState == 0) break; matchedState = currentState; ++lookahead; ++matchedLength; } else { int lookPos = lookahead - _yyLastMatchStart; bool refresh = yyRefreshBuffer (); internalBufferEnd = _yyInternalBuffer.end(); lookahead = _yyLastMatchStart + lookPos; if (! refresh) { // <> if (matchedLength == 0) return yyLexCase (_yylex_accept[_yyBaseState]); break; } } } _yyText.assign (_yyLastMatchStart, _yyLastMatchStart + matchedLength); _yyLastMatchStart += matchedLength; YYSType val (yyLexCase (_yylex_accept[matchedState])); // check BOL here since '\n' may be unput back into // the stream buffer if (_yyLastMatchStart > _yyInternalBuffer.begin () && *(_yyLastMatchStart - 1) == '\n') { _yyIsNextBOL = true; } if (_yyReturnValue) return val; } } ///////////////////////////////////////////////////////// // // the rest of the user's code // ///////////////////////////////////////////////////////// #line 78 "sample.l" // // This part is put in the end of the C++ source file // int main () { DefaultLex scanner; while (scanner.yyLex () >= 0) ; return 0; } ///////////////////////////////////////////////////////// // // YooLex Statistics // // NFA states = 36 // DFA states = 18 // equivalent classes = 4/256 // ///////////////////////////////////////////////////////// #else // __DefaultLex_RECURSIVE_INTERNAL__ ///////////////////////////////////////////////////////// // // base table name and values // ///////////////////////////////////////////////////////// #define YYSTATE_INITIAL 0 #define YYSTATE_IDENT 6 #define YYSTATE_NUMBER 12 #endif // __DefaultLex_RECURSIVE_INTERNAL__