示例#1
0
  /**
   * Generate common code for a block of alternatives; return a postscript that needs to be
   * generated at the end of the block. Other routines may append else-clauses and such for error
   * checking before the postfix is generated.
   */
  public void genCommonBlock(AlternativeBlock blk) {
    for (int i = 0; i < blk.alternatives.size(); i++) {
      Alternative alt = blk.getAlternativeAt(i);
      AlternativeElement elem = alt.head;

      // dump alt operator |
      if (i > 0 && blk.alternatives.size() > 1) {
        _println("");
        print("|\t");
      }

      // Dump the alternative, starting with predicates
      //
      boolean save = firstElementInAlt;
      firstElementInAlt = true;
      tabs++; // in case we do a newline in alt, increase the tab indent

      // RK: don't dump semantic/syntactic predicates
      // only obscures grammar.
      //
      // Dump semantic predicates
      //
      //	if (alt.semPred != null) {
      //		println("{" + alt.semPred + "}?");
      //	}
      // Dump syntactic predicate
      //	if (alt.synPred != null) {
      //		genSynPred(alt.synPred);
      //	}
      genAlt(alt);
      tabs--;
      firstElementInAlt = save;
    }
  }
示例#2
0
  /**
   * Generate a textual representation of the lookahead set for a block.
   *
   * @param blk The block of interest
   */
  public void genLookaheadSetForBlock(AlternativeBlock blk) {
    // Find the maximal lookahead depth over all alternatives
    int depth = 0;
    for (int i = 0; i < blk.alternatives.size(); i++) {
      Alternative alt = blk.getAlternativeAt(i);
      if (alt.lookaheadDepth == GrammarAnalyzer.NONDETERMINISTIC) {
        depth = grammar.maxk;
        break;
      } else if (depth < alt.lookaheadDepth) {
        depth = alt.lookaheadDepth;
      }
    }

    for (int i = 1; i <= depth; i++) {
      Lookahead lookahead = grammar.theLLkAnalyzer.look(i, blk);
      printSet(depth, i, lookahead);
    }
  }