Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
Finite State Machines

Description


  Base support for FSMs.
Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2019
Collaboration diagram for Finite State Machines:

Classes

class  elementa::adts::BaseFSM
 Common functionality for any FSM. More...
 
class  elementa::adts::FSM< Obs >
 Base interface for FSMs with a given observation type. More...
 
class  elementa::adts::BaseTextFSM
 Shortcut for FSMs that work with chars. More...
 
class  elementa::adts::CharFSM
 A FSM that recognizes only a given character. More...
 
class  elementa::adts::SeparatorsFSM
 A FSM that recognizes sequences of separator characters. More...
 
class  elementa::adts::IdentifierFSM
 A FSM that recognizes a standard identifier in text. More...
 
class  elementa::adts::KeywordFSM
 A FSM that recognizes some fixed, short (shorter than 255 chars) string. More...
 
class  elementa::adts::CommentsFSM
 A FSM that recognizes uni- or multi-line comments. More...
 
class  elementa::adts::IntegerTextFSM
 A FSM that recognizes an integer number from text. More...
 
class  elementa::adts::NumberTextFSM
 A FSM that recognizes a real or integer number from a decimal text. More...
 

Class Documentation

◆ elementa::adts::BaseFSM

class elementa::adts::BaseFSM

Common functionality for any FSM.

A FSM is formally a directed graph where there is an initial ("reset") edge from no specified vertex, and some ending vertices. Each edge recognizes some observation(s), and may lead to the same vertex or to another. Even while being in an ending vertex, there may be edges that continue recognizing observations, or that lead to a non-ending vertex.

Note
- Do not derive from this class to implement the virtual methods; use the FSM<> template instead.
See also
FSM.

Definition at line 66 of file fsms.h.

Inheritance diagram for elementa::adts::BaseFSM:

Public Types

Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

Constructors
virtual ~BaseFSM (void)=default
 Just for polymorphic deletions.
 
Methods
virtual bool atEnd (void) const =0
 Must return TRUE if the current state is an absorbing/final one. More...
 
virtual void reset (void)=0
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 
virtual std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 

Member Typedef Documentation

◆ Num

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Member Function Documentation

◆ atEnd()

virtual bool elementa::adts::BaseFSM::atEnd ( void  ) const
pure virtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implemented in elementa::adts::CharFSM, elementa::adts::SeparatorsFSM, elementa::adts::IdentifierFSM, elementa::adts::KeywordFSM, elementa::adts::CommentsFSM, elementa::adts::IntegerTextFSM, and elementa::adts::NumberTextFSM.

Referenced by resetCheck(), and to_string().

◆ reset()

virtual void elementa::adts::BaseFSM::reset ( void  )
pure virtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implemented in elementa::adts::CharFSM, elementa::adts::SeparatorsFSM, elementa::adts::IdentifierFSM, elementa::adts::KeywordFSM, elementa::adts::CommentsFSM, elementa::adts::IntegerTextFSM, and elementa::adts::NumberTextFSM.

Referenced by resetCheck().

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inline

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References atEnd(), ELE_CODE_INVSTATE, reset(), and to_string().

◆ to_string()

◆ elementa::adts::FSM

class elementa::adts::FSM
template<typename Obs = char>
class elementa::adts::FSM< Obs >

Base interface for FSMs with a given observation type.

Template Parameters
Obsis the type of the observations that the machine reads. It must be a simple type.
See also
ShortWordFSM.

Definition at line 137 of file fsms.h.

Inheritance diagram for elementa::adts::FSM< Obs >:
Collaboration diagram for elementa::adts::FSM< Obs >:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
virtual bool atEnd (void) const =0
 Must return TRUE if the current state is an absorbing/final one. More...
 
virtual void reset (void)=0
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 
virtual std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Member Function Documentation

◆ consume()

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtual

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ atEnd()

