Spectra
|
#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 *¤tFormula, 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 *¤tFormula) |
OpType | decodeType (const std::string &op) |
void | noteVar (std::string name) |
int | getIndexOfVarName (std::string name) |
std::vector< formula > | getFormulae () |
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 () |
Created: 8. 10. 2018 by Petra Sečkařová (xseck). Filename: a02@ stud. fit. vutbr .czformulaAnalyser.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.
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.
formulaStack | A stack of formulae currently being processed. |
activeFormulae | A list of ids of the formulae, that are currently on the formulaStack. |
nextId | A counter used for assigning ids of the parsed formulae, is incremented by this funcion. |
currentFormula | A pointer to a formula currently at the top of formulaStack. |
More separate formulae given in specification
OpType formulaAnalyser::decodeType | ( | const std::string & | op | ) |
Decodes string representation of operator in a formula into an OpType enum value.
op | A string representation of the operator. |
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.
currentFormula | A formula at the top of the formulaStack to be stored. |
formulaStack | A stack of not-yet-ready formulae where from the currentFormula should be removed. |
activeFormulae | A list of ids of all formulae in the formulaStack. |
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.
currentFormula | A formula at the top of the formulaStack if there is any left. |
formulaStack | A stack of formulae to be processed. |
activeFormulae | A list of ids of all formulae in formulaStack. |
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.
word | A content of an atomic formula to be added by this function. |
nextId | A counter used for assigning ids to the formulae. |
currentFormula | A formula at the top of the formulaStack. The newly created formula will be added as this formula's operand. |
formulaStack | A stack of formulae currently being processed. |
activeFormulae | A list of ids of all formulae in formulaStack. |
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.
name | A name of the variable, which index is being searched. |
void formulaAnalyser::noteVar | ( | std::string | name | ) |
Ensures, that given name of a variable is stored. Updates map of appearance of given variable in formulae.
name | A 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.
name | A name of variable encountered in some part of a formula. |
activeFormulae | A list of ids of current parent formulae. |
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.
filename | A name of file where from the data should be parsed. |
Created: 8. 10. 2018 by Petra Sečkařová (xseck). Filename: a02@ stud. fit. vutbr .czformulaAnalyser.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.
filename | A name of file where from the data should be parsed. |
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