An attempt at writing a DesignScript parser and interpreter that runs in the browser. You can use it to parse, generate, and run DesignScript code. Because there is no spec for the DesignScript language, it probably has semantic issues. :)
Most of the project is written in TypeScript.
- AST
- Parser
- Interpreter (with debugging support)
- Language blocks (Imperative and Associative)
- Replication
- Replication guides
- Type declaration for variables, function arguments
- Range expressions
See src/AST.ts
for a complete list.
- For, while loops in imperative blocks
- Classes
# npm install designscript.js
DesignScript.js is generated with browserify, so you can use it with a variety of module systems (see below).
var AST = require('./build/designscript').AST;
var sl =
new AST.StatementListNode(
new AST.AssignmentNode(
new AST.IdentifierNode("a", new AST.Type("number")),
new AST.NumberNode("3.14159")));
console.log( sl.toString() ); // prints "a : number = 3.14159;"
var designscript = require('./build/designscript');
// parse some DesignScript
var ast = designscript.Parser.parse('w = [Imperative]{ return = 4; }');
Continuing from the Parser example:
var i = new designscript.Interpreter();
i.run( ast );
console.log( i.env.lookup("w") ); // prints "4"
Pass a function to an Interpreter that will be invoked upon consuming every part of the AST. When invoked, the Interpreter passes along a callback that must be invoked in order to continue execution.
var interpreter = new designscript.Interpreter(
function(node, env, stack, callback){
// do stuff with node, env, stack
callback();
});
interpreter.run( ast );
See example/debugger.html
for a more complete example.
Install node.js
# npm install -g jison
# npm install -g browserify
# npm install -g typescript
# make build
# make release
Produces designscript.js in the build directory
# make test