Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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.

Below is what should AST claases and Parse.java must have. Make sure to give full working codes & output: 

 

IfNode: Has constructor(s), ToString, Conditions, Statements, NextIf

WhileNode: Has constructor(s), ToString, Conditions, Statements

ForNode: Has constructor(s), ToString, from, to, Statements

RepeatNode: Has constructor(s), ToString, Conditions, Statements

FunctionCallNode: Has constructor(s), ToString, name, collection of parameters

ParameterNode: Has VariableReferenceNode, Node, constructor(s), ToString() 

ParseFor(): Parses complex for statements correctly 

ParseWhile(): Parses complex while statements correctly 

ParseIf(): Parses complex, chained if statements correctly 

ParseFunctionCalls(): Parses complex function calls with expressions and vars correctly 

Ranges: Implemented for integers, strings, reals 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education