Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
General parsing of expressions

Description


  General parsing of expressions for diverse programming languages.
See also
General parsing of context-free grammars
Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2019-2023
Collaboration diagram for General parsing of expressions:

Classes

class  elementa::parsing::ExprElement
 An element within an expression. Elements are data, operations or groupings. More...
 
class  elementa::parsing::ExprSimpleGroupOpen
 A simple group-open expression element. More...
 
class  elementa::parsing::ExprSimpleGroupClose
 A simple group-close expression element. More...
 
class  elementa::parsing::ExprSimpleArgsOpen
 A simple args-open expression element. More...
 
class  elementa::parsing::ExprSimpleArgsClose
 A simple args-close expression element. More...
 
class  elementa::parsing::ExprSimpleArgsSep
 A simple args-separator expression element. More...
 
class  elementa::parsing::ExprOperElement
 An element within an expression that is an operation with a fixed arity. More...
 
class  elementa::parsing::ExprOperNop
 An operation that takes no arguments and does nothing. More...
 
class  elementa::parsing::Expression
 A general expression composed of a number of elements of type Element. More...
 

Class Documentation

◆ elementa::parsing::ExprElement

class elementa::parsing::ExprElement

An element within an expression. Elements are data, operations or groupings.

You must derive your expression data directly from this class; your groupings must derive from the special classes below; operations must derive from ExprOperElement.

See also
ExprOperElement, Expression.

Definition at line 60 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprElement:

Public Member Functions

Constructors
virtual ~ExprElement (void)=default
 Just for polymorphic deletions.
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual Kind kind (void) const =0
 Must return the kind of the element: datum, grouping or operation. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 
 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 

Member Typedef Documentation

◆ Ptr

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexcept

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References kind().

Referenced by isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexcept

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexcept

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References kind().

Referenced by isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexcept

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References kind().

Referenced by isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexcept

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References isClosingGrouping(), and isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexcept

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References kind().

Referenced by isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexcept

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References kind().

Referenced by isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexcept

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References isClosingArgs(), and isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexcept

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexcept

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References isDatum(), and type().

◆ kind()

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtual

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtual

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprSimpleGroupOpen

class elementa::parsing::ExprSimpleGroupOpen

A simple group-open expression element.

Definition at line 169 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprSimpleGroupOpen:
Collaboration diagram for elementa::parsing::ExprSimpleGroupOpen:

Public Member Functions

Kind kind (void) const
 Must return the kind of the element: datum, grouping or operation. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 
using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 

Member Typedef Documentation

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ kind()

Kind elementa::parsing::ExprSimpleGroupOpen::kind ( void  ) const
inlinevirtual

Must return the kind of the element: datum, grouping or operation.

Implements elementa::parsing::ExprElement.

Definition at line 173 of file expressions.h.

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtualinherited

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprSimpleGroupClose

class elementa::parsing::ExprSimpleGroupClose

A simple group-close expression element.

Definition at line 178 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprSimpleGroupClose:
Collaboration diagram for elementa::parsing::ExprSimpleGroupClose:

Public Member Functions

Kind kind (void) const
 Must return the kind of the element: datum, grouping or operation. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 
using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 

Member Typedef Documentation

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ kind()

Kind elementa::parsing::ExprSimpleGroupClose::kind ( void  ) const
inlinevirtual

Must return the kind of the element: datum, grouping or operation.

Implements elementa::parsing::ExprElement.

Definition at line 182 of file expressions.h.

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtualinherited

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprSimpleArgsOpen

class elementa::parsing::ExprSimpleArgsOpen

A simple args-open expression element.

Definition at line 186 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprSimpleArgsOpen:
Collaboration diagram for elementa::parsing::ExprSimpleArgsOpen:

Public Member Functions

Kind kind (void) const
 Must return the kind of the element: datum, grouping or operation. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 
using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 

Member Typedef Documentation

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ kind()

Kind elementa::parsing::ExprSimpleArgsOpen::kind ( void  ) const
inlinevirtual

Must return the kind of the element: datum, grouping or operation.

Implements elementa::parsing::ExprElement.

Definition at line 190 of file expressions.h.

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtualinherited

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprSimpleArgsClose

class elementa::parsing::ExprSimpleArgsClose

A simple args-close expression element.

Definition at line 194 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprSimpleArgsClose:
Collaboration diagram for elementa::parsing::ExprSimpleArgsClose:

