• Ei tuloksia

Definitions and Notations

5.2 N C 1 Refinements

6.1.1 Definitions and Notations

A matrix grammar is a regulated rewriting grammar in which rules are grouped into sequences of rules, each sequence defining amatrix. A matrix can be applied if all its rules can be applied one by one according to the order they occur in the matrix sequence. In the case of matrix grammars with appearance checking a rule in a matrix can be passed over if its left-hand side does not occur in the sentential form and the rule belongs to a special set of rules defined within the matrix grammar. Matrix grammars with context-free rules have been first defined in [1] in order to increase the generative power of context-free grammars. The definition has been extended for the case of phrase-structure

Chapter 6. Regulated Rewriting Grammars and Lindenmayer Systems

rules in [60]. The generative power, descriptional and decidability properties, along with several applications of these devices can be found in [14, 54, 56, 60, 62, 79, 146, 188].

Formally, a matrix grammar is defined as follows [54].

Definition 6.1. A matrix grammar is a quintuple G= (N, T, S, M, F) where S is the axiom,N and T,N∩T =∅, are finite sets of nonterminals andterminals, respectively, M = {m1, m2, ..., mk} is a finite set of finite sequences of rules of the form mj = (pmj,1, pmj,2, ..., pmj,kmj), where each pmj,i is a phrase-structure rule over N ∪T, 1 ≤ i ≤ kmj, 1 ≤ j ≤ k, and F is a subset of the rules occurring in the elements of M, i.e., F ⊆ {pmj,r|1 ≤j ≤k,1 ≤r ≤ kmj}. If F 6= ∅ then G is a matrix grammar with appearance checking and without appearance checking otherwise.

If all rules inM are phrase-structure (PS), context-sensitive (CS), context-free (CF), or regular (REG) rules thenG is a PS, CS, CF, or REG matrix grammar, respectively.

Definition 6.2. Let G = (N, T, S, M, F) be a matrix grammar and V =N ∪T. We say that x∈V+ directly derivesy ∈V inappearance checking mode by application of a rule p of the form α → β, α ∈ (N ∪T)N(N ∪T) and β ∈ (N ∪T), denoted by x⇒acp y, if one of the following conditions holds i. x=x1αx2 and y=x1βx2, orii.the rule α→β is not applicable to x, i.e.,α is not a substring of x,p∈F, and x=y.

Note that, if rulepin Definition6.2satisfies conditioni., then we say thatpis effectively applied. If G is a matrix grammars without appearance checking (F = ∅) then only condition i., in Definition 6.2, has to be checked, and then instead of x ⇒acp y the notationx⇒py is used.

Definition 6.3. Let G = (N, T, S, M, F) be a matrix grammar and V = N ∪T. For mj = (pmj,1, pmj,2, ..., pmj,kmj),kmj ≥1, 1≤j≤k, andx, y∈V, we define a derivation step in G, denoted as x ⇒mj y, by x = x0acp

mj ,1 x1acp

mj ,2 x2acp

mj ,3 ... ⇒acp

mj ,kmj

xkmj =y (and by x=x0pmj ,1 x1pmj ,2 x2pmj ,3 ...⇒p

mj ,kmj xkmj =y if F =∅).

The language L(G) generated by Gis defined as the set of all words w∈T such that there is a derivation D:S ⇒mj

1 y1mj

2 y2mj

3 ...⇒mjq w, 1≤ji ≤k, 1≤i≤q.

Denote byL(M, X) (L(M, X, ac)) the class of languages generated by matrix grammars with appearance checking (without appearance checking, respectively) with X-rules1, X∈ {REG, CF −λ, CF, CS, P S}.

Let G = (N, T, S, M, F) be a matrix grammar with M = {m1, m2..., mk}. According to Definition 6.2 when a matrix mj, 1≤j≤k, becomes active in appearance checking mode, rules inmj belonging to F can be passed over if they cannot be applied, i.e., the

1That is all rules inmjM, 1jk, are of type X. Recall that byCFλwe denote the class of non-erasing context-free rules, i.e., rules of the formαβ, whereαN,β(NT)+.

nonterminal rewritten by a rule inmj, and belonging toF, does not occur in the senten-tial form. However, rules inmj must be effectively applied, if this is possible. If F =∅ then all rules in mj must be effectively applied in the order they occur inmj. When a matrixmj is applied we say that a derivation step inGis consumed. When a rule inmj is applied (according to Definition6.2) we say that a derivation step inmj is consumed.

