# API Design
## PKB
### PKB
enum class EntityType { VARIABLE, PROCEDURE, STATEMENT };
enum class StmtType { ASSIGNMENT, PRINT, READ, IF, WHILE };
Gets all ids that satisfy the predicate
`vector<int> getAllIds(function<bool(int)> predicate);`
Gets id of the EntityType with the specified name (proc name, var name, statement number)
`optional<int> getId(string name, EntityType type);
EntityData getEntityData(int id);`
Adds new entity with the specified name, EntityType, and StmtType)
`int addNewEntity(string name, EntityType type,
optional<StmtType> StmtType = nullopt);`
Sets the relations between two entities
```
void setModifies(int lhs, int rhs);
void setUses(int lhs, int rhs);
void setParent(int lhs, int rhs, bool isMultiLevel);
void setFollow(int lhs, int rhs, bool isMultiLevel);
```
Predicates to check the type of the entity given the id
```
bool isStatement(int id);
bool isProcedure(int id);
bool isVariable(int id);
```
Predicates to check the type of the stmt given the id
```
bool isAssignment(int id);
bool isPrint(int id);
bool isRead(int id);
bool isIf(int id);
bool isWhile(int id);
```
Predicates to check the relation between two entities given the ids
```
bool isModifies(int lhs, int rhs);
bool isUses(int lhs, int rhs);
bool isParent(int lhs, int rhs, bool isMultiLevel);
bool isFollow(int lhs, int rhs, bool isMultiLevel);
```
Predicates to check the whether the statement fulfilss the pattern
```
bool isPattern(int stmtId, optional<int> lhsId, string rhsPattern, bool isRhsFullMatch);
bool isPattern(int stmtId, int lhsId);
```
## Source Processor
`void setPKB(shared_ptr<pkbns::PKB> _pkb);`
`void setLexer(shared_ptr<Lexer> _lexer);`
`void runWithFilename(string filename);`
`void runWithSource(string source);`
## PQL
### PQL
Sets the PKB pointer to be used by the PQL
`void setPKB(shared_ptr<pkbns::PKB> _pkb);`
Runs PQL to evaluate the query string, returns the list of strings
`list<string> run(const string &query);`
### PQL Parser
Constructs PQL Parser
`PQLParser();`
Tokenizes the query string into tokens recognized by the PQL parser
`void runLexer(string query);`
Parses the tokens to get the selected synonym, list of declared synonyms, list of relations, and list of patterns
`void runParser(string &selectedSynonym, vector<Synonym> &synonyms,
vector<Relation> &relations, vector<Pattern> &patterns);`
### PQL Evaluator
Constructs PQL Evaluator
`PQLEvaluator(shared_ptr<pkbns::PKB> _pkb) : pkb(_pkb){};`
Gets the list of values of the selected synonym fulfilling the relations and patterns condition
`list<string> evalQuery(string &selectedSynonym, vector<Synonym> &synonyms,
vector<Relation> &relations,
vector<Pattern> &patterns);`