Beispiel #1
0
  private static boolean rule_assignment(DefaultMutableTreeNode parent) {

    boolean error = false;
    DefaultMutableTreeNode node;

    String iden = tokens.get(currentToken).getWord();
    node =
        new DefaultMutableTreeNode("identifier" + "(" + tokens.get(currentToken).getWord() + ")");
    parent.add(node);

    String s = tokens.get(currentToken).getWord();
    if (SemanticAnalyzer.getSymbolTable().get(s) != null)
      SemanticAnalyzer.pushStack(SemanticAnalyzer.getSymbolTable().get(s).firstElement().getType());
    else {
      SemanticAnalyzer.pushStack("ERROR");
      SemanticAnalyzer.error(getgui(), 0, getlineno(), s);
    }

    currentToken++;
    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("=")) {
      node = new DefaultMutableTreeNode("=");
      parent.add(node);
      currentToken++;
    } else {
      error(5);
      while (currentToken < tokens.size()
          && !(tokens.get(currentToken).getWord().equals("!")
              || tokens.get(currentToken).getWord().equals("-")
              || tokens.get(currentToken).getToken().equals("INTEGER")
              || tokens.get(currentToken).getToken().equals("OCTAL")
              || tokens.get(currentToken).getToken().equals("HEXADECIMAL")
              || tokens.get(currentToken).getToken().equals("BINARY")
              || tokens.get(currentToken).getToken().equals("STRING")
              || tokens.get(currentToken).getToken().equals("CHARACTER")
              || tokens.get(currentToken).getToken().equals("FLOAT")
              || tokens.get(currentToken).getToken().equals("IDENTIFIER")
              || tokens.get(currentToken).getWord().equals("true")
              || tokens.get(currentToken).getWord().equals("false")
              || tokens.get(currentToken).getWord().equals("(")
              || tokens.get(currentToken).getWord().equals(")")
              || tokens.get(currentToken).getWord().equals(";"))) {
        currentToken++;
      }
    }

    node = new DefaultMutableTreeNode("expression");
    parent.add(node);
    error = rule_expression(node);

    String s1 = SemanticAnalyzer.popStack();
    String s2 = SemanticAnalyzer.popStack();
    String operator = "=";
    String res = SemanticAnalyzer.calculateCube(s1, s2, operator);
    CodeGenerator.addInstruction("STO", iden, "0");

    if (res.equals("ERROR")) SemanticAnalyzer.error(getgui(), 2, getlineno(), "");

    return error;
  }
Beispiel #2
0
  private static boolean rule_while(DefaultMutableTreeNode parent) {

    boolean error = false;
    DefaultMutableTreeNode node;

    node = new DefaultMutableTreeNode("while");
    parent.add(node);
    currentToken++;

    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("(")) {
      node = new DefaultMutableTreeNode("(");
      parent.add(node);
      currentToken++;
    } else {
      error(8);
      while (currentToken < tokens.size()
          && !(tokens.get(currentToken).getWord().equals("!")
              || tokens.get(currentToken).getWord().equals("-")
              || tokens.get(currentToken).getToken().equals("INTEGER")
              || tokens.get(currentToken).getToken().equals("OCTAL")
              || tokens.get(currentToken).getToken().equals("HEXADECIMAL")
              || tokens.get(currentToken).getToken().equals("BINARY")
              || tokens.get(currentToken).getToken().equals("STRING")
              || tokens.get(currentToken).getToken().equals("CHARACTER")
              || tokens.get(currentToken).getToken().equals("FLOAT")
              || tokens.get(currentToken).getToken().equals("IDENTIFIER")
              || tokens.get(currentToken).getWord().equals("true")
              || tokens.get(currentToken).getWord().equals("false")
              || tokens.get(currentToken).getWord().equals("(")
              || tokens.get(currentToken).getWord().equals(")"))) {
        currentToken++;
      }
    }

    node = new DefaultMutableTreeNode("expression");
    parent.add(node);
    error = rule_expression(node);
    String type = SemanticAnalyzer.popStack();
    if (!type.equals("boolean")) SemanticAnalyzer.error(getgui(), 3, getlineno(), "");
    if (tokens.get(currentToken).getWord().equals(")")) {
      node = new DefaultMutableTreeNode(")");
      parent.add(node);
      currentToken++;
    } else {
      error(7);
      while (currentToken < tokens.size() && !tokens.get(currentToken).getWord().equals("{")) {
        currentToken++;
      }
    }
    CodeGenerator.addInstruction("JMC", "e" + label_count, "false");
    label_count++;
    node = new DefaultMutableTreeNode("program");
    parent.add(node);
    error = rule_program(node);

    CodeGenerator.addInstruction("JMP", "e" + label_count, "0");

    label_count++;
    return error;
  }
