예제 #1
0
  @Override
  public Object visit(MethodDcl node) {
    String id = node.id;
    StringBuilder sb = new StringBuilder();

    sb.append(node.getT());
    sb.append(' ');
    sb.append(node.id);
    sb.append('(');

    ArrayList<Node> params = node.parameters;

    for (int i = 0; i < params.size(); i++) {
      if (i > 0) sb.append(", ");
      sb.append(visit(params.get(i)));
    }

    sb.append(")\n");
    sb.append(visit(node.GetLeftChild()));
    sb.append("END ");
    sb.append(node.id);
    sb.append('\n');

    return sb.toString();
  }
예제 #2
0
  @Override
  public Object visit(XorNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append(" XOR ");
    sb.append(visit(node.GetLeftChild()));

    return sb.toString();
  }
예제 #3
0
  @Override
  public Object visit(ElseNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append("ELSE\n");
    sb.append(visit(node.GetLeftChild()));
    sb.append("END ELSE\n");

    return sb.toString();
  }
예제 #4
0
  @Override
  public Object visit(LessNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append(visit(node.GetLeftChild()));
    sb.append(" LESS_THAN ");
    sb.append(visit(node.GetRightChild()));

    return sb.toString();
  }
예제 #5
0
  @Override
  public Object visit(GreaterNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append(visit(node.GetLeftChild()));
    sb.append(" GREATER_THAN ");
    sb.append(visit(node.GetRightChild()));

    return sb.toString();
  }
예제 #6
0
  @Override
  public Object visit(AssignNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append(visit(node.GetLeftChild()));
    sb.append(" = ");
    sb.append(visit(node.GetRightChild()));

    return sb.toString();
  }
예제 #7
0
  @Override
  public Object visit(SignalNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append("SIGNAL ");
    sb.append(visit(node.GetLeftChild()));
    sb.append(visit(node.GetRightChild()));
    sb.append(")\n");

    return sb.toString();
  }
예제 #8
0
  @Override
  public Object visit(BlockNode node) {
    StringBuilder sb = new StringBuilder();

    for (Node n : node.GetChildren()) {
      sb.append(visit(n));
      sb.append('\n');
    }

    return sb.toString();
  }
예제 #9
0
  @Override
  public Object visit(LoopNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append("REPEAT UNTIL(");
    sb.append(visit(node.GetLeftChild()));
    sb.append(")\n");
    sb.append(visit(node.GetRightChild()));
    sb.append("END REPEAT\n");

    return sb.toString();
  }
예제 #10
0
  @Override
  public Object visit(LoadNode node) {
    StringBuilder sb = new StringBuilder();

    for (Node n : node.GetChildren()) {
      sb.append("LOAD(");
      sb.append(((ProgNode) n)._id);
      sb.append(")\n");
    }

    return sb.toString();
  }
예제 #11
0
  @Override
  public Object visit(StringDcl node) {
    StringBuilder sb = new StringBuilder();
    sb.append("STRING ");
    sb.append(visit(node.GetLeftChild()));

    if (node.GetRightChild() != null) {
      sb.append(" = ");
      sb.append(visit(node.GetRightChild()));
    }

    return sb.toString();
  }
예제 #12
0
  @Override
  public Object visit(CollectionNode node) {
    StringBuilder sb = new StringBuilder();

    ArrayList<Node> children = node.GetChildren();

    for (int i = 0; i < children.size(); i++) {
      /*if(i > 0)
      sb.append(", ");*/
      sb.append(visit(children.get(i)));
    }

    return sb.toString();
  }
예제 #13
0
  @Override
  public Object visit(MethodInvocationNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append(visit(node.GetLeftChild()));
    sb.append('(');

    ArrayList<Node> children = node.GetChildren();

    for (int i = 0; i < children.size(); i++) {
      if (i > 0) sb.append(',');
      sb.append(visit(children.get(i)));
    }
    sb.append(")\n");

    return sb.toString();
  }
예제 #14
0
  @Override
  public Object visit(IfNode node) {
    StringBuilder sb = new StringBuilder();

    sb.append("IF (");
    sb.append(visit(node.GetCondition()));
    sb.append(")\n");
    sb.append(visit(node.GetBody()));
    sb.append("END IF\n");

    if (node.GetElseIf() != null) {
      sb.append(visit(node.GetElseIf()));
      sb.append('\n');
    }

    if (node.GetElse() != null) {
      sb.append(visit(node.GetElse()));
      sb.append('\n');
    }

    return sb.toString();
  }