com.agentfactory.common.util
Class Utilities

java.lang.Object
  extended by com.agentfactory.common.util.Utilities

public class Utilities
extends java.lang.Object

Utility class that rovide various helper methods that are useful for processing the list of tokens.


Constructor Summary
Utilities()
           
 
Method Summary
static java.lang.String context(java.util.List<Token> statement)
          Generates a string represetation of a given list of tokens.
static java.lang.String context(java.util.List<Token> statement, int end)
          Generates a string represetation of a given list of tokens up to a given point in the list.
static int findTokenIndex(java.util.List<Token> statement, java.lang.String token, int offset)
          Linear search that attempts to locate a given token in the list of tokens.
static int scanForParameter(java.util.List<Token> statement, int from)
          This method is used by the generateParseTree(...) method to locate individual parameters within a composite first-order type structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

context

public static java.lang.String context(java.util.List<Token> statement)
Generates a string represetation of a given list of tokens. This method delegates to the more general context method.

Parameters:
statement - a list of tokens that represents a statement in the source program
Returns:
a string representation of the token list

context

public static java.lang.String context(java.util.List<Token> statement,
                                       int end)
Generates a string represetation of a given list of tokens up to a given point in the list.

Parameters:
statement - a list of tokens that represents a statement in the source program
end - the endpoint at which the context string should cease being created
Returns:
a string representation of the token list

findTokenIndex

public static int findTokenIndex(java.util.List<Token> statement,
                                 java.lang.String token,
                                 int offset)
Linear search that attempts to locate a given token in the list of tokens. If such a token is found, then the method returns its index location, otherwise it returns -1.

Parameters:
statement - a list of tokens that represents a statement in the source code
token - a string representation of the token that is being searched for
offset - the starting point (in the list) of the search
Returns:
the index of the token in the list or -1

scanForParameter

public static int scanForParameter(java.util.List<Token> statement,
                                   int from)
                            throws SyntaxError
This method is used by the generateParseTree(...) method to locate individual parameters within a composite first-order type structure. To achieve this, the method scans forwards through the token list looking either for a comma or a close bracket that has followed an even number of open and close brackets.

Parameters:
statement - the list of tokens to be scanned
from - an offet in the list of tokens.
Throws:
SyntaxError