Skip to content

Commit

Permalink
Implementação do SE
Browse files Browse the repository at this point in the history
Implementação do SE e alteração de como se trata valores lógicos
  • Loading branch information
humbertocsjr committed Apr 5, 2020
1 parent 16357bf commit 8711f21
Show file tree
Hide file tree
Showing 27 changed files with 453 additions and 16 deletions.
27 changes: 26 additions & 1 deletion HCIPC/HCIPC/Arvore/NoDiferente.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,35 @@
using System;
namespace HCIPC.Arvore
{
public class NoDiferente
public class NoDiferente : NoComparadorBase
{
public NoDiferente()
{
}

protected override void Executar(ref EstadoExecucao estado)
{
Item1.ExecutarNo(ref estado);
var valor1 = estado.Valor;
Item2.ExecutarNo(ref estado);
var valor2 = estado.Valor;

if (SaoNumericos(valor1, valor2))
{
estado.Valor = (LerNumero(valor1) != LerNumero(valor2));
}
else if (SaoTextos(valor1, valor2))
{
estado.Valor = (valor1.ToString() != valor2.ToString()) ;
}
else if (ContemTextos(valor1, valor2))
{
estado.Valor = (valor1.ToString() != valor2.ToString());
}
else
{
throw new Erro(this, "Tipos incompatíveis com a comparação");
}
}
}
}
45 changes: 45 additions & 0 deletions HCIPC/HCIPC/Arvore/NoEntao.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// /*
// * Copyright (c) 2020
// * Humberto Costa dos Santos Junior. All rights reserved.
// *
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions
// * are met:
// * 1. Redistributions of source code must retain the above copyright
// * notice, this list of conditions and the following disclaimer.
// * 2. Redistributions in binary form must reproduce the above copyright
// * notice, this list of conditions and the following disclaimer in the
// * documentation and/or other materials provided with the distribution.
// * 3. All advertising materials mentioning features or use of this software
// * must display the following acknowledgement:
// * This product includes software developed by Humberto Costa dos Santos Junior and its contributors.
// * 4. Neither the name of the Humberto Costa dos Santos Junior nor the names
// * of its contributors may be used to endorse or promote products derived
// * from this software without specific prior written permission.
// *
// * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
// * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
// * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// * SUCH DAMAGE.
// */
using System;
namespace HCIPC.Arvore
{
public class NoEntao : No
{
public NoEntao()
{
}

protected override void Executar(ref EstadoExecucao estado)
{
}
}
}
7 changes: 6 additions & 1 deletion HCIPC/HCIPC/Arvore/NoEscreva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ protected override void Executar(ref EstadoExecucao estado)
//Escreve cada um dos argumentos na tela, desde que tenha valor
estado.Valor = null;
no.ExecutarNo(ref estado);
if(estado.Valor != null) estado.ES.Escreva(estado.Valor);
object valor = estado.Valor;
if(estado.Valor is bool)
{
valor = (bool)estado.Valor ? "Verdadeiro" : "Falso";
}
if(estado.Valor != null) estado.ES.Escreva(valor);
}
//Caso seja a variação Escreval, imprime um ENTER
if (EnterAoFinal) estado.ES.Enter();
Expand Down
46 changes: 46 additions & 0 deletions HCIPC/HCIPC/Arvore/NoFaca.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// /*
// * Copyright (c) 2020
// * Humberto Costa dos Santos Junior. All rights reserved.
// *
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions
// * are met:
// * 1. Redistributions of source code must retain the above copyright
// * notice, this list of conditions and the following disclaimer.
// * 2. Redistributions in binary form must reproduce the above copyright
// * notice, this list of conditions and the following disclaimer in the
// * documentation and/or other materials provided with the distribution.
// * 3. All advertising materials mentioning features or use of this software
// * must display the following acknowledgement:
// * This product includes software developed by Humberto Costa dos Santos Junior and its contributors.
// * 4. Neither the name of the Humberto Costa dos Santos Junior nor the names
// * of its contributors may be used to endorse or promote products derived
// * from this software without specific prior written permission.
// *
// * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
// * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
// * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// * SUCH DAMAGE.
// */
using System;
namespace HCIPC.Arvore
{
public class NoFaca : No
{
public NoFaca()
{
}

protected override void Executar(ref EstadoExecucao estado)
{

}
}
}
46 changes: 46 additions & 0 deletions HCIPC/HCIPC/Arvore/NoFalso.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// /*
// * Copyright (c) 2020
// * Humberto Costa dos Santos Junior. All rights reserved.
// *
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions
// * are met:
// * 1. Redistributions of source code must retain the above copyright
// * notice, this list of conditions and the following disclaimer.
// * 2. Redistributions in binary form must reproduce the above copyright
// * notice, this list of conditions and the following disclaimer in the
// * documentation and/or other materials provided with the distribution.
// * 3. All advertising materials mentioning features or use of this software
// * must display the following acknowledgement:
// * This product includes software developed by Humberto Costa dos Santos Junior and its contributors.
// * 4. Neither the name of the Humberto Costa dos Santos Junior nor the names
// * of its contributors may be used to endorse or promote products derived
// * from this software without specific prior written permission.
// *
// * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
// * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
// * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// * SUCH DAMAGE.
// */
using System;
namespace HCIPC.Arvore
{
public class NoFalso : No
{
public NoFalso()
{
}

protected override void Executar(ref EstadoExecucao estado)
{
estado.Valor = false;
}
}
}
45 changes: 45 additions & 0 deletions HCIPC/HCIPC/Arvore/NoFimSe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// /*
// * Copyright (c) 2020
// * Humberto Costa dos Santos Junior. All rights reserved.
// *
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions
// * are met:
// * 1. Redistributions of source code must retain the above copyright
// * notice, this list of conditions and the following disclaimer.
// * 2. Redistributions in binary form must reproduce the above copyright
// * notice, this list of conditions and the following disclaimer in the
// * documentation and/or other materials provided with the distribution.
// * 3. All advertising materials mentioning features or use of this software
// * must display the following acknowledgement:
// * This product includes software developed by Humberto Costa dos Santos Junior and its contributors.
// * 4. Neither the name of the Humberto Costa dos Santos Junior nor the names
// * of its contributors may be used to endorse or promote products derived
// * from this software without specific prior written permission.
// *
// * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
// * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
// * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// * SUCH DAMAGE.
// */
using System;
namespace HCIPC.Arvore
{
public class NoFimSe : No
{
public NoFimSe()
{
}

protected override void Executar(ref EstadoExecucao estado)
{
}
}
}
6 changes: 3 additions & 3 deletions HCIPC/HCIPC/Arvore/NoIgual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ protected override void Executar(ref EstadoExecucao estado)

