Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- @section Implementation
- For the preprocessor's implementation, we switch gears a bit. The preprocessor needs
- to be the fastest aspect of the entire parser, as directives are everywhere. As such,
- it operates on a hacked-up switch statement using a whole heap of gotos, designed to
- support a specific set of macros. Inserting a new directive into this switch is still
- simple enough, but unlike other aspects of the parser, is not as trivial as a single
- function call. Don't gripe; originally I was going to use a perfect hash.
- **/
- void lexer_cpp::handle_preprocessor() {
- while (cfile[pos] == ' ' or cfile[pos] == '\t') ++pos;
- switch (cfile[pos++])
- {
- case 'd':
- if (strbw(cfile+pos, "efine")) { pos += 5; goto case_define; }
- goto failout;
- case 'e':
- if (cfile[pos] == 'n') { if (strbw(cfile+pos+1, "dif")) { pos += 4; goto case_endif; } goto failout; }
- if (cfile[pos] == 'l')
- {
- if (cfile[++pos] == 's') { if (cfile[++pos] == 'e') { ++pos; goto case_else; } goto failout; }
- if (cfile[pos] == 'i' and cfile[++pos] == 'f')
- {
- if (strbw(cfile[++pos])) goto case_elif;
- if (cfile[pos] == 'd') { if (strbw(cfile+pos+1, "ef")) { pos += 3; goto case_elifdef; } goto failout; }
- if (cfile[pos] == 'n') { if (strbw(cfile+pos+1, "def")) { pos += 4; goto case_elifndef; } goto failout; }
- }
- goto failout;
- }
- if (strbw(cfile+pos, "rror")) { pos += 4; goto case_error; }
- goto failout;
- case 'i':
- if (cfile[pos] == 'f')
- {
- if (strbw(cfile[++pos])) goto case_if;
- if (cfile[pos] == 'd') { if (strbw(cfile+pos+1, "ef")) { pos += 3; goto case_ifdef; } goto failout; }
- if (cfile[pos] == 'n') { if (strbw(cfile+pos+1, "def")) { pos += 4; goto case_ifndef; } goto failout; }
- goto failout;
- }
- if (cfile[pos] == 'n') { if (strbw(cfile+pos+1, "clude")) { pos += 6; goto case_include; } goto failout; }
- if (cfile[pos] == 'm') { if (strbw(cfile+pos+1, "port")) { pos += 5; goto case_import; } goto failout; }
- goto failout;
- case 'l':
- if (strbw(cfile+pos, "ine")) { pos += 3; goto case_line; }
- goto failout;
- case 'p':
- if (strbw(cfile+pos, "ragma")) { pos += 5; goto case_pragma; }
- goto failout;
- case 'u':
- if (strbw(cfile+pos, "ndef")) { pos += 4; goto case_undef; }
- if (strbw(cfile+pos, "sing")) { pos += 4; goto case_using; }
- goto failout;
- case 'w':
- if (strbw(cfile+pos, "arning")) { pos += 7; goto case_warning; }
- goto failout;
- default: goto failout;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement