jmathlib.core.interpreter
Class LexicalAnalyser

java.lang.Object
  extended by jmathlib.core.interpreter.LexicalAnalyser
All Implemented Interfaces:
ErrorCodes, TokenConstants

public class LexicalAnalyser
extends java.lang.Object
implements TokenConstants, ErrorCodes

class for turning a string expression into a vector of tokens. All public methods are static so there is no need to instantiate it. it creates an instance of itself when the analyseExpression function is called.


Field Summary
private  int bracketLevel
          bracketLevel is used to implement bracketing within expressions
private  int charNo
           
private  java.lang.String codeLine
          currently scanned line of code
private  java.lang.String delimiterChars
          List of delimiters
private  java.lang.String delimiterWords
          special reserved words which act as delimiters
private  boolean EOCharsB
          If all characters are processed the value of EOCharsB is set to TRUE
private  java.lang.String exp
          The expression being worked on
private  boolean invisibleCode
          hide evaluation of invisible code (comments, signs of numbers)
private  Token lastToken
          the last token parsed
private  boolean negative
          store whether the next value should be negative
private  Token nextToken
          store the next scanned token
private  java.lang.String numberChars
          List of characters recognised as being digits
private  boolean parseWhitespaceSwitch
          switch to enable parsing of 'spaces' and 'return' characters
private  char previousChar
          previous valid character
private  java.lang.String reservedWords
          The list of reserved words
private  java.lang.String textChars
          List of alphanumeric characters
 
Fields inherited from interface jmathlib.core.constants.TokenConstants
ADDSUB_PRIORITY, AND_PRIORITY, ANDAND_PRIORITY, ASSIGN_PRIORITY, BRACKET_PRIORITY, COMPARE_PRIORITY, CONCAT, MATRIX, MULDIV_PRIORITY, OR_PRIORITY, OROR_PRIORITY, PARAMETER, POWER_PRIORITY, RELATION_PRIORITY, SINGLE, ttDelimiter, ttNotSet, ttOperand, ttOperator
 
Fields inherited from interface jmathlib.core.constants.ErrorCodes
ERR_BRACKET_OPEN, ERR_BRACKET_ORDER, ERR_FUNCTION_NOT_FOUND, ERR_FUNCTION_NOT_IMPLEMENTED, ERR_INSUFFICIENT_PARAMETERS, ERR_INVALID_PARAMETER, ERR_LVALUE_REQUIRED, ERR_MATRIX_SINGULAR, ERR_NOT_SQUARE_MATRIX, ERR_OPNOTSUPPORTED, ERR_TOO_MANY_PARAMETERS, ERR_USER_ERROR, ERR_VARIABLE_NOTDEFINED, OK, OK_FUNCTION_PROCESS
 
Constructor Summary
LexicalAnalyser()
          default constructor - creates the lexical analyser object with an empty string
 
Method Summary
private  void advance()
          increase the pointer of the character array
 void analyseExpression(java.lang.String expression)
          Interface function used to analyse an expression
private  void backTrack()
          move back to the previouse character
 boolean EOChars()
          return true if no more characters are available for parsing
private  char getNextChar()
          return next character of exp-array, also increase the pointer in the exp-array.
 Token getNextToken(int type)
           
private  char getPreviousChar()
           
 java.lang.String getScannedLineOfCode()
          return string of currently scanned line of code for error message
private  boolean handleComment(char nextChar)
          Check if the next token is a comment
private  boolean handleDelimiter(char nextChar)
          Check if the next token is a delimiter
private  boolean handleDotOperator(char nextChar)
          Check if the next token is a dot operator
private  boolean handleEmptyLine(char nextChar)
          Sometimes a file starts with some empty line or comments.
private  boolean handleNumber(char nextChar)
          Check if the next token is a number
private  boolean handleOperator(char nextChar)
          Check if the next token is an operator
private  boolean handleSpace(char nextChar)
          Check if the next token is a whitespace
private  boolean handleString(char nextChar)
          Check if the next token is a string
private  boolean handleText(char nextChar)
          Check if the next token is a text item
private  char inspectNextChar()
          return the next character in exp-array, but do not increment pointer to next character.
private  boolean scanNextToken()
          parse the array of characters (exp[]) to find next token For each character it calls a series of functions until it finds one that can handle the character
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exp

private java.lang.String exp
The expression being worked on


bracketLevel

private int bracketLevel
bracketLevel is used to implement bracketing within expressions


lastToken

private Token lastToken
the last token parsed


previousChar

private char previousChar
previous valid character


charNo

private int charNo

EOCharsB

private boolean EOCharsB
If all characters are processed the value of EOCharsB is set to TRUE


numberChars

private java.lang.String numberChars
List of characters recognised as being digits


textChars

private java.lang.String textChars
List of alphanumeric characters


delimiterChars

private java.lang.String delimiterChars
List of delimiters


reservedWords

private java.lang.String reservedWords
The list of reserved words


delimiterWords

private java.lang.String delimiterWords
special reserved words which act as delimiters


codeLine

private java.lang.String codeLine
currently scanned line of code


nextToken

private Token nextToken
store the next scanned token


negative

private boolean negative
store whether the next value should be negative


invisibleCode

private boolean invisibleCode
hide evaluation of invisible code (comments, signs of numbers)


parseWhitespaceSwitch

private boolean parseWhitespaceSwitch
switch to enable parsing of 'spaces' and 'return' characters

Constructor Detail

LexicalAnalyser

public LexicalAnalyser()
default constructor - creates the lexical analyser object with an empty string

Method Detail

analyseExpression

public void analyseExpression(java.lang.String expression)
Interface function used to analyse an expression

Parameters:
expression - - expression to be analysed

getNextToken

public Token getNextToken(int type)
Returns:
the next token in the input string

getScannedLineOfCode

public java.lang.String getScannedLineOfCode()
return string of currently scanned line of code for error message


EOChars

public boolean EOChars()
return true if no more characters are available for parsing


inspectNextChar

private char inspectNextChar()
return the next character in exp-array, but do not increment pointer to next character. Only inspect next token, but don't process it


getNextChar

private char getNextChar()
return next character of exp-array, also increase the pointer in the exp-array.


advance

private void advance()
increase the pointer of the character array


getPreviousChar

private char getPreviousChar()

backTrack

private void backTrack()
move back to the previouse character


scanNextToken

private boolean scanNextToken()
                       throws JMathLibException
parse the array of characters (exp[]) to find next token For each character it calls a series of functions until it finds one that can handle the character

Returns:
the next token contained within the expression string
Throws:
JMathLibException

handleEmptyLine

private boolean handleEmptyLine(char nextChar)
Sometimes a file starts with some empty line or comments. This methods removes all returns,tabs,comments at the beginning of a file or after a new line


handleSpace

private boolean handleSpace(char nextChar)
Check if the next token is a whitespace

Returns:
true if it is

handleComment

private boolean handleComment(char nextChar)
Check if the next token is a comment

Returns:
true if it is

handleNumber

private boolean handleNumber(char nextChar)
Check if the next token is a number

Returns:
true if it is

handleString

private boolean handleString(char nextChar)
Check if the next token is a string

Returns:
true if it is

handleText

private boolean handleText(char nextChar)
Check if the next token is a text item

Returns:
true if it is

handleOperator

private boolean handleOperator(char nextChar)
Check if the next token is an operator

Returns:
true if it is

handleDelimiter

private boolean handleDelimiter(char nextChar)
Check if the next token is a delimiter

Returns:
true if it is

handleDotOperator

private boolean handleDotOperator(char nextChar)
Check if the next token is a dot operator

Returns:
true if it is

FOOTER

BOTTOM