On this page:
2.1 Identifiers
2.2 Numeric literals
2.3 String literals
2.4 Comments
8.17.0.6

2 Lexical syntax🔗ℹ

2.1 Identifiers🔗ℹ

Names, used for variables, functions, structs, classes, interfaces, fields, and methods, must start with a letter, followed by 0 or more letters or digits. The last character also may be ? or !.

2.2 Numeric literals🔗ℹ

Numeric literals include:

  • Decimal integers: 0, 3, 18446744073709551617

  • Hexadedecimal, octal, and binary integers: 0xFFFF00, 0o0177, 0b011010010

  • Floating point: 3.5, 6.02E23, 1e-12, inf, nan

2.3 String literals🔗ℹ

String literals are delimited by either single or double quotes:

def does_not_matter(double):
    if double:
        return "This is the same string."
    else:
        return 'This is the same string.'

The contents of each kind of string is treated the same, except that each kind of quotation mark can contain the other kind unescaped:

def does_matter(double):
    if double:
        return "This isn't the same string."
    else:
        return '"This is not the same string" isn\'t the same string.'

Strings cannot contain newlines directly, but can contain newline characters via the escape code \n. Other escape codes include:

  • \a for ASCII alert (also \x07)

  • \b for ASCII backspace (also \x08)

  • \f for ASCII formfeed (also \x0C)

  • \n for ASCII newline (also \x0A)

  • \r for ASCII carriage return (also \x0D)

  • \t for ASCII tab (also \x09)

  • \v for ASCII vertical tab (also \x0B)

  • \xhh in hex, for example \x0A is newline

  • \ooo in octal, for example \011 is tab

  • A backslash immediately followed by a newline causes both characters to be ignored, which provides a way to wrap long strings across lines.

Any other character following a backslash stands for itself.

An alternative form for string literals uses three quotation marks of either kind. The contents of such a string are treated literally, rather than interpreting escapes, and they may contain any characters except the terminating quotation mark sequence.

let a_long_string = '''This string can contain ' and " and
even """ and newlines. Just not '' and one more.'''

2.4 Comments🔗ℹ

A comment in DSSL2 starts with the # character and continues to the end of the line.

Long string literals can also be used to comment out long blocks of code.