Class MathScanner

java.lang.Object
parser.MathScanner

public class MathScanner extends Object
  • Field Details

    • parser_Result

      public Parser_Result parser_Result
    • errorList

      private ArrayList<String> errorList
      Contains a list of Variable objects used that are not declared.
    • runnable

      private boolean runnable
    • scannerInput

      private String scannerInput
      The math expression to be scanned.
    • scanner

      private ArrayList<String> scanner
      Contains the scanned expression
  • Constructor Details

    • MathScanner

      public MathScanner(String scannerInput)
      Parameters:
      scannerInput - the input of this Scanner object
  • Method Details

    • setScannerInput

      public void setScannerInput(String scannerInput)
      Parameters:
      scannerInput - sets the input of this Scanner object
    • getScannerInput

      public String getScannerInput()
      Returns:
      the input into the scanner.
    • setScanner

      public void setScanner(ArrayList<String> scanner)
      Parameters:
      scanner - sets the ArrayList object that holds the scanned output.
    • getScanner

      public ArrayList<String> getScanner()
      Returns:
      the ArrayList object that holds the scanned output.
    • setRunnable

      public void setRunnable(boolean runnable)
      Parameters:
      runnable - sets whether object of this class are runnable on a calculating device or not.
    • isRunnable

      public boolean isRunnable()
      Returns:
      true if the object of this class is runnable on a calculating device.
    • setErrorList

      public void setErrorList(ArrayList<String> errorList)
      Parameters:
      errorList - sets the list of errors.
    • getErrorList

      public ArrayList<String> getErrorList()
      Returns:
      the list of errors.
    • getFirstNumberSubstring

      public static String getFirstNumberSubstring(String val) throws StringIndexOutOfBoundsException
      method getFirstNumberSubstring takes a String object and returns the first number string in the String.
      Parameters:
      val - the string to analyze
      Returns:
      the index of the first occurrence of a number character in the sequence.
      Throws:
      StringIndexOutOfBoundsException
    • splitStringAtFirstNumber

      public ArrayList<String> splitStringAtFirstNumber(String val)
      Parameters:
      val - the String to analyze
      Returns:
      an ArrayList consisting of 2 or 3 parts. a. If a number substring starts the string,then it returns an ArrayList object containing the number substring and the part of the string after the number. e.g. for 231.62A+98B+sin45C, the method returns [231.62,A+98B+sin45C] b. If a number substring does not start the string but occurs later on in it, the method returns an ArrayList object containing (i.)the substring from index 0 up to, but not including the index where the first number occurs. (ii.)The number substring (iii.)The remaining part of the string after the number. The method will not be used directly by developers but will be used as a tool in math expression scanning.
    • splitStringOnNumbers

      public ArrayList<String> splitStringOnNumbers(String val)
      method splitStringOnNumbers takes a String object and returns an ArrayList of substrings in which the original string has been split into different parts based on the amount of number substrings it has.
      Parameters:
      val - the string to analyze e.g if val="123.234+43.6",the output will be [123.234,+,43.6]
      Returns:
      An ArrayList of substrings consisting of number substrings and the other substrings of the input.
      Throws:
      StringIndexOutOfBoundsException
    • getNumberStrings

      public ArrayList<String> getNumberStrings(String val)
      method getNumberStrings takes a String object and returns an ArrayList of substrings of all numbers in the input String
      Parameters:
      val - the string to analyze e.g if val="123.234+43.6",the output will be [123.234,43.6]
      Returns:
      An ArrayList of substrings consisting of number substrings and the other substrings of the input.
      Throws:
      StringIndexOutOfBoundsException
    • splitStringOnMethods_Variables_And_Operators

      public void splitStringOnMethods_Variables_And_Operators()
      Split the scannerInput String on the operators.
    • validateInputAfterSplitOnMethodsAndOps

      public void validateInputAfterSplitOnMethodsAndOps()
      Check that variables and methods do not conflict..if that can happen. Now method names and variable names are similar. The only difference between them is that methods use parentheses while variables don't. Enforce especially then that variable-parenthesis combinations that may be mistaken for methods are not allowed. e.g sin(..) is a method. A user may name a variable sin, if he/she so wishes. make sure that the user does not do things like.. varname(expr..). Rather, he/she must separate variables from parentheses using the multiplication operator.
    • validateTokens

      public void validateTokens()
      Identifies that the input is a valid one by checking that all tokens are either Number objects, Variable objects or Operator objects. Then it registers any Variable object found and initializes it to zero.
    • plusAndMinusStringHandler

      public void plusAndMinusStringHandler()
      Handles repeated concatenations of plus and minus operators.
    • scanner

      public ArrayList<String> scanner()
      Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions. This method does not check expression variables against declared variables and is only useful in breaking down the input into scanned tokens of numbers,variables and operators. The overloaded one takes a VariableManager object that models the store of Variable objects in a computing application and checks if all variable names entered by the user have been declared.
      Returns:
      an ArrayList containing a properly scanned version of the string such that all recognized number substrings,variable substrings and operator substrings have been resolved. To use this method as a scanner for math expressions all the programmer has to do is to take care of the signs where need be(e.g in -2.873*5R+sinh34.2, the scanned view will be [-,2.873,*,5,R,+,sinh,34.2]) To make sense of this, the programmer has to write minor code to concatenate the - and the 2.873 and so on.
    • scanner

      public ArrayList<String> scanner(VariableManager varMan)
      Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions
      Parameters:
      varMan - The store of all user variables already declared. The scanner will not allow the user to use any variables he/she/it has not declared
      Returns:
      an ArrayList containing a properly scanned version of the string such that all recognized number substrings,variable substrings and operator substrings have been resolved. To use this method as a scanner for math expressions all the programmer has to do is to take care of the signs where need be(e.g in -2.873*5R+sinh34.2, the scanned view will be [-,2.873,*,5,R,+,sinh,34.2]) To make sense of this, the programmer has to write minor code to concatenate the - and the 2.873 and so on.
    • recognizeAnonymousFunctions

      public static void recognizeAnonymousFunctions(List<String> scanner)
    • $removeExcessBrackets

      public static void $removeExcessBrackets(List<String> scanner)
      This technique conserves the last single bracket as it is unsure of the rules that allow it to unwrap the last bracket.
      Parameters:
      scanner - The tokens list
    • removeExcessBrackets

      public static void removeExcessBrackets(List<String> scanner)
      This technique will rid tokens of offending brackets up to the last bracket. It assumes that it knows the rules that allow one to remove all brackets from a token. One however needs check the ruls to be sure that there is no error. If this one messes up, please switch to the $removeExcessBrackets(List) method.
      Parameters:
      scanner - The list of scanned tokens.
    • extractFunctionStringFromExpressionForMatrixMethods

      public static void extractFunctionStringFromExpressionForMatrixMethods(List<String> list)
      Analyzes the list and extracts the Function string from it.
      Parameters:
      list - The list to be analyzed. Direct examples would be: intg(@sin(x+1),4,7) intg(F,4,7) where F is a function that has been defined before in the workspace.. and so on. Simplifies the list to the form matrix_method(funcName,params)
    • main

      public static void main(String[] args)
      Parameters:
      args - Command line args (((2+3)^2))!-------((25))!-------