Beispiel #3
0
 // while
 private static void rule_while(DefaultMutableTreeNode parent) {
   DefaultMutableTreeNode node = new DefaultMutableTreeNode("while");
   parent.add(node);
   String start = "whileS" + labelNum;
   final int num = labelNum;
   String end = "whileE" + labelNum;
   labelNum++;
   CodeGenerator.addLabel(start, codeLine);
   if (tokens.get(currentToken).getWord().equals("(")) {
     node = new DefaultMutableTreeNode("(");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
   }
   node = new DefaultMutableTreeNode("expression");
   parent.add(node);
   rule_expression(node);
   CodeGenerator.addInstruction("JMC", "#" + end, "false");
   codeLine++;
   int n = tokens.get(currentToken).getLine();
   String x = SemanticAnalyzer.popStack();
   if (!x.equals("BOOLEAN")) SemanticAnalyzer.error(gui, 3, n, "");
   if (tokens.get(currentToken).getWord().equals(")")) {
     node = new DefaultMutableTreeNode(")");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
   }
   node = new DefaultMutableTreeNode("program");
   parent.add(node);
   rule_program(node);
   CodeGenerator.addInstruction("JMP", "#" + start, "0");
   codeLine++;
   CodeGenerator.addLabel("whileE" + num, codeLine);
 }