Public Member Functions

Kind kind (void) const
 Must return the kind of the element: datum, grouping or operation. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 
using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 

Member Typedef Documentation

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ kind()

Kind elementa::parsing::ExprSimpleArgsClose::kind ( void  ) const
inlinevirtual

Must return the kind of the element: datum, grouping or operation.

Implements elementa::parsing::ExprElement.

Definition at line 198 of file expressions.h.

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtualinherited

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprSimpleArgsSep

class elementa::parsing::ExprSimpleArgsSep

A simple args-separator expression element.

Definition at line 202 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprSimpleArgsSep:
Collaboration diagram for elementa::parsing::ExprSimpleArgsSep:

Public Member Functions

Kind kind (void) const
 Must return the kind of the element: datum, grouping or operation. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 
using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 

Member Typedef Documentation

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ kind()

Kind elementa::parsing::ExprSimpleArgsSep::kind ( void  ) const
inlinevirtual

Must return the kind of the element: datum, grouping or operation.

Implements elementa::parsing::ExprElement.

Definition at line 206 of file expressions.h.

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtualinherited

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprOperElement

class elementa::parsing::ExprOperElement

An element within an expression that is an operation with a fixed arity.

Note
- An operation may have different arities and/or types depending on the context, but a given operation object must have them fixed.
See also
ExprElement, Expression.

Definition at line 216 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprOperElement:
Collaboration diagram for elementa::parsing::ExprOperElement:

Public Member Functions

Base methods (not overridable)
Kind kind (void) const
 Return the kind of the element: an operation. More...
 
unsigned char arity (void) const
 Return the arity -number of arguments- of the operation (from 0 on). More...
 
virtual bool inFixed (void) const
 Return whether the op. must be in infix form if arity == 2 when in InFix. More...
 
virtual ArgsGroupOmitting argGroupingsOmit (void) const
 Return how the args grouping are allowed to be in 0/1 arity ops. More...
 
virtual ExprElement::Ptr argsOpening (void) const
 Return the opening argument element for this operation. More...
 
virtual ExprElement::Ptr argsClosing (void) const
 Return the closing argument element for this operation. More...
 
virtual ExprElement::Ptr argsSeparating (void) const
 Return the separating argument element for this operation. More...
 
Virtual methods
virtual const ParamSpecprototype (void) const =0
 Must return a const reference to the specification of parms and return. More...
 
virtual unsigned precedence (void) const =0
 Must return a number that indicates the precedence of the operation. More...
 
virtual bool withResult (void) const
 Can be overriden to return whether the operation produces a result. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 
virtual std::string to_string (void) const
 

Types, consts., etc.

using VectorOfParamSpecs = std::vector< ParamSpec >
 A number of specifications. More...
 
 ELE_CLASS_ENUM (ArgsGroupOmitting, CanOmit, MustOmit, CannotOmit)
 Mode of omitting args groupings for operations of arity 0 or 1.
 

Types, consts., etc.

using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 
 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 

Member Typedef Documentation

◆ VectorOfParamSpecs

A number of specifications.

See also
ParamSpec.

Definition at line 247 of file expressions.h.

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ kind()

Kind elementa::parsing::ExprOperElement::kind ( void  ) const
inlinevirtual

Return the kind of the element: an operation.

Implements elementa::parsing::ExprElement.

Definition at line 256 of file expressions.h.

◆ arity()

unsigned char elementa::parsing::ExprOperElement::arity ( void  ) const
inline

Return the arity -number of arguments- of the operation (from 0 on).

Return the value using prototype() and withResult(), that must be provided by the derivative class.

See also
prototype, withResult.

Definition at line 262 of file expressions.h.

References ELE_CODE_INVSTATE, prototype(), and withResult().

◆ inFixed()

virtual bool elementa::parsing::ExprOperElement::inFixed ( void  ) const
inlinevirtual

Return whether the op. must be in infix form if arity == 2 when in InFix.

Override it only in operations of arity 2 that cannot be in infix form, such as calls to functions with 2 parameters. The rest can leave it as it is here.

Definition at line 277 of file expressions.h.

◆ argGroupingsOmit()

virtual ArgsGroupOmitting elementa::parsing::ExprOperElement::argGroupingsOmit ( void  ) const
inlinevirtual

