···11# limp
22a not so very good language built on JavaScript
33+44+/lɪmp/
55+_v._ To walk lamely, especially with irregularity, as if favoring one leg.
+31-12
js/limp.js
···11+// First readNext() goes through the script, performing character/type checks;
22+// For instance, isDigit(). After finding out the type, we read the type;
33+// readNumber(). readNumber() returns an object with info such as type and
44+// value. These objects are put into the statements array, which is later
55+// processed by the parser. The parser loops through the statements array,
66+// forming the AST, a tree/network object representing the script.
77+88+19"use strict";
210311function limpLog(type, msg) {
···1624 // console.log("[limp] "+msg);
1725 }
1826}
1919-2727+var temp = [];
2028function limp(input) {
2129 var pos = 0, line = 1, col = 1; // statement
2230···121129 // if (currentChar() == "+" && currentChar(1) == "+") operator = "++", jumpChar();
122130 // if (currentChar() == "-" && currentChar(1) == "-") operator = "--", jumpChar();
123131 if ("+-*/%".indexOf(operator) >= 0) {
124124- var subType = "arithmetic"
132132+ var type = "arithmetic"
125133 } else if ("=".indexOf(operator) >= 0) {
126126- var subType = "assignment";
134134+ var type = "assignment";
127135 }
128128- return {type: "operator", value: operator, subType: subType};
136136+ return {type: type, operator: operator};
129137 }
130138 function readKeyword() {
131139 var keepRunning = true, keyword = currentChar();
···225233226234227235 var ast = statements;
228228- // loop through statements & tokens
229229- for (var si = 0; si < ast.length; si++) { // statement index
230230- for (var ti = 0; ti < ast[si].length; ti++) { // token index
231231- var token = ast[si][ti];
232232- if (token.type == "operator") {
233233- token.left = ast[si][ti-1];
234234- token.right = ast[si][ti+1];
235235- ast[si].splice(ti-1, 3, token);
236236+ function parseTokensArray(tokens) {
237237+ for (var ti = 0; ti < tokens.length; ti++) {
238238+ var token = tokens[ti];
239239+ if (token.type == "arithmetic") {
240240+ token.left = tokens[ti-1];
241241+ token.right = tokens[ti+1];
242242+ tokens.splice(ti-1, 3, token);
243243+ ti--;
244244+ } else if (token.type == "assignment") {
245245+ token.left = tokens[ti-1];
246246+ token.right = ast[si].splice(ti+1);
247247+ parseTokensArray(token.right);
248248+ token.right = token.right[0];
249249+ tokens.splice(ti-1, 3, token);
236250 ti--;
237251 }
238252 }
239253 }
254254+ // loop through statements & tokens
255255+ for (var si = 0; si < ast.length; si++) { // statement index
256256+ parseTokensArray(ast[si]);
257257+ }
240258 limpLog("inf", ast);
259259+ temp = ast;
241260 }
242261}