# CS3203 Team 11 Documentation (draft)
[TOC]
```cpp
a = 2
;
```
The above is considered a valid synax. The lecturer recommend tokenising by special characters instead of by whitespaces, etc.
This document will be a draft. Most likely the actual document will be another note. this is for design planning and can transfer over to the actual report when we are ready
## Documentation of PKB.h Abstract APIs
### varTable/varTableMap
Overview: varTable (map varTable index to variable name) and varTableMap (map variable name to its varTable index) stores variable name from the Parser.
API:
INDEX insertVarName(STRING varName);
Description: If varName is not found in the varTableMap, inserts varName into the varTable and varTableMap and return its index in the varTable. Else returns its index and the varTable and varTableMap remains unchanged. (The index can be used to pass to other insertion methods for other tables)
STRING getVarName(INDEX index);
Description: Returns the name of a variable at the index in the varTable. If index is out of range, throw an error.
INDEX getVarNameIndex(STRING varName);
Description: If varName is in the VarTable, returns its index. Otherwise, returns -1 (special value)
VARIABLENAMELIST getAllVariables();
Description: Returns the variable name list from the VarTable.
INTEGER getVarTableSize();
Description: Returns the total number of variables in the varTable. (Can be used for testing purposes)
INTEGER getVarTableMapSize();
Description: Returns the total number of variables in the varTableMap. (Can be used for testing purposes)
### procTable/procTableMap
Overview: procTable (map procTable index to procedure name) and procTableMap (map procedure name to its corresponding procTable index) stores procedure name from the Parser.
API:
INDEX insertProcName(STRING procName);
Description: If procName is not found in the procTable, inserts procName into the procTable and return its index. Else returns its index and the table remains unchanged.(The index can be used to pass to other insertion methods for other tables)
STRING getProcName(INDEX index);
Description: Returns the procedure name at the index in the procTable.
INDEX getProcNameIndex(STRING procName);
Description: If procName is in the ProcTable, returns its index. Otherwise, returns -1 (special value)
INTEGER getProcTableSize();
Description: Returns the total number of procedures in the procTable. (Can be used for testing purposes)
INTEGER getProcTableMapSize();
Description: Returns the total number of procedures in the procTableMap. (Can be used for testing purposes)
### parentTable
Overview: parentTable stores parent design abstraction relationship from the Parser.
API:
VOID insertParentTable(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Inserts stmtNum2 to the list of statement numbers (value) in which stmtNum1 (key) is mapped to. This method is only called if Parent(stmtNum1, stmtNum2) design abstraction relationship is true. (Precondition)
BOOLEAN isParent(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Returns true if the list of statement numbers (value), in which stmtNum1 (key) is mapped to, contains stmtNum2. Else return false.
STATEMENTNUMSLIST getParent(INTEGER stmtNum);
Description: Returns a list of statement numbers that corresponds to the stmtNum from the parentTable. If the stmtNum is absent in the parentTable, it will return a n empty list of statement numbers.
### parentStarTable
Overview: parentStarTable stores parent* design abstraction relationship from the Parser/design extractor.
API:
VOID insertParentStarTable(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Inserts stmtNum2 to the list of statement numbers (value) in which stmtNum1 (key) is mapped to. This method is only called if Parent*(stmtNum1, stmtNum2) design abstraction relationship is true. (Precondition)
BOOLEAN isParentStar(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Returns true if the list of statement numbers (value), in which stmtNum1 (key) is mapped to, contains stmtNum2. Else return false.
STATEMENTNUMSLIST getParentStar(INTEGER stmtNum);
Description: Returns a list of statement numbers that corresponds to the stmtNum from the parentStarTable. If the stmtNum is absent from the parentStarTable, it will return an empty list of statement numbers.
### followsTable
Overview: followsTable stores follows design abstraction relationship from the Parser.
API:
VOID insertFollowsTable(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Inserts the key value pair where stmtNum1 is the key which is mapped to stmtNum2 which is the value to the FollowsTable as one of the conditions for follows design abstraction relationship to be true is that the stmtNum2 must appears immediately after stmtNum1. This method is only called if Follows(stmtNum1, stmtNum2) design abstraction relationship is true. (Precondition)
BOOLEAN isFollows(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Returns true if the list of statement numbers (value), in which stmtNum1 (key) is mapped to, contains stmtNum2. Else return false.
STATEMENTNUM getFollows(INTEGER stmtNum);
Description: Returns a list of statement numbers that corresponds to the stmtNum from the followsTable. If the stmtNum is absent in the followStarTable, it will return -1.
### followsStarTable
Overview: followsStarTable stores follows* design abstraction relationship from the Parser/design extractor.
API:
VOID insertFollowsStarTable(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Inserts stmtNum2 to the list of statement numbers (value) in which stmtNum1 (key) is mapped to. This method is only called if Follows*(stmtNum1, stmtNum2) design abstraction relationship is true. (Precondition)
BOOLEAN isFollowsStar(INTEGER stmtNum1, INTEGER stmtNum2);
Description: Returns true if the list of statement numbers (value), in which stmtNum1 (key) is mapped to, contains stmtNum2. Else return false.
STATEMENTNUMSLIST getFollowsStar(INTEGER stmtNum);
Description: Returns a list of statement numbers that corresponds to the stmtNum from the followsStarTable. If the stmtNum is absent in the followsStarTable, it will return an empty list of statement numbers.
### statementToTypeTable/typeToStatementTable
Overview: statementToTypeTable (map statement number to statement type) and typeToStatementTable (map statement type to a list of statement numbers) stores statement number and statement type from the Parser.
API:
VOID insertStatementToTypeTable(INTEGER stmtNum, TYPE stmtType);
Description: Inserts the key value pair where stmtNum is the key which is mapped to stmtType which is the value.
STRING/TYPE getStmtTypeFromStmtNum(INTEGER stmtNum);
Description: Returns the statement type of the stmtNum.
STATEMENTNUMSLIST getStmtNumListFromStmtType(STRING/TYPE stmtType);
Description: Returns a list of statement numbers of stmtType.
### statementTable
Overview: statementTable stores the statement information (mapping statement number to the left side of the statement (lvalue) and the right side of the statement (rvalue) of a statement) from the Parser.
API:
VOID insertStatementTable(INTEGER stmtNum, STRING leftStatement, STRING rightStatement);
Description: Inserts statement number and the corresponding left statement (lvalue) and right statement (rvalue) to the statementTable.
PAIROFSTRINGS getLeftAndRightStatementFromStmtNum(INTEGER stmtNum);
Description: Returns a pair of strings containing the left and right statement of the corresponding stmtNum.
INTEGER getStatementTableSize();
Description: Returns the size of the statementTable.
### modifiesTableStmtNumAsKey/modifiesTableVarNameIndexAsKey
Overview: modifiesTableStmtNumAsKey (map statement number to a list of varName index from the varTable that satisfies modifies) and modifiesTableVarNameIndexAsKey (map varName index from the varTable to a list of statement numbers that satisfies modifies) stores modifies abstraction relationship from the Parser.
API:
VOID insertModifies(INTEGER stmtNum, INDEX varNameIndex);
Description: Inserts stmtNum and varNameIndex to the modifiesTableStmtNumAsKey (stmtNum is mapped to a list of varName indices where varNameIndex is added to the list if not already present in the list) and modifiesTableVarNameIndexAsKey (varNameIndex is mapped to a list of statement numbers where the stmtNum is added to the list if not already present in the list.) to show that modifies design abstraction relationship is satisfied.
Precondition: stmtNum and varNameIndex should be already inserted into their corresponding tables such as varTable and statementTable.
STATEMENTNUMSLIST getStmtNumListModifies(INDEX varNameIndex);
Description: Returns a list of statement numbers that varNameIndex is mapped to in the modifiesTableVarNameIndexAsKey that satisfies the Modifies relationship between the statement number and the varNameIndex's corresponding varName.
Precondition: varNameIndex should be already inserted in the varTable.
VARNAMEINDEXLIST getVarNameIndexModifies(INTEGER stmtNum);
Description: Returns the a list of varNameIndex that corresponds to the stmtNum in the modifiesTableStmtNumAsKey. They satisfies the Modifies relationship between the statement number and the varNameIndex's corresponding varName.
VARNAMEINDEXLIST getAllVarNameIndexListModifies();
Description: Returns a list of varNameIndex that is in the ModifiesTable (modifiesTableStmtNumAsKey/modifiesTableVarNameIndexAsKey)
STATEMENTNUMSLIST getAllStmtNumListModifies();
Description: Returns a list of statement numbers that is in the ModifiesTable (modifiesTableStmtNumAsKey/modifiesTableVarNameIndexAsKey)
### modifiesProcTableProcIndexAsKey/modifiesProcTableVarNameIndexAsKey
VOID insertProcModifies(INDEX procIndex, INDEX varNameIndex);
Description: Inserts procIndex and varNameIndex to the modifiesProcTableProcIndexAsKey (procIndex is mapped to a list of varName indices where varNameIndex is added to the list if not already present in the list) and modifiesProcTableVarNameIndexAsKey (varNameIndex is mapped to a list of procIndex where the procIndex is added to the list if not already present in the list.) to show that Modifies design abstraction relationship is satisfied.
BOOLEAN isProcModified(Index procIndex, Index varNameIndex);
Description: Returns true if the list of varNameIndex (value), in which procIndex (key) is mapped to, contains the varNameIndex in modifiesProcTableProcIndexAsKey. Else return false.
### usesTableStmtNumAsKey/usesTableVarNameIndexAsKey
Overview: usesTableStmtNumAsKey (map statement number to a list of varName index from the varTable that satisfies Uses) and usesTableVarNameIndexAsKey (map varName index from the varTable to a list of statement numbers that satisfies Uses) stores Uses abstraction relationship from the Parser.
API:
VOID insertUses(INTEGER stmtNum, INDEX varNameIndex);
Description: Inserts stmtNum and varNameIndex to the usesTableStmtNumAsKey (stmtNum is mapped to a list of varName indices where varNameIndex is added to the list if not already present in the list) and usesTableVarNameIndexAsKey (varNameIndex is mapped to a list of statement numbers where the stmtNum is added to the list if not already present in the list.) to show that Uses design abstraction relationship is satisfied.
Precondition: stmtNum and varNameIndex should be already inserted into their corresponding tables such as varTable and statementTable.
STATEMENTNUMSLIST getStmtNumListUses(INDEX varNameIndex);
Description: Returns a list of statement numbers that varNameIndex is mapped to in the usesTableVarNameIndexAsKey that satisfies the uses relationship between the statement number and the varNameIndex's corresponding varName.
Precondition: varNameIndex should be already inserted in the varTable.
VARNAMEINDEXLIST getVarNameIndexUses(INTEGER stmtNum);
Description: Returns the a list of varNameIndex that corresponds to the stmtNum in the usesTableStmtNumAsKey. They satisfies the Uses relationship between the statement number and the varNameIndex's corresponding varName.
VARNAMEINDEXLIST getAllVarNameIndexListUses();
Description: Returns a list of varNameIndex that is in the usesTable (usesTableStmtNumAsKey/usesTableVarNameIndexAsKey)
STATEMENTNUMSLIST getAllStmtNumListUses();
Description: Returns a list of statement numbers that is in the usesTable (usesTableStmtNumAsKey/usesTableVarNameIndexAsKey)
BOOLEAN isUsed(INTEGER stmtNum, INDEX varNameIndex);
Description: Returns true if the list of varNameIndex (value), in which stmtNum (key) is mapped to, contains the varNameIndex in usesTableStmtNumAsKey. Else return false.
### usesProcTableProcIndexAsKey/usesProcTableVarNameIndexAsKey
VOID insertProcUses(INDEX procIndex, INDEX varNameIndex);
Description: Inserts procIndex and varNameIndex to the usesProcTableProcIndexAsKey (procIndex is mapped to a list of varName indices where varNameIndex is added to the list if not already present in the list) and usesProcTableVarNameIndexAsKey (varNameIndex is mapped to a list of procIndex where the procIndex is added to the list if not already present in the list.) to show that Uses design abstraction relationship is satisfied.
BOOLEAN isProcUsed(Index procIndex, Index varNameIndex);
Description: Returns true if the list of varNameIndex (value), in which procIndex (key) is mapped to, contains the varNameIndex in usesProcTableProcIndexAsKey. Else return false.
### Miscellanous Methods
Overview: Additional methods that PKB has either to facilitate its operation or for testing purposes.
API:
VOID erasePKB();
Description: Clear all data structures such as varTable, varTableMap, etc so as to have a clean PKB (It is useful for testing purposes)
static PKB getInstance();
Description: If PKB has already been initialised, returns the object instance of the PKB else, initialise a PKB instance. (For singleton pattern)