Package parser
Class MathScanner
java.lang.Object
parser.MathScanner
public class MathScanner
extends java.lang.Object
- Author:
- GBEMIRO
-
Field Summary
Fields Modifier and Type Field Description Parser_Resultparser_Result -
Constructor Summary
Constructors Constructor Description MathScanner(java.lang.String scannerInput) -
Method Summary
Modifier and Type Method Description static void$removeExcessBrackets(java.util.List<java.lang.String> scanner)This technique conserves the last single bracket as it is unsure of the rules that allow it to unwrap the last bracket.static voidextractFunctionStringFromExpressionForMatrixMethods(java.util.List<java.lang.String> list)Analyzes the list and extracts the Function string from it.java.util.ArrayList<java.lang.String>getErrorList()static java.lang.StringgetFirstNumberSubstring(java.lang.String val)method getFirstNumberSubstring takes a String object and returns the first number string in the String.java.util.ArrayList<java.lang.String>getNumberStrings(java.lang.String val)method getNumberStrings takes a String object and returns an ArrayList of substrings of all numbers in the input Stringjava.util.ArrayList<java.lang.String>getScanner()java.lang.StringgetScannerInput()booleanisRunnable()static voidmain(java.lang.String[] args)voidplusAndMinusStringHandler()Handles repeated concatenations of plus and minus operators.static voidrecognizeAnonymousFunctions(java.util.List<java.lang.String> scanner)static voidremoveExcessBrackets(java.util.List<java.lang.String> scanner)This technique will rid tokens of offending brackets up to the last bracket.java.util.ArrayList<java.lang.String>scanner()Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions.java.util.ArrayList<java.lang.String>scanner(VariableManager varMan)Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressionsvoidsetErrorList(java.util.ArrayList<java.lang.String> errorList)voidsetRunnable(boolean runnable)voidsetScanner(java.util.ArrayList<java.lang.String> scanner)voidsetScannerInput(java.lang.String scannerInput)java.util.ArrayList<java.lang.String>splitStringAtFirstNumber(java.lang.String val)voidsplitStringOnMethods_Variables_And_Operators()Split thescannerInputString on the operators.java.util.ArrayList<java.lang.String>splitStringOnNumbers(java.lang.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.voidvalidateInputAfterSplitOnMethodsAndOps()Check that variables and methods do not conflict..if that can happen.voidvalidateTokens()Identifies that the input is a valid one by checking that all tokens are either Number objects, Variable objects or Operator objects.
-
Field Details
-
Constructor Details
-
MathScanner
public MathScanner(java.lang.String scannerInput)- Parameters:
scannerInput- the input of this Scanner object
-
-
Method Details
-
setScannerInput
public void setScannerInput(java.lang.String scannerInput)- Parameters:
scannerInput- sets the input of this Scanner object
-
getScannerInput
public java.lang.String getScannerInput()- Returns:
- the input into the scanner.
-
setScanner
public void setScanner(java.util.ArrayList<java.lang.String> scanner)- Parameters:
scanner- sets the ArrayList object that holds the scanned output.
-
getScanner
public java.util.ArrayList<java.lang.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(java.util.ArrayList<java.lang.String> errorList)- Parameters:
errorList- sets the list of errors.
-
getErrorList
public java.util.ArrayList<java.lang.String> getErrorList()- Returns:
- the list of errors.
-
getFirstNumberSubstring
public static java.lang.String getFirstNumberSubstring(java.lang.String val) throws java.lang.StringIndexOutOfBoundsExceptionmethod 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:
java.lang.StringIndexOutOfBoundsException
-
splitStringAtFirstNumber
public java.util.ArrayList<java.lang.String> splitStringAtFirstNumber(java.lang.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 java.util.ArrayList<java.lang.String> splitStringOnNumbers(java.lang.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:
java.lang.StringIndexOutOfBoundsException
-
getNumberStrings
public java.util.ArrayList<java.lang.String> getNumberStrings(java.lang.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:
java.lang.StringIndexOutOfBoundsException
-
splitStringOnMethods_Variables_And_Operators
public void splitStringOnMethods_Variables_And_Operators()Split thescannerInputString 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 java.util.ArrayList<java.lang.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
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(java.util.List<java.lang.String> scanner) -
$removeExcessBrackets
public static void $removeExcessBrackets(java.util.List<java.lang.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(java.util.List<java.lang.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(java.util.List<java.lang.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(java.lang.String[] args)- Parameters:
args- Command line args (((2+3)^2))!-------((25))!-------
-