Context-free grammar for decimal point
w =S => aSa => aaSaa => aa+aEaaa => aa+aaEaaaa => aa+aa=aaaa Accept
function delta(c, p) { // Unary addition
if (c=='a' && p=='S') return "aSa";
if (c=='+' && p=='S') return "+aEa";
if (c=='a' && p=='E') return "aEa";
if (c=='=' && p=='E') return "=";
return ''; //default -- no transition
}
function generate(w, init='S') {
//w: input String
//init: start symbol
//g: generated String
let txt = init, g = init
for (let i=0; i<w.length; i++) {
let c = w[i], p = g[i]
if (c == p) continue
let d = delta(c, p)
if (d == '') {
input.selectionStart = i
input.selectionEnd = i+1
break
}
g = g.replace(p, d)
txt += "\n=> "+g
}
return txt+'\n'+(w==g ? "Accept" : "Reject")
}