Java Programming: There must be no errors at all & show output. Attached is rubric.  Make ProgramNode (derived from Node, of course) to do this. But instead of ArrayList or LinkedList of FunctionNodes, make a HashMap, using the function name as the key and the FunctionNode as the value. This will make it fast to find FunctionNodes by name later.   Parsing Our parser should now expect any number of functions instead of any number of expressions. Let’s look at an example of a function and talk about how to parse it: Code Tokens define start (t : integer; s : real) define identifier leftParen identifier colon integer semicolon identifier colon real rightParen endOfLine constants pi=3.141 constants identifier equal number endOfLine variables a,b,c : integer variables identifier comma identifier comma identifier colon integer endOfLine   indent (((statements)))     dedent   We don’t have a mechanism to process statements yet. We will look for expressions inside of our functions so that indent and dedent will work (they won’t be output on empty lines, remember). The model of recursive descent should suggest some methods, here: function() processes a function. It expects a define token. Then an identifier (the name). Then a left paren. Then a list of 0 or more variable declarations. Then a right paren. Then an endOfLine. Then constants and variables. Then an indent. Then statements. Then a dedent. It returns a FunctionNode or null. parameterDeclarations() process the parameters and returns a collection of VariableNode. Remember that a parameter may or may not be var. Remember that there may not be any parameters. You can process constants and variables in one function or two (your decision). function() should call this function / these functions until there are no more. There is no strict ordering – you can have variable lines and constants lines intermixed. Constant parsing needs the logic we used in factor for determining negative and integer or float (based on number). It also needs to account for char, string and boolean (by looking for the relevant tokens – true, false, characterLiteral, stringLiteral). Making helper functions will be beneficial here. function() should expect indent, then call expression() until it returns null and print the resultant expressions (just to make sure that the parsing is still correct) then expect dedent. Since the expressions are just temporary, we won’t store them in our FunctionNode(). parse() should call function() in its loop. Every FunctionNode returned should go into the ProgramNode (there will be only one of these). null should end the parse() loop. parse() should return the ProgramNode. In main, where parse() is called, get the ProgramNode and print every FunctionNode (which will print the parameters, variables, and constants).

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: There must be no errors at all & show output. Attached is rubric. 

Make ProgramNode (derived from Node, of course) to do this. But instead of ArrayList or LinkedList of FunctionNodes, make a HashMap, using the function name as the key and the FunctionNode as the value. This will make it fast to find FunctionNodes by name later.

 

Parsing

Our parser should now expect any number of functions instead of any number of expressions.

Let’s look at an example of a function and talk about how to parse it:

Code

Tokens

define start (t : integer; s : real)

define identifier leftParen identifier colon integer semicolon identifier colon real rightParen endOfLine

constants pi=3.141

constants identifier equal number endOfLine

variables a,b,c : integer

variables identifier comma identifier comma identifier colon integer endOfLine

 

indent

(((statements)))

 

 

dedent

 

We don’t have a mechanism to process statements yet. We will look for expressions inside of our functions so that indent and dedent will work (they won’t be output on empty lines, remember).

The model of recursive descent should suggest some methods, here:

function() processes a function. It expects a define token. Then an identifier (the name). Then a left paren. Then a list of 0 or more variable declarations. Then a right paren. Then an endOfLine. Then constants and variables. Then an indent. Then statements. Then a dedent. It returns a FunctionNode or null.

parameterDeclarations() process the parameters and returns a collection of VariableNode. Remember that a parameter may or may not be var. Remember that there may not be any parameters.

You can process constants and variables in one function or two (your decision). function() should call this function / these functions until there are no more. There is no strict ordering – you can have variable lines and constants lines intermixed.

Constant parsing needs the logic we used in factor for determining negative and integer or float (based on number). It also needs to account for char, string and boolean (by looking for the relevant tokens – true, false, characterLiteral, stringLiteral). Making helper functions will be beneficial here.

function() should expect indent, then call expression() until it returns null and print the resultant expressions (just to make sure that the parsing is still correct) then expect dedent. Since the expressions are just temporary, we won’t store them in our FunctionNode().

parse() should call function() in its loop. Every FunctionNode returned should go into the ProgramNode (there will be only one of these). null should end the parse() loop. parse() should return the ProgramNode.

In main, where parse() is called, get the ProgramNode and print every FunctionNode (which will print the parameters, variables, and constants). 

 

Rubric
Comments
Variable/Function
naming
BoolNode
CharNode
StringNode
VariableNode
FunctionNode
StatementNode
ProgramNode
function()
parameterDeclarations()
constants
variables
parse
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)
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)
Processes at least one
parameter (5)
Processes at least one
constant and creates
VariableNode (5)
Processes at least one
variable and creates
VariableNode (5)
Returns a programNode
(5)
Great
Anything not obvious has reasoning
(10)
Full words, descriptive (10)
Has constructor(s), ToString, holds
bool(5)
Has constructor(s), ToString, holds
char(5)
Has constructor(s), ToString, holds
string(5)
Has name, changeable, value,
toString(), constructor(s) and extends
Node (5)
Has name, parameters, variables,
statements, toString(), constructor(s)
and extends Node (5)
Exists and extends Node (5)
Exists, has a HashMap of
FunctionNode and extends Node (5)
Creates new function Node, calls
subordinate methods (5)
Processes all parameters, returns
collection of VariableNodes (10)
Processes all constants and creates
VariableNodes for each (10)
Processes all variable and creates
VariableNodes for each (10)
Calls function repeatedly, creates and
populates ProgramNode (10)
Transcribed Image Text:Rubric Comments Variable/Function naming BoolNode CharNode StringNode VariableNode FunctionNode StatementNode ProgramNode function() parameterDeclarations() constants variables parse 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) 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) Processes at least one parameter (5) Processes at least one constant and creates VariableNode (5) Processes at least one variable and creates VariableNode (5) Returns a programNode (5) Great Anything not obvious has reasoning (10) Full words, descriptive (10) Has constructor(s), ToString, holds bool(5) Has constructor(s), ToString, holds char(5) Has constructor(s), ToString, holds string(5) Has name, changeable, value, toString(), constructor(s) and extends Node (5) Has name, parameters, variables, statements, toString(), constructor(s) and extends Node (5) Exists and extends Node (5) Exists, has a HashMap of FunctionNode and extends Node (5) Creates new function Node, calls subordinate methods (5) Processes all parameters, returns collection of VariableNodes (10) Processes all constants and creates VariableNodes for each (10) Processes all variable and creates VariableNodes for each (10) Calls function repeatedly, creates and populates ProgramNode (10)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Threads
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
  • SEE MORE 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