On par with
@123outerme 's request, i wrote a small program in JS to count up the ends in and indent ti-basic source code, and say something if there are too many, or an extra one is needed. You can try/use it at
https://jsfiddle.net/th4hnpmh/ (Changed to latest version)
All the code is here:
Spoiler
<!DOCTYPE html>
<head>
<script>
function test() {
var text = document.getElementById('text').value;
var i = 0;
var line = 0;
for (var x = 0; x < text.length; x++) {
var substring = text.substring(x).toLowerCase();
if (text.charAt(x) == "\n") {
line++;
while(text.charAt(x+1) == ' '){
text = text.slice(0,x+1) + text.slice(x+2);
}
substring = text.substring(x).toLowerCase();
if(substring.substring(1).startsWith("end")) {i--;}
var count=i;
if(substring.substring (1).startsWith("else")) {count--;}
for (var insert = 0; insert < count; insert++) {
text=text.slice(0,x+1)+" "+text.slice(x+1);
}
document.getElementById('text').value = text;
}
if (substring.startsWith("for")) {
i++;
}
if (substring.startsWith("then")) {
i++;
}
if (substring.startsWith("while")) {
i++;
}
if (substring.startsWith("repeat")) {
i++;
}
if (i == -1) {
alert("To many 'end's!\n" + "Line: " + line);
setCaretPosition("text", x);
insertAtCaret("text", "REMOVE thiS->")
break;
}
// alert(i);
}
if (i > 0) {
alert("Missing an End!!!")
}
}
function setCaretPosition(elemId, caretPos) {
var elem = document.getElementById(elemId);
if (elem != null) {
if (elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
} else {
if (elem.selectionStart) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
} else elem.focus();
}
}
}
function insertAtCaret(areaId, text) {
var txtarea = document.getElementById(areaId);
var scrollPos = txtarea.scrollTop;
var caretPos = txtarea.selectionStart;
var front = (txtarea.value).substring(0, caretPos);
var back = (txtarea.value).substring(txtarea.selectionEnd, txtarea.value.length);
txtarea.value = front + text + back;
caretPos = caretPos + text.length;
txtarea.selectionStart = caretPos;
txtarea.selectionEnd = caretPos;
txtarea.focus();
txtarea.scrollTop = scrollPos;
}
</script>
</head>
<body>
<textarea rows="40" cols="50" id="text">type here</textarea>
<button type="button" onClick="test()">Count!</button>
</body>
</html>