Exemplo n.º 1
0
  private void dispatch(final boolean fireOnlyIfMixed) throws SAXException {
    if (fireOnlyIfMixed && buffer.length() == 0) return; // skip it

    Object[] ctx = (Object[]) context.peek();
    String here = (String) ctx[0];
    Attributes attrs = (Attributes) ctx[1];
    buffer.delete(0, buffer.length());
  }
  /** Method with the actual generated action code. */
  public final java_cup.runtime.Symbol CUP$parser$do_action(
      int CUP$parser$act_num,
      java_cup.runtime.lr_parser CUP$parser$parser,
      java.util.Stack CUP$parser$stack,
      int CUP$parser$top)
      throws java.lang.Exception {
    /* Symbol object for return from actions */
    java_cup.runtime.Symbol CUP$parser$result;

    /* select the action based on the action number */
    switch (CUP$parser$act_num) {
        /*. . . . . . . . . . . . . . . . . . . .*/
      case 14: // expresion ::= LPARENT expresion RPARENT
        {
          Integer RESULT = null;
          int EXWleft =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).left;
          int EXWright =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).right;
          Integer EXW =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).value;
          RESULT = new Integer(EXW.intValue());
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 13: // expresion ::= RESTA expresion
        {
          Integer RESULT = null;
          int EPX1left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int EPX1right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer EPX1 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer(EPX1 * (-1));
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 12: // expresion ::= expresion POTENCIA expresion
        {
          Integer RESULT = null;
          int ED1left =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).left;
          int ED1right =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).right;
          Integer ED1 =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).value;
          int ED2left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int ED2right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer ED2 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer((int) Math.pow(ED1.intValue(), ED2.intValue()));
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 11: // expresion ::= expresion DIVISION expresion
        {
          Integer RESULT = null;
          int EC1left =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).left;
          int EC1right =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).right;
          Integer EC1 =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).value;
          int EC2left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int EC2right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer EC2 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer(EC1.intValue() / EC2.intValue());
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 10: // expresion ::= expresion MULTIPLICACION expresion
        {
          Integer RESULT = null;
          int EA1left =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).left;
          int EA1right =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).right;
          Integer EA1 =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).value;
          int EA2left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int EA2right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer EA2 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer(EA1.intValue() * EA2.intValue());
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 9: // expresion ::= expresion RESTA expresion
        {
          Integer RESULT = null;
          int EE1left =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).left;
          int EE1right =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).right;
          Integer EE1 =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).value;
          int EE2left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int EE2right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer EE2 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer(EE1.intValue() - EE2.intValue());
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 8: // expresion ::= expresion SUMA expresion
        {
          Integer RESULT = null;
          int E1left =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).left;
          int E1right =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).right;
          Integer E1 =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).value;
          int E2left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int E2right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer E2 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer(E1.intValue() + E2.intValue());
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 7: // expresion ::= ENTERO
        {
          Integer RESULT = null;
          int D1left = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int D1right = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer D1 = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          RESULT = new Integer(D1.intValue());
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "expresion",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 6: // ecuacion ::= error NT$1 RESULTADO
        {
          Object RESULT = null;
          // propagate RESULT from NT$1
          RESULT =
              (Object)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).value;

          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "ecuacion",
                      2,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 5: // NT$1 ::=
        {
          Object RESULT = null;
          System.out.println("Aprenda a escribir br..");
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "NT$1",
                      4,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 4: // ecuacion ::= expresion NT$0 RESULTADO
        {
          Object RESULT = null;
          // propagate RESULT from NT$0
          RESULT =
              (Object)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).value;
          int EQleft =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).left;
          int EQright =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).right;
          Integer EQ =
              (Integer)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)).value;

          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "ecuacion",
                      2,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 2)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 3: // NT$0 ::=
        {
          Object RESULT = null;
          int EQleft = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).left;
          int EQright = ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).right;
          Integer EQ = (Integer) ((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
          System.out.println("Sintaxis OK");
          System.out.println("Resultado = " + EQ.intValue());

          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "NT$0",
                      3,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 2: // sesion ::= ecuacion
        {
          Object RESULT = null;

          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "sesion",
                      1,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 1: // $START ::= sesion EOF
        {
          Object RESULT = null;
          int start_valleft =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).left;
          int start_valright =
              ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).right;
          Object start_val =
              (Object)
                  ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)).value;
          RESULT = start_val;
          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "$START",
                      0,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        /* ACCEPT */
        CUP$parser$parser.done_parsing();
        return CUP$parser$result;

        /*. . . . . . . . . . . . . . . . . . . .*/
      case 0: // sesion ::= sesion ecuacion
        {
          Object RESULT = null;

          CUP$parser$result =
              parser
                  .getSymbolFactory()
                  .newSymbol(
                      "sesion",
                      1,
                      ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top - 1)),
                      ((java_cup.runtime.Symbol) CUP$parser$stack.peek()),
                      RESULT);
        }
        return CUP$parser$result;

        /* . . . . . .*/
      default:
        throw new Exception("Invalid action number found in internal parse table");
    }
  }