Return how the args grouping are allowed to be in 0/1 arity ops.

Only used if the operation is 0-arity or 1-arity; operations of 2-arity do not use arg groupings if they are infix and never when they are postfix, while >2-arity must always use arg groupings.

Reimplemented in elementa::parsing::ExprOperNop.

Definition at line 283 of file expressions.h.

◆ argsOpening()

virtual ExprElement::Ptr elementa::parsing::ExprOperElement::argsOpening ( void  ) const
inlinevirtual

Return the opening argument element for this operation.

Definition at line 287 of file expressions.h.

◆ argsClosing()

virtual ExprElement::Ptr elementa::parsing::ExprOperElement::argsClosing ( void  ) const
inlinevirtual

Return the closing argument element for this operation.

Definition at line 291 of file expressions.h.

◆ argsSeparating()

virtual ExprElement::Ptr elementa::parsing::ExprOperElement::argsSeparating ( void  ) const
inlinevirtual

Return the separating argument element for this operation.

Definition at line 295 of file expressions.h.

◆ prototype()

virtual const ParamSpec & elementa::parsing::ExprOperElement::prototype ( void  ) const
pure virtual

Must return a const reference to the specification of parms and return.

Recall that the prototype must include as first element the type of the return value of the operation, and then their args.

See also
ParamSpec.

Implemented in elementa::parsing::ExprOperNop.

Referenced by arity().

◆ precedence()

virtual unsigned elementa::parsing::ExprOperElement::precedence ( void  ) const
pure virtual

Must return a number that indicates the precedence of the operation.

If it is a 0-arity operation, it can return anything because it will be ignored. Highest numbers indicate highest precedences. The precedence indicates, in the case that an operation appears in a midfix expression right after another operation, which one is executed first (the one with greater precedence).

Implemented in elementa::parsing::ExprOperNop.

◆ withResult()

virtual bool elementa::parsing::ExprOperElement::withResult ( void  ) const
inlinevirtual

Can be overriden to return whether the operation produces a result.

By default, the operation produces a result. It can be overriden for the cases where the operation produces side effects only.

Reimplemented in elementa::parsing::ExprOperNop.

Definition at line 321 of file expressions.h.

Referenced by arity().

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ to_string()

virtual std::string elementa::parsing::ExprElement::to_string ( void  ) const
inlinevirtualinherited

Reimplemented in elementa::parsing::Expression::OpDatumWrapper.

Definition at line 160 of file expressions.h.

◆ elementa::parsing::ExprOperNop

class elementa::parsing::ExprOperNop

An operation that takes no arguments and does nothing.

Definition at line 329 of file expressions.h.

Inheritance diagram for elementa::parsing::ExprOperNop:
Collaboration diagram for elementa::parsing::ExprOperNop:

Public Member Functions

const ParamSpecprototype (void) const
 Must return a const reference to the specification of parms and return. More...
 
unsigned precedence (void) const
 Must return a number that indicates the precedence of the operation. More...
 
bool withResult (void) const override
 Can be overriden to return whether the operation produces a result. More...
 
ArgsGroupOmitting argGroupingsOmit (void) const override
 Return how the args grouping are allowed to be in 0/1 arity ops. More...
 
std::string to_string (void) const override
 
Base methods (not overridable)
Kind kind (void) const
 Return the kind of the element: an operation. More...
 
unsigned char arity (void) const
 Return the arity -number of arguments- of the operation (from 0 on). More...
 
virtual bool inFixed (void) const
 Return whether the op. must be in infix form if arity == 2 when in InFix. More...
 
virtual ExprElement::Ptr argsOpening (void) const
 Return the opening argument element for this operation. More...
 
virtual ExprElement::Ptr argsClosing (void) const
 Return the closing argument element for this operation. More...
 
virtual ExprElement::Ptr argsSeparating (void) const
 Return the separating argument element for this operation. More...
 
Virtual methods
bool isDatum (void) const noexcept
 Return TRUE if the element is a datum (not a grouping). More...
 
bool isOperation (void) const noexcept
 Return TRUE if the element is an operation. More...
 
bool isOpeningGrouping (void) const noexcept
 Return TRUE if the element is an opening grouping. More...
 
bool isClosingGrouping (void) const noexcept
 Return TRUE if the element is a closing grouping. More...
 
