A small experimental programming language written in C++
with dedicated Visual Studio Code support.
XR is a small experimental programming language built from scratch in C++.
Instead of directly following the syntax of languages such as Python, Java, or C++, XR uses its own syntax and concepts.
The project consists of two main parts:
- XR Interpreter — executes
.xrsource files. - XR VS Code Extension — provides a complete development environment for XR.
The goal of XR is to experiment with language design, interpreters, syntax, developer tooling, and programming-language concepts while keeping the language simple and distinctive.
- C++17 interpreter
.xrsource files- Variables
- Conditional statements
- Loops
- Lists
- Ranges
- Indexing
- Slicing
- Arithmetic operators
- Comparison operators
- Logical operators
- String operations
- Built-in functions
- Comments
- XR language recognition
- Syntax highlighting
- Autocomplete / IntelliSense
- Variable suggestions
- Built-in function suggestions
- Code snippets
- Error diagnostics
- Problems panel integration
XR: Run Filecommand- Integrated interpreter execution
Variables are declared using the deyer keyword.
deyer -> ad;
deyer -> yas;
Values are assigned using the -> operator.
'Xorma' -> ad;
20 -> yas;
Variables can then be used directly:
> ad;
> yas;
Output:
Xorma
20
The > operator is used to print a value.
> 'Salam XR!';
Variables can also be printed:
deyer -> ad;
'Xorma' -> ad;
> ad;
Output:
Xorma
Expressions can be printed as well:
> 'Salam ' ~ ad;
XR uses ? to define a conditional statement.
? ad = 'Xorma' {
> 'Dogru';
} : {
> 'Yanlis';
}
The : block represents the alternative branch.
deyer -> yas;
20 -> yas;
? yas >= 18 {
> 'Yetkin';
} : {
> 'Yetkin deyil';
}
XR uses @ for loops.
A condition can be used directly:
@ x < 5 {
> x;
}
XR can also iterate over a list:
@ x : #[1, 2, 3] {
> x;
}
Output:
1
2
3
Lists use the #[ ] syntax.
#[1, 2, 3, 4, 5]
A list can be assigned to a variable:
deyer -> nums;
#[1, 2, 3, 4, 5] -> nums;
Lists can contain different values depending on the interpreter's supported types.
List elements are accessed using ..
deyer -> nums;
#[10, 20, 30] -> nums;
> nums.0;
> nums.1;
> nums.2;
Output:
10
20
30
Indexes can also be stored in variables:
nums.i
Expressions can be used as indexes:
nums.(i + 1)
XR supports selecting a section of a list using ranges.
nums.(1..3)
The general syntax is:
start..end
For example:
deyer -> nums;
#[10, 20, 30, 40, 50] -> nums;
> nums.(1..3);
Ranges are represented using ...
1..5
Ranges can be used with loops:
@ x : 1..5 {
> x;
}
Output:
1
2
3
4
5
XR provides operators for arithmetic, comparison, logical operations, concatenation, power, and assignment.
| Operator | Operation |
|---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
% |
Modulo |
Example:
5 + 3
10 - 2
4 * 5
20 / 4
10 % 3
The ^ operator is used for power / repetition.
2 ^ 3
| Operator | Meaning |
|---|---|
= |
Equal |
<> |
Not equal |
< |
Less than |
> |
Greater than |
<= |
Less than or equal |
>= |
Greater than or equal |
Example:
10 > 5
10 = 10
5 <> 3
| Operator | Meaning |
|---|---|
& |
AND |
| |
OR |
! |
NOT |
Example:
x > 5 & x < 10
The ~ operator combines values.
'Salam ' ~ 'XR'
Output:
Salam XR
Variables can also be combined:
deyer -> ad;
'Xorma' -> ad;
> 'Salam ' ~ ad;
The -> operator assigns a value to a variable.
5 -> x;
For example:
deyer -> x;
10 -> x;
XR currently provides the following built-in functions:
| Function | Purpose |
|---|---|
uz() |
Returns the length of a value |
qat() |
Combines two values |
cixar() |
Performs subtraction |
metn() |
Converts a value to text |
eded() |
Converts a value to a number |
sirala() |
Sorts a list |
boyuk() |
Returns the larger value |
kicik() |
Returns the smaller value |
bol() |
Performs division |
yig() |
Returns the sum of list values |
var() |
Checks whether a value exists |
Returns the length of a value.
> uz('XR');
Combines two values.
> qat('Hello', 'XR');
Performs subtraction.
> cixar(10, 3);
Converts a value to text.
> metn(123);
Converts a value to a number.
> eded('123');
Sorts a list.
> sirala(#[5, 2, 8, 1]);
Returns the larger value.
> boyuk(10, 20);
Returns the smaller value.
> kicik(10, 20);
Performs division.
> bol(20, 4);
Returns the sum of values in a list.
> yig(#[1, 2, 3, 4]);
Checks whether a value exists.
> var(x);
Comments begin with //.
// This is an XR comment
deyer -> ad;
Comments are ignored by the interpreter.
XR uses single quotes for strings.
'Salam XR!'
Strings can be combined using ~.
'Hello' ~ ' XR'
Output:
Hello XR
// XR example
deyer -> ad;
deyer -> nums;
'Xorma' -> ad;
#[1, 2, 3, 4, 5] -> nums;
> 'Salam ' ~ ad;
? ad = 'Xorma' {
> 'Dogru ad';
} : {
> 'Yanlis ad';
}
@ x : nums {
> x;
}
Output:
Salam Xorma
Dogru ad
1
2
3
4
5
XR comes with a dedicated Visual Studio Code extension designed to make .xr development easier.
The extension provides:
.xrlanguage recognition- Syntax highlighting
- Autocomplete
- Variable suggestions
- Built-in function documentation
- Code snippets
- Error diagnostics
- Problems panel integration
- XR interpreter execution
XR source files are automatically recognized as .xr files.
The syntax definition is located at:
vscode-extension/syntaxes/xr.tmLanguage.json
It provides highlighting for:
- Keywords
- Variables
- Strings
- Numbers
- Operators
- Comments
- Built-in functions
- Control structures
The extension provides autocomplete for:
- XR keywords
- Built-in functions
- Operators
- Snippets
- Declared variables
For example:
deyer -> ad;
deyer -> yas;
'Xorma' -> ad;
20 -> yas;
After declaring a variable, it can appear in autocomplete suggestions.
Built-in functions can also display documentation:
uz(value)
Dəyərin uzunluğunu qaytarır
XR provides snippets for frequently used structures.
Typing:
if
can generate:
? sert {
} : {
}
Typing:
loop
can generate:
@ sert {
}
Typing:
foreach
can generate:
@ x : siyahi {
}
Interpreter errors can be displayed directly inside Visual Studio Code.
For example:
> ad2;
If ad2 has not been declared, the interpreter can report:
Xeta: teyin olunmamis deyisen: ad2
The extension can forward interpreter errors to the Problems panel, making errors easier to locate while developing.
The XR interpreter is written in C++17.
g++ -std=c++17 xr.cpp -o xr.exexr.exe hello.xrFor example:
xr.exe examples/hello.xrOpen the VS Code extension project.
Press:
F5
This launches the Extension Development Host.
Create or open an .xr file.
Then open the Command Palette:
Ctrl + Shift + P
Search for:
XR: Run File
Press Enter.
The extension will execute the current XR file using the XR interpreter.
XR/
│
├── interpreter/
│ ├── xr.cpp
│ └── xr.exe
│
├── vscode-extension/
│ ├── package.json
│ ├── extension.js
│ ├── language-configuration.json
│ ├── xr.exe
│ │
│ ├── snippets/
│ │ └── xr.json
│ │
│ └── syntaxes/
│ └── xr.tmLanguage.json
│
├── examples/
│ ├── hello.xr
│ ├── variables.xr
│ ├── conditions.xr
│ └── loops.xr
│
└── README.md
Example programs can be found in:
examples/
Current examples include:
hello.xr
variables.xr
conditions.xr
loops.xr
These examples demonstrate the basic features of the language.
The XR interpreter is implemented in:
interpreter/xr.cpp
The extension logic is implemented in:
vscode-extension/extension.js
Syntax highlighting is defined in:
vscode-extension/syntaxes/xr.tmLanguage.json
Code snippets are located at:
vscode-extension/snippets/xr.json
XR is currently an experimental programming language project.
The current version includes:
- A working C++ interpreter
- A custom programming-language syntax
.xrsource files- Lists and ranges
- Conditions and loops
- Built-in functions
- VS Code syntax highlighting
- Autocomplete
- Snippets
- Diagnostics
- File execution through VS Code
The language and development tools are still evolving, and syntax or features may change in future versions.
Potential future improvements include:
- User-defined functions
- More data types
- Better type handling
- Improved error messages
- More advanced IntelliSense
- Debugging support
- Package / module system
- Standard library
- Better runtime error locations
- XR language server
- Cross-platform interpreter builds
- VS Code Marketplace release
XR is not intended to replace established programming languages.
It is a project for exploring how a programming language works from the inside:
Source Code
│
▼
Lexer
│
▼
Parser
│
▼
Interpreter
│
▼
Output
At the same time, the VS Code extension demonstrates how a custom language can be integrated into a modern development environment.
Xorma
GitHub:
This project is licensed under the MIT License.