Spectra
Public Member Functions | List of all members
formulaAnalyser Class Reference

#include <formulaAnalyser.h>

Public Member Functions

bool parseFormula (std::string filename)
 
bool finalizeFormulaeParsing (formula *currentFormula, std::stack< formula > &formulaStack, std::vector< int > &activeFormulae)
 
bool generateAtom (std::string &word, int &nextId, formula *&currentFormula, std::stack< formula > &formulaStack, std::vector< int > &activeFormulae, int line, int column, std::string &filename)
 
bool finalizeCurrentFormula (formula *currentFormula, std::stack< formula > *formulaStack, std::vector< int > *activeFormulae)
 
bool addNewFormula (std::stack< formula > &formulaStack, std::vector< int > &activeFormulae, int &nextId, formula *&currentFormula)
 
OpType decodeType (const std::string &op)
 
void noteVar (std::string name)
 
int getIndexOfVarName (std::string name)
 
std::vector< formulagetFormulae ()
 
std::set< std::string > getVarNames ()
 
unsigned getFormulaeCnt ()
 
std::vector< std::string > getVarDefinitions ()
 
std::vector< std::string > getFormulaeContents ()
 
int getMaxChildCnt () const
 
std::vector< std::string > getSrcList ()
 

Detailed Description

Created: 8. 10. 2018 by Petra Sečkařová (xseck.nosp@m.a02@.nosp@m.stud..nosp@m.fit..nosp@m.vutbr.nosp@m..cz). Filename: formulaAnalyser.h

Description: Declaration of a class for parsing and analysing the specification file. Class for parsing files with formulae into internal structures. Stores the parsed formulae in an implicit tree (given by order and index references) of subformulae, string representation of each formula and names of all variable names encountered in the formulae.

Member Function Documentation

◆ addNewFormula()

bool formulaAnalyser::addNewFormula ( std::stack< formula > &  formulaStack,
std::vector< int > &  activeFormulae,
int &  nextId,
formula *&  currentFormula 
)

Pushes a new formula onto the given stack, adds it's id to the activeFormulae list and updates the operands of previous top of the stack accordingly. If other formulae were parsed before already, but the formulaStack is empty, adds a new root formula with the operator && and correctly updates its operands and all previous formulae' ids.

Parameters
formulaStackA stack of formulae currently being processed.
activeFormulaeA list of ids of the formulae, that are currently on the formulaStack.
nextIdA counter used for assigning ids of the parsed formulae, is incremented by this funcion.
currentFormulaA pointer to a formula currently at the top of formulaStack.

More separate formulae given in specification

◆ decodeType()

OpType formulaAnalyser::decodeType ( const std::string &  op)

Decodes string representation of operator in a formula into an OpType enum value.

Parameters
opA string representation of the operator.
Returns
An enum value corresponding to the given string representation of operator.

◆ finalizeCurrentFormula()

bool formulaAnalyser::finalizeCurrentFormula ( formula currentFormula,
std::stack< formula > *  formulaStack,
std::vector< int > *  activeFormulae 
)

If the current formula is fully set, than this method stores it into the list of parsed formulae, pops it from the stack and erases it from the list of active formulae.

Parameters
currentFormulaA formula at the top of the formulaStack to be stored.
formulaStackA stack of not-yet-ready formulae where from the currentFormula should be removed.
activeFormulaeA list of ids of all formulae in the formulaStack.
Returns
True if currentFormula was successfully stored, false otherwise.

◆ finalizeFormulaeParsing()

bool formulaAnalyser::finalizeFormulaeParsing ( formula currentFormula,
std::stack< formula > &  formulaStack,
std::vector< int > &  activeFormulae 
)

Checks that all formulae are successfully parsed and no unfinished is left. There can be a single formula on the stack, but it has to be in the READY state.

Parameters
currentFormulaA formula at the top of the formulaStack if there is any left.
formulaStackA stack of formulae to be processed.
activeFormulaeA list of ids of all formulae in formulaStack.
Returns
True if the formulaStack was emptied correctly, false otherwise.

◆ generateAtom()

bool formulaAnalyser::generateAtom ( std::string &  word,
int &  nextId,
formula *&  currentFormula,
std::stack< formula > &  formulaStack,
std::vector< int > &  activeFormulae,
int  line,
int  column,
std::string &  filename 
)

Generates an atomic formula from given string that is considered to be a name of a variable. The new formula is added as an operand to the formula currently on the top of the formulaStack. Given string is noted as a variable name along with mapping it's appearance in currently active formulae.

Parameters
wordA content of an atomic formula to be added by this function.
nextIdA counter used for assigning ids to the formulae.
currentFormulaA formula at the top of the formulaStack. The newly created formula will be added as this formula's operand.
formulaStackA stack of formulae currently being processed.
activeFormulaeA list of ids of all formulae in formulaStack.

◆ getIndexOfVarName()

int formulaAnalyser::getIndexOfVarName ( std::string  name)

Computes the index of a variable in varNames (which is the same as for varDefinitions) given by it's name.

Parameters
nameA name of the variable, which index is being searched.
Returns
The index of a variable with given name in varNames vector. If no such name found, the value -1 is returned.

◆ noteVar()

void formulaAnalyser::noteVar ( std::string  name)

Ensures, that given name of a variable is stored. Updates map of appearance of given variable in formulae.

Parameters
nameA name of variable encountered in some part of a formula.

Ensures, that given name of a variable is stored. Updates map of appearance of given variable in formulae.

Parameters
nameA name of variable encountered in some part of a formula.
activeFormulaeA list of ids of current parent formulae.

◆ parseFormula()

bool formulaAnalyser::parseFormula ( std::string  filename)

Parses data from given file. Loads all formulae and variable definitions into internal structures of this class for later usage.

Parameters
filenameA name of file where from the data should be parsed.
Returns
True if all data was successfully read and properly stored, false otherwise.

Created: 8. 10. 2018 by Petra Sečkařová (xseck.nosp@m.a02@.nosp@m.stud..nosp@m.fit..nosp@m.vutbr.nosp@m..cz). Filename: formulaAnalyser.h

Description: Implementation of methods of a class for parsing and analysing the specification file. Parses data from given file. Loads all formulae and variable definitions into internal structures of this class for later usage.

Parameters
filenameA name of file where from the data should be parsed.
Returns
True if all data was successfully read and properly stored, false otherwise.

Parse the formulae

Start of a new formula

End of current formula

Close current formula

Start loading variable definitions

check that all formulae are parsed and stored

Load variable definitions

Store full string version of each formula


The documentation for this class was generated from the following files: