diff --git a/HCIPC/HCIPC/Arvore/NoDiferente.cs b/HCIPC/HCIPC/Arvore/NoDiferente.cs index 627b4fc..325960b 100644 --- a/HCIPC/HCIPC/Arvore/NoDiferente.cs +++ b/HCIPC/HCIPC/Arvore/NoDiferente.cs @@ -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"); + } + } } } diff --git a/HCIPC/HCIPC/Arvore/NoEntao.cs b/HCIPC/HCIPC/Arvore/NoEntao.cs new file mode 100644 index 0000000..a1b0f50 --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoEntao.cs @@ -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) + { + } + } +} diff --git a/HCIPC/HCIPC/Arvore/NoEscreva.cs b/HCIPC/HCIPC/Arvore/NoEscreva.cs index 72c96fa..190ff14 100644 --- a/HCIPC/HCIPC/Arvore/NoEscreva.cs +++ b/HCIPC/HCIPC/Arvore/NoEscreva.cs @@ -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(); diff --git a/HCIPC/HCIPC/Arvore/NoFaca.cs b/HCIPC/HCIPC/Arvore/NoFaca.cs new file mode 100644 index 0000000..dfb8277 --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoFaca.cs @@ -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) + { + + } + } +} diff --git a/HCIPC/HCIPC/Arvore/NoFalso.cs b/HCIPC/HCIPC/Arvore/NoFalso.cs new file mode 100644 index 0000000..d5be7aa --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoFalso.cs @@ -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; + } + } +} diff --git a/HCIPC/HCIPC/Arvore/NoFimSe.cs b/HCIPC/HCIPC/Arvore/NoFimSe.cs new file mode 100644 index 0000000..61ae8ab --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoFimSe.cs @@ -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) + { + } + } +} diff --git a/HCIPC/HCIPC/Arvore/NoIgual.cs b/HCIPC/HCIPC/Arvore/NoIgual.cs index 6aedc61..f83eb70 100644 --- a/HCIPC/HCIPC/Arvore/NoIgual.cs +++ b/HCIPC/HCIPC/Arvore/NoIgual.cs @@ -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 { diff --git a/HCIPC/HCIPC/Arvore/NoLeia.cs b/HCIPC/HCIPC/Arvore/NoLeia.cs index aa71778..d90539b 100644 --- a/HCIPC/HCIPC/Arvore/NoLeia.cs +++ b/HCIPC/HCIPC/Arvore/NoLeia.cs @@ -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; } @@ -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 diff --git a/HCIPC/HCIPC/Arvore/NoMaiorIgualA.cs b/HCIPC/HCIPC/Arvore/NoMaiorIgualA.cs index 2723c08..a68eb97 100644 --- a/HCIPC/HCIPC/Arvore/NoMaiorIgualA.cs +++ b/HCIPC/HCIPC/Arvore/NoMaiorIgualA.cs @@ -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 { diff --git a/HCIPC/HCIPC/Arvore/NoMaiorQue.cs b/HCIPC/HCIPC/Arvore/NoMaiorQue.cs index 24e31de..2e337d4 100644 --- a/HCIPC/HCIPC/Arvore/NoMaiorQue.cs +++ b/HCIPC/HCIPC/Arvore/NoMaiorQue.cs @@ -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 { diff --git a/HCIPC/HCIPC/Arvore/NoMenorIgualA.cs b/HCIPC/HCIPC/Arvore/NoMenorIgualA.cs index 4a5ff23..2bf36e8 100644 --- a/HCIPC/HCIPC/Arvore/NoMenorIgualA.cs +++ b/HCIPC/HCIPC/Arvore/NoMenorIgualA.cs @@ -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 { diff --git a/HCIPC/HCIPC/Arvore/NoMenorQue.cs b/HCIPC/HCIPC/Arvore/NoMenorQue.cs index 4cd145c..ca5225f 100644 --- a/HCIPC/HCIPC/Arvore/NoMenorQue.cs +++ b/HCIPC/HCIPC/Arvore/NoMenorQue.cs @@ -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 { diff --git a/HCIPC/HCIPC/Arvore/NoModulo.cs b/HCIPC/HCIPC/Arvore/NoModulo.cs index 23a9094..df98498 100644 --- a/HCIPC/HCIPC/Arvore/NoModulo.cs +++ b/HCIPC/HCIPC/Arvore/NoModulo.cs @@ -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"); diff --git a/HCIPC/HCIPC/Arvore/NoSe.cs b/HCIPC/HCIPC/Arvore/NoSe.cs index 1619486..cf010e8 100644 --- a/HCIPC/HCIPC/Arvore/NoSe.cs +++ b/HCIPC/HCIPC/Arvore/NoSe.cs @@ -42,12 +42,18 @@ public class NoSe : No public NoSe() { + SeSim = new List(); + SeNao = new List(); } 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) { diff --git a/HCIPC/HCIPC/Arvore/NoSeNao.cs b/HCIPC/HCIPC/Arvore/NoSeNao.cs new file mode 100644 index 0000000..0295d05 --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoSeNao.cs @@ -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) + { + + } + } +} diff --git a/HCIPC/HCIPC/Arvore/NoTipoLogico.cs b/HCIPC/HCIPC/Arvore/NoTipoLogico.cs new file mode 100644 index 0000000..59e1d89 --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoTipoLogico.cs @@ -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 NoTipoLogico : No + { + public NoTipoLogico() + { + } + + protected override void Executar(ref EstadoExecucao estado) + { + throw new NotImplementedException(); + } + } +} diff --git a/HCIPC/HCIPC/Arvore/NoVerdadeiro.cs b/HCIPC/HCIPC/Arvore/NoVerdadeiro.cs new file mode 100644 index 0000000..8fade92 --- /dev/null +++ b/HCIPC/HCIPC/Arvore/NoVerdadeiro.cs @@ -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 NoVerdadeiro : No + { + public NoVerdadeiro() + { + } + + protected override void Executar(ref EstadoExecucao estado) + { + estado.Valor = true; + } + } +} diff --git a/HCIPC/HCIPC/Fonte.cs b/HCIPC/HCIPC/Fonte.cs index a0fe036..f3522f3 100644 --- a/HCIPC/HCIPC/Fonte.cs +++ b/HCIPC/HCIPC/Fonte.cs @@ -426,6 +426,7 @@ public No ProcessarNo() no = new NoTipoCaracter(); break; case "inicio": + case "início": no = new NoInicio(); break; case "var": @@ -452,6 +453,30 @@ public No ProcessarNo() case "*": no = new NoMultiplicacao(); break; + case "verdadeiro": + case "sim": + no = new NoVerdadeiro(); + break; + case "falso": + case "nao": + case "não": + no = new NoFalso(); + break; + case "entao": + case "então": + no = new NoEntao(); + break; + case "senao": + case "senão": + no = new NoSeNao(); + break; + case "faca": + case "faça": + no = new NoFaca(); + break; + case "fimse": + no = new NoFimSe(); + break; case "mod": case "%": no = new NoModulo(); @@ -577,6 +602,10 @@ public No ProcessarNo() { noTemp.ValorInicial = ""; } + else if (proximo is NoTipoLogico) + { + noTemp.ValorInicial = false; + } } //Agrupa todas as declarações em um unico bloco no = new NoBloco() @@ -649,6 +678,20 @@ public No ProcessarNo() { Condicao = nosFinal.First() }; + proximo = LerNoTipo(typeof(NoEntao)); + No sub; + //Processa e armazena os nós dentro do algoritmo ate chegar no 'fimalgoritmo' + while (!((sub = ProcessarNo()) is NoFimSe) && !(sub is NoSeNao)) + { + ((NoSe)no).SeSim.Add(sub); + } + if(sub is NoSeNao) + { + while (!((sub = ProcessarNo()) is NoFimSe)) + { + ((NoSe)no).SeNao.Add(sub); + } + } break; default: //TODO: Fazer chamar procedimento diff --git a/HCIPC/HCIPC/HCIPC.csproj b/HCIPC/HCIPC/HCIPC.csproj index 961465b..d012688 100644 --- a/HCIPC/HCIPC/HCIPC.csproj +++ b/HCIPC/HCIPC/HCIPC.csproj @@ -78,6 +78,13 @@ + + + + + + + diff --git a/HCIPC/HCIPC/bin/Debug/HCIPC.exe b/HCIPC/HCIPC/bin/Debug/HCIPC.exe index 5d36a65..3a6952f 100644 Binary files a/HCIPC/HCIPC/bin/Debug/HCIPC.exe and b/HCIPC/HCIPC/bin/Debug/HCIPC.exe differ diff --git a/HCIPC/HCIPC/bin/Debug/HCIPC.pdb b/HCIPC/HCIPC/bin/Debug/HCIPC.pdb index f9daecc..a512932 100644 Binary files a/HCIPC/HCIPC/bin/Debug/HCIPC.pdb and b/HCIPC/HCIPC/bin/Debug/HCIPC.pdb differ diff --git a/HCIPC/HCIPC/bin/Debug/teste.hcp b/HCIPC/HCIPC/bin/Debug/teste.hcp index 4298d3d..b8ff5e3 100644 --- a/HCIPC/HCIPC/bin/Debug/teste.hcp +++ b/HCIPC/HCIPC/bin/Debug/teste.hcp @@ -18,7 +18,15 @@ inicio escreval("Soma......................: ", soma) escreval("Subtração.................: ", n1-n2) escreval("Multiplicação.............: ", n1*n2) - escreval("Divisão...................: ", n1/n2) - escreval("Módulo....................: ", n1 mod n2) + se (n2 > 0) entao + escreval("Divisão...................: ", n1/n2) + escreval("Módulo....................: ", n1 mod n2) + senao + escreval("Divisão...................: FALHA") + escreval("Módulo....................: FALHA") + fimse + escreval("Igual.....................: ", n1=n2) + escreval("Maior que.................: ", n1>n2) + escreval("Menor que.................: ", n1 0) entao + escreval("Divisão...................: ", n1/n2) + escreval("Módulo....................: ", n1 mod n2) + senao + escreval("Divisão...................: FALHA") + escreval("Módulo....................: FALHA") + fimse escreval("Igual.....................: ", n1=n2) + escreval("Maior que.................: ", n1>n2) + escreval("Menor que.................: ", n1