virtual bool elementa::adts::BaseFSM::atEnd ( void  ) const
pure virtualinherited

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implemented in elementa::adts::CharFSM, elementa::adts::SeparatorsFSM, elementa::adts::IdentifierFSM, elementa::adts::KeywordFSM, elementa::adts::CommentsFSM, elementa::adts::IntegerTextFSM, and elementa::adts::NumberTextFSM.

Referenced by elementa::adts::BaseFSM::resetCheck(), and elementa::adts::BaseFSM::to_string().

◆ reset()

virtual void elementa::adts::BaseFSM::reset ( void  )
pure virtualinherited

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implemented in elementa::adts::CharFSM, elementa::adts::SeparatorsFSM, elementa::adts::IdentifierFSM, elementa::adts::KeywordFSM, elementa::adts::CommentsFSM, elementa::adts::IntegerTextFSM, and elementa::adts::NumberTextFSM.

Referenced by elementa::adts::BaseFSM::resetCheck().

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ to_string()

◆ elementa::adts::BaseTextFSM

class elementa::adts::BaseTextFSM

Shortcut for FSMs that work with chars.

Definition at line 159 of file fsms.h.

Inheritance diagram for elementa::adts::BaseTextFSM:
Collaboration diagram for elementa::adts::BaseTextFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 BaseTextFSM (bool casesensitive=true)
 Constructor. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
virtual bool atEnd (void) const =0
 Must return TRUE if the current state is an absorbing/final one. More...
 
virtual void reset (void)=0
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 
virtual std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ BaseTextFSM()

elementa::adts::BaseTextFSM::BaseTextFSM ( bool  casesensitive = true)
inline

Constructor.

Parameters
casesensitiveis a flag available to derived classes, that should use it adequately when feeding with observations coming from the input channel (for instance, using the caseChar() method).

Definition at line 167 of file fsms.h.

Member Function Documentation

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotected

Definition at line 172 of file fsms.h.

◆ consume()

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ atEnd()

virtual bool elementa::adts::BaseFSM::atEnd ( void  ) const
pure virtualinherited

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implemented in elementa::adts::CharFSM, elementa::adts::SeparatorsFSM, elementa::adts::IdentifierFSM, elementa::adts::KeywordFSM, elementa::adts::CommentsFSM, elementa::adts::IntegerTextFSM, and elementa::adts::NumberTextFSM.

Referenced by elementa::adts::BaseFSM::resetCheck(), and elementa::adts::BaseFSM::to_string().

◆ reset()

virtual void elementa::adts::BaseFSM::reset ( void  )
pure virtualinherited

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implemented in elementa::adts::CharFSM, elementa::adts::SeparatorsFSM, elementa::adts::IdentifierFSM, elementa::adts::KeywordFSM, elementa::adts::CommentsFSM, elementa::adts::IntegerTextFSM, and elementa::adts::NumberTextFSM.

Referenced by elementa::adts::BaseFSM::resetCheck().

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ to_string()

◆ elementa::adts::CharFSM

class elementa::adts::CharFSM

A FSM that recognizes only a given character.

Definition at line 192 of file fsms.h.

Inheritance diagram for elementa::adts::CharFSM:
Collaboration diagram for elementa::adts::CharFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 CharFSM (char c)
 Constructor. More...
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
char character (void) const noexcept
 Return the character this fsm is able to recognize. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ CharFSM()

elementa::adts::CharFSM::CharFSM ( char  c)
inline

Constructor.

Parameters
cis the character to recognize.

Definition at line 198 of file fsms.h.

References reset().

Member Function Documentation

◆ reset()

void elementa::adts::CharFSM::reset ( void  )
inlinevirtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 200 of file fsms.h.

Referenced by CharFSM().

◆ atEnd()

bool elementa::adts::CharFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 201 of file fsms.h.

◆ consume() [1/2]

bool elementa::adts::CharFSM::consume ( char  o)
inline

Definition at line 203 of file fsms.h.

◆ character()

char elementa::adts::CharFSM::character ( void  ) const
inlinenoexcept

