question archive Consider a simple SQL query that retrieves a character string from a column of the Table "Formulae" as below: Select "Formula" from "Formulae" where "ID"=5; The returned value may be like: '(<A1>+<A2>)*0
Subject:Computer SciencePrice:0 Bought3
Consider a simple SQL query that retrieves a character string from a column of the Table "Formulae" as below:
Select "Formula" from "Formulae" where "ID"=5; The returned value may be like: '(<A1>+<A2>)*0.5 - <A3>'
where <Al>, <A2>, <A3> etc. Are to be substituted by the fieldnames stored in a Table "Fo rmul aF i e lds". An example schema can be: ("TuplelD", "VariableName","ColumnName") (1,'<A1>','Salary.Basic') (2,'<A2>','Salary.TA') (3,'<A3>','Salary.PF')
(i.e, tablename.columnname is stored in the third column of the table)
Having obtained the formula from the table by a query such as above, you need to convert it to a corresponding SQL query. For the example above, the resulting query should be
Select ((Basic + TA) * 0.5 - PF) as "Result" from "Salary" where ... (some condition here)
To do: 1. Use _I ex (flex) to scan and interpret formula that is always constructed from symbols of the form <Al>, <A2> etc., and numeric literals, and arithmetic operators +, —, *, / and ( ) [2 Marks] 2. Use yacc (bison) to generate parser for checking if formula is correctly formed according to standard grammer of arithmetic expressions involving tokens from 1 above [3 Marks] 3. Generate code equivalent to the example SQL code given above by specifiying appropriate instructions in parser using C/C++. [2 Marks] 4. Make the tables " Fo rmu 1 ae" and "Salary" in some DBMS, say MySQL, and test run the successful execution of the generated query. [2 Marks] 5. Include documentation for your design, standard comments in source code, and any special assumptions you make. [1 Mark]