alpha-language-support
Alpha Language Support was created to help write scripts using the alpha language.
Alpha scripts must have the .al extention
Features
Alpha Language Support currently supports:
- syntax highlighting
- syntax analysis
- compile and run
Syntax Analysis
The syntax analyser is activated upon file save and
the file is parsed. Error messages can be examined
in the Output Alpha panel (see View Parse Output on how to open the Output panel).
The messages are not very accurate but they provide a line number to help with debugging.

The parser can also be activated using the Parse Grammar command.
To use the command,
- open the command palette with Ctrl+Shift+P
- search Alpha Parse Grammar

The parsing results will be displayed in the Output panel
Compile and Run VM
To compile and run an alpha script,
- open the command palette with Ctrl+Shift+P
- search Alpha Compile and Run VM
Tested on bash terminal

This will compile the active alpha file
and produce a .abc file with the same name
as the active file.
Error messages from the compiler will be displayed
in the Output panel (see View Parse Output on how to open the Output panel).
The vm runs on a terminal (tested on powershell) and the output is displayed there.

You can also run an alpha script using F5, to do that
- open .vscode folder (create one if it doen't exist)
- create a launch.json
- in the inputs field add the command: extension.compileAndRunVM
- in the configurations add a launch request
Your launch.json should look like this:
{
"version": "0.2.0",
"inputs": [
{
"id": "alpha",
"type": "command",
"command": "extension.compileAndRunVM"
}
],
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${input:alpha}"
}
]
}
You can suppress runtime warnings by adding a -Wno argument:
{
"version": "0.2.0",
"inputs": [
{
"id": "alpha",
"type": "command",
"command": "extension.compileAndRunVM",
"args": {
"arg": "-Wno"
}
}
],
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${input:alpha}"
}
]
}
View Parse Output
To view the output of the parser
go to View -> Output (or Ctrl+Shift+U) and select the Alpha panel

Alpha Syntax
Types
A variable in alpha can be one of the following types:
String
var = "myvar";
print(typeof(var)); // prints string
Number
var = 10.2;
print(typeof(var)); // prints number
Boolean
var = true;
print(typeof(var)); // prints boolean
Nil
var = nil;
print(typeof(var)); // prints nil
Table
In alpha you can define tables by index or key-value pairs.
var = [];
print(typeof(var)); // prints table
- Indexed: can only be accessed using the [] operator
table = [20.3, 'string', true, print];
print(table[1]); // prints string
- Object: can be accessed using the [] operator and . operator if the key is of type string.
table = [{ key: 10 }, { 10: 'value' }];
print(table[10], ' ', table.key); // prints value 10
Objects with the key "()" can be called as a function
table = [{ '()': print }];
table('hello'); // prints hello
Using the '..' operator you can pass the table as the first argument in a function call
table = [{"foo":( ({ this }) => {print(this.x);} )}, {"x":10}];
table..foo(); // prints 10
Function
var = () => {};
print(typeof(var)); // prints function
var = ({arg1, arg2}) => {};
print(typeof(var)); // prints function
var = (function foo(){}); // function definition in an expression
print(typeof(var)); // prints function
In alpha a function can be called in three ways:
normal call
function foo() {}
foo();
functor
table = [{ '()': print }];
table('hello'); // prints hello
string call
func = 'print';
func('hello'); // prints hello
Undefined
var;
print(typeof(var)); // prints undefined
import
You can import modules like so:
/* module.al */
function test() {
println('This is a module test');
}
/* main.al */
import 'module.al';
test(); // prints This is a module test
By default in a module everything in global scope is exported. If you want to export only certain functions or variables wrap your code in a block.
/* module.al */
// exported by default
function foo() {
println('foo');
}
{
// not in global scope, not exported
function bar() {
println('bar');
}
}
/* main.al */
import 'module.al';
foo(); // prints foo
bar(); // error bar is undefined