Return the character this fsm is able to recognize.

Definition at line 207 of file fsms.h.

◆ to_string()

std::string elementa::adts::CharFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 209 of file fsms.h.

References elementa::adts::BaseFSM::to_string().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume() [2/2]

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ elementa::adts::SeparatorsFSM

class elementa::adts::SeparatorsFSM

A FSM that recognizes sequences of separator characters.

This FSM consumes observations while they correspond to separators. Reaches end states whenever a separator is consumed.

See also
FSM.

Definition at line 230 of file fsms.h.

Inheritance diagram for elementa::adts::SeparatorsFSM:
Collaboration diagram for elementa::adts::SeparatorsFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 SeparatorsFSM (const std::string &seps="\n\t \f\r\v\x00")
 Constructor. More...
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
const std::string & separators (void) const noexcept
 Return a reference to the separators this fsm is able to recognize. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ SeparatorsFSM()

elementa::adts::SeparatorsFSM::SeparatorsFSM ( const std::string &  seps = "\n\t \f\r\v\x00")
inline

Constructor.

Parameters
sepsare the characters that will be recognized as separators.

Definition at line 236 of file fsms.h.

References reset().

Member Function Documentation

◆ reset()

void elementa::adts::SeparatorsFSM::reset ( void  )
inlinevirtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 239 of file fsms.h.

Referenced by SeparatorsFSM().

◆ atEnd()

bool elementa::adts::SeparatorsFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 240 of file fsms.h.

◆ consume() [1/2]

bool elementa::adts::SeparatorsFSM::consume ( char  o)
inline

Definition at line 242 of file fsms.h.

◆ separators()

const std::string & elementa::adts::SeparatorsFSM::separators ( void  ) const
inlinenoexcept

Return a reference to the separators this fsm is able to recognize.

Definition at line 248 of file fsms.h.

◆ to_string()

std::string elementa::adts::SeparatorsFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 251 of file fsms.h.

References elementa::adts::BaseFSM::to_string().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume() [2/2]

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ elementa::adts::IdentifierFSM

class elementa::adts::IdentifierFSM

A FSM that recognizes a standard identifier in text.

This FSM consumes observations while they correspond to the identifier. Reaches end states whenever the already consumed observations form a valid identifier. A standard identifier may being with a letter or an underscore, and follows with letters, digits or underscores.

See also
FSM, KeywordFSM.

Definition at line 275 of file fsms.h.

Inheritance diagram for elementa::adts::IdentifierFSM:
Collaboration diagram for elementa::adts::IdentifierFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 IdentifierFSM (void)
 Constructor. *‍/. More...
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ IdentifierFSM()

elementa::adts::IdentifierFSM::IdentifierFSM ( void  )
inline

Constructor. *‍/.

Definition at line 280 of file fsms.h.

References reset().

Member Function Documentation

◆ atEnd()

bool elementa::adts::IdentifierFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 282 of file fsms.h.

◆ reset()

void elementa::adts::IdentifierFSM::reset ( void  )
inlinevirtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 284 of file fsms.h.

Referenced by IdentifierFSM().

◆ to_string()

std::string elementa::adts::IdentifierFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 286 of file fsms.h.

References elementa::adts::BaseFSM::to_string().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume()

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ elementa::adts::KeywordFSM

class elementa::adts::KeywordFSM

A FSM that recognizes some fixed, short (shorter than 255 chars) string.

In this FSM, the end state is reached only when the entire word has been consumed and nothing else can be consumed further. If an observation comes that cannot be consumed in the current state, that does not lead to an end state.

See also
FSM, IdentifierFSM.

Definition at line 316 of file fsms.h.

Inheritance diagram for elementa::adts::KeywordFSM:
Collaboration diagram for elementa::adts::KeywordFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 KeywordFSM (const std::string &word, bool casesens=true)
 Constructor from the word. That word is copied inside. More...
 
 KeywordFSM (const KeywordFSM &o)
 
