/* parse C comments interactively, using events and a state machine */ main() state plain @keypressed(key) { state (key == '/') slash if (key != '/') echo key } @keypressed(key) { state (key != '/') plain state (key == '*') comment echo '/' /* print '/' held back from previous state */ if (key != '/') echo key } @keypressed(key) { echo key state (key == '*') star } @keypressed(key) { echo key state (key != '*') comment state (key == '/') plain } echo(key) printchar key, yellow echo(key) printchar key, green printchar(ch, colour) { setattr .foreground = colour printf "%c", ch }