Protoslang is still in active development. The README will temporarily hold the feature set completion status.
git clone https://github.com/jlhs1001/protoslang.git
cd protoslang
cmake .
cmake --build .
./slang_prototype
./slang_prototype <path-to-file>
Protoslanguage is a dynamically typed, interpreted programming language. It is designed to be simple and powerful. This iteration is more so a syntactic proof of concept. Future versions will likely be more feature rich, statically typed, and compiled.
cd protoslang
cmake .
cmake --build .
./slang_prototype <path-to-file>
As it is the traditional introduction to any programming language, let's start with a simple "Hello, World!" program.
// The 'println' function is used to print to the console.
println("hello world");
Protoslanguage is dynamically typed. Variables are declared with the let
keyword. The type of the variable is inferred
from the value assigned to it. Variables can be reassigned to values of different types.
// Variables are declared with the 'let' keyword.
let x = 5;
let y = x;
// Variables can be reassigned.
x = 10;
println(x + y);
// This is a bit of an interesting expression.
// It combines all the supported operators.
let x = 30;
let y = x + 2 * 3 / (4 - 2);
println(y % 3);
Functions are declared with the fn
keyword. They can take any number of arguments and return a single value.
// Function argument can be of any type.
fn add(x, y) {
return x + y;
}
Calling the function is as simple as expected.
let result = add(5, 10);
println(result);
Protoslanguage supports lists of values.
let list = [1, 2, 3, 4, 5];
// Lists can be indexed.
println(list[0]);
// A list index may be assigned a new value.
list[0] = 10;
println(list[0]);
Lists may contain any type of value.
let list = [1, "two", 3.0, true];
// Lists can conveniently be printed.
println(list);
Protoslanguage supports if-else statements, range-based for loops, iterative loops, and while loops.
let x = 5;
// A neat little syntax. Quite rust-like.
if x > 10 {
println("x is greater than 10");
} else {
println("x is less than 10");
}
The range-based for loop is a simple way to iterate over a range of values. A range in slang is a built-in type that represents a range of values. It simply contains a lower and upper bound.
// A range-based for loop.
for i in 0..10 {
println(i);
}
The iterative loop is a simple way to iterate over a list of values. It is similar to the range-based for loop, but it grants the loop body access to the current value in the list. Quite convenient.
// An iterative loop.
let grocery_list = [
"apples",
"bananas",
"oranges",
"grapes",
"pears",
];
for let item in list {
println(item);
}
The while loop is a simple way to iterate over a block of code until a condition is met.
let x = 0;
while x < 10 {
println(x);
x = x + 1;
}
That's slanguage for now. More language constructs and features will surely be added soon.
- Arithmetic
-
+
-
-
-
*
-
/
-
%
-
- Comparison
-
<
-
>
-
<=
-
>=
-
==
-
!=
-
- Logical
-
&&
-
||
-
!
-
- Assignment
-
=
-
- Integers
- Floats
- Strings
- Booleans
- Declaration
- Assignment
- Declaration
- Arguments
- Return
- Call
- If-else
- For-in (iterable)
- For-range