bool isGrouping (void) const noexcept
 Return TRUE if the element is a grouping. More...
 
bool isOpeningArgs (void) const noexcept
 Return TRUE if the element is an opening args. More...
 
bool isClosingArgs (void) const noexcept
 Return TRUE if the element is a closing args. More...
 
bool isGroupingArgs (void) const noexcept
 Return TRUE if the element is an args grouping. More...
 
bool isSepArgs (void) const noexcept
 Return TRUE if the element is a sep args. More...
 
bool isDatumTypedAs (int ty) const noexcept
 Return TRUE if the element is a datum of a given type. More...
 
virtual int type (void) const
 Can be overriden to return the type of the element (an int value). More...
 

Types, consts., etc.

 ELE_CLASS_ENUM (ArgsGroupOmitting, CanOmit, MustOmit, CannotOmit)
 Mode of omitting args groupings for operations of arity 0 or 1.
 
using VectorOfParamSpecs = std::vector< ParamSpec >
 A number of specifications. More...
 

Types, consts., etc.

 ELE_CLASS_ENUM (Kind, kDatum, kGroupOpen, kGroupClose, kArgsOpen, kArgsClose, kArgsSep, kOperation)
 Kind ot the elements.
 
using Ptr = std::shared_ptr< ExprElement >
 A safe, polymorphic pointer to an element for container use. More...
 

Member Typedef Documentation

◆ VectorOfParamSpecs

A number of specifications.

See also
ParamSpec.

Definition at line 247 of file expressions.h.

◆ Ptr

using elementa::parsing::ExprElement::Ptr = std::shared_ptr<ExprElement>
inherited

A safe, polymorphic pointer to an element for container use.

Definition at line 68 of file expressions.h.

Member Function Documentation

◆ prototype()

const ParamSpec & elementa::parsing::ExprOperNop::prototype ( void  ) const
inlinevirtual

Must return a const reference to the specification of parms and return.

Recall that the prototype must include as first element the type of the return value of the operation, and then their args.

See also
ParamSpec.

Implements elementa::parsing::ExprOperElement.

Definition at line 333 of file expressions.h.

◆ precedence()

unsigned elementa::parsing::ExprOperNop::precedence ( void  ) const
inlinevirtual

Must return a number that indicates the precedence of the operation.

If it is a 0-arity operation, it can return anything because it will be ignored. Highest numbers indicate highest precedences. The precedence indicates, in the case that an operation appears in a midfix expression right after another operation, which one is executed first (the one with greater precedence).

Implements elementa::parsing::ExprOperElement.

Definition at line 335 of file expressions.h.

◆ withResult()

bool elementa::parsing::ExprOperNop::withResult ( void  ) const
inlineoverridevirtual

Can be overriden to return whether the operation produces a result.

By default, the operation produces a result. It can be overriden for the cases where the operation produces side effects only.

Reimplemented from elementa::parsing::ExprOperElement.

Definition at line 336 of file expressions.h.

◆ argGroupingsOmit()

ArgsGroupOmitting elementa::parsing::ExprOperNop::argGroupingsOmit ( void  ) const
inlineoverridevirtual

Return how the args grouping are allowed to be in 0/1 arity ops.

Only used if the operation is 0-arity or 1-arity; operations of 2-arity do not use arg groupings if they are infix and never when they are postfix, while >2-arity must always use arg groupings.

Reimplemented from elementa::parsing::ExprOperElement.

Definition at line 338 of file expressions.h.

◆ to_string()

std::string elementa::parsing::ExprOperNop::to_string ( void  ) const
inlineoverridevirtual

Reimplemented from elementa::parsing::ExprElement.

Definition at line 341 of file expressions.h.

◆ kind()

Kind elementa::parsing::ExprOperElement::kind ( void  ) const
inlinevirtualinherited

Return the kind of the element: an operation.

Implements elementa::parsing::ExprElement.

Definition at line 256 of file expressions.h.

◆ arity()

unsigned char elementa::parsing::ExprOperElement::arity ( void  ) const
inlineinherited

Return the arity -number of arguments- of the operation (from 0 on).

Return the value using prototype() and withResult(), that must be provided by the derivative class.

See also
prototype, withResult.

Definition at line 262 of file expressions.h.

References ELE_CODE_INVSTATE, elementa::parsing::ExprOperElement::prototype(), and elementa::parsing::ExprOperElement::withResult().

