A new programming language is being designed. One of its new features is related to the
specification of arrays. The language deals only with arrays of integers, and there are two
ways of specifying new arrays:
- 1.
- by explicit declaration of its size. For example:
These sentences specify A and B as arrays of 1 and 3 elements, respectively. This
implies that any sequence with the specified size is a possible value for the array.
- 2.
- by inclusion of previously defined arrays. For example:
C is
D is
SEQ is [1] A [4]
The size for arrays specified in this manner is determined by the size of its sub-arrays.
Besides, if a specification includes the same array more than once, the subsequences in
the array corresponding to the repeated parts have to hold the same value.
For the aforementioned specification of A and B, we have C with size 4, D with size
2, and SEQ with size 14.
Assignments are expressed in the language by the following statement:
<
array >
=
For example,
B = 3 4 15
is a valid assignment for B. Notice that the assignment B = 3 4 would be inconsistent
with B's specification (which stated that B would hold a sequence of integers with size 3).
The assignment D = 1 2 would also be inconsistent, since D's specification implies that
D is formed by the repetition of a size 1 sequence of integers. D = 1 1 is an example of a
consistent assignment for D.
In other words, for the specification
the assignment
is said to be consistent if and only if S is a sequence
where
and
- for every previously defined subsequences Sa, Sb (
)
such
that Sa = Sb we have (
)
= (
).
The language designers want you to cooperate with the compiler construction effort: you
have to write a program that receives as input a collection of array specifications and a
sequence of assignments, and produces as output the list of inconsistent assignments.
The input file is composed by a list of array specifications followed by a list of assignments.
An array specification has the following format:
- <id>
- is
.
- <id>
- is a sequence of characters representing the array name.
You can assume that (1) the length of this sequence is between 1 and 32 and
(2) the sequence follows the rules for identifier names in the programming
language that you are using.
- di
- is
either [k] where k is a strictly positive integer (there may be spaces between k and its
surrounding brackets)
or <id>, where <id> is the name of a previously specified array.
The sequence of di's is terminated by a period.
An assignment sepcification has the following format:
<id> =
.
<id> is the name of a previously specified array and ij are
positive integers. The list of ij's is terminated by a period.
In both types of specifications, an arbritrary number of spaces or empty lines can appear
between the tokens.
The output file must contain the list of assignment specifications from the input file that are
inconsistent. The output for each of the inconsistent assignments should be its specification
as it appeared in the input file.
A is [1].
B is [3].
C is A B.
SEQ is [1 ] A [4] B A.
A = 10.
B = 1 2 3.
C = 1 1 2 3 4.
SEQ = 1 10 1 1 1 1 2 2 2 10.
SEQ = 1 10 1 1 1 1 1 2 3 9.
C = 1 1 2 3 4.
SEQ = 1 10 1 1 1 1 1 2 3 9.
Miguel Revilla
2000-12-30