[READ-ONLY] Mirror of https://github.com/probablykasper/limp. Programming language made in JS, for fun (unfinished) limp.kasper.space
language
0

Configure Feed

Select the types of activity you want to include in your feed.

+Assignment parsing

KH (Jun 10, 2017, 3:55 PM +0200) 572d5db7 8cf7390d

+35 -13
+3
README.md
··· 1 1 # limp 2 2 a not so very good language built on JavaScript 3 + 4 + /lɪmp/ 5 + _v._ To walk lamely, especially with irregularity, as if favoring one leg.
+31 -12
js/limp.js
··· 1 + // First readNext() goes through the script, performing character/type checks; 2 + // For instance, isDigit(). After finding out the type, we read the type; 3 + // readNumber(). readNumber() returns an object with info such as type and 4 + // value. These objects are put into the statements array, which is later 5 + // processed by the parser. The parser loops through the statements array, 6 + // forming the AST, a tree/network object representing the script. 7 + 8 + 1 9 "use strict"; 2 10 3 11 function limpLog(type, msg) { ··· 16 24 // console.log("[limp] "+msg); 17 25 } 18 26 } 19 - 27 + var temp = []; 20 28 function limp(input) { 21 29 var pos = 0, line = 1, col = 1; // statement 22 30 ··· 121 129 // if (currentChar() == "+" && currentChar(1) == "+") operator = "++", jumpChar(); 122 130 // if (currentChar() == "-" && currentChar(1) == "-") operator = "--", jumpChar(); 123 131 if ("+-*/%".indexOf(operator) >= 0) { 124 - var subType = "arithmetic" 132 + var type = "arithmetic" 125 133 } else if ("=".indexOf(operator) >= 0) { 126 - var subType = "assignment"; 134 + var type = "assignment"; 127 135 } 128 - return {type: "operator", value: operator, subType: subType}; 136 + return {type: type, operator: operator}; 129 137 } 130 138 function readKeyword() { 131 139 var keepRunning = true, keyword = currentChar(); ··· 225 233 226 234 227 235 var ast = statements; 228 - // loop through statements & tokens 229 - for (var si = 0; si < ast.length; si++) { // statement index 230 - for (var ti = 0; ti < ast[si].length; ti++) { // token index 231 - var token = ast[si][ti]; 232 - if (token.type == "operator") { 233 - token.left = ast[si][ti-1]; 234 - token.right = ast[si][ti+1]; 235 - ast[si].splice(ti-1, 3, token); 236 + function parseTokensArray(tokens) { 237 + for (var ti = 0; ti < tokens.length; ti++) { 238 + var token = tokens[ti]; 239 + if (token.type == "arithmetic") { 240 + token.left = tokens[ti-1]; 241 + token.right = tokens[ti+1]; 242 + tokens.splice(ti-1, 3, token); 243 + ti--; 244 + } else if (token.type == "assignment") { 245 + token.left = tokens[ti-1]; 246 + token.right = ast[si].splice(ti+1); 247 + parseTokensArray(token.right); 248 + token.right = token.right[0]; 249 + tokens.splice(ti-1, 3, token); 236 250 ti--; 237 251 } 238 252 } 239 253 } 254 + // loop through statements & tokens 255 + for (var si = 0; si < ast.length; si++) { // statement index 256 + parseTokensArray(ast[si]); 257 + } 240 258 limpLog("inf", ast); 259 + temp = ast; 241 260 } 242 261 }
+1 -1
js/script.limp
··· 1 1 limp(` 2 - 1+2-2-5-6; 2 + x = 3+2 3 3 `);