Mescal
Loading...
Searching...
No Matches
nfa.h
Go to the documentation of this file.
1
6
7#ifndef NFA_H_
8#define NFA_H_
9
10 /* _ _ _____ _ */
11 /* | \ | | ___/ \ */
12 /* | \| | |_ / _ \ */
13 /* | |\ | _/ ___ \ */
14 /* |_| \_|_|/_/ \_\ */
15
16#include "graphs.h"
17#include "graphs_transclos.h"
18#include "type_abr.h"
19#include "type_basic.h"
20#include "type_binheap.h"
21#include "type_boolarray.h"
22#include "type_dequeue.h"
23#include "words.h"
24#include <stdarg.h>
25#include <stdbool.h>
26#include <stdio.h>
27#include <stdlib.h>
28
29
30
43typedef struct {
44 /* Mandatory */
49
50 /* Optional */
53 char** state_names;
54} nfa;
55
56
61typedef struct {
62 /* Mandatory */
64 uint initial;
65 uint nb_finals;
66 uint* finals;
68
69 /* Optional */
70 char** state_names;
71 bool** order;
72} dfa;
73
74/*****************/
75/*+ State names +*/
76/*****************/
77
85void nfa_print_state(const nfa*,
86 uint,
87 FILE*
88);
89
97void dfa_print_state(const dfa*,
98 uint,
99 FILE*
100);
101
106void nfa_reset_state_names(nfa* // The NFA.
107);
108
114);
115
124char** copy_all_names(char** names,
125 uint size
126);
127
128/**********************/
129/*+ Copy and release +*/
130/**********************/
131
136void nfa_delete(nfa*
137);
138
143void dfa_delete(dfa* A
144);
145
146
155);
156
164dfa* dfa_copy(dfa* A
165);
166
183 letter*,
184 uint
185);
186
199 letter* alpha,
200 uint size
201);
202
207void nfa_overwrite(nfa*,
208 nfa*
209);
210
211/**************************************************************/
212/*+ Computation of basic NFAs (used in Thompson's algorithm) +*/
213/**************************************************************/
214
225nfa* create_emptylang(void);
226
238
251);
252
265);
266
267/*******************************/
268/*+ Simple operations on NFAs +*/
269/*******************************/
270
271
283nfa* nfa_union(void* I1,
284 bool is_dfa_I1,
285 void* I2,
286 bool is_dfa_I2
287);
288
300nfa* nfa_concat(void* I1,
301 bool is_dfa_I1,
302 void* I2,
303 bool is_dfa_I2
304);
305
314);
315
316
325);
326
335);
336
345);
346
355);
356
365);
366
371void nfa_elimeps_mod(nfa*
372);
373
383);
384
392dfa* dfa_trim(dfa* A
393);
394
400void nfa_trim_mod(nfa*
401);
402
403
405 dfa* B
406);
407
408/***********************************/
409/*+ Generation of random automata +*/
410/***********************************/
411
419nfa* nfa_random(uint,
420 uint,
421 uint
422);
423
431dfa* dfa_random(uint,
432 uint,
433 uint
434);
435
436
437/*****************/
438/*+ Information +*/
439/*****************/
440
448int nfa_nb_trans(nfa*
449);
450
458bool nfa_is_det(nfa*
459);
460
468bool nfa_is_comp(nfa*
469);
470
478bool nfa_is_empty(nfa*
479);
480
488bool nfa_accepts(nfa*,
489 word*
490);
491
500 word*
501);
502
503
514bool dfa_exists_path(dfa*,
515 uint,
516 uint,
517 bool*
518);
519
528uint dfa_compute_run(dfa* A,
529 word* w
530);
531
532
533
534
535
536
537
538
539/************************/
540/* Partitions of states */
541/************************/
542
558 parti*
559);
560
561
562
563/****************/
564/*+ Conversion +*/
565/****************/
566
581);
582
590nfa* dfa_to_nfa(dfa* A
591);
592
600nfa* dfa_to_nfa_exalpha(dfa* A, letter* alpha, uint size);
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615#endif // NFA_H_
Implementation of graphs.
Computation of transitive closures in graphs.
nfa * create_emptylang(void)
Computes a NFA recognizing the empty language.
Definition nfa.c:400
bool nfa_accepts(nfa *, word *)
Tests if a word is accepted by a NFA.
Definition nfa.c:1359
nfa * create_sing_letter(letter)
Computes a NFA recognizing a singleton language {a} containing a single letter word.
Definition nfa.c:420
nfa * dfa_star(dfa *)
Kleene star of a DFA.
Definition nfa.c:682
nfa * nfa_plus(nfa *)
Kleene plus of a NFA.
Definition nfa.c:715
nfa * nfa_concat(void *I1, bool is_dfa_I1, void *I2, bool is_dfa_I2)
Concatenation of two NFAs.
Definition nfa.c:566
bool dfa_exists_path(dfa *, uint, uint, bool *)
Checks if there exists a path between two states in a DFA.
Definition nfa.c:1398
nfa * nfa_merge_states(nfa *, parti *)
Merges the states of a NFA according to the partition given as input.
Definition nfa.c:1455
dfa * dfa_direct_product(dfa *A, dfa *B)
Definition nfa.c:1124
nfa * nfa_random(uint, uint, uint)
Generates a random NFA.
Definition nfa.c:1190
int nfa_nb_trans(nfa *)
Computes the number of transitions in a NFA.
Definition nfa.c:1314
nfa * nfa_copy_exalpha(nfa *, letter *, uint)
Copies an NFA with an extended alphabet.
Definition nfa.c:249
void nfa_trim_mod(nfa *)
Elimination of all states that are not simultaneously reachable from an initial state and co-reachabl...
Definition nfa.c:1036
dfa * dfa_copy(dfa *A)
Copies a DFA.
Definition nfa.c:167
void dfa_print_state(const dfa *, uint, FILE *)
Displays the name of a state in a DFA on a given stream.
Definition nfa.c:29
void nfa_reset_state_names(nfa *)
Release the state names in a NFA (if there are states names).
Definition nfa.c:41
nfa * create_sing_epsilon(void)
Computes a NFA recognizing the singleton language {ε}.
Definition nfa.c:409
void nfa_overwrite(nfa *, nfa *)
Overwrites a NFA by copying another NFA and releasing this other NFA.
Definition nfa.c:365
void dfa_reset_state_names(dfa *A)
Release the state names in a DFA (if there are states names).
Definition nfa.c:54
bool nfa_is_empty(nfa *)
Tests if a NFA recognizes the empty language.
Definition nfa.c:1352
bool nfa_is_det(nfa *)
Tests if a NFA is deterministic.
Definition nfa.c:1324
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.
Definition nfa.c:501
dfa * dfa_copy_exalpha(dfa *A, letter *alpha, uint size)
Copies a DFA with an extended alphabet.
Definition nfa.c:305
nfa * nfa_star(nfa *)
Kleene star of a NFA.
Definition nfa.c:632
nfa * dfa_to_nfa_exalpha(dfa *A, letter *alpha, uint size)
Converts a DFA into a NFA with an extended alphabet.
Definition nfa.c:1639
void nfa_delete(nfa *)
Release of a NFA.
Definition nfa.c:85
nfa * nfa_mirror(nfa *)
Mirror of a NFA.
Definition nfa.c:764
dfa * dfa_trim(dfa *A)
Removes all non-accessible states from a DFA.
Definition nfa.c:961
void dfa_delete(dfa *A)
Deletes a DFA.
Definition nfa.c:114
nfa * dfa_mirror(dfa *)
Mirror of a DFA.
Definition nfa.c:788
nfa * dfa_to_nfa(dfa *A)
Converts a DFA into a NFA.
Definition nfa.c:1593
bool nfa_is_comp(nfa *)
Tests if a NFA is complete.
Definition nfa.c:1338
dfa * dfa_random(uint, uint, uint)
Generates a random DFA.
Definition nfa.c:1249
dequeue * nfa_compute_runs(nfa *, word *)
Computes the set of states reached by a word in a NFA.
Definition nfa.c:1370
void nfa_print_state(const nfa *, uint, FILE *)
Displays the name of a state in a NFA on a given stream.
Definition nfa.c:16
nfa * nfa_elimeps(nfa *)
Elimination of the epsilon transitions in a NFA.
Definition nfa.c:1042
dfa * detnfa_to_dfa(nfa *A)
Converts a NFA which is deterministic into the complete DFA representation.
Definition nfa.c:1552
nfa * nfa_trim(nfa *)
Elimination of all states that are not simultaneously reachable from an initial state and co-reachabl...
Definition nfa.c:815
void nfa_elimeps_mod(nfa *)
Elimination of the epsilon transitions in a NFA. Overwrites the input NFA.
Definition nfa.c:1117
char ** copy_all_names(char **names, uint size)
Returns a copy of the array of state names.
Definition nfa.c:66
nfa * nfa_copy(nfa *)
Copy of a NFA.
Definition nfa.c:132
uint dfa_compute_run(dfa *A, word *w)
Computes the run of a DFA on a word.
Definition nfa.c:1434
nfa * create_sing_word(word *)
Computes a NFA recognizing a singleton language {w} for some input word w.
Definition nfa.c:434
Type used to represent a dequeue of unsigned integers.
Definition type_dequeue.h:26
Type used to represent a complete DFA.
Definition nfa.h:61
char ** state_names
Array of state names (only utilized when displaying the DFA). Each state is mapped to its name (NULL ...
Definition nfa.h:70
uint * finals
Array of final states (sorted in increasing order).
Definition nfa.h:66
letter * alphabet
Array indexed by the indices of letters. Maps each index to its actual letter (NULL if the alphabet i...
Definition nfa.h:67
uint initial
The index of the initial state.
Definition nfa.h:64
bool ** order
The canonical order of the states (NULL if not used). The order is defined by the indices of the stat...
Definition nfa.h:71
uint nb_finals
Number of final states.
Definition nfa.h:65
dgraph * trans
Graph of transitions (also stores the number of states and the size of the alphabet)....
Definition nfa.h:63
Type used to represent a complete deterministic directed labeled graph.
Definition graphs.h:73
Type used to represent a directed unlabeled graph.
Definition graphs.h:42
The type used to represent a letter.
Definition words.h:33
Type used to represent a directed labeled graph.
Definition graphs.h:57
Type used to represent a NFA.
Definition nfa.h:43
lgraph * trans_i
Graph of inverse transitions (NULL if there are no such transitions).
Definition nfa.h:52
lgraph * trans
Graph of transitions (also stores the number of states and the size of the alphabet).
Definition nfa.h:45
char ** state_names
Array of state names (only utilized when displaying the NFA). Each state is mapped to its name (NULL ...
Definition nfa.h:53
dequeue * initials
The list of initial states (sorted in increasing order).
Definition nfa.h:46
graph * trans_e
Graph of espilon transitions (NULL if there are no such transitions).
Definition nfa.h:51
letter * alphabet
Array indexed by the indices of letters. Maps each index to its actual letter (NULL if the alphabet i...
Definition nfa.h:48
dequeue * finals
The list of final states (sorted in increasing order).
Definition nfa.h:47
First type used to represent a partition. This is not the one used by Union-Find.
Definition type_partitions.h:36
The type used to represent a word.
Definition words.h:143
Implementation of AVLs for representing sets of objects.
Basic types.
Implementation of generic binary heaps.
Implementation of Boolean arrays.
Implementation of dequeues of unsigned integers.
Implementation of letters and words.