Those of you who participated in the NCSS Challenge this year, or attended NCSS at the start of the year may have encountered Fantasy VM, a rather silly Virtual Machine with direct hardware support for variables!
Some people have started a programming meme, so I thought I'd join in.
For this program however, it soon became apparent that the simple Fantasy VM would not come up to the job, as it had no support for strings. However, with a little bit of hacking, I've created Fantasy VM 2! The specifications for the VM are similar, it's fully backwards compatible, but adds a few instructions to make working with strings possible. The silliest part which I've added is the support of the ADD operator for strings, but considering that it's a very silly language, I'm regarding it as a feature, not a bug.
So, here's the program in FVM2:
SET name_prompt "Please enter your name:" SET age_prompt "Please enter your age:" SET counter 0 SET test 0 SET one 1 SET start ") Hello, " READ$ name name_prompt READ$ age age_prompt INT age age SUB age age one SUB test age counter # pretest JGE test 13 # skip JGE one 19 STR counter_s counter # skip ADD greeting start name ADD greeting counter_s greeting PRINT greeting ADD counter counter one JGE one 10 #pretest NOP
And here is an interpreter for the language, written in Python. To run, just save the above program to a file, and call "python fvm2.py filename.vm".
flowblok’s blog