edu.buffalo.fs7.mathlib
Class Tokenizer

java.lang.Object
  |
  +--edu.buffalo.fs7.mathlib.Tokenizer

public class Tokenizer
extends java.lang.Object

This class is one of the central classes for the parsing process. It analyzes a Java String object and extracts tokens from the string for which corresponding MathObject are created. The Tokenizer class is working in close connection to the Parse class, in which the identified MathObjects are further processed.

The parsing process is usually done after the preprocessing stage of the Parse class and identifies all objects in the string. It therefore is responsible for the semantics of the Mathlib parsing method.

There are two general modi, in which the Tokenizer class can be run: (a) assignments within the expression are allowed (b) assignments are not allowed.

See Also:
Parse, Mathlib

Constructor Summary
Tokenizer(java.lang.String str, boolean assignmentAllowed)
          creates a Tokenizer object for the given string.
 
Method Summary
 java.lang.String getAnswerVar()
          returns the name of the answer variable in case of an assignment
 java.lang.String getNextTokenName()
          returns the name of the next token if available.
 java.lang.String getTokenName()
          returns the name of the current token if available.
 boolean hasMoreTokens()
          returns whether or not there are more tokens.
 MathObject nextToken()
          returns the next token, returns null if there are no more tokens
 MathObject nextToken(java.lang.String errorMsg)
          returns the next token and generates an error message in case there are no more tokens.
 void pushBack()
          goes back one token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tokenizer

public Tokenizer(java.lang.String str,
                 boolean assignmentAllowed)
creates a Tokenizer object for the given string. The string is parsed and the tokens can be accessed with nextToken()
Parameters:
str - string to work on
assignmentAllowed - switch whether or not assignments are allowed
Method Detail

getAnswerVar

public java.lang.String getAnswerVar()
returns the name of the answer variable in case of an assignment

getTokenName

public java.lang.String getTokenName()
returns the name of the current token if available. Since the Parse class executes expressions in the moment they can resolved, names of variables get lost. For some operations though the name of the variable is important, e.g. Commands
See Also:
Command

getNextTokenName

public java.lang.String getNextTokenName()
returns the name of the next token if available. Since the Parse class executes expressions in the moment they can resolved, names of variables get lost. For some operations though the name of the variable is important, e.g. Commands
See Also:
Command

hasMoreTokens

public boolean hasMoreTokens()
returns whether or not there are more tokens.

nextToken

public MathObject nextToken()
returns the next token, returns null if there are no more tokens
Returns:
MathObject

nextToken

public MathObject nextToken(java.lang.String errorMsg)
returns the next token and generates an error message in case there are no more tokens. This method is used by the Parse class to generate appropriate error messages.
Parameters:
errorMsg - string to display if there are no more tokens
Returns:
MathObject

pushBack

public void pushBack()
goes back one token. A nextToken() followed by pushBack() followed by nextToken() will give the same object twice.