◆ inFixed()

virtual bool elementa::parsing::ExprOperElement::inFixed ( void  ) const
inlinevirtualinherited

Return whether the op. must be in infix form if arity == 2 when in InFix.

Override it only in operations of arity 2 that cannot be in infix form, such as calls to functions with 2 parameters. The rest can leave it as it is here.

Definition at line 277 of file expressions.h.

◆ argsOpening()

virtual ExprElement::Ptr elementa::parsing::ExprOperElement::argsOpening ( void  ) const
inlinevirtualinherited

Return the opening argument element for this operation.

Definition at line 287 of file expressions.h.

◆ argsClosing()

virtual ExprElement::Ptr elementa::parsing::ExprOperElement::argsClosing ( void  ) const
inlinevirtualinherited

Return the closing argument element for this operation.

Definition at line 291 of file expressions.h.

◆ argsSeparating()

virtual ExprElement::Ptr elementa::parsing::ExprOperElement::argsSeparating ( void  ) const
inlinevirtualinherited

Return the separating argument element for this operation.

Definition at line 295 of file expressions.h.

◆ isDatum()

bool elementa::parsing::ExprElement::isDatum ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a datum (not a grouping).

Definition at line 114 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ isOperation()

bool elementa::parsing::ExprElement::isOperation ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an operation.

Definition at line 117 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isOpeningGrouping()

bool elementa::parsing::ExprElement::isOpeningGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening grouping.

Definition at line 120 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isClosingGrouping()

bool elementa::parsing::ExprElement::isClosingGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing grouping.

Definition at line 124 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGrouping().

◆ isGrouping()

bool elementa::parsing::ExprElement::isGrouping ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a grouping.

Definition at line 128 of file expressions.h.

References elementa::parsing::ExprElement::isClosingGrouping(), and elementa::parsing::ExprElement::isOpeningGrouping().

◆ isOpeningArgs()

bool elementa::parsing::ExprElement::isOpeningArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an opening args.

Definition at line 132 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isClosingArgs()

bool elementa::parsing::ExprElement::isClosingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a closing args.

Definition at line 136 of file expressions.h.

References elementa::parsing::ExprElement::kind().

Referenced by elementa::parsing::ExprElement::isGroupingArgs().

◆ isGroupingArgs()

bool elementa::parsing::ExprElement::isGroupingArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is an args grouping.

Definition at line 140 of file expressions.h.

References elementa::parsing::ExprElement::isClosingArgs(), and elementa::parsing::ExprElement::isOpeningArgs().

◆ isSepArgs()

bool elementa::parsing::ExprElement::isSepArgs ( void  ) const
inlinenoexceptinherited

Return TRUE if the element is a sep args.

Definition at line 144 of file expressions.h.

References elementa::parsing::ExprElement::kind().

◆ isDatumTypedAs()

bool elementa::parsing::ExprElement::isDatumTypedAs ( int  ty) const
inlinenoexceptinherited

Return TRUE if the element is a datum of a given type.

Definition at line 148 of file expressions.h.

References elementa::parsing::ExprElement::isDatum(), and elementa::parsing::ExprElement::type().

◆ type()

virtual int elementa::parsing::ExprElement::type ( void  ) const
inlinevirtualinherited

Can be overriden to return the type of the element (an int value).

Override it to provide a particular type if you are working with typed expressions. Ignore it otherwise.

Definition at line 157 of file expressions.h.

Referenced by elementa::parsing::ExprElement::isDatumTypedAs().

◆ elementa::parsing::Expression

class elementa::parsing::Expression

A general expression composed of a number of elements of type Element.

See also
ExprElement, ExprOperElement.

Definition at line 354 of file expressions.h.

Inheritance diagram for elementa::parsing::Expression:
Collaboration diagram for elementa::parsing::Expression:

Public Attributes

elements
 STL member.
 

Public Member Functions

virtual std::string to_string (void) const
 Build a text with the sequence of elements.
 
