Using JFlex and JCup, write a parser that also builds an expression tree for Complex Attributes, a database concept.
Consider the following complex attribute program:
schema a(b(c:integer, d:string), e(f(g:integer,h:string),j:integer,k:integer) ) instances a(b(5,'Jones'),e(f(10,'Smith'),11,12)) a(b(6,'Blake'),e(f(11,'Donald'),21,22)) endThe above describes one complex attribute and two possible (valid) instances. The complex attribute being described is a "composite" attribute. Implementation of multi-valued attributes is for extra credit.
The Java program should read the above file as input and verify if the syntax is correct (according to the associated grammar). If the syntax is correct, the program should build an expression tree for the schema and one expression tree per instance. These expression trees should be returned in a vector (item 0 should be the schema tree and items 1, 2, ... should be the instance trees). Once the trees are build, the program should traverse the trees and print the schema and the instances. Sample runs are given later.
complex_attribute_program ::= SCHEMA complex_attribute INSTANCES complex_attribute_instances END complex_attribute ::= composite_attribute | multivalued_attribute composite_attribute ::= ATTRIBUTE LPAREN attribute_list RPAREN attribute_list ::= attribute | attribute COMMA attribute_list attribute ::= simple_attribute | complex_attribute simple_attribute ::= ATTRIBUTE COLON INTEGER | ATTRIBUTE COLON STRING multivalued_attribute ::= LBRACE simple_attribute RBRACE | LBRACE composite_attribute RBRACE // instance rules complex_attribute_instances ::= complex_attribute_instance | complex_attribute_instance complex_attribute_instances complex_attribute_instance ::= composite_attribute_instance | multivalued_attribute_instance composite_attribute_instance ::= ATTRIBUTE LPAREN attribute_list_instance RPAREN attribute_list_instance ::= attribute_instance | attribute_instance COMMA attribute_list_instance attribute_instance ::= simple_attribute_instance | complex_attribute_instance simple_attribute_instance ::= INTEGERVAL | STRINGVAL multivalued_attribute_instance ::= LBRACE manyvalued_attribute_instance RBRACE manyvalued_attribute_instance ::= mv_simple_attribute_instance | mv_composite_attribute_instance mv_simple_attribute_instance ::= simple_attribute_instance | simple_attribute_instance COMMA mv_simple_attribute_instance mv_composite_attribute_instance ::= composite_attribute_instance | composite_attribute_instance COMMA mv_composite_attribute_instance
[raj@tinman hw1]$ more in.1 schema a(b(c:integer, d:string), e(f(g:integer,h:string),j:integer,k:integer) ) instances a(b(5,'Jones'),e(f(10,'Smith'),11,12)) a(b(6,'Blake'),e(f(11,'Donald'),21,22)) end [raj@tinman hw1]$ java CA in.1 Number of CA instances in input file is: 2 CA Schema: a(b(c:INTEGER,d:STRING),e(f(g:INTEGER,h:STRING),j:INTEGER,k:INTEGER)) Instances in file: Instance: a(b(5,'Jones'),e(f(10,'Smith'),11,12)) Instance: a(b(6,'Blake'),e(f(11,'Donald'),21,22))
[raj@tinman hw1]$ more in.1 schema a(b(c:integer, d:string), e(f(g:integer,h:string),j:integer,k:integer) ) instances a(b(5,'Jones'),e(f(10,'Smith'),11,12)) a(b(6,'Blake'),e(f(11,'Donald'),21,22) end [raj@tinman hw1]$ java CA in.1 Parse Error - Please fix and re-run
sudo handin 1 hw1.tarYou will be prompted for your password; You must see a SUCCESS message for each file submitted. Please include your name at the top of the file for identification purposes.