Problem E: Structural Equivalence In programming language design circles, there has been much debate about the merits of "structural equivalence" vs. "name equivalence" for type matching. Pascal purports to have "name equivalence", but it doesn't; C purports to have structural equivalence, but it doesn't. Algol 68, the Latin of programming languages, has pure structural equivalence. Here is a simplified syntax for Algol 68 type definitions. Each type definition consists of the keyword "type" followed by the type name (a single uppercase letter) followed by "=" followed by a type expression. A type expression is one of the following: 1) a basic type ("int", "real" or "char"), or 2) a type name, or 3) the keyword "struct" followed by "(", then a list of type names, then ")". Whenever a type name is used on the right hand side of an equal sign you can assume that it has already been defined in a previous type definition. The following are examples of type definitions: type A = int type B = real type C = struct ( A B ) type D = B type E = struct ( A D ) Algol 68 type equivalence say that two types are equivalent if they are the same primitive type or they are both structures containing equivalent types in the same order. In the above example, D and B are equivalent. C and E are also equivalent. In this problem, you will have to determine whether two types are equivalent. Input consists of several test cases. Each test case is a sequence of Algol 68 definitions, as described above, one per line. Next, there will be a sequence of lines containing queries of the form ? X Y (where X and Y are type names). For each query output "equivalent" or "not equivalent". A line containing "*" separates test cases. A line containing "#" follows the last test case. Output an empty line between test cases. Sample Input ------------ type A = int type B = int type C = struct ( A ) ? A B ? B C * type A = int type B = A type C = int type X = struct ( A B ) type Y = struct ( B A ) type Z = struct ( A Z ) type S = struct ( A S ) type W = struct ( B R ) type R = struct ( C W ) ? R W ? A A ? C R ? A B # Output for Sample Input ----------------------- equivalent not equivalent equivalent equivalent not equivalent equivalent