Make 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 c-6  Make parsing functions for each. Java won't let you create methods called if(), etc. parseIf() 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 0 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 VariableNode. Make sure to involve a parser.java to include all the functions for the parser as shown in the rubric.  Below is the shank.txt that must be printed out as the output and attached is rubric. Make sure there are no errors in any of the files at all.      shank.txt Fibonoacci (Iterative) define add (num1,num2:integer var sum : integer) variable counter : integer   Finonacci(N)   int N = 10;        while counter < N define start () variables num1,num2,num3 : integer           add num1,num2,var num3           {num1 and num2 are added together to get num3}            num1 = num2;            num2 = num3;            counter = counter + 1;     GCD (Recursive) define add (int a,int b : gcd)  if b = 0    sum = a  sum gcd(b, a % b) GCD (Iterative) define add (inta, intb : gcd) if a = 0 sum = b if b = 0 sum = a while counter a != b             if a > b                a = a - b;            else                b = b - a;        sum = a; variables a,b : integer         a = 60    b = 96        subtract a,b

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java Programming

Make 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 c-6 

Make parsing functions for each. Java won't let you create methods called if(), etc. parseIf() 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 0 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 VariableNode.

Make sure to involve a parser.java to include all the functions for the parser as shown in the rubric. 

Below is the shank.txt that must be printed out as the output and attached is rubric. Make sure there are no errors in any of the files at all. 

 

 

shank.txt

Fibonoacci (Iterative)

define add (num1,num2:integer var sum : integer)
variable counter : integer
  Finonacci(N)
  int N = 10;
       while counter < N
define start ()
variables num1,num2,num3 : integer
          add num1,num2,var num3
          {num1 and num2 are added together to get num3}
           num1 = num2;
           num2 = num3;
           counter = counter + 1;
   

GCD (Recursive)

define add (int a,int b : gcd)
 if b = 0
   sum = a
 sum gcd(b, a % b)


GCD (Iterative)

define add (inta, intb : gcd)
if a = 0
sum = b
if b = 0
sum = a
while counter a != b 
           if a > b
               a = a - b;
           else
               b = b - a;
       sum = a;
variables a,b : integer
        a = 60
   b = 96
       subtract a,b
 

 

Rubric
Comments
Variable/Function
naming
IfNode
WhileNode
ForNode
RepeatNode
FunctionCallNode
ParameterNode
parseFor()
parseWhile()
parself()
parseFunctionCalls()
Ranges
Poor
None/Excessive
(0)
Single letters
everywhere (0)
None (0)
None (0)
None (0)
None (0)
None (0)
None (0)
None (0)
None (0)
None (0)
None (0)
None (0)
OK
"What" not
"Why", few (5)
Lots of
abbreviations (5)
Good
Some "what" comments
or missing some (7)
Full words most of the
time (8)
Parses simple for
statements correctly (5)
Parses simple while
statements correctly (5)
Parses simple if
statements correctly (5)
Parses simple function
calls correctly (5)
Implemented for
integers, strings (5)
Great
Anything not obvious has reasoning
(10)
Full words, descriptive (10)
Has constructor(s), ToString,
Conditions, Statements, Nextlf (5)
Has constructor(s), ToString,
Conditions, Statements(5)
Has constructor(s), ToString, from, to,
Statements(5)
Has constructor(s), ToString,
Conditions, Statements(5)
Has constructor(s), ToString, name,
collection of parameters(5)
Has VariableReferenceNode, Node,
constructor(s), ToString() (5)
Parses complex for statements
correctly (10)
Parses complex while statements
correctly (10)
Parses complex, chained if statements
correctly (10)
Parses complex function calls with
expressions and vars correctly (10)
Implemented for integers, strings,
reals (10)
Transcribed Image Text:Rubric Comments Variable/Function naming IfNode WhileNode ForNode RepeatNode FunctionCallNode ParameterNode parseFor() parseWhile() parself() parseFunctionCalls() Ranges Poor None/Excessive (0) Single letters everywhere (0) None (0) None (0) None (0) None (0) None (0) None (0) None (0) None (0) None (0) None (0) None (0) OK "What" not "Why", few (5) Lots of abbreviations (5) Good Some "what" comments or missing some (7) Full words most of the time (8) Parses simple for statements correctly (5) Parses simple while statements correctly (5) Parses simple if statements correctly (5) Parses simple function calls correctly (5) Implemented for integers, strings (5) Great Anything not obvious has reasoning (10) Full words, descriptive (10) Has constructor(s), ToString, Conditions, Statements, Nextlf (5) Has constructor(s), ToString, Conditions, Statements(5) Has constructor(s), ToString, from, to, Statements(5) Has constructor(s), ToString, Conditions, Statements(5) Has constructor(s), ToString, name, collection of parameters(5) Has VariableReferenceNode, Node, constructor(s), ToString() (5) Parses complex for statements correctly (10) Parses complex while statements correctly (10) Parses complex, chained if statements correctly (10) Parses complex function calls with expressions and vars correctly (10) Implemented for integers, strings, reals (10)
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Potential Method of Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education