Skip to content

Syntax Overview

AndcoolSystems edited this page Jun 19, 2026 · 2 revisions

Ultraviolet uses a syntax inspired by both HTML and XML. Every program is built from nested tags that represent values, operations, control-flow constructs, type declarations, and other language elements.

Basic Syntax

All Ultraviolet code is composed of special blocks called tags. A tag can be written in two forms:

Standard Tag

<tag_name>
    ...
</tag_name>

Self-Closing Tag

<tag_name />

The difference between these forms is that a self-closing tag cannot contain any nested content.

Standard tags are typically used for operations, values, and code blocks, while self-closing tags are commonly used for type declarations, variable access, and other constructs that do not require a body.

Extra Parameters

A tag may contain an extra parameter — a value specified immediately after the tag name.

<tag_name extra_param>
    ...
</tag_name>

or

<tag_name extra_param />

Note

The extra parameter is only specified in the opening tag. It must not be repeated in the closing tag.

Example

<call println>
    <str>Hello World!</str>
</call>

In this example:

  • call is the tag name.
  • println is the extra parameter.

The interpretation of an extra parameter depends on the specific tag being used.

Program Structure

Every Ultraviolet source file must contain exactly one root tag.

The root tag depends on the file type:

File Type Required Root Tag
Entry point main
Module mod

The entry point file passed to the interpreter must always use the main tag. Imported modules must use the mod tag as their root element.

Entry Point Example

<main>
    <call println>
        <str>Hello World!</str>
    </call>
</main>

Nesting Rules

Tags may contain other tags, allowing programs to be expressed as a tree structure.

For example:

<sum>
    <i32>10</i32>
    <mul>
        <i32>5</i32>
        <i32>2</i32>
    </mul>
</sum>

This structure is evaluated from the innermost tags outward.

Syntax Rules

  • Every opening tag must have a matching closing tag unless it is self-closing.
  • Tag names are case-sensitive.
  • A source file may contain only one root tag.
  • Extra parameters are only written in opening tags.
  • Self-closing tags cannot contain nested content.

Hello World

<main>
    <call println>
        <str>Hello World!</str>
    </call>
</main>

Clone this wiki locally