I've found many "Cannot read property '0' of undefined"s but they all are very context specific - or I don't understand JS very well.
What I've tried is looking to other problems, but as said, they are all context-specific. Here is the code. The error is on ln 64, although it probably results from a mistyped function call. Please help.
To reproduce, after copy-pasting transpiler code into the console:
input = '!say ::hello'
parse(tokenize(input));
transpiler code:
//actually useful is down here
function type (s) {
if (s[0] == '!') {
return 'f'; //function
} else if (s[0] == '?') {
return 'e'; //end
} else if (s[0] + s[1] == '::') {
return 'p'; //parameter
} else {
return 'o'; //operator or other
}
}
var output = [];
function parse (r) {
var i;
for (i = 0; i < r.length; i++) {
var rv = new Array();
var scopecmd = false;
if (scopecmd == false) {
if (type(r[i]) == 'f') {
scopecmd = true;
var c = r[i];
c = c.replace('!', '');
rv.push(c)
} else if (type(r[i]) == 'p') {
var c = r[i];
c = c.replace('::', '');
rv.push(c);
}
} else if (scopecmd == true) {
if (type(r[i]) == 'p') {
var c = r[i];
c = c.replace('::', '');
rv.push(c);
}
} else if (scopecmd == true && type(r[i]) == 'f') {
scopecmd = false;
var i2;
var m;
for (i2 = 1; i2 <= rv.length - 1; i2++) {
var m = m + rv[i2] + ',';
}
m = m + rv[rv.length];
output.push(eval(rv[0]+'('+m+');'));
}
}
var i;
for (i = 0; i <= output.length; i++) {
eval(output[i]);
}
}
function tokenize (input) {
var r = new Array();
r = input.split(' ');
return r;
}