Class AbstractFSMParser<I>

    • Constructor Detail

      • AbstractFSMParser

        protected AbstractFSMParser​(@Nullable Collection<? extends I> targetInputs,
                                    Function<String,​I> inputParser)
        Constructs a new AbstractFSMParser and defines all possible tokens.
        Parameters:
        targetInputs - A collection containing the inputs which should constitute the input alphabet of the parsed automaton. If null, the inputs will be automatically gathered from the read FSM file.
        inputParser - the Function that parses strings in the FSM file to input.
    • Method Detail

      • getInputParser

        protected Function<String,​I> getInputParser()
        Gets the function that transforms strings in the FSM file to input.
        Returns:
        the function.
      • getPartLineNumber

        protected int getPartLineNumber()
        Returns the line number that is being parsed in the current part.
        Returns:
        the line number.
      • getStreamTokenizer

        protected StreamTokenizer getStreamTokenizer​(Reader reader)
        Gets the StreamTokenizer, that tokenizes tokens in the FSM file.
        Parameters:
        reader - the source of the FSM file
        Returns:
        the StreamTokenizer.
      • getInputs

        protected Set<I> getInputs()
        Gets the set that contains all inputs that end up in the input alphabet.
        Returns:
        the set of inputs.
      • parseDataDefinition

        protected abstract void parseDataDefinition​(StreamTokenizer streamTokenizer)
                                             throws IOException
        Parse a data definition.
        Parameters:
        streamTokenizer - tokenizer containing the input
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.
      • checkDataDefinitions

        protected abstract void checkDataDefinitions​(StreamTokenizer streamTokenizer)
                                              throws IOException
        Perform some actions after all data definitions have been parsed.
        Parameters:
        streamTokenizer - tokenizer containing the input
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.
      • parseStateVector

        protected abstract void parseStateVector​(StreamTokenizer streamTokenizer)
                                          throws IOException
        Parse a state vector.
        Parameters:
        streamTokenizer - tokenizer containing the input
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.
      • checkStateVectors

        protected abstract void checkStateVectors​(StreamTokenizer streamTokenizer)
                                           throws IOException
        Perform some actions after all state vectors have been parsed.
        Parameters:
        streamTokenizer - tokenizer containing the input
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.
      • parseTransition

        protected abstract void parseTransition​(StreamTokenizer streamTokenizer)
                                         throws IOException
        Parse a transition.
        Parameters:
        streamTokenizer - tokenizer containing the input
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.
      • checkTransitions

        protected abstract void checkTransitions​(StreamTokenizer streamTokenizer)
                                          throws IOException
        Perform some actions after all transitions have been parsed.
        Parameters:
        streamTokenizer - tokenizer containing the input
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.
      • parse

        protected void parse​(Reader reader)
                      throws IOException
        Parsed the FSM file line-by-line. At first this method expects to parse data definitions, and calls parseDataDefinition(StreamTokenizer) for each data definition. After "---" is encountered checkDataDefinitions(StreamTokenizer) is called, and this method expects to parse state vectors. The behavior is similar for state vectors and transitions. For each line this method will increment partLineNumber, and reset it when a new part in the FSM file begins.

        Note that StreamTokenizer allows one to push back tokens. This is used whenever we have checked the type of token we are going to read.

        Parameters:
        reader - the source of the FSM file
        Throws:
        FSMFormatException - when the FSM source is invalid.
        IOException - when FSM source could not be read.