KeywordFSMoperator= (const KeywordFSM &o)
 
 KeywordFSM (KeywordFSM &&o)=delete
 
KeywordFSMoperator= (KeywordFSM &&o)=delete
 
 ~KeywordFSM (void)
 Destructor. More...
 
std::string word (void) const
 Getter for the word. More...
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ KeywordFSM() [1/2]

elementa::adts::KeywordFSM::KeywordFSM ( const std::string &  word,
bool  casesens = true 
)

Constructor from the word. That word is copied inside.

The word can be empty, but it must be shorter than 255 chars.

◆ KeywordFSM() [2/2]

elementa::adts::KeywordFSM::KeywordFSM ( const KeywordFSM o)
inline

Definition at line 324 of file fsms.h.

◆ ~KeywordFSM()

elementa::adts::KeywordFSM::~KeywordFSM ( void  )
inline

Destructor.

Definition at line 331 of file fsms.h.

Member Function Documentation

◆ operator=()

KeywordFSM & elementa::adts::KeywordFSM::operator= ( const KeywordFSM o)
inline

Definition at line 325 of file fsms.h.

◆ word()

std::string elementa::adts::KeywordFSM::word ( void  ) const
inline

Getter for the word.

Definition at line 334 of file fsms.h.

Referenced by to_string().

◆ atEnd()

bool elementa::adts::KeywordFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 336 of file fsms.h.

◆ consume() [1/2]

bool elementa::adts::KeywordFSM::consume ( char  o)
inline

Definition at line 337 of file fsms.h.

◆ reset()

void elementa::adts::KeywordFSM::reset ( void  )
inlinevirtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 341 of file fsms.h.

◆ to_string()

std::string elementa::adts::KeywordFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 343 of file fsms.h.

References elementa::adts::BaseFSM::to_string(), and word().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume() [2/2]

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ elementa::adts::CommentsFSM

class elementa::adts::CommentsFSM

A FSM that recognizes uni- or multi-line comments.

This FSM consumes observations while they are in a comment. Reaches end state whenever the comment is finished.

See also
FSM.

Definition at line 375 of file fsms.h.

Inheritance diagram for elementa::adts::CommentsFSM:
Collaboration diagram for elementa::adts::CommentsFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 CommentsFSM (const std::string &commstart="/*", const std::string &commend="*/")
 Constructor. More...
 
 CommentsFSM (const CommentsFSM &)=delete
 
 CommentsFSM (CommentsFSM &&)=delete
 
CommentsFSMoperator= (const CommentsFSM &)=delete
 
CommentsFSMoperator= (CommentsFSM &&)=delete
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
std::string beginText (void) const
 Return the start text for comments. More...
 
std::string endText (void) const
 Return the end text for comments. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ CommentsFSM()

elementa::adts::CommentsFSM::CommentsFSM ( const std::string &  commstart = "/*",
const std::string &  commend = "*/" 
)

Constructor.

Parameters
commstartis the sequence of characters that begin the comment.
commendis the sequence of characters that end the comment.

◆ ~CommentsFSM()

elementa::adts::CommentsFSM::~CommentsFSM ( void  )
inline

Definition at line 390 of file fsms.h.

Member Function Documentation

◆ reset()

void elementa::adts::CommentsFSM::reset ( void  )
inlinevirtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 392 of file fsms.h.

◆ atEnd()

bool elementa::adts::CommentsFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 393 of file fsms.h.

◆ beginText()

std::string elementa::adts::CommentsFSM::beginText ( void  ) const
inline

Return the start text for comments.

Definition at line 398 of file fsms.h.

◆ endText()

std::string elementa::adts::CommentsFSM::endText ( void  ) const
inline

Return the end text for comments.

Definition at line 402 of file fsms.h.

◆ to_string()

std::string elementa::adts::CommentsFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 405 of file fsms.h.

References elementa::adts::BaseFSM::to_string().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume()

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ elementa::adts::IntegerTextFSM

