Mescal
|
Implementation of NFAs. More...
#include "graphs.h"
#include "graphs_transclos.h"
#include "type_abr.h"
#include "type_basic.h"
#include "type_binheap.h"
#include "type_boolarray.h"
#include "type_dequeue.h"
#include "words.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | nfa |
Type used to represent a NFA. More... | |
struct | dfa |
Type used to represent a complete DFA. More... | |
Functions | |
void | nfa_print_state (const nfa *, uint, FILE *) |
Displays the name of a state in a NFA on a given stream. | |
void | dfa_print_state (const dfa *, uint, FILE *) |
Displays the name of a state in a DFA on a given stream. | |
void | nfa_reset_state_names (nfa *) |
Release the state names in a NFA (if there are states names). | |
void | dfa_reset_state_names (dfa *A) |
Release the state names in a DFA (if there are states names). | |
char ** | copy_all_names (char **names, uint size) |
Returns a copy of the array of state names. | |
void | nfa_delete (nfa *) |
Release of a NFA. | |
void | dfa_delete (dfa *A) |
Deletes a DFA. | |
nfa * | nfa_copy (nfa *) |
Copy of a NFA. | |
dfa * | dfa_copy (dfa *A) |
Copies a DFA. | |
nfa * | nfa_copy_exalpha (nfa *, letter *, uint) |
Copies an NFA with an extended alphabet. | |
dfa * | dfa_copy_exalpha (dfa *A, letter *alpha, uint size) |
Copies a DFA with an extended alphabet. | |
void | nfa_overwrite (nfa *, nfa *) |
Overwrites a NFA by copying another NFA and releasing this other NFA. | |
nfa * | create_emptylang (void) |
Computes a NFA recognizing the empty language. | |
nfa * | create_sing_epsilon (void) |
Computes a NFA recognizing the singleton language {ε}. | |
nfa * | create_sing_letter (letter) |
Computes a NFA recognizing a singleton language {a} containing a single letter word. | |
nfa * | create_sing_word (word *) |
Computes a NFA recognizing a singleton language {w} for some input word w. | |
nfa * | nfa_union (void *I1, bool is_dfa_I1, void *I2, bool is_dfa_I2) |
Union of two automata (NFAs or DFAs) into a single NFA. | |
nfa * | nfa_concat (void *I1, bool is_dfa_I1, void *I2, bool is_dfa_I2) |
Concatenation of two NFAs. | |
nfa * | nfa_star (nfa *) |
Kleene star of a NFA. | |
nfa * | dfa_star (dfa *) |
Kleene star of a DFA. | |
nfa * | nfa_plus (nfa *) |
Kleene plus of a NFA. | |
nfa * | nfa_mirror (nfa *) |
Mirror of a NFA. | |
nfa * | dfa_mirror (dfa *) |
Mirror of a DFA. | |
nfa * | nfa_elimeps (nfa *) |
Elimination of the epsilon transitions in a NFA. | |
void | nfa_elimeps_mod (nfa *) |
Elimination of the epsilon transitions in a NFA. Overwrites the input NFA. | |
nfa * | nfa_trim (nfa *) |
Elimination of all states that are not simultaneously reachable from an initial state and co-reachable from a final state. | |
dfa * | dfa_trim (dfa *A) |
Removes all non-accessible states from a DFA. | |
void | nfa_trim_mod (nfa *) |
Elimination of all states that are not simultaneously reachable from an initial state and co-reachable from a final state. Overwrites the input NFA. | |
dfa * | dfa_direct_product (dfa *A, dfa *B) |
nfa * | nfa_random (uint, uint, uint) |
Generates a random NFA. | |
dfa * | dfa_random (uint, uint, uint) |
Generates a random DFA. | |
int | nfa_nb_trans (nfa *) |
Computes the number of transitions in a NFA. | |
bool | nfa_is_det (nfa *) |
Tests if a NFA is deterministic. | |
bool | nfa_is_comp (nfa *) |
Tests if a NFA is complete. | |
bool | nfa_is_empty (nfa *) |
Tests if a NFA recognizes the empty language. | |
bool | nfa_accepts (nfa *, word *) |
Tests if a word is accepted by a NFA. | |
dequeue * | nfa_compute_runs (nfa *, word *) |
Computes the set of states reached by a word in a NFA. | |
bool | dfa_exists_path (dfa *, uint, uint, bool *) |
Checks if there exists a path between two states in a DFA. | |
uint | dfa_compute_run (dfa *A, word *w) |
Computes the run of a DFA on a word. | |
nfa * | nfa_merge_states (nfa *, parti *) |
Merges the states of a NFA according to the partition given as input. | |
dfa * | detnfa_to_dfa (nfa *A) |
Converts a NFA which is deterministic into the complete DFA representation. | |
nfa * | dfa_to_nfa (dfa *A) |
Converts a DFA into a NFA. | |
nfa * | dfa_to_nfa_exalpha (dfa *A, letter *alpha, uint size) |
Converts a DFA into a NFA with an extended alphabet. | |
Implementation of NFAs.
char ** copy_all_names | ( | char ** | names, |
uint | size ) |
Returns a copy of the array of state names.
names | The array of state names. |
size | Size of the array of state names. |
nfa * create_emptylang | ( | void | ) |
Computes a NFA recognizing the empty language.
nfa * create_sing_epsilon | ( | void | ) |
Computes a NFA recognizing the singleton language {ε}.
Computes a NFA recognizing a singleton language {a} containing a single letter word.
the_letter | The letter. |
Computes a NFA recognizing a singleton language {w} for some input word w.
the_word | The word. |
Converts a NFA which is deterministic into the complete DFA representation.
A | The NFA. |
Computes the run of a DFA on a word.
A | The DFA. |
w | The word. |
Copies a DFA with an extended alphabet.
A | The DFA. |
alpha | Array containing the new letters (sorted in increasing order). |
size | Size of the array. |
void dfa_delete | ( | dfa * | A | ) |
Deletes a DFA.
A | The DFA. |
bool dfa_exists_path | ( | dfa * | A, |
uint | in, | ||
uint | out, | ||
bool * | alph ) |
Checks if there exists a path between two states in a DFA.
A | The DFA. |
in | The source state. |
out | The target state. |
alph | The restriction of the alphabet (NULL if no restriction). |
Mirror of a DFA.
A | The NFA. |
void dfa_print_state | ( | const dfa * | A, |
uint | q, | ||
FILE * | out ) |
Displays the name of a state in a DFA on a given stream.
A | The DFA. |
q | Index of the state. |
out | The stream. |
dfa * dfa_random | ( | uint | size_alpha, |
uint | min_size, | ||
uint | max_size ) |
Generates a random DFA.
size_alpha | Size of the alphabet. |
min_size | Minimum number of states. |
max_size | Maximum number of states. |
void dfa_reset_state_names | ( | dfa * | A | ) |
Release the state names in a DFA (if there are states names).
A | The DFA. |
Kleene star of a DFA.
A | The DFA. |
Converts a DFA into a NFA with an extended alphabet.
Removes all non-accessible states from a DFA.
A | The DFA. |
Tests if a word is accepted by a NFA.
A | The NFA. |
w | The word. |
Computes the set of states reached by a word in a NFA.
A | The NFA. |
w | The word. |
nfa * nfa_concat | ( | void * | I1, |
bool | is_dfa_I1, | ||
void * | I2, | ||
bool | is_dfa_I2 ) |
Concatenation of two NFAs.
I1 | First NFA or DFA. |
is_dfa_I1 | True if the first input is a DFA, false if it is a NFA. |
I2 | Second NFA or DFA. |
is_dfa_I2 | True if the second input is a DFA, false if it is a NFA. |
Copies an NFA with an extended alphabet.
A | The NFA. |
alpha | Array containing the new letters (sorted in increasing order). |
size | Size of the array. |
void nfa_delete | ( | nfa * | A | ) |
Release of a NFA.
A | The NFA. |
Elimination of the epsilon transitions in a NFA.
A | The NFA. |
void nfa_elimeps_mod | ( | nfa * | A | ) |
Elimination of the epsilon transitions in a NFA. Overwrites the input NFA.
A | The NFA. |
bool nfa_is_comp | ( | nfa * | A | ) |
Tests if a NFA is complete.
A | The NFA. |
bool nfa_is_det | ( | nfa * | A | ) |
Tests if a NFA is deterministic.
A | The NFA. |
bool nfa_is_empty | ( | nfa * | A | ) |
Tests if a NFA recognizes the empty language.
A | The NFA. |
Merges the states of a NFA according to the partition given as input.
The new states are the classes of the partition. Given two classes c,c' and a letter a, a transition (c,a,c') is added if and only if there are two states q in c and q' in c' and a transition (q,a,q') in the original automaton. Similarly, a class c is initial (resp. final) if and only if it contains an intial (resp.final) state.
A | The NFA. |
P | Partition of the states. |
Mirror of a NFA.
A | The NFA. |
int nfa_nb_trans | ( | nfa * | A | ) |
Computes the number of transitions in a NFA.
A | The NFA. |
Overwrites a NFA by copying another NFA and releasing this other NFA.
A | The NFA that is being overwritten (its original fields are released). |
B | The NFA being copied (it is completely released). |
Kleene plus of a NFA.
A | The NFA. |
void nfa_print_state | ( | const nfa * | A, |
uint | q, | ||
FILE * | out ) |
Displays the name of a state in a NFA on a given stream.
A | The NFA. |
q | Index of the state. |
out | The stream. |
nfa * nfa_random | ( | uint | size_alpha, |
uint | min_size, | ||
uint | max_size ) |
Generates a random NFA.
< At least one initial state.
size_alpha | Size of the alphabet. |
min_size | Minimum number of states. |
max_size | Maximum number of states. |
Kleene star of a NFA.
A | The NFA. |
Elimination of all states that are not simultaneously reachable from an initial state and co-reachable from a final state.
A | The NFA. |
void nfa_trim_mod | ( | nfa * | A | ) |
Elimination of all states that are not simultaneously reachable from an initial state and co-reachable from a final state. Overwrites the input NFA.
A | The NFA. |
nfa * nfa_union | ( | void * | I1, |
bool | is_dfa_I1, | ||
void * | I2, | ||
bool | is_dfa_I2 ) |
Union of two automata (NFAs or DFAs) into a single NFA.
I1 | First NFA or DFA. |
is_dfa_I1 | True if the first input is a DFA, false if it is a NFA. |
I2 | Second NFA or DFA. |
is_dfa_I2 | True if the second input is a DFA, false if it is a NFA. |