HAL
hal::BooleanFunctionParser Namespace Reference

Classes

struct  Token
 Token refers to a token identifier and accompanied data. More...
 

Enumerations

enum class  ParserType { Liberty , Standard }
 ParserType refers to the parser identifier. More...
 
enum class  TokenType {
  And , Not , NotSuffix , Or ,
  Xor , Variable , Constant , BracketOpen ,
  BracketClose
}
 TokenType refers to a token identifier for a Boolean function string. More...
 

Functions

Result< std::vector< Token > > parse_with_liberty_grammar (const std::string &expression)
 
Result< std::vector< Token > > parse_with_standard_grammar (const std::string &expression)
 
std::ostream & operator<< (std::ostream &os, const Token &token)
 
Result< std::vector< Token > > reverse_polish_notation (std::vector< Token > &&tokens, const std::string &expression, const ParserType &parser)
 
Result< BooleanFunctiontranslate (std::vector< Token > &&tokens, const std::string &expression)
 

Enumeration Type Documentation

◆ ParserType

ParserType refers to the parser identifier.

Enumerator
Liberty 

refers to the 'Liberty' Boolean function parser

Standard 

refers to the 'Standard' Boolean function parser

Definition at line 35 of file parser.h.

◆ TokenType

TokenType refers to a token identifier for a Boolean function string.

Enumerator
And 

Boolean And operation (e.g., "&").

Not 

Boolean Not operation (e.g., "!&").

NotSuffix 
Or 

<Boolean Not operation as a expresion suffix (e.g., "'" for liberty grammar). Boolean Or operation (e.g., "|").

Xor 

Boolean Xor operation (e.g., "^").

Variable 

Boolean variable (e.g., "i0").

Constant 

Boolean constant (e.g., "0" or "1").

BracketOpen 

An opening bracket (e.g., "(").

BracketClose 

A closing bracket (e.g., "(").

Definition at line 44 of file parser.h.

Function Documentation

◆ operator<<()

std::ostream& hal::BooleanFunctionParser::operator<< ( std::ostream &  os,
const Token token 
)

Outputs a token to the given output stream.

Parameters
[in]os- The output stream.
[in]token- The token to be output.
Returns
The output stream.

Definition at line 90 of file parser_types.cpp.

◆ parse_with_liberty_grammar()

Result< std::vector< Token > > hal::BooleanFunctionParser::parse_with_liberty_grammar ( const std::string &  expression)

Parses a Boolean function from a string representation into its tokens based on the data format defined for Liberty, see Liberty user guide.

Parameters
[in]expression- Boolean function string.
Returns
Ok() and the list of tokens on success, Err() otherwise.

Definition at line 13 of file parser_liberty.cpp.

References hal::BooleanFunctionParser::Token::And(), hal::BooleanFunctionParser::Token::BracketClose(), hal::BooleanFunctionParser::Token::BracketOpen(), hal::BooleanFunctionParser::Token::Constant(), ERR, name, hal::BooleanFunctionParser::Token::Not(), hal::BooleanFunctionParser::Token::NotSuffix(), OK, hal::BooleanFunctionParser::Token::Or(), hal::BooleanFunctionParser::Token::Variable(), and hal::BooleanFunctionParser::Token::Xor().

Referenced by hal::BooleanFunction::from_string().

◆ parse_with_standard_grammar()

Result< std::vector< Token > > hal::BooleanFunctionParser::parse_with_standard_grammar ( const std::string &  expression)

◆ reverse_polish_notation()

Result< std::vector< Token > > hal::BooleanFunctionParser::reverse_polish_notation ( std::vector< Token > &&  tokens,
const std::string &  expression,
const ParserType parser 
)

Transforms a list of tokens in infix notation (e.g., "A & B") into the reverse polish notation notation (e.g., "A B &") that allows for an easy translation into the AST data structure.

In order to translate between the different notations, we leverage the well-known Shunting Yard algorithm, see wikipedia for an example: https://en.wikipedia.org/wiki/Shunting-yard_algorithm

Parameters
[in]tokens- List of tokens in infix notation.
[in]expression- Expression string.
[in]parser- Parser identifier
Returns
Ok() and list of tokens in reverse-polish notation on success, Err() otherwise.

Definition at line 137 of file parser_types.cpp.

References And, BracketClose, BracketOpen, Constant, ERR, Not, hal::BooleanFunctionParser::Token::Not(), NotSuffix, OK, Or, hal::output, control::parser, Variable, and Xor.

Referenced by hal::BooleanFunction::from_string().

◆ translate()

Result< BooleanFunction > hal::BooleanFunctionParser::translate ( std::vector< Token > &&  tokens,
const std::string &  expression 
)

Translates a list of tokens (in reverse-polish notation form) into a list of BooleanFunction nodes that are then assembled into a Boolean function.

Parameters
[in]tokens- List of tokens.
[in]expression- Expression string.
Returns
Ok() and the Boolean function on success, Err() otherwise.

Definition at line 214 of file parser_types.cpp.

References hal::BooleanFunction::NodeType::And, And, hal::BooleanFunction::build(), hal::BooleanFunction::Node::Constant(), Constant, ERR, ERR_APPEND, hal::BooleanFunction::NodeType::Not, Not, hal::BooleanFunction::Node::Operation(), hal::BooleanFunction::NodeType::Or, Or, hal::BooleanFunction::Node::Variable(), Variable, hal::BooleanFunction::NodeType::Xor, and Xor.

Referenced by hal::BooleanFunction::from_string().