Пример #1
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();
  }
Пример #2
0
  // returning false means we're done executing now.
  public Boolean handleDeclaration(ASTDeclaration node) {

    // System.out.println("Visiting decl");
    SimpleNode child = (SimpleNode) node.jjtGetChild(0);
    if (child.getId() == JJTFUNCTION) {
      System.out.println("Found a function");

      startQuestion = questionFactory.getStartQuestion();
      connector.endPar(); // ENDPAR
      connector.endSnap();
      ASTFunction main = Global.getFunction("main");
      connector.addScope(main.getSymbolTable(), "main", "Global");

      main.jjtAccept(this, null);

      return false;
    } else {
      node.jjtGetChild(0).jjtAccept(this, null);
      // update();
      return true;
    }
  }