Constructors. Copy ctor/assign copy smart pointers.
 Expression (Order order=Order::kInfix, const ExprElement::Ptr &groupopening=ExprElement::Ptr{new ExprSimpleGroupOpen{}}, const ExprElement::Ptr &groupclosing=ExprElement::Ptr{new ExprSimpleGroupClose{}})
 Default constructor: empty expression in InFix. More...
 
 Expression (Order order, Base &&elems, const ExprElement::Ptr &groupopening=ExprElement::Ptr{new ExprSimpleGroupOpen{}}, const ExprElement::Ptr &groupclosing=ExprElement::Ptr{new ExprSimpleGroupClose{}})
 Constructor from a list of elements assumed to be in the given order. More...
 
 Expression (const Expression &oth)
 
 Expression (Expression &&oth)
 
Expressionoperator= (const Expression &oth)
 
Expressionoperator= (Expression &&oth)
 
Getters
Order order (void) const
 Return the current order of the expression. More...
 
ExprElement::Ptr buildTree (void) const
 Build a tree from the expression and return the root node. More...
 
Checking/execution methods
long checkGrouping (void) const
 Check grouping validity in the expression (not args-grouping). More...
 
long checkArgGrouping (void) const
 The same as checkGrouping but for the args-open and -close elements.
 
int checkType (Base::const_iterator &errloc, const TypeCompatChecker &tcc=defaultTypeCompatChecker, const TypeConfirming &tcf=defaultTypeConfirming) const
 Evaluate the type of the expression, returning the resulting type. More...
 
ExprElement::Ptr evaluate (Base::const_iterator &errloc, Evaluator &evaluator) const
 Evaluate the expression using the given evaluator; only if postfix. More...
 
bool reduce (Evaluator &evaluator)
 Reduce the expression partial or totally. More...
 
Transforming methods
void changeOrder (Order neword, bool forcegrouping=false)
 Change the order of operations to NEWORD, if possible. More...
 
void deleteNOPs (void)
 Delete all NOP operations. More...
 
void changeElements (const std::function< std::pair< bool, ExprElement::Ptr >(ExprElement::Ptr &) > &pred)
 Change all elements in the expression that satisfy a predicate. More...
 
void deleteElements (const std::function< bool(ExprElement::Ptr &) > &pred)
 Delete all elements in the expression that satisfy a predicate. More...
 

Types, consts., etc.

using Base = ExprElement::PList
 Shortcut. More...
 
using Length = Base::size_type
 Shortcut. More...
 
using Evaluator = std::function< ExprElement::Ptr(const ExprElement::Ptr &, const ExprElement::PList &) >
 An evaluator function of a given operation or datum. More...
 
using TypeCompatChecker = std::function< bool(const ExprOperElement &, const ExprElement::Ptr &, ExprOperElement::ParamSpec::Base::size_type, int, int) >
 An op arg type compatibility checker used when checking types. More...
 
using TypeConfirming = std::function< int(ExprOperElement &, const ExprOperElement::ParamSpec &, int) >
 An op result type confirming routine used when checking types. More...
 
 ELE_CLASS_ENUM (Order, kPostfix, kInfix)
 Kind of ordering in the expression. More...
 
static bool defaultTypeCompatChecker (const ExprOperElement &oper, const ExprElement::Ptr &, ExprOperElement::ParamSpec::Base::size_type apos, int tparm, int targ)
 Default compatibility checker. More...
 
static int defaultTypeConfirming (ExprOperElement &oper, const ExprOperElement::ParamSpec &actualproto, int proposed)
 Default confirming routine that just return the proposed type. More...
 

Member Typedef Documentation

◆ Base

Shortcut.

Definition at line 362 of file expressions.h.

◆ Length

using elementa::parsing::Expression::Length = Base::size_type

Shortcut.

Definition at line 365 of file expressions.h.

◆ Evaluator

An evaluator function of a given operation or datum.

The first parameter is the operation, the second the list of operands, that is guaranteed to agree with the operation arity (type checking is not carried out) and to be all Datum. Any exception in the evaluator produced by some error in the expression should derive from EvalError. It will receive the list of operands for the operation (same length as its arity, and empty if arity is 0 or if the element is a datum), all of them of kind kDatum, in the same order as found in the expression. It must return either a new element of kind kDatum with the result or a copy of some argument if that is the resulting datum. If the operation has no result, then the returned ExprElement::Ptr will be discarded.

See also
EvalError, evaluate.

Definition at line 394 of file expressions.h.

◆ TypeCompatChecker