Since rules in a matrix grammar are arranged into matrices, and rules inside each matrix are applied in a predefined order, it is more convenient to associate labels with matrices than with rules. In this manner each terminal derivation in a matrix grammar can be expressed as a word over the set of labels associated in one-to-one correspondence with the matrices in the grammar, such that labels are concatenated in the same order they have been used during the derivation. Informally, the Szilard language associated with a matrix grammar is the set of all words obtained in this way. In the sequel, for the sake of simplicity, we use the same notation both for a matrix and the label associated with it. Formally, we have [38,39]

Definition 6.4. Let G= (N, T, S, M, F) be a matrix grammar, M ={m1, m2, ..., mk} the set of matrices ofG,L(G) the language generated byG, andw∈L(G). TheSzilard word of w associated with the derivation D: S ⇒mj

1 y1mj

2 y2mj

3 ... ⇒mjq w in G is defined as SzD(w) =mj1mj2...mjq, mji ∈M, 1≤ji ≤k, 1 ≤i≤q. The Szilard language of Gis Sz(G) ={SzD(w)|w∈L(G), D is a derivation ofw}.

At each step of derivation a context-free matrix grammar nondeterministically chooses which matrix is applied. Once a matrix becomes active, it works deterministically, in the sense that the order in which the rules are applied is predefined by their order in the matrix sequence. However, the order in which multiple occurrences of a nonterminal in a sentential form are rewritten, is still nondeterministically chosen. A possibility to reduce the nondeterminism in context-free matrix grammars is to impose an order in which nonterminals occurring in a sentential form can be rewritten. As in the case of Chomsky grammars, the most significant are the leftmost-like derivation orders, such as leftmost of type i, i ∈ {1,2,3}, defined and studied in [56, 60, 79, 146, 188]. For context-free matrix grammars, they are formally defined in [60], as follows:

Definition 6.5. Let G= (N, T, S, M, F) be a context-free matrix grammar, with or without appearance checking. A derivation in Gis called

• leftmost-1 if each rule used in the derivation rewrites the leftmost nonterminal occurring in the current sentential form,

• leftmost-2 if at each step of derivation the leftmost occurrence of a nonterminal which can be rewritten (by first rules of matrices that can be effectively applied, with no restrictions on the other rules) is rewritten,

Chapter 6. Regulated Rewriting Grammars and Lindenmayer Systems

• leftmost-3 if each rule used in the derivation rewrites the leftmost occurrence of its left-hand side in the current sentential form.

In other words, forleftmost-1 derivation in matrix grammars without appearance check-ing, each rule in the sequence that defines a matrix rewrites the leftmost nonterminal occurring in the current sentential form (otherwise the matrix cannot be applied in the leftmost-1 derivation manner). In matrix grammars with appearance checking, if a cer-tain rule of a matrix cannot rewrite the leftmost nonterminal, because the nonterminal rewritten by the rule does not occur in the sentential form, then the rule is passed over if it belongs toF. If the nonterminal rewritten by the rule occurs in the sentential form, but this is not the leftmost nonterminal in the sentential form, then the rule, and hence the matrix, cannot be applied in the leftmost-1 manner on that branch of derivation.

A matrix is applied in leftmost-2 derivation manner if the first rule in the matrix se-quence rewrites the leftmost nonterminal that can be rewritten by any matrix. Hence, a matrix mj can be applied in leftmost-2 derivation manner, if the first rule of mj (ef-fectively applied, for the case of appearance checking) rewrites the first occurrence of a nonterminalX, and no other matrixmj0 exists such that the first rule inmj0 (effectively applicable) rewrites a nonterminalX0, whereX0 occurs beforeX in the sentential form on which mj is applied. No other restrictions are imposed on the other rules of mj. A matrix is applied in leftmost-3 derivation manner if each rule of the matrix rewrites the leftmost occurrence of its left-hand side in the sentential form. If a certain rule in the matrix cannot rewrite the leftmost occurrence of its left-hand side (because this does not occur in the sentential form) then the rule is passed over if it belongs toF.

Szilard languages associated with leftmost-i derivations are defined in the same way as in Definition6.4with the specification thatDis a leftmost-iderivation ofw. Denote by SZMac(CF) (SZM(CF)) andSZM Laci (CF) (SZM Li(CF)) the classes of Szilard lan-guages and leftmost-i, i∈{1,2,3}, Szilard languages of matrix grammars with appear-ance checking (matrix grammars without appearappear-ance checking) with context-free rules.