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 voidIntroduces brackets around products of variables with themselves and with numbers.private static voidRemoves unconventional code generated and introduces final optimization modifications before the output goes to the differentiator stages.static voidprivate static voidAttempts to reduce output complexity by multiplying out bracketed expressions that are separated by the*operator.static voidOpen up unnecessary brackets..e.g.private static voidquicksimplify(ArrayList<String> scan) Runs through the scanner output and simplifies expressions like 2,*,3..2,+,3...5,^,2 and so on.static voidsimplifyTokens(ArrayList<String> scan) Coordinating method to generate math code almost ready for calculus.private static voidtokenRearranger(ArrayList<String> scan) Condenses numbers and variables to be added within a bracket to the end of the bracket.toString()private static voidunbracketNumbers(ArrayList<String> scan) Open up unnecessary brackets..e.g.private static Object[]utilitySimplifier(ArrayList<String> scan, int i)
-
Field Details
-
scanner
-
-
Constructor Details
-
CodeGenerator
-
-
Method Details
-
getScanner
-
simplifyTokens
-
unbracketNumbers
-
openUpUnnecessaryBrackets
-
bracketVariableProductsAndQuotients
-
quicksimplify
-
multiplyOutProductBrackets
-
tokenRearranger
-
cleanUp
-
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
-