org.problets.domain.model.implement
Class SymbolTable

java.lang.Object
  extended by org.problets.domain.model.implement.SymbolTable

public class SymbolTable
extends java.lang.Object

A static class to hold the variable, pointer and function names for the program, available data types for the chosen language, and a list of random constants used in the program template

Author:
Amruth Kumar

Field Summary
static int NOT_FOUND_INDEX
          Integer index returned if a variable name is not found in the symbol table
static java.lang.String NOTFOUND
          String returned if a variable name is not found in the symbol table
 
Constructor Summary
SymbolTable()
           
 
Method Summary
static void addNameAt(java.lang.String type, java.lang.String name, int index)
          Adds the name of a new variable/pointer/function to the symbol table at the given index
static boolean exists(java.lang.String type, java.lang.String name)
          Returns whether an object of given type and name already exists in the program
static int getIndex(java.lang.String type, java.lang.String name)
          Returns the index (e.g., 1 in ) corresponding to the name of a variable, pointer, function or data type
static java.lang.String getName(java.lang.String token)
          Given a token such as , returns the corresponding name, after automatically determining the type of the token (variable/pointer/function/data type/random constant)
static java.lang.String getName(java.lang.String type, int index)
          Returns the name corresponding to the template index (e.g., 1 in ) of a variable, pointer, function or data type
static RandomModel getRandomValue(int index)
          Fetches the random value (RandomModel object) of the given index in the symbol table.
static RandomModel getRandomValue(java.lang.String template, java.lang.String contextDataType)
          Fetches the random value (RandomModel object) corresponding to the template.
static void main(java.lang.String[] args)
           
static void print()
          Prints all the variable names, pointer names, function names and data types in the symbol table along with the index with which they are referred to in the problem template, e.g., count is
static void reset(java.lang.String template)
          Clears the symbol table of all prior names of pointers, variables, and functions; clears all random values from the symbol table and randomizes the data types for the new template.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOTFOUND

public static final java.lang.String NOTFOUND
String returned if a variable name is not found in the symbol table

See Also:
Constant Field Values

NOT_FOUND_INDEX

public static final int NOT_FOUND_INDEX
Integer index returned if a variable name is not found in the symbol table

See Also:
Constant Field Values
Constructor Detail

SymbolTable

public SymbolTable()
Method Detail

getName

public static java.lang.String getName(java.lang.String token)
Given a token such as , returns the corresponding name, after automatically determining the type of the token (variable/pointer/function/data type/random constant)

Parameters:
token - String token such as , , , and (angle brackets mandatory)
Returns:
String name corresponding to the token parameter

getName

public static java.lang.String getName(java.lang.String type,
                                       int index)
Returns the name corresponding to the template index (e.g., 1 in ) of a variable, pointer, function or data type

Parameters:
type - String with one of the following values: pointer/variable/function/datatype
int - Integer index of the object whose name is sought (e.g., 1 in )
Returns:
String name of the object of type at index

getIndex

public static int getIndex(java.lang.String type,
                           java.lang.String name)
Returns the index (e.g., 1 in ) corresponding to the name of a variable, pointer, function or data type

Parameters:
type - String with one of the following values: variable/pointer/datatype/function
name - String name of the variable/pointer/datatype/function whose index is sought
Returns:
Integer index of the variable/pointer/datatype/function whose name was provided

exists

public static boolean exists(java.lang.String type,
                             java.lang.String name)
Returns whether an object of given type and name already exists in the program

Parameters:
type - String with one of the following values: variable/pointer/datatype/function (not case-sensitive)
name - String name of the variable/pointer/datatype/function whose existence is of interest (case-sensitive)
Returns:
true if variable/pointer/datatype/function of given name exists in the program/Symbol Table and false otherwise

getRandomValue

public static RandomModel getRandomValue(java.lang.String template,
                                         java.lang.String contextDataType)
Fetches the random value (RandomModel object) corresponding to the template. If the random value does not already exist, creates and adds it to the symbol table before returning it.

Parameters:
template - String template of the random object sought, such as or
contextDataType - String representing the desired data type of the random object if it has to be created
Returns:
RandomModel object corresponding to the template

getRandomValue

public static RandomModel getRandomValue(int index)
Fetches the random value (RandomModel object) of the given index in the symbol table.

Parameters:
index - Integer index of the desired random object (e.g., 1 as in )
Returns:
RandomModel object corresponding to the given index; null if the object does not exist

addNameAt

public static void addNameAt(java.lang.String type,
                             java.lang.String name,
                             int index)
Adds the name of a new variable/pointer/function to the symbol table at the given index

Parameters:
type - String with a value of pointer, variable, or function (not case-sensitive)
name - String name of the pointer, variable, or function that must be added to the symbol table
index - Integer index at which the name of the new pointer, variable, or function must be added to the symbol table

reset

public static void reset(java.lang.String template)
Clears the symbol table of all prior names of pointers, variables, and functions; clears all random values from the symbol table and randomizes the data types for the new template.

Parameters:
template - String template of the new problem for which the symbol table is re-initialized

print

public static void print()
Prints all the variable names, pointer names, function names and data types in the symbol table along with the index with which they are referred to in the problem template, e.g., count is


main

public static void main(java.lang.String[] args)