I've created my own C-based scripting language. While it strongly resembles other languages, it has features that others alone do not have. It includes Java's static type checking, C++'s primitive types, Python's binary operations and nested functions, and JavaScript's expression evaluation and objects.
It is designed to overcome some of the more annoying aspects of C++, such as its inability to be used as a scripting language and resolve functions defined later in the file or nested within other functions.
Simultaneously, it retains many of the great features of C++ as well as features from other languages like Python and JavaScript, all while keeping the speed C++ is known for. This is possible because the compiler uses ANTLR and a context-free grammar to parse the code and then transpile it directly into C++.
I'm still working on this project and looking to add more features. Below is a brief example of a the language implementation which demonstrates some of the features of the language so far, followed by the abstract syntax tree generated by the parser.
print(test(0)); // Use as scripting language
unsigned short test(int n) { // unsigned short return type
long double x = 2;
if (n) { // if n != 0
return (unsigned short) x ** n; // x to the power of n
}
return tryAgain();
unsigned short tryAgain() { // Nested function
return test(n + 1);
}
}
// Binary Search
int binarySearch(int[] arr, int value, int left, int right) {
while (left <= right) {
int middle = (left + right) / 2;
if (arr[middle] == value)
return middle;
else if (arr[middle] > value)
right = middle - 1;
else
left = middle + 1;
}
return -1;
}
// Ackermann Function
int ackermann(int m, int n) {
if (m == 0) return n + 1;
if (n == 0) return ackermann(m - 1, 1);
return ackermann(m - 1, ackermann(m, n - 1));
}