DEV Community

Bruce Axtens
Bruce Axtens

Posted on

DSL (from the repository and probably not the best way of doing one either)

Just posted a piece of programming memorabilia: a simple "Script Language Interpreter" originally written in MoonRock BASIC and then reimplemented in C#.

The original MoonRock BASIC source is provided along with the more recent C#. A number of sample scripts are also provided, including the classic "99 Bottles of Beer".

    MACRO dec inc $1 -1
    define times 1
    defined %2
    ifyes set times {%2}

    define bottles 99
    define pronoun one
label drink
    message {bottles} bottles of beer on the wall\n
    message {bottles} bottles of beer\n
    message take {pronoun} down and pass it round\n
    inc bottles -1
    test eq {bottles} 1
    ifyes goto lastone
    message {bottles} bottles of beer on the wall\n
    message \n
    goto drink

label lastone
    message {bottles} bottle of beer on the wall\n\n
    set pronoun it
    message {bottles} bottle of beer on the wall\n
    message {bottles} bottle of beer\n
    message take {pronoun} down and pass it round\n
    message no more bottles of beer on the wall\n\n
    message no more bottles of beer on the wall\n
    message no more bottles of beer\n
    message go to the store and buy some more\n
    set bottles 99
    set pronoun one
    message {bottles} bottles of beer on the wall\n
    message \n

    inc times -1
    test eq {times} 0
    ifno goto drink
    end Burrrrp!
Enter fullscreen mode Exit fullscreen mode

For other implementations of 99BoB, see 99 Bottles of Beer on RosettaCode.

RosettaCode is good for more than just irrelevant drinking songs. There's lots of good programming code demonstrated there.

Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another. Rosetta Code currently has 961 tasks, 215 draft tasks, and is aware of 744 languages, though we do not (and cannot) have solutions to every task in every language.

Top comments (0)