Exemple #1
0
 /**
  * Comipla uma expressão textual para uma instância de <code>Expression</code>.
  *
  * @param source O código fonte da expressão a ser compilada.
  * @return A instância de expressão compilada.
  */
 public Expression compile(String source) {
   // Passo 1 (Parsing) Transforma texto em objetos do tipo Statement
   try {
     statementList = parser.parse(source);
   } catch (ParseException e) {
     System.err.println(PARSING + source);
     throw new LangException(E10, e);
   } catch (CTDException ctde) {
     System.err.println(PARSING + source);
     throw new LangException(E10, ctde);
   }
   // Passo 2 (Checking) Valida gramática e semântica
   try {
     checker.check(statementList);
   } catch (CTDException ctde) {
     System.err.println(CHECKING + statementList + debugList());
     throw ctde;
   }
   // Passo 3 (Linking) Liga os elementos em uma árvore binária
   try {
     Statement root = linker.link(statementList);
     if (root.isLiteral()) {
       root.result(null); // não precisa de DataContainer
     }
     if (root.resultType().equals(BOOLEAN)) {
       return new BooleanExpression(source, root);
     } else {
       return new Expression(source, root);
     }
   } catch (CTDException ctde) {
     System.err.println(LINKING + statementList + debugList());
     throw ctde;
   }
 }
Exemple #2
0
 protected String debugList() {
   StringBuilder sb = new StringBuilder();
   for (Statement statement : statementList) {
     sb.append("\n");
     sb.append(statement.asToken());
     sb.append(" (");
     sb.append(statement.getClass().getSimpleName());
     sb.append(":");
     if (statement instanceof ParenthesisOperator) {
       sb.append("Parenthesis");
     } else {
       try {
         sb.append(statement.resultType());
       } catch (Exception e) {
         sb.append("<EMPTY>");
       }
     }
     sb.append(")");
   }
   return sb.toString();
 }
Exemple #3
0
 public void execute(DataContainer container, String targetToken, Statement parameter) {
   out.println(parameter.result(container));
 }