├── .gitignore ├── LICENSE ├── README.md ├── bin ├── cngen.js └── cni.js ├── examples ├── hello_world.cnpl ├── loop.cnpl └── server.cnpl ├── index.js ├── lib └── abc.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Andrés 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Chuck Norris Programming Language 2 | ================================= 3 | _by @angrykoala_ 4 | 5 | [![npm version](https://badge.fury.io/js/chuckscript.svg)](https://badge.fury.io/js/chuckscript) 6 | [![bitHound Overall Score](https://www.bithound.io/github/angrykoala/chuckscript/badges/score.svg)](https://www.bithound.io/github/angrykoala/chuckscript) 7 | [![bitHound Dependencies](https://www.bithound.io/github/angrykoala/chuckscript/badges/dependencies.svg)](https://www.bithound.io/github/angrykoala/chuckscript/master/dependencies/npm) 8 | 9 | 10 | Chuck Norris can code using binary without 1, with Chuck Norris Programming Language (**CNPL**) you also can!. For those who think assembler is a high level language. 11 | 12 | ## Syntax 13 | The syntax is probably the easiest to learn: `0` is the only command you'll need. What does `0` do? Everything. 14 | 15 | ## ChuckScript 16 | Chuck Norris code is so powerful that no current machine can process it, so a higher abstraction was made to make the code comprehensible for humans (and machines): 17 | `[0]{12}` means _"twelve zeroes"_ and it is translated `000000000000` in pure Chuck Norris Code. 18 | 19 | All ChuckScripts allow comments, and only the first command with the syntax `[0]{...}` will be executed. The extension is `.cnpl` 20 | 21 | ## Hello World! 22 | CNPL is fully functional, based on JavaScript. To start coding, just tweak this simple hello world: 23 | ``` 24 | [0]{9582516168086304533950061199088375933762201813077804024987245718616842} 25 | ``` 26 | _hello_world.cnpl_ 27 | 28 | ## Installation 29 | You can install chuckScript from the official npm repository typing: 30 | ``` 31 | npm install -g chuckscript 32 | ``` 33 | Or you can manually clone from [github](https://github.com/angrykoala/chuckscript) and install with `npm install` 34 | 35 | 36 | >You need node and npm installed on your system 37 | 38 | 39 | ### CNI 40 | CNI (_Chuck Norris Interpreter_) is the official CNPL interpreter and allows you to execute CNPL (extension .cnpl) in your machine: 41 | 42 | ``` 43 | cni myprogram.cnpl 44 | ``` 45 | 46 | ### CNGEN 47 | Of course, CNPL is the only language you'll ever need again, however, to start learning it cni also brings a cnpl code generator, which will convert your old, un-epic JavaScript code into a bright new CNPL code, to use it: 48 | ``` 49 | cngen myoldjs.js newsupercode.cnpl 50 | ``` 51 | 52 | ### Examples 53 | In the folder `/examples` you'll find some ready-to-use examples of cnpl code: 54 | 55 | * **hello_world.cnpl:** The proper way to start learning a new language, with a easy-to-learn hello world 56 | * **loop.cnpl:** Learn the easy loop syntax of ChuckScript with this example 57 | * **sever.cnpl:** ChuckScript is web-development ready, in this example you will learn how to make your own server 58 | 59 | ## Module Usage 60 | To use _chuckscript_ in your node.js code, simply `require('chuckscript')`: 61 | 62 | * `execute(code)`: Executes given cnpl code (using javascript cni). 63 | * `cnpl2js(code)`: Translates cnpl code to javascript, returns string with js. 64 | * `compile(jsCode)`: Compiles javascript code into chuckscript. 65 | 66 | 67 | > CNPL is a improved version of [Unary esoteric language](https://esolangs.org/wiki/Unary) 68 | 69 | > ABC.js (c) 2013 Stephan Schmitz 70 | -------------------------------------------------------------------------------- /bin/cngen.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Chuck Norris Code Generator 5 | by @demiurgosoft 6 | Allows you to execute CNPL code 7 | Usage: node cngen.js myprogram.js newcode.cnpl 8 | */ 9 | 10 | var fs = require('fs'); 11 | var process = require('process'); 12 | 13 | var chuckScript = require('../index'); 14 | 15 | var text = process.argv[2]; 16 | var out = process.argv[3]; 17 | 18 | if (!text || !out) return console.log("Usage: node cngen.js [myprogram.js] [newcode.cnpl]"); 19 | 20 | fs.readFile(text, 'utf8', function(err, data) { 21 | if (err) { 22 | return console.log(err); 23 | } 24 | var cnpl = chuckScript.compile(data); 25 | fs.writeFile(out, cnpl, function(err) { 26 | if (err) { 27 | return console.log(err); 28 | } 29 | 30 | return console.log("cnpl succesfully generated"); 31 | }); 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /bin/cni.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Chuck Norris Interpreter 5 | by @ demiurgosoft 6 | Allows you to execute CNPL code 7 | Usage: node cni.js myprogram.cnpl 8 | */ 9 | 10 | var fs = require('fs'); 11 | var process = require('process'); 12 | 13 | var chuckScript = require('../index'); 14 | 15 | var cnCode = process.argv[2]; 16 | if (!cnCode) return console.log("Usage: node cni.js program.cnpl"); 17 | fs.readFile(cnCode, 'utf8', function(err, data) { 18 | if (err) { 19 | return console.log(err); 20 | } 21 | 22 | chuckScript.execute(data); 23 | }); 24 | -------------------------------------------------------------------------------- /examples/hello_world.cnpl: -------------------------------------------------------------------------------- 1 | [0]{9582516168086304533950061199088375933762201813077804024987245718616842} 2 | -------------------------------------------------------------------------------- /examples/loop.cnpl: -------------------------------------------------------------------------------- 1 | [0]{128480536267270702633263631096697390863184481716477179022037631861412548099855931198072928281042368706556936273149175436273819880265408401547429336355290289322705866717808872277668655389807052961769213491193904192423423802634} -------------------------------------------------------------------------------- /examples/server.cnpl: -------------------------------------------------------------------------------- 1 | [0]{88703523001131395011568035053805112393172583886475322390926574377727964578993987192524078996589911218864803945644069156915920798371343066115756089440843714680823595238277761827604237327188482417717538861617192995757166310990050884416743903040285306082464506446882692991470451098185740887277422187465368475377944160217567864501419751289221101080892917908489930574052325777083370782930082094064979308435662610980167123435380219516438280285218632237493404411566320694842134561368035893497309629319751323661908457233099694629368298773739489209597901154034498679513939664235286857667145856479116683234083977466528083881545249301749567617985557121923148114140111059353841366929773120257896376195770617197331154005860332706938709271356370968390256147204985491564126891806395855832559100204422574708586279129193027058639536933282356114574176702549448542907991063686324765416045322} -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | Chuck Norris Interpreter 3 | by @angrykoala 4 | Allows you to execute CNPL code 5 | */ 6 | 7 | var bigInt = require('big-integer'); 8 | var ABC = require('./lib/abc.js'); 9 | 10 | // cnpl regex 11 | var regex = /\[0\]{\d+}/; 12 | 13 | module.exports = { 14 | // Executes JavaScript cnpl code 15 | execute: function(code) { 16 | var txt = this.cnpl2js(code); 17 | eval(txt); 18 | }, 19 | // Translates from cnpl to js 20 | cnpl2js: function(code) { 21 | var cnpl = code.match(regex)[0]; 22 | 23 | var value = cnpl.slice(4, -1); 24 | var num = bigInt(value); 25 | 26 | var b1 = num.toString(2); 27 | var b2 = b1.substring(1); 28 | var txt = ABC.toAscii(b2); 29 | 30 | return txt; 31 | }, 32 | // Compiles to cnpl code 33 | compile: function(jsCode) { 34 | var cnc = 1 + ABC.toBinary(jsCode, ""); 35 | var num = bigInt(cnc, 2); 36 | return "[0]{" + num.toString() + "}"; 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /lib/abc.js: -------------------------------------------------------------------------------- 1 | // ABC - a generic, native JS (A)scii(B)inary(C)onverter. 2 | // (c) 2013 Stephan Schmitz 3 | // License: MIT, http://eyecatchup.mit-license.org 4 | // URL: https://gist.github.com/eyecatchup/6742657 5 | // Minor changes by @demiurgosoft 6 | var ABC = { 7 | toAscii: function(bin) { 8 | return bin.replace(/\s*[01]{8}\s*/g, function(bin) { 9 | return String.fromCharCode(parseInt(bin, 2)); 10 | }); 11 | }, 12 | toBinary: function(str, spaceSeparatedOctets) { 13 | return str.replace(/[\s\S]/g, function(str) { 14 | str = ABC.zeroPad(str.charCodeAt().toString(2)); 15 | return !spaceSeparatedOctets ? str : str + " "; 16 | }); 17 | }, 18 | zeroPad: function(num) { 19 | return "00000000".slice(String(num).length) + num; 20 | } 21 | }; 22 | 23 | module.exports = ABC; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chuckscript", 3 | "version": "0.3.3", 4 | "description": "Chuck Norris programing language, code only with zeroes", 5 | "main": "index.js", 6 | "bin":{ 7 | "cni": "./bin/cni.js", 8 | "cngen": "./bin/cngen.js" 9 | }, 10 | "directories": { 11 | "example": "examples" 12 | }, 13 | "scripts": { 14 | "test": "echo \"Error: no test specified\" && exit 1", 15 | "start": "node bin/cni.js" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/angrykoala/chuckscript.git" 20 | }, 21 | "keywords": [ 22 | "chuck", 23 | "norris", 24 | "programming", 25 | "language", 26 | "unary", 27 | "chuckscript", 28 | "cnpl" 29 | ], 30 | "author": "angrykoala ", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/angrykoala/chuckscript/issues" 34 | }, 35 | "homepage": "https://github.com/angrykoala/chuckscript#readme", 36 | "dependencies": { 37 | "big-integer": "^1.6.15" 38 | } 39 | } 40 | --------------------------------------------------------------------------------