flpq_data.queries.rpq.readwrite.rsa#

Read (and write) a Recursive State Automaton from (and to) different sources.

Functions

rsa_from_text(text, *[, start_symbol])

Create a Recursive State Automaton [1] from text.

rsa_from_txt(path, *[, start_symbol])

Create a Recursive State Automaton [1] from TXT file.

rsa_to_text(rsa)

Turns a Recursive State Automaton [1] into its text representation.

rsa_to_txt(rsa, path)

Saves a Recursive State Automaton text representation into TXT file.

rsa_from_text(text: str, *, start_symbol: Symbol = S) → RecursiveAutomaton[source]#

Create a Recursive State Automaton [1] from text.

The text uses one of two description styles, selected automatically:

  • EBNF style: one production per line, N -> E, where E is a regular expression over terminals and nonterminals; each production becomes one box.

  • Transition-system style: explicit boxes as labelled graphs with start and final states (a [box <name>] section header selects this style).

In both styles an optional start: <N> line names the start box (S by default).

Parameters:
textstr

The text with which the Recursive State Machine will be created.

start_symbolSymbol

Start symbol of a Recursive State Machine.

Returns:
rsaRSA

Recursive State Automaton.

References

[1] (1,2)

Alur R., Etessami K., Yannakakis M. (2001) Analysis of Recursive State Machines. In: Berry G., Comon H., Finkel A. (eds) Computer Aided Verification. CAV 2001. Lecture Notes in Computer Science, vol 2102. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-44585-4_18

Examples

>>> from flpq_data import *
>>> rsa = rsa_from_text("S -> a*")
>>> cfg_to_text(cfg_from_rsa(rsa))
'S -> \nS -> a S'
>>> rsa = rsa_from_text(
...     "start: S\n"
...     "[box S]\n"
...     "start: 0\n"
...     "final: 2\n"
...     "0 --a--> 1\n"
...     "1 --b--> 2"
... )
>>> cfg_to_text(cfg_from_rsa(rsa))
'S -> a S_1\nS_1 -> b S_2\nS_2 -> '
rsa_from_txt(path: Path | str, *, start_symbol: Symbol = S) → RecursiveAutomaton[source]#

Create a Recursive State Automaton [1] from TXT file.

Parameters:
pathUnion[Path, str]

The path to the TXT file with which the Recursive State Machine will be created.

start_symbolSymbol

Start symbol of a Recursive State Machine.

Returns:
rsaRSA

Recursive State Automaton.

References

[1] (1,2)

Alur R., Etessami K., Yannakakis M. (2001) Analysis of Recursive State Machines. In: Berry G., Comon H., Finkel A. (eds) Computer Aided Verification. CAV 2001. Lecture Notes in Computer Science, vol 2102. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-44585-4_18

Examples

>>> from flpq_data import *
>>> rsa_1 = rsa_from_text("S -> a*")
>>> path = rsa_to_txt(rsa_1, "test.txt")
>>> rsa = rsa_from_txt(path)
>>> rsa_to_text(rsa)
'S -> (a)*'
rsa_to_text(rsa: RecursiveAutomaton) → str[source]#

Turns a Recursive State Automaton [1] into its text representation.

Parameters:
rsaRSA

Recursive State Automaton.

Returns:
textstr

Recursive State Automaton text representation.

References

[1] (1,2)

Alur R., Etessami K., Yannakakis M. (2001) Analysis of Recursive State Machines. In: Berry G., Comon H., Finkel A. (eds) Computer Aided Verification. CAV 2001. Lecture Notes in Computer Science, vol 2102. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-44585-4_18

Examples

>>> from flpq_data import *
>>> rsa = rsa_from_text("S -> a*")
>>> rsa_to_text(rsa)
'S -> (a)*'
rsa_to_txt(rsa: RecursiveAutomaton, path: Path | str) → Path[source]#

Saves a Recursive State Automaton text representation into TXT file.

Parameters:
rsaRSA

Recursive State Automaton.

pathUnion[Path, str]

The path to the TXT file where Recursive State Machine text representation will be saved.

Returns:
pathPath

The path to the TXT file where Recursive State Automaton text representation will be saved.

References

[1]

Alur R., Etessami K., Yannakakis M. (2001) Analysis of Recursive State Machines. In: Berry G., Comon H., Finkel A. (eds) Computer Aided Verification. CAV 2001. Lecture Notes in Computer Science, vol 2102. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-44585-4_18

Examples

>>> from flpq_data import *
>>> rsa = rsa_from_text("S -> (a S* b S*)*")
>>> path = rsa_to_txt(rsa, "test.txt")