class elementa::adts::IntegerTextFSM

A FSM that recognizes an integer number from text.

This FSM consumes observations while they correspond to the number. Reaches end states whenever the alreay consumed observations form a valid number. It can go to a non-ending state after being in an ending state.

See also
FSM, NumberTextFSM.

Definition at line 429 of file fsms.h.

Inheritance diagram for elementa::adts::IntegerTextFSM:
Collaboration diagram for elementa::adts::IntegerTextFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 ELE_CLASS_ENUM (Kind, kDec, kHex, kOct, kBin)
 Kinds of number that can be recognized.
 
 IntegerTextFSM (Kind kind=Kind::kDec, bool withsign=true)
 Constructor. More...
 
 IntegerTextFSM (const IntegerTextFSM &o)
 
 IntegerTextFSM (IntegerTextFSM &&o)
 
IntegerTextFSMoperator= (const IntegerTextFSM &o)
 
IntegerTextFSMoperator= (IntegerTextFSM &&o)
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ IntegerTextFSM() [1/3]

elementa::adts::IntegerTextFSM::IntegerTextFSM ( Kind  kind = Kind::kDec,
bool  withsign = true 
)
inline

Constructor.

Parameters
withsignsets whether we wish to recognize an initial sign or not. It is valid for any kind of number.

Definition at line 443 of file fsms.h.

References reset().

◆ IntegerTextFSM() [2/3]

elementa::adts::IntegerTextFSM::IntegerTextFSM ( const IntegerTextFSM o)
inline

Definition at line 447 of file fsms.h.

◆ IntegerTextFSM() [3/3]

elementa::adts::IntegerTextFSM::IntegerTextFSM ( IntegerTextFSM &&  o)
inline

Definition at line 448 of file fsms.h.

Member Function Documentation

◆ operator=() [1/2]

IntegerTextFSM & elementa::adts::IntegerTextFSM::operator= ( const IntegerTextFSM o)
inline

Definition at line 449 of file fsms.h.

◆ operator=() [2/2]

IntegerTextFSM & elementa::adts::IntegerTextFSM::operator= ( IntegerTextFSM &&  o)
inline

Definition at line 451 of file fsms.h.

◆ atEnd()

bool elementa::adts::IntegerTextFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 454 of file fsms.h.

◆ reset()

void elementa::adts::IntegerTextFSM::reset ( void  )
virtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Referenced by IntegerTextFSM().

◆ to_string()

std::string elementa::adts::IntegerTextFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 458 of file fsms.h.

References elementa::adts::BaseFSM::to_string().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume()

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().

◆ elementa::adts::NumberTextFSM

class elementa::adts::NumberTextFSM

A FSM that recognizes a real or integer number from a decimal text.

This FSM consumes observations while they correspond to the number. Reaches end states whenever the alreay consumed observations form a valid number. It can go to a non-ending state after being in an ending state.

Note
- This FSM also recognizes integerss.
See also
FSM, IntegerTextFSM.

Definition at line 490 of file fsms.h.

Inheritance diagram for elementa::adts::NumberTextFSM:
Collaboration diagram for elementa::adts::NumberTextFSM:

Public Types

using Ptr = std::shared_ptr< FSM >
 Pointer to a FSM that consumes observations of type Obs. More...
 
Types, consts, etc.
using Num = size_t
 To represent a number of FSMs. More...
 

Public Member Functions

 NumberTextFSM (void)
 Constructor. More...
 
 NumberTextFSM (const NumberTextFSM &o)
 
 NumberTextFSM (NumberTextFSM &&o)
 
NumberTextFSMoperator= (const NumberTextFSM &o)
 
NumberTextFSMoperator= (NumberTextFSM &&o)
 
bool atEnd (void) const
 Must return TRUE if the current state is an absorbing/final one. More...
 
bool consume (char o)
 
void reset (void)
 Must set the FSM to a preliminary state when it has not been fed yet. More...
 
