-
Notifications
You must be signed in to change notification settings - Fork 2
Syntax Overview
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.
All Ultraviolet code is composed of special blocks called tags. A tag can be written in two forms:
<tag_name>
...
</tag_name><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.
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.
<call println>
<str>Hello World!</str>
</call>In this example:
-
callis the tag name. -
printlnis the extra parameter.
The interpretation of an extra parameter depends on the specific tag being used.
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.
<main>
<call println>
<str>Hello World!</str>
</call>
</main>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.
- 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.
<main>
<call println>
<str>Hello World!</str>
</call>
</main>Created by Ultraviolet lang org, AndcoolSystems