Exemplo n.º 1
0
  public void compileParser(Trace trace, Strictness strictness) {

    SGrammar sGrammar = new SGrammar(this);
    OldGrammar oldGrammar = null;
    for (Production production : sGrammar.getProductions()) {

      if (oldGrammar == null) {
        oldGrammar = new OldGrammar(this, production.getName(), production);
      }

      OldProduction oldProduction = oldGrammar.getProduction(production.getName(), production);

      for (Alternative alternative : production.getAlternatives()) {

        OldAlternative oldAlternative = oldProduction.addAlternative("", alternative);

        for (Element element : alternative.getElements()) {
          OldElement oldElement;
          if (element instanceof Element.TokenElement) {
            Element.TokenElement tokenElement = (Element.TokenElement) element;
            oldElement =
                oldAlternative.addTokenElement(
                    this,
                    element.getName(),
                    oldGrammar.getToken(tokenElement.getTypeName()),
                    tokenElement);
          } else {
            Element.ProductionElement productionElement = (Element.ProductionElement) element;
            oldElement =
                oldAlternative.addProductionElement(
                    element.getName(),
                    oldGrammar.getProduction(
                        element.getTypeName(), productionElement.getReference()),
                    productionElement);
          }
          sGrammar.addOldElement(element, oldElement);
        }
      }
    }

    oldGrammar.stabilize();
    oldGrammar.computeShortestLengthAndDetectUselessProductions();
    sGrammar.setLRAutomaton(new LRAutomaton(oldGrammar, trace));
    this.simplifiedGrammar = sGrammar;
  }