Gathering detailed insights and metrics for intrear
Gathering detailed insights and metrics for intrear
Gathering detailed insights and metrics for intrear
Gathering detailed insights and metrics for intrear
npm install intrear
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
Such an AST Node Interpreter
Intrear is an AST‑based interpreter written in TypeScript. It gives you full control over building, type‑checking, optimizing and executing custom AST nodes—ideal for learning, scripting, testing new language ideas, or embedding DSLs in your projects.
If you like my framework, I would be happy if you could share it with others. As the framework becomes more popular, it will inspire me to make Intrear even more powerful and stable.
While Intrear is described as a “next‑gen way to create your own programming language,” it’s important to clarify that Intrear is only the interpreter part of that process.
To build a full interpreted programming language, you typically need:
Tokenizer (or Lexer)
Converts raw source code into a list of meaningful tokens (e.g., keywords, identifiers, symbols).
Example frameworks: Chevrotain, Moo, jison-lex
Parser
Takes those tokens and builds an Abstract Syntax Tree (AST)—a structured representation of the code.
Example frameworks: Chevrotain, Nearley, Peggy, Jison
Interpreter
Walks the AST to evaluate and execute the code.
Framework: Intrear
👉 Intrear covers only step 3: the interpreter.
You can build your own tokenizer and parser, then plug the AST into Intrear to execute it.
Added
and fixed bugs
An Abstract Syntax Tree (AST) is a tree‑shaped representation of source code structure:
An interpreter takes AST nodes and executes them directly, without emitting machine code:
Unlike a compiler, an interpreter runs your code on the fly—perfect for REPLs, scripting, or embedding a mini‑language in your app.
Clean, Type‑Safe
Static type inference and checking (number
, string
, boolean
, array
, object
, function
, null
, undefined
, bigint
, symbol
, any
) catch errors early.
Fully Extensible
Add new AST node classes (e.g. custom control‑flow, operators, built‑ins) with minimal boilerplate.
Powerful Features
– First‑class functions & closures
– Arrow functions & lambdas
– Memoized pure functions
– Control flow: if
/else
, loops, switch
, break
/continue
– Data structures: arrays, objects, property & method calls
– Error handling: try
/catch
– Built‑ins: print
, abs
, fetch
, toUpperCase()
, etc.
Optimizations
– AST preprocessing & constant folding
– Memoization for pure functions
– JIT compilation stubs (hot‑path support)
Ideal for Learning & Experimentation
– See each stage (AST → inference → execute) in isolation
– Rapidly prototype language features or embed DSLs
1npm install intrear
1import { 2 Interpreter, 3 VariableDeclarationNode, 4 ArrowFunctionNode, 5 FunctionCallNode, 6 LiteralNode, 7 VariableReferenceNode, 8} from "intrear"; 9 10const nodes = [ 11 new VariableDeclarationNode( 12 "function", 13 "double", 14 new ArrowFunctionNode( 15 ["x"], 16 new FunctionCallNode("print", [new VariableReferenceNode("x")]) 17 ) 18 ), 19 new FunctionCallNode("double", [new LiteralNode(42)]), 20]; 21 22new Interpreter(nodes).execute();
1new VariableDeclarationNode("number", "a", new LiteralNode(5));
Equivalents to
1let a: number = 5;
1new VariableDeclarationNode( 2 "plus", 3 "function", 4 new ArrowFunctionNode( 5 ["a", "b"], 6 new OperatorNode("+", [ 7 new VariableReferenceNode("a"), 8 new VariableReferenceNode("b"), 9 ]) 10 ) 11);
Equivalents to
1let plus = (a, b) => a + b;
1new IfNode( 2 new OperatorNode("==", [new LiteralNode(3), new LiteralNode(3)]), 3 [new FunctionCallNode("print", [new LiteralNode("Equal!")])], 4 [new FunctionCallNode("print", [new LiteralNode("Not equal!")])] 5);
Equivalents to
1if (3 === 3) { 2 console.log("Equal!"); 3} else { 4 console.log("Not equal!"); 5}
1new VariableDeclarationNode( 2 "user", 3 "object", 4 new ObjectLiteralNode({ 5 name: new LiteralNode("John Doe"), 6 }) 7), 8 new FunctionCallNode("print", [ 9 new PropertyAccessNode(new VariableReferenceNode("user"), "name"), 10 ]);
Equivalents to
1let user = { name: "John Doe" }; 2print(user.name);
For running codes that is still currently unavailable in Intrear
1CustomASTNode((context: ExecutionContext) => { 2 setTimeout(() => { 3 console.log("Hello"); 4 }, 1000); 5}, "void");
Equivalents to
1setTimeout(() => { 2 console.log("Hello"); 3}, 1000);
ASTNode
and must implement execute()
and inferType()
.Interpreter
.You're welcome to contribute new nodes, improve error handling, or build a parser!
See ROADMAP.md
for ideas.
MIT License.
No vulnerabilities found.
No security vulnerabilities found.