if(SaoNumericos(valor1, valor2))
{
estado.Valor = (LerNumero(valor1) == LerNumero(valor2)) ? 1 : 0;
estado.Valor = (LerNumero(valor1) == LerNumero(valor2)) ;
}
else if (SaoTextos(valor1, valor2))
{
estado.Valor = (valor1.ToString() == valor2.ToString()) ? 1 : 0;
estado.Valor = (valor1.ToString() == valor2.ToString()) ;
}
else if (ContemTextos(valor1, valor2))
{
estado.Valor = (valor1.ToString() == valor2.ToString()) ? 1 : 0;
estado.Valor = (valor1.ToString() == valor2.ToString()) ;
}
else
{
Expand Down
14 changes: 13 additions & 1 deletion HCIPC/HCIPC/Arvore/NoLeia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void Executar(ref EstadoExecucao estado)
{
//Se for ponto flutuante (Real), converte e armazena
decimal valor = 0m;
if(decimal.TryParse(dados, out valor))
if (decimal.TryParse(dados, out valor))
{
estado.Valor = estado[Nome] = valor;
}
Expand All @@ -68,6 +68,18 @@ protected override void Executar(ref EstadoExecucao estado)
throw new Erro(this, "Esperada inserção de valor numérico real pelo usuário");
}
}
else if (estado[Nome] is bool)
{
//Se for logico
if (estado[Nome].ToString().ToLower() == "verdadeiro" || estado[Nome].ToString().ToLower() == "falso" || estado[Nome].ToString().ToLower() == "sim" || estado[Nome].ToString().ToLower() == "nao" || estado[Nome].ToString().ToLower() == "não")
{
estado.Valor = estado[Nome] = estado[Nome].ToString().ToLower() == "verdadeiro" | estado[Nome].ToString().ToLower() == "sim";
}
else
{
throw new Erro(this, "Esperada inserção de valor lógico pelo usuário");
}
}
else if (estado[Nome] is int)
{
//Se for inteiro, converte e armazena
Expand Down
2 changes: 1 addition & 1 deletion HCIPC/HCIPC/Arvore/NoMaiorIgualA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void Executar(ref EstadoExecucao estado)

if (SaoNumericos(valor1, valor2))
{
estado.Valor = (LerNumero(valor1) >= LerNumero(valor2)) ? 1 : 0;
estado.Valor = (LerNumero(valor1) >= LerNumero(valor2));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion HCIPC/HCIPC/Arvore/NoMaiorQue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void Executar(ref EstadoExecucao estado)

if (SaoNumericos(valor1, valor2))
{
estado.Valor = (LerNumero(valor1) > LerNumero(valor2)) ? 1 : 0;
estado.Valor = (LerNumero(valor1) > LerNumero(valor2));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion HCIPC/HCIPC/Arvore/NoMenorIgualA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void Executar(ref EstadoExecucao estado)

if (SaoNumericos(valor1, valor2))
{
estado.Valor = (LerNumero(valor1) <= LerNumero(valor2)) ? 1 : 0;
estado.Valor = (LerNumero(valor1) <= LerNumero(valor2));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion HCIPC/HCIPC/Arvore/NoMenorQue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void Executar(ref EstadoExecucao estado)

if (SaoNumericos(valor1, valor2))
{
estado.Valor = (LerNumero(valor1) < LerNumero(valor2)) ? 1 : 0;
estado.Valor = (LerNumero(valor1) < LerNumero(valor2)) ;
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions HCIPC/HCIPC/Arvore/NoModulo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ protected override void Executar(ref EstadoExecucao estado)
decimal valor = ProcessarNo(Item1, ref estado) % ProcessarNo(Item2, ref estado);
estado.Valor = valor;
}
catch (DivideByZeroException)
{
throw new Erro(this, "Divisão por zero");
}
catch (OverflowException)
{
throw new Erro(this, "Resultado do cálculo ultrapassa o limite de valor do destino");
Expand Down
8 changes: 7 additions & 1 deletion HCIPC/HCIPC/Arvore/NoSe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ public class NoSe : No

public NoSe()
{
SeSim = new List<No>();
SeNao = new List<No>();
}

protected override void Executar(ref EstadoExecucao estado)
{
Condicao.ExecutarNo(ref estado);
if((int)estado.Valor > 0)
if(!(estado.Valor is bool))
{
throw new Erro(this, "Não é possível converter um valor não lógico em lógico");
}
if((bool)estado.Valor)
{
foreach (var no in SeSim)
{
Expand Down
46 changes: 46 additions & 0 deletions HCIPC/HCIPC/Arvore/NoSeNao.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// /*
// * Copyright (c) 2020
// * Humberto Costa dos Santos Junior. All rights reserved.
// *
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions
// * are met:
// * 1. Redistributions of source code must retain the above copyright
// * notice, this list of conditions and the following disclaimer.
// * 2. Redistributions in binary form must reproduce the above copyright
// * notice, this list of conditions and the following disclaimer in the
// * documentation and/or other materials provided with the distribution.
// * 3. All advertising materials mentioning features or use of this software
// * must display the following acknowledgement:
// * This product includes software developed by Humberto Costa dos Santos Junior and its contributors.
// * 4. Neither the name of the Humberto Costa dos Santos Junior nor the names
// * of its contributors may be used to endorse or promote products derived
// * from this software without specific prior written permission.
// *
// * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
// * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
// * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// * SUCH DAMAGE.
// */
using System;
namespace HCIPC.Arvore
{
public class NoSeNao : No
{
public NoSeNao()
{
}

protected override void Executar(ref EstadoExecucao estado)
{

}
}
}
Loading

0 comments on commit 8711f21

Please sign in to comment.