mutationUtils

This component was developed to provided functions needed to manage mutations. As such it deals heavily with the DanaToken and DanaType data types which are produced by the code parser.

Types

  • DanaToken - Created by parser, contains a token from the code with pointer to following tokens.

  • DanaType - Created by parser, used to assign token type.

  • Operator - Contains the literal used in the operators DanaToken, the number of variables the operator takes and the input and return types.

  • Variable - From the randData interface, has the literal used in the variables DanaToken and the variables type.

allowedMutations()

  • Inputs: DanaToken token, dec weights[]

  • Outputs: dec newWeights[]

Takes the DanaToken to be effected and the existing weights for mutations. It assesses the token in regards to different mutation types. This is based on the token type and literal and not any scope issues which are resolved during the mutation attempt. If a mutation is possible its weight is multiplied by 1 and if it is not possible its weight is multiplied by zero. The modified weights are returned.

getTokenList()

  • Inputs: DanaToken tree

  • Outputs: DanaToken tokenList[]

Returns a list of all line level DanaTokens in the provided tree. For instance for: a = b + c, only the “=” token would be placed in the list as the top level token in this line of code. It stops before including a “return” token as this is exempt from mutation and crossover or at the end of the tree.

randOp()

  • Inputs: None

  • Output: Operator randomOperator

This function returns a randomly selected operator around which code synthesis can build a statement.

typeMatchVariable()

  • Inputs: DanaToken tree, DanaToken where, bool after, DanaType typeset[]

  • Outputs: Variable matchingVariables[]

Takes information on where the variable is needed to use to check the scope for variables available at that point in the code. It then compares the list of variables to create pairs of variables with matching types. It then randomly selects a pair of variables from the matched list to return.

nextVariableNameList()

  • Inputs: Variable list[]

  • Outputs: char name[]

Function searches for a variable name in our internal list that is not in the list of pre-existing variables handed into the the function.

nextVariableName()

  • Inputs: DanaToken tree, DanaToken location, DanaType typeset[]

  • Outputs: char name[]

Checks scope to form variable list and then uses nextVariableNameList() to find and return a variable name.

matchingOperator()

  • Inputs: Operator toMatch

  • Outputs: Operator matchingOp

Returns a different operator with the same input/output types and taking the same number of variables.

matchingVariable()

  • Inputs: Variable toMatch, DanaToken tree, DanaToken where, bool after, DanaType typeset[], opt bool write

  • Outputs: Variable matchingVar

Returns a variable available in scope at the where token within the tree with the same type as the toMatch variable.

matchingComparison()

  • Inputs: Operator toMatch

  • Outputs: Operator matchingOp

Returns a different comparison with the same input/output types and taking the same number of variables.

setOperation()

  • Inputs: DanaToken opToken

  • Outputs: Operator matchingOp

Generates an Operator from the DanaToken.

setComparison()

  • Inputs: DanaToken compToken

  • Outputs: Operator matchingOp

Generates an Operator for a comparison token.

setVariable()

  • Inputs: DanaToken tree, DanaToken where, DanaToken var, DanaType typeset[]

  • Outputs: Variable variable

Generates a variable from the DanaToken var. Full scope is needed to identify type of the variable.

numVariable()

  • Inputs: DanaToken tree, DanaToken where, bool after, bool integer, DanaType typeset[], opt bool write

  • Outputs: Variable numericVar

Finds all numerical variables in scope at the where token within the tree, this can be set to consider integers only. A random variable is selected for return from the list.

fullFunctionScope()

  • Inputs: DanaToken func, DanaType typeset[]

  • Outputs: Variable scope[]

Returns list of all variables within a function including those declared in the header. Used for generation list of used variables names to check against before selecting a new variable name.