Class Translet.PermutationParser<R,A,B,C,D,E,F,G,H>

java.lang.Object
eu.bandm.tscore.base.Translet.Parser<R>
eu.bandm.tscore.base.Translet.ProductParser<R,A,B,C,D,E,F,G,H>
eu.bandm.tscore.base.Translet.PermutationParser<R,A,B,C,D,E,F,G,H>
Enclosing class:
Translet

public static class Translet.PermutationParser<R,A,B,C,D,E,F,G,H> extends Translet.ProductParser<R,A,B,C,D,E,F,G,H>
Variant of Translet.ProductParser which accepts all permutations of sub-parsers. As with product parsers in general, after all sub-parsers have been evaluated to their results, a function object or a constructor can be applied to these to construct the result.

The field Translet.ProductParser.separator gives optionally a non-terminal which must appear between all inputs consumed by sub-parsers which are not empty.

The treatment of empty (="epsilon") results must be special to prevent explosion of redundant solutions, and is described in detail in Lepper,Trancón "Translets", Bad Honnef 2018, pgs.113-130.

  • Field Details

    • parser2state

      protected Multimap<Translet.Parser<?>,Translet.State<?>> parser2state
      Maps all sub-parsers to all states the created during all parsing apptempts. The image sets will later be used to find the result of one particular sub-parser in one particular parsing tree.
  • Constructor Details

  • Method Details

    • unparse

      public String unparse(Object key)
      Description copied from class: Translet.Parser
      Reverse the parsing process (as far as possible) and deliver a string representation which when parsed delivered the parse result.
      Specified by:
      unparse in class Translet.Parser<R>
    • or

      public static BitSet or(BitSet a, BitSet b)
      Auxiliary function to create a new Java bitset which is the or-ing of the two args.
    • or

      public static BitSet or(BitSet a, int b)
      Auxiliary function to create a new Java bitset which is the or-ing of the two args.
    • makerestperm

      protected Translet.Parser<?> makerestperm(BitSet tested, int tested1)
      Construct a new permutation parser from all sub-parsers not yet tested. In the special case that only one(1) is left, this is returned immediately.
      Parameters:
      tested - set of the indexes of already tested sub-parsers.
      tested1 - index of another tested sub-parser
    • test2

      protected Set<? extends Translet.State<?>> test2(Translet.State<?> oneState, BitSet tested, BitSet toEpsilon, Set<Translet.Alternative> alternatives)
      Tests all permutations by breadth first search: first testing all sub-parsers once, and then calling this function recursively for all states resulting from these calls. Epsilon results are treated specially and further narrowed.
      Parameters:
      oneState - the state from which these tests start
      tested - already used and not to be parsed again
      toEpsilon - epsilon case already done, no further empty match is acceptable
      alternatives - the usual output parameter (result set) for non-successful alternatives
    • args

      protected Object[] args(Translet.State<?> s)
      Collects results of sub-parsers out of the selected parse tree "s" and stores them in one array for constructor application by reflection.
      Parameters:
      s - the last state in the successful parsing tree which shall be evaluated
    • findResult_p

      protected <R> R findResult_p(Translet.State<?> s, Translet.Parser<R> p)
      Aux function for casting only: find the result of the application of parser "p" in the (successful) parse tree ending in state "s".
      See Also:
    • parseOneState

      public Set<Translet.State<R>> parseOneState(Translet.State<?> inState, Set<Translet.Alternative> alternatives)
      Description copied from class: Translet.Parser
      Calculate a set of possible successor states by applying this parser to the incoming state and append all altenatives found underways to the parameter "alternatives". This method is specific to and overridden by the subclasses of Parser.
      Specified by:
      parseOneState in class Translet.Parser<R>
    • name

      public Format name(boolean full, Map<Translet.Recursive,String> names)
      Description copied from class: Translet.Parser
      Returns a user-readable text representation. This is in most cases, but not always, source text to construct the parser.
      Specified by:
      name in class Translet.Parser<R>
      Parameters:
      full - whether storage constructs do appear in the rendering.
      names - a map for managing the renderings of recursive calls