std::string to_string (void) const
 Return a text representation of the FSM. Can be overriden. More...
 
virtual bool consume (Obs o)=0
 Must consume the given observation and change state if necessary. More...
 
Methods
void resetCheck (void)
 Reset checking the post-condition that the FSM does not go to an ending. More...
 

Protected Member Functions

char caseChar (char c)
 

Member Typedef Documentation

◆ Ptr

template<typename Obs = char>
using elementa::adts::FSM< Obs >::Ptr = std::shared_ptr<FSM>
inherited

Pointer to a FSM that consumes observations of type Obs.

Definition at line 142 of file fsms.h.

◆ Num

using elementa::adts::BaseFSM::Num = size_t
inherited

To represent a number of FSMs.

Definition at line 74 of file fsms.h.

Constructor & Destructor Documentation

◆ NumberTextFSM() [1/3]

elementa::adts::NumberTextFSM::NumberTextFSM ( void  )
inline

Constructor.

Definition at line 495 of file fsms.h.

References reset().

◆ NumberTextFSM() [2/3]

elementa::adts::NumberTextFSM::NumberTextFSM ( const NumberTextFSM o)
inline

Definition at line 497 of file fsms.h.

◆ NumberTextFSM() [3/3]

elementa::adts::NumberTextFSM::NumberTextFSM ( NumberTextFSM &&  o)
inline

Definition at line 498 of file fsms.h.

Member Function Documentation

◆ operator=() [1/2]

NumberTextFSM & elementa::adts::NumberTextFSM::operator= ( const NumberTextFSM o)
inline

Definition at line 499 of file fsms.h.

◆ operator=() [2/2]

NumberTextFSM & elementa::adts::NumberTextFSM::operator= ( NumberTextFSM &&  o)
inline

Definition at line 501 of file fsms.h.

◆ atEnd()

bool elementa::adts::NumberTextFSM::atEnd ( void  ) const
inlinevirtual

Must return TRUE if the current state is an absorbing/final one.

After a reset, the fsm must not be in an ending state.

Note
- Some FSMs can change from ending state to non-ending state or vice versa while consuming obsrevations, and that is ok.
See also
resetCheck()

Implements elementa::adts::BaseFSM.

Definition at line 504 of file fsms.h.

◆ reset()

void elementa::adts::NumberTextFSM::reset ( void  )
virtual

Must set the FSM to a preliminary state when it has not been fed yet.

Therefore, after this method, atEnd() must return FALSE. This method should be called from the constructors of derived FSMs to prepare them for reading observations.

See also
resetCheck()

Implements elementa::adts::BaseFSM.

Referenced by NumberTextFSM().

◆ to_string()

std::string elementa::adts::NumberTextFSM::to_string ( void  ) const
inlinevirtual

Return a text representation of the FSM. Can be overriden.

Reimplemented from elementa::adts::BaseFSM.

Definition at line 508 of file fsms.h.

References elementa::adts::BaseFSM::to_string().

◆ caseChar()

char elementa::adts::BaseTextFSM::caseChar ( char  c)
inlineprotectedinherited

Definition at line 172 of file fsms.h.

◆ consume()

template<typename Obs = char>
virtual bool elementa::adts::FSM< Obs >::consume ( Obs  o)
pure virtualinherited

Must consume the given observation and change state if necessary.

Must return TRUE if the observation can be consumed in the current state, either changing state or not. Must do nothing and return FALSE if it cannot consume that observation (it may change to end state if it is not there already).

◆ resetCheck()

void elementa::adts::BaseFSM::resetCheck ( void  )
inlineinherited

Reset checking the post-condition that the FSM does not go to an ending.

See also
reset(), atEnd().

Definition at line 107 of file fsms.h.

References elementa::adts::BaseFSM::atEnd(), ELE_CODE_INVSTATE, elementa::adts::BaseFSM::reset(), and elementa::adts::BaseFSM::to_string().