Package math.differentialcalculus
Class CodeGenerator
java.lang.Object
math.differentialcalculus.CodeGenerator
Objects of this class take the output of the semantic
analyzer and uses it to generate code that the derivative engine can
work with.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
Introduces brackets around products of variables with themselves and with numbers.private static void
Removes unconventional code generated and introduces final optimization modifications before the output goes to the differentiator stages.static void
private static void
Attempts to reduce output complexity by multiplying out bracketed expressions that are separated by the*
operator.static void
Open up unnecessary brackets..e.g.private static void
quicksimplify
(ArrayList<String> scan) Runs through the scanner output and simplifies expressions like 2,*,3..2,+,3...5,^,2 and so on.static void
simplifyTokens
(ArrayList<String> scan) Coordinating method to generate math code almost ready for calculus.private static void
tokenRearranger
(ArrayList<String> scan) Condenses numbers and variables to be added within a bracket to the end of the bracket.toString()
private static void
unbracketNumbers
(ArrayList<String> scan) Open up unnecessary brackets..e.g.private static Object[]
utilitySimplifier
(ArrayList<String> scan, int i)
-
Field Details
-
scanner
-
-
Constructor Details
-
CodeGenerator
- Parameters:
expression
-- Throws:
Exception
-
-
Method Details
-
getScanner
-
simplifyTokens
Coordinating method to generate math code almost ready for calculus.- Parameters:
scan
- An ArrayList object containing math tokens.
-
unbracketNumbers
Open up unnecessary brackets..e.g. (5) becomes 5- Parameters:
scan
- The scanner output.
-
openUpUnnecessaryBrackets
Open up unnecessary brackets..e.g. (5) or 3+(2-9+8+cos(4))-7*x..should become 3+2-9+8+cos(4)-7*x- Parameters:
scan
- The scanner output.
-
bracketVariableProductsAndQuotients
Introduces brackets around products of variables with themselves and with numbers.- Parameters:
scan
- The scanner output.
-
quicksimplify
Runs through the scanner output and simplifies expressions like 2,*,3..2,+,3...5,^,2 and so on. It does this in readiness for token re-arranging. It also removes some unnecessary brackets.- Parameters:
scan
- The scanner output.
-
multiplyOutProductBrackets
Attempts to reduce output complexity by multiplying out bracketed expressions that are separated by the*
operator.- Parameters:
scan
- The scanner output.
-
tokenRearranger
Condenses numbers and variables to be added within a bracket to the end of the bracket. For instance,(3+x+sin(3*x)+5-7) becomes (sin(3*x)+3+x+5-7)- Parameters:
scan
- The scanner output.
-
cleanUp
Removes unconventional code generated and introduces final optimization modifications before the output goes to the differentiator stages.- Parameters:
scan
- The scanner output.
-
utilitySimplifier
- Parameters:
scan
- The ArrayList object containing the scanned tokens.i
- The starting index in the ArrayList.- Returns:
- an object array containing in the first index, the ending index after simplifying as far as possible and in the second index, the ArrayList object that stores the simplified version of the scanner output in the given range. This stage simplifies portions of the expression that have strings of multiplications and divisions of numbers and variables, generating number products and variable powers. Come here to allow the parser deal with the pattern x^constant_name also. For now, it deals with x^constant_value...e.g. x^3 but not x^a. Once this is done, update the other parser methods as relevant all through the parser.
-
toString
-
main
-