Class AbstractFSMParser<I>
- java.lang.Object
-
- net.automatalib.serialization.fsm.parser.AbstractFSMParser<I>
-
- Direct Known Subclasses:
AbstractFSM2MealyParser,FSM2DFAParser
public abstract class AbstractFSMParser<I> extends Object
This class provides methods to parse automata in FSM format.The FSM is parsed by means of a tokenizer (a grammar is not used).
- See Also:
- the FSM format
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractFSMParser.PartAn enumeration for the three parts in the FSM file.
-
Field Summary
Fields Modifier and Type Field Description static StringEXPECT_CHARstatic StringEXPECT_IDENTIFIERstatic StringEXPECT_NUMBERstatic StringEXPECT_STRINGstatic StringNO_SUCH_STATEstatic StringNON_DETERMINISM_DETECTEDprotected @Nullable Collection<? extends I>targetInputsThe set that contains all inputs that end up in the input alphabet (provided by the user, may benull).
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractFSMParser(@Nullable Collection<? extends I> targetInputs, Function<String,I> inputParser)Constructs a new AbstractFSMParser and defines all possible tokens.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcheckDataDefinitions(StreamTokenizer streamTokenizer)Perform some actions after all data definitions have been parsed.protected abstract voidcheckStateVectors(StreamTokenizer streamTokenizer)Perform some actions after all state vectors have been parsed.protected abstract voidcheckTransitions(StreamTokenizer streamTokenizer)Perform some actions after all transitions have been parsed.protected Function<String,I>getInputParser()Gets the function that transforms strings in the FSM file to input.protected Set<I>getInputs()Gets the set that contains all inputs that end up in the input alphabet.protected intgetPartLineNumber()Returns the line number that is being parsed in the current part.protected StreamTokenizergetStreamTokenizer(Reader reader)Gets the StreamTokenizer, that tokenizes tokens in the FSM file.protected voidparse(Reader reader)Parsed the FSM file line-by-line.protected abstract voidparseDataDefinition(StreamTokenizer streamTokenizer)Parse a data definition.protected abstract voidparseStateVector(StreamTokenizer streamTokenizer)Parse a state vector.protected abstract voidparseTransition(StreamTokenizer streamTokenizer)Parse a transition.
-
-
-
Field Detail
-
NO_SUCH_STATE
public static final String NO_SUCH_STATE
- See Also:
- Constant Field Values
-
NON_DETERMINISM_DETECTED
public static final String NON_DETERMINISM_DETECTED
- See Also:
- Constant Field Values
-
EXPECT_CHAR
public static final String EXPECT_CHAR
- See Also:
- Constant Field Values
-
EXPECT_NUMBER
public static final String EXPECT_NUMBER
- See Also:
- Constant Field Values
-
EXPECT_IDENTIFIER
public static final String EXPECT_IDENTIFIER
- See Also:
- Constant Field Values
-
EXPECT_STRING
public static final String EXPECT_STRING
- See Also:
- Constant Field Values
-
targetInputs
protected final @Nullable Collection<? extends I> targetInputs
The set that contains all inputs that end up in the input alphabet (provided by the user, may benull).
-
-
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. Ifnull, 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, FormatException
Parse a data definition.- Parameters:
streamTokenizer- tokenizer containing the input- Throws:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
checkDataDefinitions
protected abstract void checkDataDefinitions(StreamTokenizer streamTokenizer) throws IOException, FormatException
Perform some actions after all data definitions have been parsed.- Parameters:
streamTokenizer- tokenizer containing the input- Throws:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
parseStateVector
protected abstract void parseStateVector(StreamTokenizer streamTokenizer) throws IOException, FormatException
Parse a state vector.- Parameters:
streamTokenizer- tokenizer containing the input- Throws:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
checkStateVectors
protected abstract void checkStateVectors(StreamTokenizer streamTokenizer) throws IOException, FormatException
Perform some actions after all state vectors have been parsed.- Parameters:
streamTokenizer- tokenizer containing the input- Throws:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
parseTransition
protected abstract void parseTransition(StreamTokenizer streamTokenizer) throws IOException, FormatException
Parse a transition.- Parameters:
streamTokenizer- tokenizer containing the input- Throws:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
checkTransitions
protected abstract void checkTransitions(StreamTokenizer streamTokenizer) throws IOException, FormatException
Perform some actions after all transitions have been parsed.- Parameters:
streamTokenizer- tokenizer containing the input- Throws:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
parse
protected void parse(Reader reader) throws IOException, FormatException
Parsed the FSM file line-by-line. At first this method expects to parse data definitions, and callsparseDataDefinition(StreamTokenizer)for each data definition. After "---" is encounteredcheckDataDefinitions(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 incrementpartLineNumber, and reset it when a new part in the FSM file begins.Note that
StreamTokenizerallows 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:
FormatException- when the FSM source is invalid.IOException- when FSM source could not be read.
-
-