Beispiel #4
0
 // switch
 private static void rule_switch(DefaultMutableTreeNode parent) {
   DefaultMutableTreeNode node = null;
   DefaultMutableTreeNode parentS = parent;
   node = new DefaultMutableTreeNode("switch");
   parent.add(node);
   String id = "";
   if (tokens.get(currentToken).getWord().equals("(")) {
     node = new DefaultMutableTreeNode("(");
     parent.add(node);
     currentToken++;
   }
   if (tokens.get(currentToken).getToken().equals("IDENTIFIER")) {
     node = new DefaultMutableTreeNode("identifier(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     int line = tokens.get(currentToken).getLine();
     id = tokens.get(currentToken).getWord();
     String type = SemanticAnalyzer.doesExist(id);
     String value = SemanticAnalyzer.getValue(id);
     if (type.equals("error")) SemanticAnalyzer.error(gui, 0, line, id);
     currentToken++;
   }
   if (tokens.get(currentToken).getWord().equals(")")) {
     node = new DefaultMutableTreeNode(")");
     parent.add(node);
     currentToken++;
   }
   if (tokens.get(currentToken).getWord().equals("{")) {
     node = new DefaultMutableTreeNode("{");
     parent.add(node);
     currentToken++;
   }
   if (tokens.get(currentToken).getWord().equals("case")) {
     node = new DefaultMutableTreeNode("case");
     parentS.add(node);
     currentToken++;
   }
   rule_cases(parentS, node, id);
   if (tokens.get(currentToken).getWord().equals("default")) {
     node = new DefaultMutableTreeNode("default");
     parent.add(node);
     currentToken++;
     CodeGenerator.addInstruction("JMP", "#labelD", "0");
     codeLine++;
     rule_default(node);
   }
   if (tokens.get(currentToken).getWord().equals("}")) {
     node = new DefaultMutableTreeNode("}");
     parent.add(node);
     currentToken++;
   }
   // codeLine++;
   // codeLine++;
   CodeGenerator.addLabel("labelES", codeLine);
 }
Beispiel #5
0
 // assignment
 private static void rule_assignment(DefaultMutableTreeNode parent) {
   String id = tokens.get(currentToken - 1).getWord();
   DefaultMutableTreeNode node = new DefaultMutableTreeNode("identifier(" + id + ")");
   parent.add(node);
   if (tokens.get(currentToken).getWord().equals("=")) {
     node = new DefaultMutableTreeNode("=");
     parent.add(node);
   }
   node = new DefaultMutableTreeNode("expression");
   parent.add(node);
   int line = tokens.get(currentToken).getLine();
   if (currentToken < tokens.size() - 1 && !tokens.get(currentToken).getWord().equals(")"))
     currentToken++;
   rule_expression(node);
   CodeGenerator.addInstruction("STO", id, "0");
   codeLine++;
   String x = SemanticAnalyzer.popStack();
   String y = SemanticAnalyzer.popStack();
   String result = SemanticAnalyzer.calculateCube(x, y, "=");
   if (!result.equals("ok")) SemanticAnalyzer.error(gui, 2, line, "");
 }
Beispiel #6
0
 // if
 private static void rule_if(DefaultMutableTreeNode parent) {
   DefaultMutableTreeNode node = new DefaultMutableTreeNode("if");
   parent.add(node);
   String end = "ifE" + ifNum;
   int num = ifNum;
   ifNum++;
   if (tokens.get(currentToken).getWord().equals("(")) {
     node = new DefaultMutableTreeNode("(");
     parent.add(node);
     node = new DefaultMutableTreeNode("expression");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
     rule_expression(node);
     CodeGenerator.addInstruction("JMC", "#ifE" + ifNum, "false");
     codeLine++;
     int n = tokens.get(currentToken).getLine();
     String x = SemanticAnalyzer.popStack();
     if (!x.equals("BOOLEAN")) SemanticAnalyzer.error(gui, 3, n, "");
     if (tokens.get(currentToken).getWord().equals(")")) {
       node = new DefaultMutableTreeNode(")");
       parent.add(node);
       node = new DefaultMutableTreeNode("program");
       parent.add(node);
       if (currentToken < tokens.size() - 1) currentToken++;
       rule_program(node);
       CodeGenerator.addInstruction("JMP", "#ifE" + num, "0");
       codeLine++;
       CodeGenerator.addLabel("ifE" + ifNum, codeLine);
       if (tokens.get(currentToken).getWord().equals("else")) {
         node = new DefaultMutableTreeNode("else");
         parent.add(node);
         node = new DefaultMutableTreeNode("program");
         parent.add(node);
         if (currentToken < tokens.size() - 1) currentToken++;
         rule_program(node);
       }
       CodeGenerator.addLabel("ifE" + num, codeLine);
     }
   }
 }
Beispiel #7
0
  private static boolean rule_C(DefaultMutableTreeNode parent) {
    boolean error = false;
    DefaultMutableTreeNode node;

    if (currentToken < tokens.size() && tokens.get(currentToken).getToken().equals("INTEGER")) {
      node = new DefaultMutableTreeNode("integer" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("int");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("OCTAL")) {
      node = new DefaultMutableTreeNode("octal" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("int");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("HEXADECIMAL")) {
      node =
          new DefaultMutableTreeNode(
              "hexadecimal" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("int");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("BINARY")) {
      node = new DefaultMutableTreeNode("binary" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("int");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("STRING")) {
      node = new DefaultMutableTreeNode("string" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("string");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("CHARACTER")) {
      node =
          new DefaultMutableTreeNode("character" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("char");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("FLOAT")) {
      node = new DefaultMutableTreeNode("float" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("float");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getWord().equalsIgnoreCase("true")) {
      node = new DefaultMutableTreeNode("boolean" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("boolean");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("false")) {
      node = new DefaultMutableTreeNode("boolean" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      SemanticAnalyzer.pushStack("boolean");
      CodeGenerator.addInstruction("LIT", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equals("IDENTIFIER")) {
      node =
          new DefaultMutableTreeNode("identifier" + "(" + tokens.get(currentToken).getWord() + ")");
      parent.add(node);
      if (SemanticAnalyzer.getSymbolTable().get(tokens.get(currentToken).getWord()) != null)
        SemanticAnalyzer.pushStack(
            SemanticAnalyzer.getSymbolTable()
                .get(tokens.get(currentToken).getWord())
                .firstElement()
                .getType());
      else {
        SemanticAnalyzer.error(getgui(), 0, getlineno(), tokens.get(currentToken).getWord());
        SemanticAnalyzer.pushStack("ERROR");
      }
      CodeGenerator.addInstruction("LOD", tokens.get(currentToken).getWord(), "0");
      currentToken++;
    } else if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("(")) {
      node = new DefaultMutableTreeNode("(");
      parent.add(node);
      currentToken++;
      //
      node = new DefaultMutableTreeNode("expression");
      parent.add(node);
      error = rule_expression(node);
      //
      if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals(")")) {
        node = new DefaultMutableTreeNode(")");
        parent.add(node);
        currentToken++;
      } else error(7);
    } else {
      error(9);
    }

    return false;
  }
Beispiel #8
0
 private static void rule_c(DefaultMutableTreeNode parent) {
   String id = tokens.get(currentToken).getWord();
   String type = SemanticAnalyzer.doesExist(id);
   int n = tokens.get(currentToken).getLine();
   DefaultMutableTreeNode node = null;
   if (tokens.get(currentToken).getToken().equals("INTEGER")) {
     node = new DefaultMutableTreeNode("integer(" + id + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack(tokens.get(currentToken).getToken());
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("OCTAL")) {
     node = new DefaultMutableTreeNode("octal(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack("INTEGER");
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("HEXADECIMAL")) {
     node = new DefaultMutableTreeNode("hexadecimal(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack("INTEGER");
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("BINARY")) {
     node = new DefaultMutableTreeNode("binary(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack("INTEGER");
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getWord().equals("true")) {
     node = new DefaultMutableTreeNode("true");
     parent.add(node);
     SemanticAnalyzer.pushStack("BOOLEAN");
     CodeGenerator.addInstruction("LIT", "true", "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getWord().equals("false")) {
     node = new DefaultMutableTreeNode("false");
     parent.add(node);
     SemanticAnalyzer.pushStack("BOOLEAN");
     CodeGenerator.addInstruction("LIT", "false", "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("STRING")) {
     node = new DefaultMutableTreeNode("string(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack("STRING");
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("CHARACTER")) {
     node = new DefaultMutableTreeNode("char(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack("CHARACTER");
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("FLOAT")) {
     node = new DefaultMutableTreeNode("float(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     SemanticAnalyzer.pushStack("FLOAT");
     CodeGenerator.addInstruction("LIT", id, "0");
     codeLine++;
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getToken().equals("IDENTIFIER")) {
     node = new DefaultMutableTreeNode("identifier(" + tokens.get(currentToken).getWord() + ")");
     parent.add(node);
     CodeGenerator.addInstruction("LOD", id, "0");
     codeLine++;
     if (type.equals("void")) SemanticAnalyzer.pushStack("VOID");
     else if (type.equals("float")) SemanticAnalyzer.pushStack("FLOAT");
     else if (type.equals("boolean")) SemanticAnalyzer.pushStack("BOOLEAN");
     else if (type.equals("int")) SemanticAnalyzer.pushStack("INTEGER");
     else if (type.equals("char")) SemanticAnalyzer.pushStack("CHARACTER");
     else if (type.equals("string")) SemanticAnalyzer.pushStack("STRING");
     else {
       SemanticAnalyzer.pushStack("other");
       SemanticAnalyzer.error(gui, 0, n, id);
     }
     if (currentToken < tokens.size() - 1) currentToken++;
   } else if (tokens.get(currentToken).getWord().equals("(")) {
     node = new DefaultMutableTreeNode("(");
     parent.add(node);
     node = new DefaultMutableTreeNode("expression");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
     rule_expression(node);
     if (tokens.get(currentToken).getWord().equals(")")) {
       node = new DefaultMutableTreeNode(")");
       parent.add(node);
       if (currentToken < tokens.size() - 1) currentToken++;
     }
   }
 }
Beispiel #9
0
  // body
  private static void rule_body(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode node = null;
    while (!tokens.get(currentToken).getWord().equals("}")
        && !(currentToken >= tokens.size() - 1)) {
      String name = tokens.get(currentToken).getWord();
      // call print
      if (tokens.get(currentToken).getWord().equals("print")) {
        node = new DefaultMutableTreeNode("print");
        parent.add(node);
        if (currentToken < tokens.size() - 1) currentToken++;
        rule_print(node);
        if (tokens.get(currentToken).getWord().equals(";")) {
          node = new DefaultMutableTreeNode(";");
          parent.add(node);
          if (currentToken < tokens.size() - 1) currentToken++;
        }
      }
      // call assignment
      else if (tokens.get(currentToken).getToken().equals("IDENTIFIER")) {
        String id = tokens.get(currentToken).getWord();
        int line = tokens.get(currentToken).getLine();
        String type = SemanticAnalyzer.doesExist(id);
        if (type.equals("int")) type = "INTEGER";
        else if (type.equals("float")) type = "FLOAT";
        else if (type.equals("string")) type = "STRING";
        else if (type.equals("char")) type = "CHARACTER";
        else if (type.equals("octal")) type = "OCTAL";
        else if (type.equals("binary")) type = "BINARY";
        else if (type.equals("hexadecimal")) type = "HEXADECIMAL";
        else if (type.equals("void")) type = "VOID";
        else if (type.equals("boolean")) type = "BOOLEAN";
        else {
          SemanticAnalyzer.error(gui, 0, line, id);
          // SemanticAnalyzer.error(gui, 2, line, "");
        }
        SemanticAnalyzer.pushStack(type);
        node = new DefaultMutableTreeNode("assignment");
        parent.add(node);
        if (currentToken < tokens.size() - 1) currentToken++;
        rule_assignment(node);
        if (tokens.get(currentToken).getWord().equals(";")) {
          node = new DefaultMutableTreeNode(";");
          parent.add(node);
          if (currentToken < tokens.size() - 1) currentToken++;
        }

        if (tokens.get(currentToken).getWord().equals(")")) currentToken++;
      }
      // call variable
      else if (tokens.get(currentToken).getWord().equals("int")
          | tokens.get(currentToken).getWord().equals("float")
          | tokens.get(currentToken).getWord().equals("boolean")
          | tokens.get(currentToken).getWord().equals("char")
          | tokens.get(currentToken).getWord().equals("string")
          | tokens.get(currentToken).getWord().equals("void")) {
        node = new DefaultMutableTreeNode("variable");
        parent.add(node);
        if (currentToken < tokens.size() - 1) currentToken++;
        rule_variable(node);
        if (tokens.get(currentToken).getWord().equals(";")) {
          node = new DefaultMutableTreeNode(";");
          parent.add(node);
          if (currentToken < tokens.size() - 1) currentToken++;
        }
      }
      // call while
      else if (tokens.get(currentToken).getWord().equals("while")) {
        node = new DefaultMutableTreeNode("while");
        parent.add(node);
        if (currentToken < tokens.size() - 1) currentToken++;
        rule_while(node);
      }
      // call if
      else if (tokens.get(currentToken).getWord().equals("if")) {
        node = new DefaultMutableTreeNode("if");
        parent.add(node);
        if (currentToken < tokens.size() - 1) currentToken++;
        rule_if(node);
      }
      // call switch
      else if (tokens.get(currentToken).getWord().equals("switch")) {
        node = new DefaultMutableTreeNode("switch");
        parent.add(node);
        if (currentToken < tokens.size() - 1) currentToken++;
        rule_switch(node);
      }
      // call return
      else if (tokens.get(currentToken).getWord().equals("return")) {
        node = new DefaultMutableTreeNode("return");
        parent.add(node);
        DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("return");
        node.add(node1);
        if (currentToken < tokens.size() - 1) currentToken++;
        if (tokens.get(currentToken).getWord().equals(";")) {
          node = new DefaultMutableTreeNode(";");
          parent.add(node);
          if (currentToken < tokens.size() - 1) currentToken++;
        }
        CodeGenerator.addInstruction("OPR", "1", "0");
        codeLine++;
      }
    }
  }