コード例 #1
0
  // $ANTLR start "attrib"
  // /Users/Pedro/Dropbox/MEI/EL/PI/Static-Code-Analyzer/AulasEG/calculadora/calc.g:64:1:
  // attrib[HashMap<String,Par> declarations_in] : ID '=' expression[declarations_in] ;
  public final void attrib(HashMap<String, Par> declarations_in) throws RecognitionException {
    Token ID3 = null;
    calcParser.expression_return expression4 = null;

    try {
      dbg.enterRule(getGrammarFileName(), "attrib");
      if (getRuleLevel() == 0) {
        dbg.commence();
      }
      incRuleLevel();
      dbg.location(64, 1);

      try {
        // /Users/Pedro/Dropbox/MEI/EL/PI/Static-Code-Analyzer/AulasEG/calculadora/calc.g:65:2: ( ID
        // '=' expression[declarations_in] )
        dbg.enterAlt(1);

        // /Users/Pedro/Dropbox/MEI/EL/PI/Static-Code-Analyzer/AulasEG/calculadora/calc.g:65:4: ID
        // '=' expression[declarations_in]
        {
          dbg.location(65, 4);
          ID3 = (Token) match(input, ID, FOLLOW_ID_in_attrib120);
          dbg.location(65, 7);
          match(input, 13, FOLLOW_13_in_attrib122);
          dbg.location(65, 11);
          pushFollow(FOLLOW_expression_in_attrib124);
          expression4 = expression(declarations_in);

          state._fsp--;

          dbg.location(66, 4);

          if (!declarations_in.containsKey((ID3 != null ? ID3.getText() : null))) {
            System.out.println(
                "A variavel "
                    + (ID3 != null ? ID3.getText() : null)
                    + " ainda nao foi declarada!\n");
          } else {
            if (declarations_in.get((ID3 != null ? ID3.getText() : null)).getTipo().equals("int")
                && (expression4 != null ? expression4.tipo : null) == Tipo.REAL) {
              System.out.println("Possivel perda de precis‹o! (guardar real em variavel inteira)");
              Par p = declarations_in.get((ID3 != null ? ID3.getText() : null));
              p.setValue(Math.round((expression4 != null ? expression4.valor : 0.0f)));
            } else {
              Par p = declarations_in.get((ID3 != null ? ID3.getText() : null));
              p.setValue((expression4 != null ? expression4.valor : 0.0f));
            }
            System.out.println(
                (ID3 != null ? ID3.getText() : null)
                    + " == "
                    + declarations_in.get((ID3 != null ? ID3.getText() : null)).getValue());
          }
        }

      } catch (RecognitionException re) {
        reportError(re);
        recover(input, re);
      } finally {
      }
      dbg.location(84, 2);

    } finally {
      dbg.exitRule(getGrammarFileName(), "attrib");
      decRuleLevel();
      if (getRuleLevel() == 0) {
        dbg.terminate();
      }
    }

    return;
  }