Skip to content

Instantly share code, notes, and snippets.

@ksherlock
Created December 4, 2015 21:57
Show Gist options
  • Save ksherlock/d45d4665730d63429f09 to your computer and use it in GitHub Desktop.
Save ksherlock/d45d4665730d63429f09 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
void none(void) {
std::cout << "I'm none..." << std::endl;
}
void red(void) {
std::cout << "I'm red!" << std::endl;
}
void blue(void) {
std::cout << "I'm blue!" << std::endl;
}
void process(const std::string &s) {
%%{
machine process;
main :=
/red/i %{ return red(); }
|
/blue/i %{ return blue(); }
;
}%%
%% write data;
int cs;
const char *p = s.data();
const char *pe = s.data() + s.size();
const char *eof = pe;
%% write init;
%% write exec;
return none();
}
int main(int argc, char **argv) {
std::string s;
while (std::cin >> s) {
process(s);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment