Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE PROVIDE ME THE EXACT CODE FOR JAVA FROM START TO THE END Check from the details and provide the code from what you understood
PLEASE PROVIDE ME THE EXACT CODE FOR JAVA FROM START TO THE END
Check from the details and provide the code from what you understood
Introduction In this assignment, we will add the rest of the statements. That might sound a little intimidating. There is a pattern to it. Make an AST node that holds all of the pieces of the statement. Then make a new method to look for that statement type and create the AST node that you just made. Perhaps the most difficult part of this is the function call. Let's look at that in more depth. A function call is: IDENTIFIER [PARAMETER]\{,PARAMETER\} Remember that [] means optional and \{\} means repeated 0 or more times. What's a parameter? Either var IDENTIFIER or booleanCompare (which, of course, includes expression). The other slightly trick part is dealing with nested if blocks. The key here is to make (manually) a linked list. Consider this example: if imod15=0 then write "FizzBuzz" if i mod 15=0 then write "FizzBuzz " elsif i mod 3=0 then write "Fizz " elsif i mod 5=0 then write "Buzz " Leaving the statements out to clarify the diagram, here is what an AST tree for this statement look like. Remember that the condition is a booleanCompare, so that code is already written. code for processing statements (statements() method). Leaving the statements out to clarify the diagram, here is what an AST tree for this statement should look like. Remember that the condition is a booleanCompare, so that code is already written. So is the code for processing statements (statements() method). Details Create AST Nodes: IfNode, WhileNode, RepeatNode. All will have BooleanCompare for a condition and a collection of StatementNode. Details Create AST Nodes: IfNode, WhileNode, RepeatNode. All will have BooleanCompare for a condition and a collection of StatementNode. ForNode will have a Node for from and a node for to. This will have to be of type Node because it could be any expression. For example: for a from 1+1 to c6 Create parsing functions for each. Java won't let you create methods called if(), etc. parself() is an example of a way around that; use whatever you like but use good sense in your names. Next let's look at function calls. Each function has a name and a collection of parameters. A parameter can be a VAR variable or something that came from booleanCompare (IntegerNode, VariableReferenceNode, etc). It would be reasonable to make 2 objects - ParameterVariableNode and ParameterExpressionNode. But for this very simple and well-defined case, we can do something simple: for a from 1+1 to c6 Create parsing functions for each. Java won't let you create methods called if(), etc, parself() is an example of a way around that; use whatever you like but use good sense in your names. Next let's look at function calls. Each function has a name and a collection of parameters. A parameter can be a VAR variable or something that came from booleanCompare (IntegerNode, VariableReferenceNode, etc). It would be reasonable to make 2 objects - ParameterVariableNode and ParameterExpressionNode. But for this very simple and well-defined case, we can do something simple: ParameterNode has a VariableReferenceNode (for VAR IDENTIFIER) and a Node for the case where the parameter is not a VAR. One more thing - type limits. Remember that these are a way to put a range on your variables. variables numberofCards : integer from to 52 These apply to integer, real, string. Array already has this built in with the from and to. We can reuse that from/to range. We will have to make a mirror pair (realFrom, realTo - both float) for supporting ranges on real. Make the variable declaration parser changes and add the floating-point ranges to VariableNodeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started