A quick, programmatic, interpreted language inspired by Molang.
Before you get too deep, please take note that as of right now Ascent can only be implemented in C# codebases. I plan on expanding to a C++ version of Ascent in the future.
Ascent isn't meant to be a full programming language. It's meant to be more simple and also very fast to quick.
Ascent's primary use case is adding scripting to places that are user-controlled and otherwise hardcoded.
- For example animating game elements in user-made objects through JSON. For this we have a feature inspired by Molang called Query Variables (Read more about these in the Basics section!). These are especially helpful when thinking about implementation within games and other real-time applications.
Basic performance metrics are laid out here!
- The Evaluator
- The Evaluator is the main part of Ascent. It's static so all you have to do to get started is call
AscentEvaluator.Evaluate(expression, variableMap?, cache?, debug?);
and get back the float value returned! It's super simple.
- The Evaluator is the main part of Ascent. It's static so all you have to do to get started is call
- Query Variables
- Query Variables are passed into the evaluator using a
AscentVariableMap
and allow the implementing program to pass outside values into Ascent expressions. These are the basis of the language. Query Variables are prefixed with eitherquery.
orq.
. - Example:
- Implementation
var result = AscentEvaluator.Evaluate("q.x", new AscentVariableMap(new Dictionary<string, float>() { { "x", 5f }}));
- Result:
5
- Implementation
- Query Variables are passed into the evaluator using a
- Expressions
- Expressions are essentially a group of instructions. Expressions can also contain expressions inside (for example function arguments). Expressions are separated by semi-colons.
- Implicit Return
- The return of a statement is defined by the last separate expression with neither a assignment, definition, or similar. For example an expression of
lerp(5, 10, 0.5)
will return 7.5. Returns can also be explicit! Just place return before your statement.
- The return of a statement is defined by the last separate expression with neither a assignment, definition, or similar. For example an expression of
- Variables
- Variables are similar to Query Variables in that they can be accessed within Ascent, but they are different in a few ways. One way is that Variables cannot be defined in the implementing code but they can be read after evaluation. Another way is that Variables are defined in the expression using
let
similar to JavaScript. - Example:
- Ascent:
let queryExample = 15; queryExample;
- Result:
15
- Ascent:
- Variables are similar to Query Variables in that they can be accessed within Ascent, but they are different in a few ways. One way is that Variables cannot be defined in the implementing code but they can be read after evaluation. Another way is that Variables are defined in the expression using
- Operations
- The currently supported operations include
- Addition
+
- Subtraction
-
- Multiplication
*
- Division
/
- Power
^
- Modulus
%
- Greater than
>
- Lesser than
<
- Addition Assignment
+=
- Subtraction Assignment
-=
- Increment
++
- Decrement
--
- Ternary
conditionExpression ? trueExpression : falseExpression
- Functions
- Ascent supports a set of functions, mostly focused on math operations.
- Currently supported functions include
- Sin
- Cos
- Tan
- Clamp
- Sign
- Sqrt
- Int
- Abs
- Pow
- Exp
- Frac
- Lerp
- Debug (prints all given arguments to console)
- ... And more Here
- Function Definitions
- Function definitions are written by you! They follow very similar syntax to javascript and also support nesting!
- Example:
function test(add1, add2) {
function k(a) {
return a * 2;
}
let result = k(add1) + k(add2);
return result;
}
return test(2, 2);
- Loops
- Currently there are two loops implemented, for loops and while loops. These also follow very similar syntax to other languages.
let g = 10;
while(g > 0) {
g--;
debug(g);
}
return g;
for(let i = 0; i < 10; i++)
{
debug(i);
}
- Performance metrics.
- Syntax Error Handling
- API to add functions from implementing code.
- Translate to C++ as an additional language.
- Support creating functions from within Ascent code.
- Rewrite parser to be more modular/legible.
- Further clean up to make the parser more pretty.
- Refactor to allow strings, booleans, etc.
- Translate to C++ as an additional language.
- Add Ascent code examples.
- Add more functions to the default list.
- More in the future?