Class MathScanner
java.lang.Object
parser.MathScanner
-
Field Summary
FieldsModifier and TypeFieldDescriptionContains a list of Variable objects used that are not declared.private boolean
Contains the scanned expressionprivate String
The math expression to be scanned. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static void
Analyzes the list and extracts the Function string from it.static String
method getFirstNumberSubstring takes a String object and returns the first number string in the String.getNumberStrings
(String val) method getNumberStrings takes a String object and returns an ArrayList of substrings of all numbers in the input Stringboolean
static void
void
Handles repeated concatenations of plus and minus operators.static void
recognizeAnonymousFunctions
(List<String> scanner) static void
removeExcessBrackets
(List<String> scanner) This technique will rid tokens of offending brackets up to the last bracket.scanner()
Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions.scanner
(VariableManager varMan) Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressionsvoid
setErrorList
(ArrayList<String> errorList) void
setRunnable
(boolean runnable) void
setScanner
(ArrayList<String> scanner) void
setScannerInput
(String scannerInput) void
Split thescannerInput
String on the operators.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.void
Check that variables and methods do not conflict..if that can happen.void
Identifies that the input is a valid one by checking that all tokens are either Number objects, Variable objects or Operator objects.
-
Field Details
-
parser_Result
-
errorList
-
runnable
private boolean runnable -
scannerInput
The math expression to be scanned. -
scanner
-
-
Constructor Details
-
MathScanner
- Parameters:
scannerInput
- the input of this Scanner object
-
-
Method Details
-
setScannerInput
- Parameters:
scannerInput
- sets the input of this Scanner object
-
getScannerInput
- Returns:
- the input into the scanner.
-
setScanner
-
getScanner
-
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
-
getErrorList
-
getFirstNumberSubstring
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
- 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
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
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 thescannerInput
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
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
-
$removeExcessBrackets
-
removeExcessBrackets
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
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
- Parameters:
args
- Command line args (((2+3)^2))!-------((25))!-------
-