Comment the code for ShrubBoi.

This commit is contained in:
ElementG9 2019-01-14 10:47:43 -07:00
parent bce0463f8e
commit e0fc8bd2b1
4 changed files with 38 additions and 15 deletions

View File

@ -1,7 +1,9 @@
// This is the most basic type of token.
var token = function (type, value) { var token = function (type, value) {
this.type = type; this.type = type;
this.value = value; this.value = value;
}; };
// This is a group of tokens.
var group = function (type, tokens) { var group = function (type, tokens) {
this.type = "Group"; this.type = "Group";
this.value = type; this.value = type;

View File

@ -1,8 +1,15 @@
// Import the group class.
const group = require("./classes.js").group; const group = require("./classes.js").group;
// Create the parser function.
// parse() takes an array of tokens in, and outputs an
// Abstract Syntax Tree (a structured array of tokens).
module.exports = tokens => { module.exports = tokens => {
// Variables for later.
var layer = 0; var layer = 0;
var delimiterCount = 0; var delimiterCount = 0;
var deepestLayer = 0; var deepestLayer = 0;
// Give each token a layer number based on delimiters.
for (var i = 0; i < tokens.length; i++) { for (var i = 0; i < tokens.length; i++) {
if (tokens[i].type == "Left Delimiter") { if (tokens[i].type == "Left Delimiter") {
layer++; layer++;
@ -16,6 +23,7 @@ module.exports = tokens => {
layer--; layer--;
} }
} }
// Lower the layer of delimiters.
for (var i = 0; i < tokens.length; i++) { for (var i = 0; i < tokens.length; i++) {
if ((tokens[i].type == "Left Delimiter") || (tokens[i].type == "Right Delimiter")) { if ((tokens[i].type == "Left Delimiter") || (tokens[i].type == "Right Delimiter")) {
tokens[i].layer--; tokens[i].layer--;
@ -24,7 +32,9 @@ module.exports = tokens => {
if (layer > 0) { // Unclosed delimiter. if (layer > 0) { // Unclosed delimiter.
} else if (layer < 0) { // Overclosed delimiter. } else if (layer < 0) { // Overclosed delimiter.
} }
// Reset layer for structuring.
layer = 0; layer = 0;
/* - - - DO NOT TOUCH THIS - - - */
for(var i=deepestLayer;i>=0;i--) { for(var i=deepestLayer;i>=0;i--) {
var temp = []; var temp = [];
var firstIndex; var firstIndex;
@ -43,5 +53,7 @@ module.exports = tokens => {
} }
} }
} }
/* - - - OK YOU CAN TOUCH AGAIN - - - */
// Return the structured tokens.
return tokens; return tokens;
}; };

View File

@ -1,5 +1,6 @@
x = 4 // Example Pivot code.
y = 3 * x // This is a comment.
asdf = (a) {return(a++)} x = 4 // This creates a variable x with the value of 4.
a = asdf(2) y = 3 * x // This creates a variable y with the value of the output of (3 * x).
log(asdf(a(x,0))) asdf = (a) {return(a++)} // This creates a function asdf that takes a number and returns that number + 1/
a = asdf(2) // This creates a variable a with the value of the output of asdf(2).

View File

@ -1,5 +1,10 @@
// Import the token class.
const token = require("./classes.js").token; const token = require("./classes.js").token;
// Create the tokenizer function.
// tokenize() takes Pivot code in, and outputs an array of tokens.
module.exports = exp => { module.exports = exp => {
// Check functions for different token types.
var isDigit = char => { var isDigit = char => {
return /\d/.test(char); return /\d/.test(char);
}; };
@ -21,16 +26,17 @@ module.exports = exp => {
var isPeriod = char => { var isPeriod = char => {
return (char === "."); return (char === ".");
}; };
var result = []; var result = []; // The final array of tokens.
var nb = []; var nb = []; // Number buffer. Allows for multiple digits to be one number.
var lb = []; var lb = []; // Letter buffer. Allows for multiple letters to be one variable / function.
var ob = []; var ob = []; // Operator buffer. Allows for multi-character operators. E.g. ++ or ==.
var sb = []; var sb = []; // String buffer. Allows for multi-character strings.
var inString = false; var inString = false; // Keep track of whether in string or not.
var stringType; var stringType; // Keep track of what type of string. E.g. "" or ''.
exp = exp.split(""); exp = exp.split(""); // Split the expression into an array of characters.
for (var i = 0; i < exp.length; i++) { /* - - - DO NOT TOUCH THIS - - - */
var char = exp[i]; for (var i = 0; i < exp.length; i++) { // Loop through all of the characters.
var char = exp[i]; // Create a quick reference to the current char.
if (i >= 1) { if (i >= 1) {
if (exp[i - 1] == "\\") { if (exp[i - 1] == "\\") {
exp.splice(i - 1, 2, `\\${char}`); exp.splice(i - 1, 2, `\\${char}`);
@ -44,6 +50,8 @@ module.exports = exp => {
} }
} }
} }
/* - - - OK YOU CAN TOUCH AGAIN - - - */
// Nevermind, just don't mess with any of this file.
for (var i = 0; i < exp.length; i++) { for (var i = 0; i < exp.length; i++) {
var char = exp[i]; var char = exp[i];
if (inString) { if (inString) {