コード例 #1
0
  public void handleStatement(ASTStatement node) {

    // System.out.println(node.getCode());

    // Drawing
    connector.startSnap(node.getLineNumber());

    // FIXME we'll see how this works

    // Nested scope for by macro
    SimpleNode s = (SimpleNode) node.jjtGetChild(0);

    if (s instanceof ASTStatementList) {
      System.out.println("This'll never happen");
      SymbolTable st = new SymbolTable(Global.getCurrentSymbolTable());
      st.setName("nested");
      Global.setCurrentSymbolTable(st);
      s.jjtAccept(this, null);
      Global.setCurrentSymbolTable(st.getPrevious());
    } else {

      node.jjtGetChild(0).jjtAccept(this, null);
      if (((SimpleNode) node.jjtGetChild(0)).getId() == JJTCALL) {
        ((ASTCall) (node.jjtGetChild(0))).setLineNumber(node.getLineNumber());
      }

      update(node.getLineNumber(), UPDATE_REASON_STATEMENT);
    }
    // System.out.println("endStatement");
    connector.endSnap();
  }
コード例 #2
0
  public void handleFunction(ASTFunction node) {
    // Get the function's symbol table, set it's previous to the
    // calling function's, and then set it to current.
    connector.startSnap(node.getLineNumber());
    if (node.getName().equals("main")) {
      connector.addQuestion(startQuestion);
      connector.showScope("main");

    } else {
    }
    connector.endSnap();
    if (!node.getUsed()) {
      return;
    }
    SymbolTable currentSymbolTable = node.getSymbolTable();
    for (String p : node.getParameters()) {
      ByNameVariable v = new ByNameVariable();
      v.setParam();
      currentSymbolTable.put(p, v);
    }
    Global.setCurrentSymbolTable(currentSymbolTable);

    node.jjtGetChild(0).jjtAccept(this, null);
    leaveScope();
  }
コード例 #3
0
  public void handleStatementList(ASTStatementList node) {
    // connector.endPar();						//ENDPAR

    int numStatements = node.jjtGetNumChildren();
    for (int i = 0; i < numStatements; i++) {
      node.jjtGetChild(i).jjtAccept(this, null);
    }
    if (!node.getIsFunction()) {
      Global.setCurrentSymbolTable(Global.getCurrentSymbolTable().getPrevious());
    }
  }
コード例 #4
0
  public void handleProgram(ASTProgram node) {
    program = node;
    // System.out.println("visiting program");
    Global.setCurrentSymbolTable(Global.getSymbolTable());
    update(1, UPDATE_REASON_BEGIN);
    startQuestion = questionFactory.getStartQuestion();
    // Drawing Stuff
    connector.addScope(Global.getSymbolTable(), "Global", null);
    connector.startPar(); // STARTPAR
    connector.showScope("Global");
    connector.endPar(); // ENDPAR
    // connector.endSnap();

    node.jjtGetChild(0).jjtAccept(this, null);
    update(LINE_NUMBER_END, UPDATE_REASON_END);

    int value = 0;

    try {
      value = Global.getSymbolTable().get(startQuestion.getVariable());
      System.out.println(startQuestion.getVariable() + " is " + value);
    } catch (Exception e) {
      System.out.println(e);
    }
    if (startQuestion instanceof FIBQuestion) {

      ((FIBQuestion) startQuestion).addAnswer(value + "");
    } else if (startQuestion instanceof TFQuestion) {
      Random r = new Random();
      int prob = r.nextInt(10);
      int qa = value;
      if (prob >= 3 && value != startQuestion.getValue()) {
        qa = startQuestion.getValue();
        ((TFQuestion) startQuestion).setAnswer(false);
      } else {
        ((TFQuestion) startQuestion).setAnswer(true);
      }
      startQuestion.setText(startQuestion.getText() + qa + ".");
    }

    // TODO Write the last snap nicely

    connector.startSnap(node.getPseudocode().length);
    connector.startPar(); // STARTPAR
    // we can't hide foo in by macro cuz it doesn't exist
    if (!byMacroFlag) connector.hideScope("foo");
    connector.endPar(); // ENDPAR
    connector.endSnap();
  }