0
I would like to connect a function to work with finite automata.
The intention is that from the forms I can work with her js:
var ListaNo = new function () {
this.Nos;
function CriaNo(idNo){
var NovoNo = new No(idNo);
this.Nos.push(NovoNo);
return NovoNo;
}
function AdicionaLigacao(idNo, termo)
{
var aux = buscaNo(idNo);
if (aux == null) aux = CriaNo(idNo);
aux.AdcionaNo(termo);
}
function verificaGr(chave, nAtual, i){
if(i<chave.length)
{
var cAtual = chave[i];
nAtual.terminal.foreach(element, index =>{
if(element == cAtual)
{
var NovNo = buscaNo(nAtual.variavel[index])
var aux;
if (NovNo != null) aux = verificaGr(chave, NovNo, i+1);
else if (NovNo == null && i == chave.length-1)
{
if(nAtual.variavel[index] == 'λ') return true;
}
if (aux == true) return true;
}
else if (element == 'λ')
{
var NovNo = buscaNo(nAtual.variavel[index])
var aux;
if (NovNo != null) aux = verificaGr(chave, NovNo, i);
if (aux == true) return true;
}
return false;
});
}
else if(i == chave.length)
{
nAtual.terminal.foreach(element, index =>{
if (element == 'λ' && nAtual.variavel[index] == 'λ') return true;
});
}
else return false;
}
function buscaNo(idNo)
{
if(idNo == 'λ') return null;
this.Nos.foreach(element, index =>{
if(element.id == idNo)
{
return Nos[index];
}
});
return null;
}
function LimpaNos()
{
this.Nos = [];
}
return{
ListaNo, LimpaNos, buscaNo, verificaGr, AdicionaLigacao
};
}
html:
<div class="cardGramatica">
<h4>Gramatica</h4>
<div class="Header" id="hd03">
<form id="gramar">
Id
<input id="inputvar" maxlength="1" style="width:5%" type="text" name="fname"><i class="fas fa-long-arrow-alt-right" style="font-size:15px; padding-left:5px"></i>
String
<input id="inputter" style="width:40%" type="text" name="fname">
<button type="button" style="width:100%" value="Adicionar" onclick="AdicionaLigacao(inputvar,inputter)" id="adicionar">Adicionar No</button>
<br>
</form>
</div>
</div>
Error: ![Uncaught Referenceerror: Additionlink is not defined At Htmlbuttonelement.onclick (index.html:59)]1
Thanks for the answer and help Fábio, in the example it worked, but now gave the following error: Listano.js:75 Uncaught Typeerror: Cannot set Property 'onclick' of null at Listano.js:75
– Carlos Alberto
The intention of the code is that at each node entry I can put them in the list and then check if the grammar is correct
– Carlos Alberto
Try to put the script before the </body>. I think you will no longer have this error.
– Fabio Assuncao