UnoScript

From Esolang
Jump to navigation Jump to search

UnoScript is a stack-based, interpreted language inspired by the UNO card game. It aims to be as general-purpose and usable as possible while meeting the constraint that any sequence of UNO cards can be interpreted as an UNO program.

Language description

Symbols

A standard UNO card game comes with cards of the following types:

  • Color cards in red, yellow, green and blue, each with a digit between 0 and 9
  • Skip cards
  • Reverse cards
  • Draw Two cards in red, yellow, green and blue
  • Wild Draw Four cards
  • Wild cards

An UnoScript program consists of a sequence of these cards, with the original UNO cards mapped to the strings:

  • Color -> [rygb][0-9]
  • Skip -> skip
  • Reverse -> reverse
  • Draw Twp -> draw2
  • Wild Draw Four -> draw4
  • Wild -> wild

Resources

The language specifies an internal stack capable of holding Color, Draw Two, Wild Draw Four and Wild card types. This internal stack is used to perform operations.

The language also specifies an array of length 40 capable of holding any card type. Each Color card can be used as an index into the array.

Execution model

UnoScript is interpreted in a similar manner to a Turing machine, where the program source can be pictured as symbols printed on a tape. The interpreter head begins with the first item. Based on its value and the top value of the stack, the head can choose to manipulate the stack or card array, and then must move to the right or left.

In order to meet the constraint that any sequence of UNO cards be valid, the language makes provisions to handle out-of-bounds resource access, e.g. reading the top value of an empty stack will return a Wild card.

Sample program

The following "hello world" program is taken from the examples provided by the interpreter. It will print "Hello world" to standard out, followed by a new line.

# ( -- \ndlrow olleH )
y1y0
r1r0r0
y1y0y8
r1r1r4
y1y1y1
r1r1r9
y3y2
r1r1r1
y1y0y8
r1r0r8
y1y0y1
r7r2
# ( \ndlrow olleH -- )
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2
draw2g2

Interpreter

Currently, the only interpreter for UnoScript is implemented in C++ and flex.

External links