rubric-lang
v0.0.1
Published
A simple, interpreted programming language designed for learning and experimentation.
Maintainers
Readme
Rubric Lang
Rubric Lang is a simple, dynamically-typed, interpreted programming language built with TypeScript. It's designed for educational purposes, demonstrating the core components of a language interpreter: a lexer, parser, and evaluator.
Installation
To use Rubric Lang as a command-line tool, you can install it globally via npm (once published):
npm install -g rubric-langMake sure you have Node.js (version 14.0.0 or higher) installed.
Usage
Once installed (or when running locally during development), you can execute Rubric Lang scripts:
rubric-lang path/to/your/script.rlOr, for development using ts-node:
npm run dev path/to/your/script.rlRubric Lang files typically use the .rl extension.
Features & Syntax
Rubric Lang supports the following core programming constructs:
1. Data Types & Literals
- Integer:
10,-5,0 - Float:
3.14,-0.5,0.0 - Boolean:
true,false - String:
"hello",'world'(double or single quotes) - Internal Null: The language uses an internal
NullValuefor uninitialized variables or the result of empty blocks/void functions, butnullis not a general-purpose literal or type keyword for direct use in variable declarations or annotations yet.
2. Variables
- Declaration:
var identifier: type = value;(e.g.,var age: int = 30;)const identifier: type = value;(e.g.,const pi: float = 3.14;)
- Type Annotations:
: int,: float,: string,: boolean,: void. Also accepts other identifiers as type names (e.g.: any) but complex type checking for these is not yet implemented. - Type Inference: If an initializer is provided without a type annotation, the type is inferred (e.g.,
var name = "Rubric";infersstring). - Uninitialized
var:var x;(defaults to typeanyand internalNullValue). - Assignment:
identifier = newValue;(only forvar).
3. Operators
- Arithmetic:
+,-,*,/(integer division for int/int, float otherwise),% - Comparison:
==,!=,<,>,<=,>= - Logical:
&&(short-circuiting AND),||(short-circuiting OR),!(NOT) - Increment/Decrement:
++identifier(prefix),identifier++(postfix),--identifier,identifier-- - Ternary:
condition ? expressionIfTrue : expressionIfFalse
4. Control Flow
- If-Else Statements:
if (condition) { // ... } else if (otherCondition) { // ... } else { // ... } - For Loops:
(Initializer, condition, and update are all optional)for (var i: int = 0; i < 10; i = i + 1) { // ... } - While Loops:
while (condition) { // ... } - Do-While Loops:
do { // ... } while (condition);
5. Functions
- Declaration:
fn functionName(param1: type, param2: type): returnType { // ... statements ... return value; } - Function Literals (Anonymous Functions):
var myFunc = fn(param: type): returnType { return param; }; - Return Statement:
return expression;orreturn;(implicitly returnsNullValue). The last expression in a block is also implicitly returned if noreturnstatement is hit. - Recursion: Supported.
6. Scoping
- Lexical Scoping.
- Block Scope for
varandconst.
7. Output
display(arg1, arg2, ...);(prints arguments to console, space-separated).
8. Comments
- Single-line:
// comment - Block:
/* comment */
Development
- Clone:
git clone <repository-url> - Install:
npm install - Build:
npm run build(compiles TypeScript todist) - Test:
npm test - Run Demo File:
npm run demo(builds & runsdemo.rl) - Dev Run:
npm run dev path/to/script.rl(usests-node)
Future Enhancements
This list reflects some of the ideas previously discussed for future development:
- Improved Type System:
- More robust type inference (e.g., for function call results).
- Proper parsing and semantic analysis for complex function type signatures (e.g.,
fn(int): fn(string):boolean). - Explicit
nulltype and nullable types (e.g.,int?). - Arrays/Lists, Structs/Classes, Generics.
- Language Features:
- Immediately Invoked Function Expressions (IIFEs).
- String template literals.
- Control Flow:
switch,break,continue. - Error Handling:
try...catch. - Modules: Import/export system.
- Standard Library: More built-in functions.