using elementa::parsing::Expression::TypeCompatChecker = std::function< bool(const ExprOperElement &, const ExprElement::Ptr &, ExprOperElement::ParamSpec::Base::size_type, int,int) >

An op arg type compatibility checker used when checking types.

A routine that must return TRUE if an operation admitting a parameter of some type can also work if the argument passed is of another type. I.e., checker(oper,arg,apos,tparm,targ) must return TRUE if the operation OPER, when called with argument arg of type TARG for its parameter number APOS (from 0), which in principle should be of type TPARM, should not complaint.

Note
- ARG can be a datum or an operation, since both can have assigned a type during the type checking process.

Definition at line 406 of file expressions.h.

◆ TypeConfirming

An op result type confirming routine used when checking types.

The call confirming(const ExprOperElement & oper, const ExprOperElement::ParamSpec & proto, int proposed) receives in PROTO the actual prototype generated for the OPER operation during type checking of the expression, and the PROPOSED type by the prototype of the expression, and must return the same proposed type or any other if it wishes to cast.

Definition at line 420 of file expressions.h.

Constructor & Destructor Documentation

◆ Expression() [1/4]

elementa::parsing::Expression::Expression ( Order  order = Order::kInfix,
const ExprElement::Ptr groupopening = ExprElement::Ptr{new ExprSimpleGroupOpen{}},
const ExprElement::Ptr groupclosing = ExprElement::Ptr{new ExprSimpleGroupClose{}} 
)
inline

Default constructor: empty expression in InFix.

Parameters
groupopening,groupclosingare used to generate kInFix expressions automatically from kPostFix.

Definition at line 568 of file expressions.h.

◆ Expression() [2/4]

elementa::parsing::Expression::Expression ( Order  order,
Base &&  elems,
const ExprElement::Ptr groupopening = ExprElement::Ptr{new ExprSimpleGroupOpen{}},
const ExprElement::Ptr groupclosing = ExprElement::Ptr{new ExprSimpleGroupClose{}} 
)
inline

Constructor from a list of elements assumed to be in the given order.

Move the others elements inside this.

Definition at line 580 of file expressions.h.

◆ Expression() [3/4]

elementa::parsing::Expression::Expression ( const Expression oth)
inline

Definition at line 590 of file expressions.h.

◆ Expression() [4/4]

elementa::parsing::Expression::Expression ( Expression &&  oth)
inline

Definition at line 591 of file expressions.h.

Member Function Documentation

◆ ELE_CLASS_ENUM()

elementa::parsing::Expression::ELE_CLASS_ENUM ( Order  ,
kPostfix  ,
kInfix   
)

Kind of ordering in the expression.

Note
- In kPostfix order there are no args-open/close or group-open/close elements, since the order produces the expression univocally.
- In normal (kInFix) order, operations of arity 2 appear between their operands or not depending on their "inFixable()" method, and use ArgOpen/ArgClose/ArgSep elements for listing their elements.

◆ defaultTypeCompatChecker()

static bool elementa::parsing::Expression::defaultTypeCompatChecker ( const ExprOperElement oper,
const ExprElement::Ptr ,
ExprOperElement::ParamSpec::Base::size_type  apos,
int  tparm,
int  targ 
)
inlinestatic

Default compatibility checker.

Return TRUE only if both parameter and argument have the same type.

Definition at line 427 of file expressions.h.

◆ defaultTypeConfirming()

static int elementa::parsing::Expression::defaultTypeConfirming ( ExprOperElement oper,
const ExprOperElement::ParamSpec actualproto,
int  proposed 
)
inlinestatic

Default confirming routine that just return the proposed type.

Definition at line 435 of file expressions.h.

◆ operator=() [1/2]

Expression & elementa::parsing::Expression::operator= ( const Expression oth)
inline

Definition at line 592 of file expressions.h.

◆ operator=() [2/2]

Expression & elementa::parsing::Expression::operator= ( Expression &&  oth)
inline

Definition at line 594 of file expressions.h.

◆ order()

Order elementa::parsing::Expression::order ( void  ) const
inline

Return the current order of the expression.

Definition at line 604 of file expressions.h.

◆ buildTree()

ExprElement::Ptr elementa::parsing::Expression::buildTree ( void  ) const

Build a tree from the expression and return the root node.

This only works if the expression is in Postfix order. The returned element actually contains a pointer to a TreeNode.

◆ checkGrouping()

