Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax

DETLEF has a deliberately small syntax. A program consists of a sequence of expressions, and every expression is one of a small number of forms.

Features such as variable declarations, arithmetic, conditionals, and loops do not have dedicated syntax in the core language. They can instead be provided through calls.

Grammar

The core grammar of DETLEF can be summarized as follows:

program     := expression*
expression  := literal | identifier | call | block
call        := expression "(" arguments? ")"
arguments   := expression ("," expression)*
block       := "{" expression* "}"
literal     := integer | float | string

In this notation, * means zero or more occurrences and ? marks an optional element. Text in quotation marks represents literal punctuation.

Literals

Literals directly represent values in source code.

DETLEF currently supports integer, floating-point, and string literals.

Integer Literals

Integer literals represent integer values.

0
42
1000

Negative numbers do not require dedicated literal syntax in the core language. Negation can instead be provided as an operation by the host environment or standard library.

Floating-Point Literals

Floating-point literals represent floating-point values.

0.5
3.14
100.0

Integers and floating-point numbers are distinct types.

String Literals

String literals are enclosed in double quotes.

"hello"
"DETLEF"

Identifiers

Identifiers name entities that can be resolved during evaluation.

x
integer
print
some_name

DETLEF does not require dedicated syntax for names such as types or boolean values. For example, integer, true, and false are syntactically ordinary identifiers.

Their meaning is determined during evaluation.

Calls

A call consists of an expression followed by a parenthesized argument list.

print("hello")
add(1, 2)
foo()

Arguments are themselves arbitrary expressions:

add(multiply(2, 3), 4)

The grammar permits an arbitrary expression in the callee position:

expression(arguments)

Whether that expression is callable is determined during evaluation. The current runtime requires callable names to be identifiers.

Calls do not imply a particular evaluation strategy. The distinction between Functions and Controls, including how their arguments are evaluated, is described in Evaluation.

Blocks

A block is a sequence of expressions enclosed in braces.

{
    print("hello")
    print("world")
}

Blocks may contain any number of expressions, including none:

{}

A block is itself an expression. Its evaluation and scoping behavior are described in Evaluation and Scoping.

Programs

A DETLEF program is a sequence of expressions.

print("one")
print("two")
print("three")

There is no syntactic distinction between statements and expressions, and expressions do not require semicolons.

Whitespace separates tokens where necessary but otherwise does not determine program structure.

Punctuation

The core syntax uses only a small amount of punctuation:

PunctuationPurpose
( )Call arguments
{ }Blocks
,Separates arguments
"String literals

There is no operator syntax in the core language. Expressions such as addition or comparison can be represented through calls:

add(1, 2)
greater(x, 10)

Keywords

DETLEF currently has no reserved keyword set.

Names that may appear special in a particular environment are still ordinary identifiers at the syntactic level. This allows constructs to be added without extending the core grammar.

String Escapes

Double-quoted strings decode these backslash escapes:

EscapeCharacter
\nNewline
\rCarriage return
\tTab
\bBackspace
\fForm feed
\0NUL
\"Double quote
\\Backslash
\/Forward slash
\u{HEX}Unicode scalar value, using one to six hexadecimal digits
"first line\nsecond line"
"He said \"hello\"."
"C:\\Users\\example"
"An owl: \u{1F989}"

Unknown and incomplete escapes are syntax errors. Unicode escapes reject surrogate code points and values above 10FFFF. Literal Unicode characters and literal line breaks remain supported. To represent a literal backslash, write \\; "\\n" contains a backslash and the letter n, not a newline.

Comments

A slash (/) outside a string starts a line comment. It continues to the next line ending or the end of the source:

/ A line comment
operation(value) / An inline comment

Square brackets enclose block comments, which may span lines and nest:

[
A block comment.
[ A nested block comment. ]
]

Comments act as whitespace and can appear between tokens, including call arguments. They do not supply missing commas or join separate identifiers. Inside strings, slashes and brackets are literal characters. Inside block comments, only brackets have special meaning; quotes and slashes are ordinary comment text. An unclosed block comment or a stray closing bracket outside a string or comment is a syntax error.