Created
March 20, 2012 19:18
-
-
Save amorri40/2140090 to your computer and use it in GitHub Desktop.
Interpreter101_simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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