long elementa::parsing::Expression::checkGrouping ( void  ) const

Check grouping validity in the expression (not args-grouping).

Only for kInfix expressions. If grouping is valid, return 0. Otherwise, return the number of unbalanced grouping indicators: positive if there are more opening than closings, negative if there are more closings than openings.

Note
- This method is more efficient than evaluating the expression.
- The only source of exceptions in this method is in accessing the kind of each element in the expression.

◆ checkType()

int elementa::parsing::Expression::checkType ( Base::const_iterator &  errloc,
const TypeCompatChecker tcc = defaultTypeCompatChecker,
const TypeConfirming tcf = defaultTypeConfirming 
) const

Evaluate the type of the expression, returning the resulting type.

This method also check the correct arities in all arguments of operations. Throw if any error. Cannot work with expressions that are not in kPostfix order.

Parameters
errlocwill be filled with the location of the offending element if any error.
tccis the type compatibility checker to be used. It will be called for every argument type in operation calls, not for datum.
tcfis the type confirming routine to be used. It will be called for every operation that has a return type, not for datum, and after tcc has done its work on all arguments.
Note
- This method call evaluate() to evaluate the type of the expression.
See also
TypeCompatChecker, evaluate.

◆ evaluate()

ExprElement::Ptr elementa::parsing::Expression::evaluate ( Base::const_iterator &  errloc,
Evaluator evaluator 
) const

Evaluate the expression using the given evaluator; only if postfix.

The arguments passed to the evaluator in each operation are not checked against type, i.e., they are ok for this method as long as they are of kind ExprElement::kDatum. Return the resulting datum, that can be either a copy of any of the data in the expression or a new object resulting from calculations. If some error is detected during the execution, fill ERRLOC with an iterator pointing just before the offending element, and then throw. All errors throw by this method must be derived from EvalError.

See also
Evaluator, EvalError.

◆ reduce()

bool elementa::parsing::Expression::reduce ( Evaluator evaluator)

Reduce the expression partial or totally.

It only works in postfix order. The EVALUATOR must throw EvalError if a part of the evaluation cannot be reduced, or a valid value for the reduction otherwise. The difference between this method and evaluate() is that in this one the evaluator will be called after any error to detect other parts of the expression that can be reduced. Return TRUE if the original expression has changed.

◆ changeOrder()

void elementa::parsing::Expression::changeOrder ( Order  neword,
bool  forcegrouping = false 
)

Change the order of operations to NEWORD, if possible.

This method check some issues, such as unbalanced groupings, but not others, such as invalid use of arities. Do nothing if the expression is already in the desired order. \parm neword is the target order. \parm forcegrouping includes groupings when some changes of order occur even if those groupings are not needed according to the precedences of operators; if FALSE, only the strictly needed groupings for disambiguating operators according to their precedences are included (i.e., FALSE should be enough for most cases).

Note
- In the transformation, some elements can be changed/dropped, e.g., in passing from infix to postfix all groupings are dropped since that does not change the expression functionality.
- Dropped elements are shared ptrs, thus if no one uses them, they will be destroyed; non-dropped elements are ptrs to the same elements that there were in the expression before changing the order.
- Other elements may be created anew: for instance, passing from postfix to infix, opening-closing-separating args and opening- closing groups are created when needed. In the case of groups, the elements created will refer to the group opening and closing objects passed to the constructor. Anyway, you can change these elements afterwards using changeElementsBy(). In the case of args, the created elements come from the methods of the operation object.

◆ deleteNOPs()

void elementa::parsing::Expression::deleteNOPs ( void  )

Delete all NOP operations.

NOP operations must be of class ExprOperNop of derived from it.

◆ changeElements()

void elementa::parsing::Expression::changeElements ( const std::function< std::pair< bool, ExprElement::Ptr >(ExprElement::Ptr &) > &  pred)

Change all elements in the expression that satisfy a predicate.

Parameters
predmust return a pair with the first value a boolean indicating whether to change the element and the second value, if the first one is true, with the new element to use. If the first one is false, the second value of the pair is not used.

◆ deleteElements()

void elementa::parsing::Expression::deleteElements ( const std::function< bool(ExprElement::Ptr &) > &  pred)

Delete all elements in the expression that satisfy a predicate.

Parameters
predmust return TRUE to delete that element.