Question: Build a SQL-subset compiler program IN JAVA that has semantic checks and syntax checks. You will build an abstract syntax tree and perform the following
Build a SQL-subset compiler program IN JAVA that has semantic checks and syntax checks. You will build an abstract syntax tree and perform the following semantic checks:
- Type checking (in the where-clause).
- Valid references to database objects (e.g. column not defined, relation does not exist in catalog etc.)
- Is nested query "co-related" or not?
The program should be interactive that behaves as follows (These are your test cases as well.) Take note that the program ends as soon as a ";" is inputed (Do not submit an answer that is not coded in Java):
--------------------------------------------------------------------------------------------------------------------
(Test Case 1)
$ java OurSQL
SQL>select pno,pname
SQL>from parts;
No Semantic Errors.
Not Nested.
--------------------------------------------------------------------------------------------------------------------
(Test Case 2)
$ java OurSQL
SQL>select distinct CNAME
SQL>from CUSTOMERS
SQL>where CNO in (select CNO
SQL>from ORDERS
SQL>where ONO in (select ONO
SQL>from ODETAILS
SQL>where PNO in (select PNO
SQL>from PARTS
SQL>where PRICE < 20.00 )));
No Syntax Error
No Semantic Error
Nested-Not Correlated
--------------------------------------------------------------------------------------------------------------------
(Test Case 3)
$ java OurSQL
SQL>select CNO
SQL>from ORDERS
SQL>where exists (select ONO
SQL>from ODETAILS
SQL>where ODETAILS.ONO = ORDERS.ONO and
SQL>ODETAILS.PNO = 10506) and
SQL>exists (select ONO
SQL>from ODETAILS
SQL>where ODETAILS.ONO = ORDERS.ONO and
SQL>ODETAILS.PNO = 10507) and;
Syntax Error
--------------------------------------------------------------------------------------------------------------------
(Test Case 4)
$ java OurSQL
SQL>@q1;
SQL>select CNO
SQL>from ORDERS
SQL>where exists (select ONO
SQL>from ODETAILS
SQL>where ODETAILS.ONO = ORDERS.ONO and
SQL>ODETAILS.PNO = 10506) and
SQL>exists (select ONO
SQL>from ODETAILS
SQL>where ODETAILS.ONO = ORDERS.ONO and
SQL>ODETAILS.PNO = 10507);
No Syntax Error
No Semantic Error
Nested-Correlated
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
