00001 package plp.orientadaObjetos1.testes;
00002
00003 import plp.expressions2.memory.VariavelJaDeclaradaException;
00004 import plp.expressions2.memory.VariavelNaoDeclaradaException;
00005 import plp.orientadaObjetos1.Programa;
00006 import plp.orientadaObjetos1.comando.Atribuicao;
00007 import plp.orientadaObjetos1.comando.ChamadaMetodo;
00008 import plp.orientadaObjetos1.comando.ComDeclaracao;
00009 import plp.orientadaObjetos1.comando.IfThenElse;
00010 import plp.orientadaObjetos1.comando.New;
00011 import plp.orientadaObjetos1.comando.Sequencial;
00012 import plp.orientadaObjetos1.comando.Skip;
00013 import plp.orientadaObjetos1.comando.While;
00014 import plp.orientadaObjetos1.comando.Write;
00015 import plp.orientadaObjetos1.declaracao.classe.DecClasseSimples;
00016 import plp.orientadaObjetos1.declaracao.procedimento.DecParametro;
00017 import plp.orientadaObjetos1.declaracao.procedimento.DecProcedimentoComposta;
00018 import plp.orientadaObjetos1.declaracao.procedimento.DecProcedimentoSimples;
00019 import plp.orientadaObjetos1.declaracao.procedimento.ListaDeclaracaoParametro;
00020 import plp.orientadaObjetos1.declaracao.variavel.CompostaDecVariavel;
00021 import plp.orientadaObjetos1.declaracao.variavel.DecVariavelObjeto;
00022 import plp.orientadaObjetos1.declaracao.variavel.SimplesDecVariavel;
00023 import plp.orientadaObjetos1.excecao.declaracao.ClasseJaDeclaradaException;
00024 import plp.orientadaObjetos1.excecao.declaracao.ClasseNaoDeclaradaException;
00025 import plp.orientadaObjetos1.excecao.declaracao.ObjetoJaDeclaradoException;
00026 import plp.orientadaObjetos1.excecao.declaracao.ObjetoNaoDeclaradoException;
00027 import plp.orientadaObjetos1.excecao.declaracao.ProcedimentoJaDeclaradoException;
00028 import plp.orientadaObjetos1.excecao.declaracao.ProcedimentoNaoDeclaradoException;
00029 import plp.orientadaObjetos1.excecao.execucao.EntradaInvalidaException;
00030 import plp.orientadaObjetos1.excecao.execucao.EntradaNaoFornecidaException;
00031 import plp.orientadaObjetos1.expressao.ListaExpressao;
00032 import plp.orientadaObjetos1.expressao.This;
00033 import plp.orientadaObjetos1.expressao.binaria.ExpAnd;
00034 import plp.orientadaObjetos1.expressao.binaria.ExpEquals;
00035 import plp.orientadaObjetos1.expressao.leftExpression.AcessoAtributoId;
00036 import plp.orientadaObjetos1.expressao.leftExpression.AcessoAtributoThis;
00037 import plp.orientadaObjetos1.expressao.leftExpression.Id;
00038 import plp.orientadaObjetos1.expressao.unaria.ExpNot;
00039 import plp.orientadaObjetos1.expressao.valor.ValorInteiro;
00040 import plp.orientadaObjetos1.expressao.valor.ValorNull;
00041 import plp.orientadaObjetos1.memoria.ContextoCompilacaoOO1;
00042 import plp.orientadaObjetos1.memoria.ContextoExecucaoOO1;
00043 import plp.orientadaObjetos1.memoria.colecao.ListaValor;
00044 import plp.orientadaObjetos1.util.TipoClasse;
00045 import plp.orientadaObjetos1.util.TipoPrimitivo;
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 public class TLOO1{
00108
00109 public static void main(String [] args){
00110
00111 Programa prg = new Programa
00112
00113 (
00114
00115 new DecClasseSimples
00116 (
00117 new Id("LValor")
00118 ,
00119 new CompostaDecVariavel
00120 (
00121 new SimplesDecVariavel(new TipoPrimitivo(1), new Id("valor"), new ValorInteiro(1))
00122 ,
00123 new SimplesDecVariavel(new TipoClasse(new Id("LValor")),new Id("prox"), new ValorNull())
00124 )
00125 ,
00126 new DecProcedimentoComposta
00127 (
00128 new DecProcedimentoSimples
00129 (
00130 new Id("insere"),
00131 new ListaDeclaracaoParametro(new DecParametro(new Id("v"), new TipoPrimitivo(1))),
00132 new ComDeclaracao
00133 (
00134 new SimplesDecVariavel( new TipoClasse(new Id("LValor")),new Id("aux") , new This()),
00135 new Sequencial
00136 (
00137 new Sequencial
00138 (
00139 new While
00140 (
00141 new ExpNot(new ExpEquals(new AcessoAtributoId(new Id("aux"), new Id("prox")) ,new ValorNull()))
00142 ,
00143 new Atribuicao( new Id("aux") , new AcessoAtributoId(new Id("aux"), new Id("prox")) )
00144 )
00145 ,
00146 new New ( new AcessoAtributoId(new Id("aux"), new Id("prox")) , new Id("LValor"))
00147 )
00148 ,
00149 new Atribuicao
00150 (
00151 new AcessoAtributoId(new AcessoAtributoId(new Id("aux"), new Id("prox")), new Id("valor")),
00152 new Id("v")
00153 )
00154 )
00155 )
00156 )
00157 ,
00158 new DecProcedimentoComposta
00159 (
00160 new DecProcedimentoSimples
00161 (
00162 new Id("print"),
00163 new ListaDeclaracaoParametro(),
00164 new Sequencial
00165 (
00166 new Write(new AcessoAtributoThis(new This(), new Id("valor")))
00167 ,
00168 new IfThenElse
00169 (
00170 new ExpNot(new ExpEquals(new AcessoAtributoThis(new This(), new Id("prox")) ,new ValorNull()))
00171 ,
00172 new ChamadaMetodo( new AcessoAtributoThis(new This(), new Id("prox")) , new Id("print"), new ListaExpressao())
00173 ,
00174 new Skip()
00175 )
00176 )
00177 )
00178 ,
00179 new DecProcedimentoSimples
00180 (
00181 new Id("remove")
00182 ,
00183 new ListaDeclaracaoParametro(new DecParametro( new Id("v"), new TipoPrimitivo(1)))
00184 ,
00185 new ComDeclaracao
00186 (
00187 new SimplesDecVariavel(new TipoClasse(new Id("LValor")), new Id("aux") , new This() )
00188 ,
00189 new Sequencial
00190 (
00191 new While
00192 (
00193 new ExpAnd
00194 (
00195 new ExpNot(new ExpEquals(new AcessoAtributoId(new Id("aux"), new Id("prox")) ,new ValorNull()))
00196 ,
00197 new ExpNot(new ExpEquals
00198 (
00199 new AcessoAtributoId(new AcessoAtributoId(new Id("aux"), new Id("prox")), new Id("valor"))
00200 ,
00201 new Id("v")
00202 )
00203 )
00204 )
00205 ,
00206 new Atribuicao( new Id("aux") , new AcessoAtributoId(new Id("aux"), new Id("prox")) )
00207 )
00208 ,
00209 new IfThenElse
00210 (
00211 new ExpNot(new ExpEquals(new AcessoAtributoId(new Id("aux"), new Id("prox")) , new ValorNull()))
00212 ,
00213 new Atribuicao
00214 (
00215 new AcessoAtributoId(new Id("aux"), new Id("prox"))
00216 ,
00217 new AcessoAtributoId(new AcessoAtributoId(new Id("aux"), new Id("prox")), new Id("prox"))
00218 )
00219 ,
00220 new Skip()
00221 )
00222
00223 )
00224 )
00225 )
00226 )
00227 )
00228 )
00229
00230 ,
00231
00232 new ComDeclaracao
00233 (
00234 new DecVariavelObjeto( new TipoClasse(new Id ("LValor")), new Id("lv"), new Id("LValor"))
00235 ,
00236 new Sequencial
00237 (
00238 new ChamadaMetodo( new Id("lv") , new Id("insere"), new ListaExpressao(new ValorInteiro(2)))
00239 ,
00240 new Sequencial
00241 (
00242 new Sequencial
00243 (
00244 new ChamadaMetodo( new Id("lv") , new Id("insere"), new ListaExpressao(new ValorInteiro(3)))
00245 ,
00246 new Sequencial
00247 (
00248 new ChamadaMetodo( new Id("lv") , new Id("insere"), new ListaExpressao(new ValorInteiro(4)))
00249 ,
00250 new ChamadaMetodo( new Id("lv") , new Id("print"), new ListaExpressao())
00251 )
00252 )
00253 ,
00254 new Sequencial
00255 (
00256 new ChamadaMetodo( new Id("lv") , new Id("remove"), new ListaExpressao(new ValorInteiro(3)))
00257 ,
00258 new ChamadaMetodo( new Id("lv") , new Id("print"), new ListaExpressao())
00259 )
00260 )
00261 )
00262
00263
00264 )
00265 );
00266
00267 try{
00268 if(prg.checaTipo(new ContextoCompilacaoOO1(new ListaValor()))) {
00269 System.out.println(prg.executar(new ContextoExecucaoOO1(new ListaValor())));
00270 }
00271 else {
00272 System.out.println("Erro de tipo!");
00273 }
00274 }
00275 catch (VariavelNaoDeclaradaException e){
00276 System.out.println("Alguma variavel nao declarada foi referenciada!"+e.toString());
00277 }
00278 catch (EntradaNaoFornecidaException e){
00279 System.out.println("Entrada nao fornecida"+e.toString());
00280 }
00281 catch (VariavelJaDeclaradaException e){
00282 System.out.println("Valores de Entrada ja Declarados"+e.toString());
00283 }
00284 catch (ClasseNaoDeclaradaException e){
00285 System.out.println("Falta declarar a classe!"+e.toString());
00286 }
00287 catch (ClasseJaDeclaradaException e){
00288 System.out.println("Classe ja Declarada"+e.toString());
00289 }
00290 catch (ObjetoJaDeclaradoException e){
00291 System.out.println("Objeto de Entrada já Declarados!"+e.toString());
00292 }
00293 catch (ObjetoNaoDeclaradoException e){
00294 System.out.println("Falta fornecer o Objeto de Entrada!"+e.toString());
00295 e.printStackTrace();
00296 }
00297 catch (ProcedimentoJaDeclaradoException e){
00298 System.out.println("Metodos já Declarados!"+e.toString());
00299 }
00300 catch (ProcedimentoNaoDeclaradoException e){
00301 System.out.println("Falta fornecer algum Metodo!"+e.toString());
00302 }
00303 catch (EntradaInvalidaException e){
00304 System.out.println(e.toString());
00305 }
00306 }
00307
00308
00309 }