private static boolean rule_variable(DefaultMutableTreeNode parent) {
    boolean error = false;
    DefaultMutableTreeNode node;

    String type = tokens.get(currentToken).getWord();
    String iden = "";
    node = new DefaultMutableTreeNode(tokens.get(currentToken).getWord());
    parent.add(node);
    currentToken++;
    if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equalsIgnoreCase("identifier")) {
      SemanticAnalyzer.checkVariable(
          tokens.get(currentToken - 1).getWord(), tokens.get(currentToken).getWord());
      node =
          new DefaultMutableTreeNode("identifier" + "(" + tokens.get(currentToken).getWord() + ")");
      iden = tokens.get(currentToken).getWord();
      CodeGenerator.addVariable(type, iden);
      parent.add(node);
      currentToken++;
    } else {

      error(6);
    }

    return error;
  }
Exemple #2
0
 // variable
 private static void rule_variable(DefaultMutableTreeNode parent) {
   String type = tokens.get(currentToken - 1).getWord();
   String id = tokens.get(currentToken).getWord();
   DefaultMutableTreeNode node = new DefaultMutableTreeNode(type);
   parent.add(node);
   if (tokens.get(currentToken).getToken().equals("IDENTIFIER")) {
     SemanticAnalyzer.checkVariable(
         tokens.get(currentToken - 1).getWord(),
         tokens.get(currentToken).getWord(),
         tokens.get(currentToken).getLine(),
         gui);
     node = new DefaultMutableTreeNode("identifier(" + id + ")");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
     CodeGenerator.addVariable(type, id);
   }
 }
Exemple #3
0
  /**
   * Rule: Variable
   *
   * @param DefaultMutableTreeNode parent
   * @return boolean
   */
  public static void rule_variable(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode node;

    // type

    node = new DefaultMutableTreeNode(tokens.get(currentToken).getWord());
    parent.add(node);
    currentToken++;

    // identifier

    if (tokens.get(currentToken).getToken().equals("IDENTIFIER")) {
      SemanticAnalyzer.checkVariable(
          tokens.get(currentToken - 1).getWord(), tokens.get(currentToken).getWord());

      node =
          new DefaultMutableTreeNode("identifier" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      currentToken++;
    } else {
      error(6); // expected identifier
    }
  }