Exemplos.java

Go to the documentation of this file.
00001 package plp.expressions2;
00002 
00003 import java.util.LinkedList;
00004 import java.util.List;
00005 
00006 import plp.expressions2.declaration.DecVariavel;
00007 import plp.expressions2.expression.ExpDeclaracao;
00008 import plp.expressions2.expression.ExpSoma;
00009 import plp.expressions2.expression.Id;
00010 import plp.expressions2.expression.ValorInteiro;
00011 
00012 public class Exemplos {
00013 
00014         public static void main(String [] args){
00015         
00016         /*
00017         // let var x = 3 in
00018         //     let var x = x + 1, var y = x in
00019         //           x + y
00020         //           
00021         
00022         
00023             Id idX = new Id("x");
00024             Id idY = new Id("y");
00025         
00026         
00027             DecVariavel decVar1 = new DecVariavel( idX ,  new ValorInteiro(3) );
00028         
00029         
00030             DecVariavel decVar2 = new DecVariavel( idX , new ExpSoma( idX, new ValorInteiro(1) ) );
00031         
00032         
00033             DecVariavel decVar3 = new DecVariavel( idY ,  idX );
00034         
00035         
00036             ExpDeclaracao expDeclara2 = new ExpDeclaracao(new SeqDec(decVar2,
00037                                                                                                                                  new SeqDec(decVar3)),
00038                                                                                                           new ExpSoma(idX,idY));
00039         
00040         
00041             ExpDeclaracao expDeclara = new ExpDeclaracao(new SeqDec(decVar1),expDeclara2);
00042         
00043         
00044             Programa prg = new Programa( expDeclara );
00045         
00046         
00047                 try {
00048                         if (!prg.checaTipo()) {
00049                                 System.out.println("Erro de tipo");
00050                         } else {
00051                                 System.out.println(prg.executar());
00052                         }
00053                 } catch (Exception e) {
00054                         System.out.println("Erro: " + e);
00055                         e.printStackTrace();
00056                 }
00057         
00058         */
00059         // let var x = 3 in
00060         //     let var y = x + 1 in
00061         //         let var x = 5 in
00062         //             y
00063                 Id idX = new Id("x");
00064                 Id idY = new Id("y");
00065         
00066                 DecVariavel decX2 = new DecVariavel(idX, new ValorInteiro(5));
00067                 List<DecVariavel> list3 = new LinkedList<DecVariavel>();
00068                 list3.add(decX2);
00069                 ExpDeclaracao exp3 = new ExpDeclaracao(list3, idY);
00070                 
00071                 DecVariavel decY = new DecVariavel(idY, new ExpSoma(idX, new ValorInteiro(1)));
00072                 List<DecVariavel> list2 = new LinkedList<DecVariavel>();
00073                 list2.add(decY);
00074                 ExpDeclaracao exp2 = new ExpDeclaracao(list2, exp3);
00075                 
00076                 DecVariavel decX1 = new DecVariavel(idX, new ValorInteiro(3));
00077                 List<DecVariavel> list1 = new LinkedList<DecVariavel>();
00078                 list1.add(decX1);
00079                 ExpDeclaracao exp1 = new ExpDeclaracao(list1, exp2);
00080                 
00081                 Programa prg = new Programa(exp1);
00082 
00083                 try {
00084                         if (!prg.checaTipo()) {
00085                                 System.out.println("Erro de tipo");
00086                         } else {
00087                                 System.out.println(prg.executar());
00088                         }
00089                 } catch (Exception e) {
00090                         System.out.println("Erro: " + e);
00091                         e.printStackTrace();
00092                 }
00093 
00094         }
00095 
00096 }

Generated on Tue Sep 12 21:36:02 2006 for PLP by  doxygen 1.4.7