2 FLEX_PP_CLASS theLexer;
3 #define LEX_DOT theLexer .
8 bool c_keywords = false;
9 bool echo_line_numbers = false;
10 bool echo_line_text = false;
11 size_t line_number = 0;
14 int yywrap() { return 1; }
17 CxxToken *yylex_token()
25 // Configure the lexer to reflect successful parsing of a character value, assigning it to yylval.
27 // The source someText[aLength] should correspond to the parsed text including any L or ' prefix
28 // but excluding any ' suffix. In this way the return can indicate whether a wide character has
29 // been detected and the routine can accommodate a variety of erroneous terminations.
31 CxxToken *make_character(const char *someText, size_t aLength)
34 if (someText && aLength)
42 if (!aLength || (*someText != '\''))
43 ERRMSG("BUG - bad start of character literal.");
51 return make_wide_character(someText, aLength);
53 return make_narrow_character(someText, aLength);
56 CxxToken *make_identifier(const char *someText, size_t aLength)
58 return new CxxNaffToken(PARSE_TOKEN(Identifier), someText, aLength);
62 // Buffer the incoming line, before any characters are analysed.
64 void make_line(const char *yyText, size_t yyLeng)
67 cout << tokenMarkDepth << ": " << line_number << ": " << yyText << flush;
68 else if (echo_line_numbers)
69 cout << line_number << endl;
73 CxxToken *make_literal_character(const char *someText, size_t aLength)
75 return new CxxNaffToken(PARSE_TOKEN(CharacterLiteral), someText, aLength);
78 CxxToken *make_narrow_character(const char *someText, size_t aLength)
80 return new CxxNaffToken(PARSE_TOKEN(CharacterLiteral), someText, aLength);
83 CxxToken *make_narrow_string(const char *someText, size_t aLength)
85 return new CxxNaffToken(PARSE_TOKEN(StringLiteral), someText, aLength);
88 CxxToken *make_number(const char *someText, size_t aLength)
90 return new CxxNaffToken(PARSE_TOKEN(IntegerLiteral), someText, aLength);
94 // Configure the lexer to reflect successful parsing of a categorised string.
96 // The source someText[aLength] should correspond to the parsed text including any
97 // L or " prefix but excluding any " suffix. In this way the return can indicate whether a wide
98 // character has been detected and the routine can accommodate a variety of erroneous terminations.
100 CxxToken *make_string(const char *someText, size_t aLength)
103 if (someText && aLength)
105 if (*someText == 'L')
111 if (!aLength || (*someText != '"'))
112 ERRMSG("BUG - bad start of string literal.");
120 return make_wide_string(someText, aLength);
122 return make_narrow_string(someText, aLength);
126 // Return the appropriate 1 of 256 flyweight tokens for the ASCII characters.
128 CxxToken *make_token(size_t tokenValue)
130 static CxxToken *asciiTokens[256];
131 if (tokenValue >= (sizeof(asciiTokens)/sizeof(asciiTokens[0])))
133 ERRMSG("Cannot make_token for " << tokenValue);
136 CxxToken **p = &asciiTokens[tokenValue];
137 CxxToken *theToken = *p;
139 *p = theToken = new CxxToken(tokenValue);
143 CxxToken *make_wide_character(const char *someText, size_t aLength)
145 return new CxxNaffToken(PARSE_TOKEN(CharacterLiteral), someText, aLength);
148 CxxToken *make_wide_string(const char *someText, size_t aLength)
150 return new CxxNaffToken(PARSE_TOKEN(StringLiteral), someText, aLength);