FAdo.fio¶
In/Out.
FAdo I/O methods. The parsing grammars for most of the objects reside here.
- readFromFile(FileName)[source]¶
Reads list of finite automata definition from a file.
The format of these files must be the as simple as possible:
#
begins a comment@DFA
or@NFA
begin a new automata (and determines its type) and must be followed by the list of the final states separated by blanksfields are separated by a blank and transitions by a CR:
state
symbol
new state
in case of a NFA declaration, the “symbol” @epsilon is interpreted as an epsilon-transition
the source state of the first transition is the initial state
in the case of a NFA, its declaration
@NFA
can, after the declaration of the final states, have a*
followed by the list of initial statesboth, NFA and DFA, may have a declaration of alphabet starting with a
$
followed by the symbols of the alphabeta line with a sigle name, decrares a state
FAdo ::= FA | FA CR FAdo FA ::= DFA | NFA | Transducer DFA ::= "@DFA" LsStates Alphabet CR dTrans NFA ::= "@NFA" LsStates Initials Alphabet CR nTrans Transducer ::= "@Transducer" LsStates Initials Alphabet Output CR tTrans Initials ::= "*" LsStates | /Epsilon Alphabet ::= "$" LsSymbols | /Epsilon Output ::= "$" LsSymbols | /Epsilon nSymbol ::= symbol | "@epsilon" LsStates ::= stateid | stateid , LsStates LsSymbols ::= symbol | symbol , LsSymbols dTrans ::= stateid symbol stateid | | stateid symbol stateid CR dTrans nTrans ::= stateid nSymbol stateid | | stateid nSymbol stateid CR nTrans tTrans ::= stateid nSymbol nSymbol stateid | | stateid nSymbol nSymbol stateid CR nTrans
Note
If an error occur, either syntactic or because of a violation of the declared automata type, an exception is raised
Changed in version 0.9.6.
Changed in version 1.0.
- readOneFromString(s)[source]¶
Reads one finite automata definition from a file.
See also
readFromFile for description of format
- saveToFile(FileName, fa, mode='a')[source]¶
Saves a list finite automata definition to a file using the input format
Changed in version 0.9.5.
Changed in version 0.9.6.
Changed in version 0.9.7: New format with quotes and alphabet
- saveToJson(FileName, aut, mode='w')[source]¶
Saves a finite automata definition to a file using the JSON format
- saveToString(fa)[source]¶
Saves a finite automaton definition to a string :param fa: automaton :return: the string containing the automaton definition :rtype: str
..versionadded:: 1.2.1