Skip to content

06. Primitive Types

Tom Dodd edited this page Nov 20, 2023 · 40 revisions

DSSL has five primitive types built into the language: Int, Bool, Float, Char and String. Integers can be arbitrarily big, floats are double-precision, and the characters of a string can be iterated over.

Primitive values are the arguments to all basic mathematical operators, such as addition +, multiplication * and concatenation ~ (aside from classes with operator overloading). If an operator is not defined for the arguments it pops from the stack, it will throw an error. Primitive variables can also be modified by assignment operators such as and +=, *= and ~=, as in Python, Java and other languages, using their labels as the first argument.

Strings can be written in two ways: either with single-line syntax between two quotation marks ", or with multi-line syntax between two sets of three backticks ```.

"This is a single-line string." println
    ```
    This is a multi-line string.
    The common whitespace at the start of each line is ignored.
        For that reason, this line will retain four spaces.
    The first set of quotation marks must be on its own line.``` println

Strings can also be prefixed with an r, which will tell the interpreter to treat \ as a literal character rather than the start of an escape sequence, just like raw strings in Python. The escape sequences in DSSL include the single-character escapes in Java, \t, \b, \n, \r, \f, \', \" and \\, and a backtick escape \`​.

The classes associated with the primitive types can be added to the stack by simply using the type name. They each have a simple constructor which pops a value of their respective type and pushes it back to the stack.

Clone this wiki locally