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) {
this.type = type;
this.value = value;
};
// This is a group of tokens.
var group = function (type, tokens) {
this.type = "Group";
this.value = type;

View File

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

View File

@ -1,5 +1,6 @@
x = 4
y = 3 * x
asdf = (a) {return(a++)}
a = asdf(2)
log(asdf(a(x,0)))
// Example Pivot code.
// This is a comment.
x = 4 // This creates a variable x with the value of 4.
y = 3 * x // This creates a variable y with the value of the output of (3 * x).
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;
// Create the tokenizer function.
// tokenize() takes Pivot code in, and outputs an array of tokens.
module.exports = exp => {
// Check functions for different token types.
var isDigit = char => {
return /\d/.test(char);
};
@ -21,16 +26,17 @@ module.exports = exp => {
var isPeriod = char => {
return (char === ".");
};
var result = [];
var nb = [];
var lb = [];
var ob = [];
var sb = [];
var inString = false;
var stringType;
exp = exp.split("");
for (var i = 0; i < exp.length; i++) {
var char = exp[i];
var result = []; // The final array of tokens.
var nb = []; // Number buffer. Allows for multiple digits to be one number.
var lb = []; // Letter buffer. Allows for multiple letters to be one variable / function.
var ob = []; // Operator buffer. Allows for multi-character operators. E.g. ++ or ==.
var sb = []; // String buffer. Allows for multi-character strings.
var inString = false; // Keep track of whether in string or not.
var stringType; // Keep track of what type of string. E.g. "" or ''.
exp = exp.split(""); // Split the expression into an array of characters.
/* - - - DO NOT TOUCH THIS - - - */
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 (exp[i - 1] == "\\") {
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++) {
var char = exp[i];
if (inString) {