From 13c771e16cc2f26408b97490eb33500b6e497bae Mon Sep 17 00:00:00 2001 From: Vihan Bhargava Date: Sat, 26 Mar 2016 15:51:10 -0700 Subject: [PATCH] Initial Commit --- chars.es6 | 41 ++++++ chars.js | 45 +++++++ expr/tok.es6 | 252 +++++++++++++++++++++++++++++++++++++ expr/tok.js | 275 +++++++++++++++++++++++++++++++++++++++++ o/old/vsl.es6 | 247 ++++++++++++++++++++++++++++++++++++ o/old/vsl.js | 261 ++++++++++++++++++++++++++++++++++++++ o/tests/definitons.vsl | 80 ++++++++++++ o/tests/notes.vsl | 42 +++++++ o/tests/test.vsl | 20 +++ tok/tks.es6 | 30 +++++ tok/tks.js | 80 ++++++++++++ tok/tok.es6 | 20 +++ tok/tok.js | 38 ++++++ vsl.es6 | 6 + vsl.js | 13 ++ 15 files changed, 1450 insertions(+) create mode 100644 chars.es6 create mode 100644 chars.js create mode 100644 expr/tok.es6 create mode 100644 expr/tok.js create mode 100644 o/old/vsl.es6 create mode 100644 o/old/vsl.js create mode 100644 o/tests/definitons.vsl create mode 100644 o/tests/notes.vsl create mode 100644 o/tests/test.vsl create mode 100644 tok/tks.es6 create mode 100644 tok/tks.js create mode 100644 tok/tok.es6 create mode 100644 tok/tok.js create mode 100644 vsl.es6 create mode 100644 vsl.js diff --git a/chars.es6 b/chars.es6 new file mode 100644 index 00000000..911df3a9 --- /dev/null +++ b/chars.es6 @@ -0,0 +1,41 @@ +/* + * DEFAULT CONSTANTS + * List: + * DIGITS 0-9 + * ALPHA a-z + * UALPHA A-Z + * MALPHA A-Za-z + * NUMERALS 0-9A-F + * WHTIESPACE \s + * + * OP infix operators + * UOP unary operators + * SYMBOL_FILTER valid characters in operators +**/ +export const DIGITS = "0123456789"; +export const ALPHA = "abcdefghijklmnopqrstuvwxyz"; +export const UALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +export const MALPHA = ALPHA + UALPHA; + +export const NUMERALS = `0123456789ABCDEF`; + +export const WHITESPACE = "\r\n\t\f "; + +/*== Operator Constants ==*/ + +export const OP = [ + ['!'], + ['^'], + ['*', '/', '%'], + ['+', '-'], + ['<=', '>=', '<', '>'], + ['=', '!='], + [':=', '+=', '-=', '*=', '/=', '^='] +]; + +export const UOP = [ + ['sqrt', 'cos', 'sin', 'sign'], + ['-', '+'] +]; + +export const SYMBOL_FILTER = `!%&*+-:<=>@\^|~`; \ No newline at end of file diff --git a/chars.js b/chars.js new file mode 100644 index 00000000..79bc2b36 --- /dev/null +++ b/chars.js @@ -0,0 +1,45 @@ +/* Generated by Babel */ +/* + * DEFAULT CONSTANTS + * List: + * DIGITS 0-9 + * ALPHA a-z + * UALPHA A-Z + * MALPHA A-Za-z + * NUMERALS 0-9A-F + * WHTIESPACE \s + * + * OP infix operators + * UOP unary operators + * SYMBOL_FILTER valid characters in operators +**/ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var DIGITS = "0123456789"; +exports.DIGITS = DIGITS; +var ALPHA = "abcdefghijklmnopqrstuvwxyz"; +exports.ALPHA = ALPHA; +var UALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +exports.UALPHA = UALPHA; +var MALPHA = ALPHA + UALPHA; + +exports.MALPHA = MALPHA; +var NUMERALS = "0123456789ABCDEF"; + +exports.NUMERALS = NUMERALS; +var WHITESPACE = "\r\n\t\f "; + +exports.WHITESPACE = WHITESPACE; +/*== Operator Constants ==*/ + +var OP = [['!'], ['^'], ['*', '/', '%'], ['+', '-'], ['<=', '>=', '<', '>'], ['=', '!='], [':=', '+=', '-=', '*=', '/=', '^=']]; + +exports.OP = OP; +var UOP = [['sqrt', 'cos', 'sin', 'sign'], ['-', '+']]; + +exports.UOP = UOP; +var SYMBOL_FILTER = "!%&*+-:<=>@^|~"; +exports.SYMBOL_FILTER = SYMBOL_FILTER; \ No newline at end of file diff --git a/expr/tok.es6 b/expr/tok.es6 new file mode 100644 index 00000000..c248186e --- /dev/null +++ b/expr/tok.es6 @@ -0,0 +1,252 @@ +// Import all constants +import {DIGITS, ALPHA, UALPHA, MALPHA, NUMERALS, WHITESPACE, OP, UOP, SYMBOL_FILTER} from '../chars'; +import '../tok/tok'; // Import Tokenizer class + +// Set data +const OPLIST = [].concat(...OP.concat(UOP)); + +// Symbol operators +const UOLIST = OPLIST.filter( + op => op.split("").every( + o => SYMBOL_FILTER.indexOf(o))); + +const Tokenize = (c, i = 0, r = false) => { + + // c - input + // i - index + // r - expect recursed + + + // tokens + // |- properties + // | |- unary prop operators + // |- digit + // | |- integers + // | |- decimals + // | |- bases + // | |- binary + // | |- hexadecimal + // | --- TODO --- + // |- binary operators + // |- unary operators + + const tok_list = []; + + main: for (; i < c.length; i++) { + + // whitespace + + if (WHITESPACE.indexOf(c[i]) > -1) continue; // Ignore whitespace + + + // properties + + if (MALPHA.indexOf(c[i]) > -1) { // Alpha beginning + + let tok = c[i]; // Token variable + + i++; + + while (i < c.length) { // Get char + + if (MALPHA.indexOf(c[i]) > -1) { + tok += c[i++]; // next char + } + else { + // Go back and eit; + --i; + break; + } + + } + + if (OPLIST.indexOf(tok) == -1) { + // return [1, "Unknown operator"]; + } + + tok_list.push(tok); + continue; + } + + + // digits + + if (DIGITS.indexOf(c[i]) > -1 || c[i] === "." || c[i] === "-") { + if (c[i] === "-") i++; + let tok = (c[i - 1] === "-" ? "-" : "") + (c[i] === "." ? "0." : c[i]); // + let dec = c[i] === "."; // is a decimal? + + i++; + + while (i < c.length) { + + if (DIGITS.indexOf(c[i]) > -1) { + tok += c[i++]; + } + + else if (c[i] == ".") { + + if (dec === true) { + + // decimal after a decimal in the number already occured + return [i, [1, "Repeated decimal"]]; + + } + else { + + tok += c[i]; + + i++; + if (DIGITS.indexOf(c[i ]) > -1) { + tok += c[i]; + } else { + return [i, [1, `Unexpected token after decimal: ${c[i]}`]]; + } + + dec = true; + i++; + } + + } + + else if (c[i - 1] === '0' && c[i]) { // backreference for 0 + + // MARK: BASE CONVERSIONS + // base conversions: + // 012 4567 10 16 + const bases = `ubt???soni?d???x`; + const b = bases.indexOf(c[i]); // base # + const numerals = NUMERALS.slice(0, b + 1); // numerals + + tok += c[i]; + + if (ALPHA.indexOf(bases[b]) > -1) { // valid base id + while (i < c.length) { + i++; + if (NUMERALS.indexOf(c[i]) > -1) { // Is a numberal + + if (numerals.indexOf(c[i]) > -1) tok += c[i]; + else return [i, [1, `Numeral out of specified base range`]]; + + } else { + break; + } + + } + + } else { + return [i, [1, `Unexpected base op \`${c[i]}\``]]; + } + + dec = true; + + } + + else { + --i; + break; + } + + } + + tok_list.push(tok); + continue; + + } + + if (c[i] === "(") { // expression + + // runs tokenizer on nested expresson + // Ensure + let nest_res = Tokenize(c, i + 1, true); + + tok_list.push(nest_res[1]); + i = nest_res[0]; + + continue; + + } + + if (c[i] === r) { // exit expression level + + // should it be exiting? + // checks if `r`, the recurse + // variable is set which + // is set by a to-nest + // expression. + + break; + + } + + // Match an operator + // Greedy matches largest operator + if (SYMBOL_FILTER.indexOf(c[i]) > -1) { + + // Pending possible operators + // Used to hold ambiguous choices. + let PENDING_OP = c[i]; + let STATE_DONE = false; + + // Ensure operator exists + //if (.length === 0) + // return [i, [1, `Unknown operator ${PENDING_OP}`]]; + + // While: + // 1. ambiougous op + // &2. code len + 1 + while (i <= c.length) { + + if (i === c.length) { + // End of file + // Errors for two reasons: + // 1. Ambiguous Op + // 2. Postfix OP + return [i, [1, `Unexpected EOF when tokenizing expression`]]; + } + + // Next char + i++; + + // If it's a symbol disambiguate + if (SYMBOL_FILTER.indexOf(c[i])) { + + let OP_COPY = PENDING_OP + c[i]; // store working operator + + // If the operator exists + if (UOLIST.indexOf(OP_COPY) > -1) + PENDING_OP = OP_COPY; // store it + else + STATE_DONE = true; // interpret operator state + + } else { + STATE_DONE = true; // interpret operator state + } + + if (STATE_DONE) { + // Not a symbol character + // backup, and send for parsing + + // First add to stack + tok_list.push(PENDING_OP); + + --i; + continue main; // next char + } + } + } + + } + + return [i, tok_list]; + +}; + +export default class VSLTokExpression extends VSLTok { + constructor(Code = "", Index = 0) { + super(Code, Index) + } + exec(Recurse = false) { + this.Tokens = Tokenize(this.Code, this.Index, Recurse); + } +} \ No newline at end of file diff --git a/expr/tok.js b/expr/tok.js new file mode 100644 index 00000000..42f4a367 --- /dev/null +++ b/expr/tok.js @@ -0,0 +1,275 @@ +/* Generated by Babel */ +// Import all constants +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _ref; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x6, _x7, _x8) { var _again = true; _function: while (_again) { var object = _x6, property = _x7, receiver = _x8; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x6 = parent; _x7 = property; _x8 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _chars = require('../chars'); + +require('../tok/tok'); + +// Import Tokenizer class + +// Set data +var OPLIST = (_ref = []).concat.apply(_ref, _toConsumableArray(_chars.OP.concat(_chars.UOP))); + +// Symbol operators +var UOLIST = OPLIST.filter(function (op) { + return op.split("").every(function (o) { + return _chars.SYMBOL_FILTER.indexOf(o); + }); +}); + +var Tokenize = function Tokenize(c) { + var i = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; + var r = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; + + // c - input + // i - index + // r - expect recursed + + // tokens + // |- properties + // | |- unary prop operators + // |- digit + // | |- integers + // | |- decimals + // | |- bases + // | |- binary + // | |- hexadecimal + // | --- TODO --- + // |- binary operators + // |- unary operators + + var tok_list = []; + + main: for (; i < c.length; i++) { + + // whitespace + + if (_chars.WHITESPACE.indexOf(c[i]) > -1) continue; // Ignore whitespace + + // properties + + if (_chars.MALPHA.indexOf(c[i]) > -1) { + // Alpha beginning + + var tok = c[i]; // Token variable + + i++; + + while (i < c.length) { + // Get char + + if (_chars.MALPHA.indexOf(c[i]) > -1) { + tok += c[i++]; // next char + } else { + // Go back and eit; + --i; + break; + } + } + + if (OPLIST.indexOf(tok) == -1) { + // return [1, "Unknown operator"]; + } + + tok_list.push(tok); + continue; + } + + // digits + + if (_chars.DIGITS.indexOf(c[i]) > -1 || c[i] === "." || c[i] === "-") { + if (c[i] === "-") i++; + var tok = (c[i - 1] === "-" ? "-" : "") + (c[i] === "." ? "0." : c[i]); // + var dec = c[i] === "."; // is a decimal? + + i++; + + while (i < c.length) { + + if (_chars.DIGITS.indexOf(c[i]) > -1) { + tok += c[i++]; + } else if (c[i] == ".") { + + if (dec === true) { + + // decimal after a decimal in the number already occured + return [i, [1, "Repeated decimal"]]; + } else { + + tok += c[i]; + + i++; + if (_chars.DIGITS.indexOf(c[i]) > -1) { + tok += c[i]; + } else { + return [i, [1, 'Unexpected token after decimal: ' + c[i]]]; + } + + dec = true; + i++; + } + } else if (c[i - 1] === '0' && c[i]) { + // backreference for 0 + + // MARK: BASE CONVERSIONS + // base conversions: + // 012 4567 10 16 + var bases = 'ubt???soni?d???x'; + var b = bases.indexOf(c[i]); // base # + var numerals = _chars.NUMERALS.slice(0, b + 1); // numerals + + tok += c[i]; + + if (_chars.ALPHA.indexOf(bases[b]) > -1) { + // valid base id + while (i < c.length) { + i++; + if (_chars.NUMERALS.indexOf(c[i]) > -1) { + // Is a numberal + + if (numerals.indexOf(c[i]) > -1) tok += c[i];else return [i, [1, 'Numeral out of specified base range']]; + } else { + break; + } + } + } else { + return [i, [1, 'Unexpected base op `' + c[i] + '`']]; + } + + dec = true; + } else { + --i; + break; + } + } + + tok_list.push(tok); + continue; + } + + if (c[i] === "(") { + // expression + + // runs tokenizer on nested expresson + // Ensure + var nest_res = Tokenize(c, i + 1, true); + + tok_list.push(nest_res[1]); + i = nest_res[0]; + + continue; + } + + if (c[i] === r) { + // exit expression level + + // should it be exiting? + // checks if `r`, the recurse + // variable is set which + // is set by a to-nest + // expression. + + break; + } + + // Match an operator + // Greedy matches largest operator + if (_chars.SYMBOL_FILTER.indexOf(c[i]) > -1) { + + // Pending possible operators + // Used to hold ambiguous choices. + var PENDING_OP = c[i]; + var STATE_DONE = false; + + // Ensure operator exists + //if (.length === 0) + // return [i, [1, `Unknown operator ${PENDING_OP}`]]; + + // While: + // 1. ambiougous op + // &2. code len + 1 + while (i <= c.length) { + + if (i === c.length) { + // End of file + // Errors for two reasons: + // 1. Ambiguous Op + // 2. Postfix OP + return [i, [1, 'Unexpected EOF when tokenizing expression']]; + } + + // Next char + i++; + + // If it's a symbol disambiguate + if (_chars.SYMBOL_FILTER.indexOf(c[i])) { + + var OP_COPY = PENDING_OP + c[i]; // store working operator + + // If the operator exists + if (UOLIST.indexOf(OP_COPY) > -1) PENDING_OP = OP_COPY; // store it + else STATE_DONE = true; // interpret operator state + } else { + STATE_DONE = true; // interpret operator state + } + + if (STATE_DONE) { + // Not a symbol character + // backup, and send for parsing + + // First add to stack + tok_list.push(PENDING_OP); + + --i; + continue main; // next char + } + } + } + } + + return [i, tok_list]; +}; + +var VSLTokExpression = (function (_VSLTok) { + _inherits(VSLTokExpression, _VSLTok); + + function VSLTokExpression() { + var Code = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0]; + var Index = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; + + _classCallCheck(this, VSLTokExpression); + + _get(Object.getPrototypeOf(VSLTokExpression.prototype), 'constructor', this).call(this, Code, Index); + } + + _createClass(VSLTokExpression, [{ + key: 'exec', + value: function exec() { + var Recurse = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + + this.Tokens = Tokenize(this.Code, this.Index, Recurse); + } + }]); + + return VSLTokExpression; +})(VSLTok); + +exports['default'] = VSLTokExpression; +module.exports = exports['default']; \ No newline at end of file diff --git a/o/old/vsl.es6 b/o/old/vsl.es6 new file mode 100644 index 00000000..7c926bf8 --- /dev/null +++ b/o/old/vsl.es6 @@ -0,0 +1,247 @@ +////// DEFINE PARSER ELEMENTS +const EOF = 218; +const NONE = null; + +// Character Classes + +const UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const LOWER = "abcdefghijklmnopqrstuvwxyz"; +const WHITE = "\u0013\u0010\u0009\u0012 "; +const DIGIT = "0123456789"; + +// Tokenization Part Definitions + +const TOKEN = UPPER + LOWER + "_"; +const TOKEN_B = TOKEN + DIGIT; +const TOKEN_C = WHITE /* EOF */; + +const VAR = TOKEN + "_"; +const VAR_B = VAR + DIGIT; + +const OP = "+-*/"; + +// Declerations + +const ___FORMAL = new Map([ + ["TOK_A", TOKEN], + ["TOK_B", TOKEN], +]); + +/* +DEFINITION types + + := -><- -> + := :<__::LEX> + + := -><- + + := + := + + := + := () + := . + + := ( ) + := + + or +*/ + +//////////////////// START //////////////////// + +/// START DATA +const CODE = ` //`; + +// TOKENIZER +let STDERR = ""; +let STDLOG = ""; // Debug notes +(function() { + + let ITERATOR = 0; + + // Error handling + function $ERROR(w, c, r) { + STDERR += `Compile Error: ${w} at ${c}:${r}\n`; + ITERATOR = CODE.length; + } + + function $TOKEN(n, c, r) { // Name, Column, Row + $ERROR(`Unexpected token "${n}"`, c, r); + } + + // Code Navigating Functions + + function __JUMP(palette) { // Jump through palette + STDLOG += `JUMPED from ${ITERATOR}`; + while (ITERATOR < CODE.length && palette.indexOf(CODE[ITERATOR]) > -1) ITERATOR++; + STDLOG += ` to ${ITERATOR}\n`; + } + + function __SKIP(pa, pb, s) { // Returns between a two paritions + if (CODE.slice(ITERATOR).indexOf(pa) === 0) { + ITERATOR += pa.length; // JUMP + do { + if (ITERATOR < CODE.length) { + ITERATOR++; + } else { + if (s !== EOF) { + let _DIST = CODE.slice(0, ITERATOR); + $TOKEN("EOF", ITERATOR - (_DIST.lastIndexOf("\n")), _DIST.split("\n").length); + } else { + STDLOG += "SKIPED to EOF"; + } + break; + } + } while (CODE.slice(ITERATOR).indexOf(pa) !== 0); + } else { + STDLOG += `Jumped __SKIP at ${ITERATOR}\n`; + } + } + + ////// TOKENIZATION DEFINITIONS ///// + + class ___REGISTER { + + // Class Register + // Creates Parse Register + + constructor(FORM, ...NEST) { + + this.FORM = FORM; + this.REGISTER = new RegExp( + FORM + .replace(/<([A-Za-z_]+?)>/g,(_, DATA) => ___FORMAL.get(DATA) + .replace(/\\/g, "\\\\") + .replace(/]/g, "\\]") ) + .replace(/<<(\d+)>>/g, (_, DATA) => NEST[DATA]) + ); + } + + // Handle resister checking + + toString() { return this.FORM } + } + + + function __EXPRESSION() { + + __JUMP(WHITE); + const __E_OP = "+-*/"; + //const __EOP + + } + + + function __MATCH(REGISTER) { + + // for item in expand(register) { + // switch typeof item { + // case string: + // <= [item] + // case array: + // <= item[1] + // } + // } + + if (REGISTER instanceof ___REGISTER) { // Register? + + // Get jump register + const JUMP = REGISTER.REGISTER; + + // Set jump resgister + + + } else { + + // Invalid parse register + // Internal error + + $ERROR("Invalid Register", "INT", "INT::REGISTER"); + + } + + } + + + class Lexer { + + constructor(i, code) { + + this.i = i; + this.Code = code; + + this.Out = []; + + } + + // Retrieve current char at index + // Lexer..get + get get() { return this.Code[ this.i ] } + + + // Stores `..get` + // Lexer..Out <- Lexer..get + keep() { this.Out.push(this.get) } + + // Closes lexer register + // + close() { + + } + + } + + + + for (; ITERATOR < CODE.length; ITERATOR++) { + ///// LEVELED CORE ///// + const ____STREAM = { IN: 1, OUT: 2, ERR: 3 }; + + ///// PREPROCCESSING ///// + + // Align to Tokeen + + __JUMP(WHITE); + + // Comment Jumps + + __SKIP("/*", "*/", EOF); + __SKIP("//", "\n", EOF); + __SKIP("#" , "\n", EOF); + + ////// DEFIINITION ////// + + // Expression Definition + + const ___T_STR = new ___REGISTER(); + + // Tokens + const ___TOK = new ___REGISTER(`[][]*`) + const ___TYPE = new ___REGISTER(`<<0>>`, ___TOK) + + + + // NOTE: syntax is still currently being descided + // const ___TOK = ___REGISTER([TOKEN, ["*", TOK_B]]); + // const ___TYPE = ___REGISTER([___TOK, ":", ["//", "LEXOGRAPHIC DEFINITION"]]); + + __MATCH(___TOK); + + // OPEN + } +}()); + + +/////////// LEVELED DEFINITIONS /////////// + +/// +// == LEXICAL TYPES == +// Expression +// Variable +// Closure +// +/// +//__MACRO__("if", ___MACROSTATE([ ___EXPRESSION, ___CLOSURE ]), (E, C) => { }) +//__MACRO__("def", ___MACROSTATE([ ___VARIABLE, ___TYPE ]), (V, T) => { }) +//__MACRO__("while", ___MACROSTATE([ ___EXPRESSION, ___CLOSURE ]), (E, C) => { }) \ No newline at end of file diff --git a/o/old/vsl.js b/o/old/vsl.js new file mode 100644 index 00000000..0a6688f7 --- /dev/null +++ b/o/old/vsl.js @@ -0,0 +1,261 @@ +/* Generated by Babel */ +////// DEFINE PARSER ELEMENTS +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var EOF = 218; +var NONE = null; + +// Character Classes + +var UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +var LOWER = "abcdefghijklmnopqrstuvwxyz"; +var WHITE = "\u0013\u0010\t\u0012 "; +var DIGIT = "0123456789"; + +// Tokenization Part Definitions + +var TOKEN = UPPER + LOWER + "_"; +var TOKEN_B = TOKEN + DIGIT; +var TOKEN_C = WHITE /* EOF */; + +var VAR = TOKEN + "_"; +var VAR_B = VAR + DIGIT; + +var OP = "+-*/"; + +// Declerations + +var ___FORMAL = new Map([["TOK_A", TOKEN], ["TOK_B", TOKEN]]); + +/* +DEFINITION types + + := -><- -> + := :<__::LEX> + + := -><- + + := + := + + := + := () + := . + + := ( ) + := + + or +*/ + +//////////////////// START //////////////////// + +/// START DATA +var CODE = " //"; + +// TOKENIZER +var STDERR = ""; +var STDLOG = ""; // Debug notes +(function () { + + var ITERATOR = 0; + + // Error handling + function $ERROR(w, c, r) { + STDERR += "Compile Error: " + w + " at " + c + ":" + r + "\n"; + ITERATOR = CODE.length; + } + + function $TOKEN(n, c, r) { + // Name, Column, Row + $ERROR("Unexpected token \"" + n + "\"", c, r); + } + + // Code Navigating Functions + + function __JUMP(palette) { + // Jump through palette + STDLOG += "JUMPED from " + ITERATOR; + while (ITERATOR < CODE.length && palette.indexOf(CODE[ITERATOR]) > -1) ITERATOR++; + STDLOG += " to " + ITERATOR + "\n"; + } + + function __SKIP(pa, pb, s) { + // Returns between a two paritions + if (CODE.slice(ITERATOR).indexOf(pa) === 0) { + ITERATOR += pa.length; // JUMP + do { + if (ITERATOR < CODE.length) { + ITERATOR++; + } else { + if (s !== EOF) { + var _DIST = CODE.slice(0, ITERATOR); + $TOKEN("EOF", ITERATOR - _DIST.lastIndexOf("\n"), _DIST.split("\n").length); + } else { + STDLOG += "SKIPED to EOF"; + } + break; + } + } while (CODE.slice(ITERATOR).indexOf(pa) !== 0); + } else { + STDLOG += "Jumped __SKIP at " + ITERATOR + "\n"; + } + } + + ////// TOKENIZATION DEFINITIONS ///// + + var ___REGISTER = (function () { + + // Class Register + // Creates Parse Register + + function ___REGISTER(FORM) { + for (var _len = arguments.length, NEST = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + NEST[_key - 1] = arguments[_key]; + } + + _classCallCheck(this, ___REGISTER); + + this.FORM = FORM; + this.REGISTER = new RegExp(FORM.replace(/<([A-Za-z_]+?)>/g, function (_, DATA) { + return ___FORMAL.get(DATA).replace(/\\/g, "\\\\").replace(/]/g, "\\]"); + }).replace(/<<(\d+)>>/g, function (_, DATA) { + return NEST[DATA]; + })); + } + + // Handle resister checking + + _createClass(___REGISTER, [{ + key: "toString", + value: function toString() { + return this.FORM; + } + }]); + + return ___REGISTER; + })(); + + function __EXPRESSION() { + + __JUMP(WHITE); + var __E_OP = "+-*/"; + //const __EOP + } + + function __MATCH(REGISTER) { + + // for item in expand(register) { + // switch typeof item { + // case string: + // <= [item] + // case array: + // <= item[1] + // } + // } + + if (REGISTER instanceof ___REGISTER) { + // Register? + + // Get jump register + var JUMP = REGISTER.REGISTER; + + // Set jump resgister + } else { + + // Invalid parse register + // Internal error + + $ERROR("Invalid Register", "INT", "INT::REGISTER"); + } + } + + var Lexer = (function () { + function Lexer(i, code) { + _classCallCheck(this, Lexer); + + this.i = i; + this.Code = code; + + this.Out = []; + } + + // Retrieve current char at index + // Lexer..get + + _createClass(Lexer, [{ + key: "keep", + + // Stores `..get` + // Lexer..Out <- Lexer..get + value: function keep() { + this.Out.push(this.get); + } + + // Closes lexer register + // + }, { + key: "close", + value: function close() {} + }, { + key: "get", + get: function get() { + return this.Code[this.i]; + } + }]); + + return Lexer; + })(); + + for (; ITERATOR < CODE.length; ITERATOR++) { + ///// LEVELED CORE ///// + var ____STREAM = { IN: 1, OUT: 2, ERR: 3 }; + + ///// PREPROCCESSING ///// + + // Align to Tokeen + + __JUMP(WHITE); + + // Comment Jumps + + __SKIP("/*", "*/", EOF); + __SKIP("//", "\n", EOF); + __SKIP("#", "\n", EOF); + + ////// DEFIINITION ////// + + // Expression Definition + + var ___T_STR = new ___REGISTER(); + + // Tokens + var ___TOK = new ___REGISTER("[][]*"); + var ___TYPE = new ___REGISTER("<<0>>", ___TOK); + + // NOTE: syntax is still currently being descided + // const ___TOK = ___REGISTER([TOKEN, ["*", TOK_B]]); + // const ___TYPE = ___REGISTER([___TOK, ":", ["//", "LEXOGRAPHIC DEFINITION"]]); + + __MATCH(___TOK); + + // OPEN + } +})(); + +/////////// LEVELED DEFINITIONS /////////// + +/// +// == LEXICAL TYPES == +// Expression +// Variable +// Closure +// +/// +//__MACRO__("if", ___MACROSTATE([ ___EXPRESSION, ___CLOSURE ]), (E, C) => { }) +//__MACRO__("def", ___MACROSTATE([ ___VARIABLE, ___TYPE ]), (V, T) => { }) +//__MACRO__("while", ___MACROSTATE([ ___EXPRESSION, ___CLOSURE ]), (E, C) => { }) \ No newline at end of file diff --git a/o/tests/definitons.vsl b/o/tests/definitons.vsl new file mode 100644 index 00000000..5d3b1b7b --- /dev/null +++ b/o/tests/definitons.vsl @@ -0,0 +1,80 @@ +// Defines String class + + +// new VSL.__TYPE__(VSL.__CLASS__.String, LITERAL, VALUE); + +extends String { + + ::CONSTRUCTOR -> (LEXER) { + } + + ::CAST Number -> { + return this.__REGISTER__[0] + } + + ::CAST Array -> { + return this.__REGISTER__[0].split("") + } + + + ::GET len -> { + return Number:this.__REGISTER__[0].split("").length; + } + + ::SET len -> { + + } + + split -> DELIMITER { + def r Array:[]; + for i in this { + if this[i] == DELIMITER { + r.end("") + } else { + r.last += this[i] + } + } + } + + cut -> (START, END = START) { + def A Number; + def B Number; + + if START.type !== Number { + throw ValueError "Expected cut value type #" + } + + if START < 0 { + A = this.len + START + } + + if END < 0 { + B = this.len + END + } + + if START > END { + return "" + } + + def R String:""; + for (i, j) in this { + if END > j > START { + R += this[i] + } + } + } + + find -> (STRING, START = 0) { + def index Number:-1; + for (i, j) in this { + if this.cut(STRING.len) == STRING & j > START { + index = STRING + break; + } + } + return index; + } + +} + +interface __TYPE__.__DIGIT__="04689" \ No newline at end of file diff --git a/o/tests/notes.vsl b/o/tests/notes.vsl new file mode 100644 index 00000000..18a9d39d --- /dev/null +++ b/o/tests/notes.vsl @@ -0,0 +1,42 @@ +/* +EXPRESSION Definition + + := [0123456789] + + := + + := -+ + + := [+-/*] + + := + := + := () + +(2 + (4 * (4 / 3))) +(D O D) +*/ + +class BigNum(Number:num) { + ::LITERAL -> (val) this.init(val) + ::SELF -> () num + + ::OVERLOAD + this.add + ::OVERLOAD / this.div + ::OVERLOAD ^ this.pow + ::OVERLOAD - this.minus + ::OVERLOAD * this.times + + add := int.BigNum.add + div := int.BigNum.div + pow := int.BigNum.pow + minus := int.BigNum.minus + times := int.BigNum.times +} + +def mylargeinteger BigNum:-1234567890123456789012345678901234567898.571236895709234458762054957345982703850 +assert(mylargeinteger - mylargeinteger = 0) + +int.DefaultClass := BigNum + +def integer freetype(mylargeinteger) +assert(integer.Class = BigNum) \ No newline at end of file diff --git a/o/tests/test.vsl b/o/tests/test.vsl new file mode 100644 index 00000000..aea519ec --- /dev/null +++ b/o/tests/test.vsl @@ -0,0 +1,20 @@ +# Test Class + +object Age(Int: age) { + days { + GET floor(age * 365.25) + SET age self / 365.25 + } +} + +class Person(String: name, Int: age) { + main { + self name name + self age Age:(age) + } +} + +def PersonA Person:("Frank", 23) +print PersonA.age.days # Outputs 8,400 +personA.age.days := 8766 +print PersonA.age # Outputs 24 \ No newline at end of file diff --git a/tok/tks.es6 b/tok/tks.es6 new file mode 100644 index 00000000..9cbc1987 --- /dev/null +++ b/tok/tks.es6 @@ -0,0 +1,30 @@ +export default class VSLTokens { + constructor(tokens) { + if (Number.isInteger(tokens.length) && tokens.splice) { + this.length = tokens.length; + for (let i = 0; i < tokens.length; i++) this[i] = tokens[i]; + } else if (tokens === null) { + this.length = -1; + } else { + throw new TypeError("VSLTokens: provided instantiation token is invalid"); + } + } + + UpdateTokends(tokens) { + if (Number.isInteger(tokens.length) && tokens.splice) { + this.length = tokens.length; + for (let i = 0; i < tokens.length; i++) this[i] = tokens[i]; + } else if (tokens === null) { + this.length = -1; + } else { + throw new TypeError("VSLTokens: provided update token is invalid"); + } + } + + * [Symbol.iterator]() { + for (let i = 0; i < this.length; i++) { + yield this[i]; + } + return this; + } +} \ No newline at end of file diff --git a/tok/tks.js b/tok/tks.js new file mode 100644 index 00000000..6227abc1 --- /dev/null +++ b/tok/tks.js @@ -0,0 +1,80 @@ +/* Generated by Babel */ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var VSLTokens = (function () { + function VSLTokens(tokens) { + _classCallCheck(this, VSLTokens); + + if (Number.isInteger(tokens.length) && tokens.splice) { + this.length = tokens.length; + for (var i = 0; i < tokens.length; i++) { + this[i] = tokens[i]; + } + } else if (tokens === null) { + this.length = -1; + } else { + throw new TypeError("VSLTokens: provided instantiation token is invalid"); + } + } + + _createClass(VSLTokens, [{ + key: "UpdateTokends", + value: function UpdateTokends(tokens) { + if (Number.isInteger(tokens.length) && tokens.splice) { + this.length = tokens.length; + for (var i = 0; i < tokens.length; i++) { + this[i] = tokens[i]; + } + } else if (tokens === null) { + this.length = -1; + } else { + throw new TypeError("VSLTokens: provided update token is invalid"); + } + } + }, { + key: Symbol.iterator, + value: regeneratorRuntime.mark(function value() { + var i; + return regeneratorRuntime.wrap(function value$(context$2$0) { + while (1) switch (context$2$0.prev = context$2$0.next) { + case 0: + i = 0; + + case 1: + if (!(i < this.length)) { + context$2$0.next = 7; + break; + } + + context$2$0.next = 4; + return this[i]; + + case 4: + i++; + context$2$0.next = 1; + break; + + case 7: + return context$2$0.abrupt("return", this); + + case 8: + case "end": + return context$2$0.stop(); + } + }, value, this); + }) + }]); + + return VSLTokens; +})(); + +exports["default"] = VSLTokens; +module.exports = exports["default"]; \ No newline at end of file diff --git a/tok/tok.es6 b/tok/tok.es6 new file mode 100644 index 00000000..dfe5a5ca --- /dev/null +++ b/tok/tok.es6 @@ -0,0 +1,20 @@ +// Tokenizer Class +import 'VSLTokens'; +export default class VSLTok { + + constructor(Code = "", Index = 0) { + + this.Code = Code; // Tokenize given code + this.Index = Index; // Tokenize given code at given index + this.Tokens = new VSLTokens(null); // Result for Tokenized + + } + + set Tokens(v) { + if (v instanceof VSLTokens) + this.Tokens = v; + else + throw new TypeError("VSLTok: provided update `Tokens` is invalid"); + } + +} \ No newline at end of file diff --git a/tok/tok.js b/tok/tok.js new file mode 100644 index 00000000..c86ae2cc --- /dev/null +++ b/tok/tok.js @@ -0,0 +1,38 @@ +/* Generated by Babel */ +// Tokenizer Class +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +require('VSLTokens'); + +var VSLTok = (function () { + function VSLTok() { + var Code = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0]; + var Index = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; + + _classCallCheck(this, VSLTok); + + this.Code = Code; // Tokenize given code + this.Index = Index; // Tokenize given code at given index + this.Tokens = new VSLTokens(null); // Result for Tokenized + } + + _createClass(VSLTok, [{ + key: "Tokens", + set: function set(v) { + if (v instanceof VSLTokens) this.Tokens = v;else throw new TypeError("VSLTok: provided update `Tokens` is invalid"); + } + }]); + + return VSLTok; +})(); + +exports["default"] = VSLTok; +module.exports = exports["default"]; \ No newline at end of file diff --git a/vsl.es6 b/vsl.es6 new file mode 100644 index 00000000..1e65f29b --- /dev/null +++ b/vsl.es6 @@ -0,0 +1,6 @@ +// VSL Wrapper +// VSL Interface & Controls + +const VSL = {}; + +import * as _ENGINE_EXPRESSION from "expr/expr"; \ No newline at end of file diff --git a/vsl.js b/vsl.js new file mode 100644 index 00000000..0d060af0 --- /dev/null +++ b/vsl.js @@ -0,0 +1,13 @@ +/* Generated by Babel */ +// VSL Wrapper +// VSL Interface & Controls + +"use strict"; + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } + +var _exprExpr = require("expr/expr"); + +var _ENGINE_EXPRESSION = _interopRequireWildcard(_exprExpr); + +var VSL = {}; \ No newline at end of file