TAML

From Esolang
Jump to navigation Jump to search
TAML
Paradigm(s) imperative declerative
Designed by User:LabRicecat
Appeared in 2021
Computational class Unknown
Reference implementation Unimplemented
Influenced by ini
File extension(s) .taml

TAML, the Text Adventure Markup Language, is an esoteric programming language intending to lay out the program as a kind of text adventure-like tree structure.

Language overview

A TAML program, called an Adventure consists of a set of Questions, where each one has a fixed amount of Answers. Syntactically these are split into three parts: Name, Event and Answers.
Typically a question would look like this

 [Start]                    # Name
 Hello my dear adventurer.  # Event
 {Greetings!} HappyAnswer   # Answers
 {Go away!} RudeAnswer

This successfully creates a Question called Start which executes its Event and afterwards leaves the user with two Answers to pick from.
The output of this program might look like this:

 Hello my dear adventurer.
 [1] Greetings!
 [2] Go away!
 > 

The # indicates a comment and every character afterward until a newline will be ignored.

Questions

As a Adventure might have multiple Questions, the TAML interpreter will always pick the first defined one as a starting point.
There is no limit on how many Questions are allowed, but all must have a non-empty, unique name and not contain any whitespaces in them.

Events

Events are an optional part of a Question which performs specific actions.
Special instructions can be performed by using the <instruction args...> syntax.
Variables can be inserted via $name. Everything else will be printed to the console as is.

Variables

Variables are stored in a global hashmap. When an undefined variable is accessed, it gets replaced by an empty string.
All variables are stored as strings. They are castable to a number using %(<expr>).
Names must not start with a digit but can contain a-z A-Z 0-9 as well as . _ and :

Literals

Number literals have to consist of only numbers and at most one . to indicate a floating point.
String literals have to start and end with a double quote ", they support all ANSI escape sequences, starting with a slash /.

Instructions

Syntax Description
input -> VAR Prompts the user and stores the input into VAR
expr (EXPR) -> VAR Calculates the simple C-like expression into VAR (See Expressions)
var NAME is VAL Sets the variable <name> to Val.
if VAL <BODY> Executes BODY if VAL is truthy. (See Expression)
else <BODY> Executes BODY if the last if failed
ask QUESTION Jumps to the Question
textspeed MILLISECONDS Sets the speed at which the Events text gets printed
clear Clears the screen

Expressions

TAML evaluates expressions very similar to the C programming language.
Truthy is not 0, and every operator returning a boolean value will always return 1 or 0.
Supported operators are:

Operator C equivalent Name On Strings On Numbers
+ plus + Plus concatenates adds
- minus - Minus errors subtracts
* multiplied * Asterisk error multiplies
/ divided / Slash concatenates and inserts the systems directory slash (/, \ ...) divides
equals == Equals truthy if both strings are the same truthy if both numbers are the same
greater > Greater errors truthy if left is greater than right
less < Less errors truthy if left is less than right
not ! Not errors turns truthy to falsy and vice versa
and && And errors truthy if left and right are truthy
or || Or errors truthy if left or right are truthy
xor ^ Exclusive Or errors truthy if left or right, but not both are truthy

Note: Not can be used to invert the operator that follows.

 1 not equals 2   # truthy
 1 not greater 2  # same as C's <=
 1 not plus 2     # 1 - 2 => -1 
 not not 1        # 1

The opposite of And is Or. Exclusive Or's opposite is Equals.

Answers

Answers are just as the Event optional and can be left out.
The syntax looks like this:

 {OPTION} QUESTION

After the Event of an Question is finished, a list of all Answers gets printed and the user has to pick one. Starting with index 1.
Special cases:

OPTION empty? QUESTION empty? Only Answer? Action
yes no yes Asks QUESTION after the Event
no yes no Exits the program when picked
yes yes yes Exits the program after the Event

Examples

Not enough? Add some lol!

Hello, World!

 [HELLO_WORLD]
 Hello, World!

Cat program

 [CAT]
 <input -> foo>
 $foo

Infinite cat program

 [CAT]
 <input -> foo>
 $foo
 {} CAT

Interpreters

None!