Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Interpreter101_simple
/*
Google I/O 2008 - Dalvik Virtual Machine Internals
Interpreters 101, toy interpreter
This is a simple toy bytecode interpreter
*/
#include <cstdio>
static void interpreter(const char* stringOfBytecode);
int main(int argc, char *argv[]) {
interpreter("abcbbbbde");
}
static void interpreter(const char* stringOfBytecode) {
for (;;) {
switch (*(stringOfBytecode++)) {
case 'a': printf("Hell"); break;
case 'b': printf("o"); break;
case 'c': printf(" w"); break;
case 'd': printf("rld!\n"); break;
case 'e': return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment