GithubHelp home page GithubHelp logo

gnalxom / designscript.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pboyer/designscript.js

0.0 2.0 0.0 640 KB

Run DesignScript in the browser, node.js

Home Page: http://pboyer.github.io/designscript.js/

Makefile 0.16% JavaScript 83.24% HTML 0.58% CSS 1.56% TypeScript 14.47%

designscript.js's Introduction

Build Status

designscript.js

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.

This project currently includes:

  • AST
  • Parser
  • Interpreter (with debugging support)

Language features:

  • Language blocks (Imperative and Associative)
  • Replication
  • Replication guides
  • Type declaration for variables, function arguments
  • Range expressions

See src/AST.ts for a complete list.

Not yet implemented

  • For, while loops in imperative blocks
  • Classes

Installing from npm

# npm install designscript.js

DesignScript.js is generated with browserify, so you can use it with a variety of module systems (see below).

Usage

Code generation

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;"

Parser

var designscript = require('./build/designscript');

// parse some DesignScript
var ast = designscript.Parser.parse('w = [Imperative]{ return = 4; }'); 

Interpreter

Continuing from the Parser example:

var i = new designscript.Interpreter();
i.run( ast ); 

console.log( i.env.lookup("w") ); // prints "4"

Debugging

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

Install node.js

# npm install -g jison
# npm install -g browserify
# npm install -g typescript

Build

# make build

Build for the web

# make release

Produces designscript.js in the build directory

Test

# make test

designscript.js's People

Contributors

pboyer avatar

Watchers

James Cloos avatar Nazim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.