Mescal
Loading...
Searching...
No Matches
words.h File Reference

Implementation of letters and words. More...

#include "alloc.h"
#include "tools.h"
#include "type_basic.h"
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  letter
 The type used to represent a letter. More...
 
struct  word
 The type used to represent a word. More...
 

Functions

uint length_letter_utf8 (letter)
 Computes the length of a letter when displayed in UTF8, including the subscript.
 
uint fprint_letter_utf8 (letter, FILE *)
 Displays a letter on a given stream: UTF8 version for the subscripts.
 
int sprint_letter_utf8 (letter, char *)
 Prints a letter in a given char array: UTF8 version for the subscripts.
 
void fprint_letter_gviz (letter, FILE *, bool)
 Displays a letter on a given stream: graphviz version for the subscript.
 
void fprint_letter_latex (letter, FILE *, bool)
 Displays a letter on a given stream: latex version for the subscripts.
 
int compare_letters (const void *, const void *)
 Comparison of two letters for sorting algorithms.
 
letterduplicate_alphabet (const letter *, uint)
 Creates a copy of an array of letters.
 
uint letter_index (letter l, const letter *alphabet, uint size_alphabet)
 Retrieves the index of a letter in an alphabet (sorted array of letters.
 
wordcreate_empty_word (void)
 Creation of an empty word.
 
void delete_word (word *)
 Release of a word.
 
uint size_word (const word *)
 Computes the length of a word.
 
bool isempty_word (const word *)
 Tests whether a word is empty.
 
void lefcon_word (letter, word *)
 Concatenates a letter to the left of a word.
 
void rigcon_word (letter, word *)
 Concatenates a letter to the right of a word.
 
letter lefread_word (const word *, uint)
 Reads a letter inside a word without removing it: left-right version.
 
letter rigread_word (const word *, uint)
 Reads a letter inside a word without removing it: right-left version.
 
letter lefpull_word (word *)
 Removes the leftmost letter of a word.
 
letter rigpull_word (word *)
 Removes the rightmost letter of a word.
 
void concatenate_word (word *, const word *)
 Concatenates two words into the left one.
 
void display_word (const word *, FILE *)
 Dislpays a word on a given stream (UTF8 is used for the subscripts of letters).
 
letterget_alphabet_word (const word *, uint *)
 Computes the set of letters occuring inside a word.
 

Detailed Description

Implementation of letters and words.

Function Documentation

◆ compare_letters()

int compare_letters ( const void * p1,
const void * p2 )

Comparison of two letters for sorting algorithms.

Returns
The comparison.
Parameters
p1The first letter.
p2The second letter.

◆ concatenate_word()

void concatenate_word ( word * l,
const word * r )

Concatenates two words into the left one.

Parameters
lThe left word (modified).
rThe right word (not modified).

◆ create_empty_word()

word * create_empty_word ( void )

Creation of an empty word.

Returns
An empty word.

◆ delete_word()

void delete_word ( word * p)

Release of a word.

Parameters
pThe word.

◆ display_word()

void display_word ( const word * w,
FILE * out )

Dislpays a word on a given stream (UTF8 is used for the subscripts of letters).

Parameters
wThe word.
outThe stream.

◆ duplicate_alphabet()

letter * duplicate_alphabet ( const letter * alph,
uint size )

Creates a copy of an array of letters.

Returns
A copy of the array of letters.
Parameters
alphThe array of letters.
sizeThe size of the array of letters.

◆ fprint_letter_gviz()

void fprint_letter_gviz ( letter l,
FILE * out,
bool inv )

Displays a letter on a given stream: graphviz version for the subscript.

Remarks
Includes an option for displaying an inverse power "-1" on the letter. This is used for the inverse transitions in NFAs.
Parameters
lThe letter.
outThe stream.
invTrue if an inverse power has to be displayed, false otherwise.

◆ fprint_letter_latex()

void fprint_letter_latex ( letter l,
FILE * out,
bool inv )

Displays a letter on a given stream: latex version for the subscripts.

Parameters
lThe letter.
outThe stream.
invTrue if an inverse power has to be displayed, false otherwise.

◆ fprint_letter_utf8()

uint fprint_letter_utf8 ( letter l,
FILE * out )

Displays a letter on a given stream: UTF8 version for the subscripts.

Returns
The on-screen length of the displayed letter.
Parameters
lThe letter.
outThe stream.

◆ get_alphabet_word()

letter * get_alphabet_word ( const word * w,
uint * l )

Computes the set of letters occuring inside a word.

Returns
An array containing all letters that occur in the word, without repetition. The length of this array is returned using the second parameter.
Parameters
wThe word.
lA pointer used to return the length of the computed array.

◆ isempty_word()

bool isempty_word ( const word * p)

Tests whether a word is empty.

Returns
. A Boolean indicating whether the word is empty.
Parameters
pThe word.

◆ lefcon_word()

void lefcon_word ( letter val,
word * p )

Concatenates a letter to the left of a word.

Parameters
valThe letter.
pThe word.

◆ lefpull_word()

letter lefpull_word ( word * p)

Removes the leftmost letter of a word.

Returns
The removed letter.
Parameters
pThe word.

◆ lefread_word()

letter lefread_word ( const word * p,
uint i )

Reads a letter inside a word without removing it: left-right version.

Remarks
The letters are indexed from left to right (the leftmost one has index 0).
Returns
The letter.
Parameters
pThe word.
iThe index.

◆ length_letter_utf8()

uint length_letter_utf8 ( letter l)

Computes the length of a letter when displayed in UTF8, including the subscript.

Returns
The length of the letter including its subscript.
Parameters
lThe letter.

◆ letter_index()

uint letter_index ( letter l,
const letter * alphabet,
uint size_alphabet )

Retrieves the index of a letter in an alphabet (sorted array of letters.

Remarks
If the letter does not belong to the alphabet the invalid index UINT_MAX is returned.
Returns
The index of the letter.
Parameters
lThe letter.
alphabetThe alphabet (sorted in increasing order).
size_alphabetThe size of the alphabet (number of letters).

◆ rigcon_word()

void rigcon_word ( letter val,
word * p )

Concatenates a letter to the right of a word.

Parameters
valThe letter.
pThe word.

◆ rigpull_word()

letter rigpull_word ( word * p)

Removes the rightmost letter of a word.

Returns
The removed letter.
Parameters
pThe word.

◆ rigread_word()

letter rigread_word ( const word * p,
uint i )

Reads a letter inside a word without removing it: right-left version.

Remarks
The letters are indexed from right to left (the righmost one has index 0).
Returns
The letter.
Parameters
pThe word.
iThe index.

◆ size_word()

uint size_word ( const word * p)

Computes the length of a word.

Returns
The length of the word.
Parameters
pThe word.

◆ sprint_letter_utf8()

int sprint_letter_utf8 ( letter l,
char * out )

Prints a letter in a given char array: UTF8 version for the subscripts.

Returns
The length of the displayed letter in bytes (generally larger than the on-screen length if there are UTF8 characters).
Parameters
lThe letter.
outThe string (must be large enough).