FAdo.fio

In/Out.

FAdo I/O methods. The parsing grammars for most of the objects reside here.

class BuildFadoObject(visit_tokens: bool = True)[source]

Semantics of the FAdo grammars’ objects

readFromFile(FileName)[source]

Reads list of finite automata definition from a file.

Parameters:

FileName (str) – file name

Return type:

list

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 blanks

  • fields 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 states

  • both, NFA and DFA, may have a declaration of alphabet starting with a $ followed by the symbols of the alphabet

  • a 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.

readOneFromFile(fileName)[source]

Read the first of the FAdo objects from File

Parameters:

fileName (str) – name of the file

Return type:

DFA|FA|STF|SST

readOneFromString(s)[source]

Reads one finite automata definition from a file.

See also

readFromFile for description of format

Parameters:

s (str) – the string

Return type:

DFA|NFA|SFT

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

Parameters:
  • FileName (str) – file name

  • fa (list of FA) – the FA

  • mode (str) – writing mode

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

show(obj)[source]

General, context sensitive, display method :param obj: the object to show

New in version 1.2.1.

toJson(aut)[source]

Json for a FA

Parameters:

aut (FA) – the automaton

Return type:

str