On efficient implementation of LR-attributed grammars

On efficient implementation of LR-attributed grammars

Information Processing North-Holland Letters 14February 41 (1991) 67-75 1992 On efficient implementation of LR-attributed grammars Petr Pavlii * ...

777KB Sizes 1 Downloads 42 Views

Information Processing North-Holland

Letters

14February

41 (1991) 67-75

1992

On efficient implementation of LR-attributed grammars Petr Pavlii * Department

of Computers,

Czech Technical University, Karlovo Na’mbti

13, 121 35 Prague 2, Czechoslovakia

Communicated by K. Ikeda Received 10 August 1991 Revised 8 November 1991

Abstract Pa&,

P., On efficient

implementation

of LR-attributed

grammars,

Information

Processing

Letters

41 (1991) 67-75.

Several methods have been proposed for the evaluation of attributes during LR parsing. Some of these methods are based on the construction of semantic expressions for computing the values of inherited attributes, associated with states of the LR-automaton. In these methods, the semantic expressions are constructed and evaluated separately. This may lead to situations, where some computations are repeated. This paper exposes the redundant computations in these methods, and an optimization is introduced to avoid them. Keywords:

Specification expressions,

languages, formal semantics, LR parsing, compilers, compiler writing systems

1. Introduction

If attribute evaluation is performed during LR parsing, a problem arises because of the evaluation of inherited attributes. The top-down “information stream” represented by inherited attributes does not fit in the bottom-up pass over the parse tree, performed by the LR parser. The use of semantic expressions for evaluation of inherited attributes during LR parsing has originally been proposed in [6] and 131,and elaborated later in [8] and [9]. Inherited attributes are associated with the states of the LR-automaton, and semantic expressions are computed for them

* This paper was prepared during the author’s study-period at the Department of Computer Science of the University of Twente, Enschede, The Netherlands. This study-period was supported by a mobility grant of the Commission of the European Communities within the framework of the TEMPUS scheme. 0020-0190/92/$05.00

0 1992 - Elsevier

Science

Publishers

attribute

grammars,

LR-attributed

grammars,

semantic

in the parser-construction phase. The semantic expressions are then used during parsing to compute values of inherited attributes. If the semantic expressions are constructed using the method described in [8], the attribute evaluation can suffer from inefficiency. In a particular LR state, some semantic expressions may be equivalent, or may have common parts. Despite that, each semantic expression is evaluated regardless of the others. Conseseparately, quently, a computation may be performed several times, even though the result is known since the first execution. In [9], a more efficient method of attribute evaluation has been proposed that is based on the partition of inherited attributes into equivalence classes. Nevertheless, as shown in Section 4 of this paper, this approach does not exclude all the redundant (repeated) computations. Moreover, the efficiency of attribute evaluation strongly depends on the definition of equivalence classes.

B.V. All rights reserved

67

Volume 41, Number 2

INFORMATION

PROCESSING

And the requirement of finding the optimal partition confronts the parser generator (we should not burden the user with this work) with a difficult task. We propose in Section 5 an optimized approach to the construction and evaluation of semantic expressions in which all the redundant computations are avoided. The optimization is based on an ordering of the semantic expressions in a particular LR state, and on the construction of the smallest possible number of semantic expressions that are sufficient for evaluating all inherited attributes in this state. In this way, also the number of attribute values actually stored in the stack during parsing is minimized.

LETTERS

14 February 1992

An attribute grammar (AG) is a context-free grammar (called the underlying CFG) augmented with attributes and semantic rules [4]. The set A of atributes of the AG is divided into two mutually disjoint sets ZA of inherited, and &I of synthesized attributes. A = LA USA. The set of attributes of a grammar symbol X is denoted A(X), and A(X) = LA(X) U SA(X), where LA(X) and SA(X) are the sets of inherited and synthesized attributes of X, respectively. Attribute a of grammar symbol X is denoted X.a. The start symbol and the terminal symbols of the attribute grammar are assumed to have no inherited attributes. In production p:x,-x,x,...x,, X,.b

2. Basic concpets and notations It is assumed that the reader is familiar with context-free grammars and LR parsing, and that he or she has some knowledge of attribute grammars. Most of the notions and notations used in this paper can be found in [21, [l], and [7]. A context-free grammar (CFG) is a four-tuple G = (N, 2, P, Z), where N is the set of nonterminal symbols, 2 the set of terminal symbols (the union N u _Z is called the uocabufary, denoted V, and its elements are called grammar symbols), P is the set of productions (of the form A + (Y,A is from N, and (Y from I/ *) and 2 is the start (nonterminal) symbol. Every grammar in this paper is assumed to be reduced-i.e. there are no useless symbols in I/. Grammar symbols are denoted by roman capitals X, Y,. . . , nonterminals by A, B, . . . , and terminals by a, b,. . . . Terminal strings (elements of .Z*) are denoted by U, U, w, . . . . For strings of grammar symbols (elements of V * 1, we use greek letters a, p,. . . . The empty string is denoted by E. For LR parsing, we refer to [2], or to [l]. KERNEL(S) indicates the kernel of a state S of the LR(k)-automaton. We write an LR(k) item in the usual way: [A + CY./3, ul. For simplicity, the cores ([A -+ cy. p]) are used instead of complete LR(k) items. 68

(for k = 0, l,..., n) is an input (or used) attribute occurrence of p, if either b is an inherited attribute and k = 0, or b is a synthesized attribute and k > 0. In other cases, X,.b is an output (or defined) attribute occurrence of p. For each output attribute occurrence X,.b, there is one semantic rule X,.b

:=f(Xj,.aI,

Xjz.a2 ,...,

Xjm.am)

associated with production p, where all Xj,.a, are attribute occurrences of p. If f is an identity or a constant function, then the semantic rule is called a copy rule or a constant rule, respectively. Attribute grammars in this paper are assumed to be in Bochman normal form. This means that in each semantic rule X,.b

:=f(Xj,.a,,

Xjz.a2 ,...,

Xjm.a,)

associated with a production p of the AG, all Xj,.a, are input attribute occurrences. An AG is L-attributed, if for each semantic rule X,.b

:=f(Xj,al,

Xj,.a2 ,...,

Xj,.a,),

such that b E LA, holds: ji < k for all i = 1, 2,. . .) m. If not stated otherwise, an attribute grammar in this paper is assumed to be L-attributed.

Volume

INFORMATION

41, Number 2

3. The construction

of semantic

PROCESSING

expressions

In this section, we show the principles of attribute evaluation during LR parsing, as proposed in [8], except for the fact that we do not make use of partial states of the LR-automaton. The main idea followed in this method originates from [3], and can briefly be summarized as follows. The inherited attributes are associated with LR states, and semantic expressions are constructed for them during the evaluator (parser) construction phase. The semantic expressions are based on the semantic rules of the AG, and for each inherited attribute in each LR state, the number of semantic expressions obtained has to be at most one. Then, in the course of parsing, the parser gets values of inherited attributes by evaluating the corresponding semantic expressions. The inherited attributes are evaluated when a state is pushed on the parsing stack. The set of inherited attributes of a state S is M(S)

= {B.alB

.a =&l(B)

ES}.

Since nonterminal B can follow the dot in several items of state S, we distinguish occurrences of the inherited attributes. As in [81, we denote the set of inherited attribute occurrences of state S by IN’(S), and IN’(S)

defines the position of x in the parsing stack (relative to the top) at the moment when S is pushed on the stack. The parsing stack is the first component of the following parsing configuration (which is extended, in comparison to that of the pure LR(k) parser, by introducing records for storing the attribute values): CS,S,X,Xt..

.

Sn-lSn_lXnxSn,

aj...a,),

(*)

where (for r = 0, 1,. . . , n and z = 1, 2,. . . , n) - S, is an LR state, - S; is a record containing the values of all inherited attributes in N(S,), - X,-is a grammar symbol, - X, is a record containing the values of all synthesized attributes in SA(X,), - aj...am is the remaining input string. With respect to this configuration, defined as follows.

the offset is

Definition 3.1. In the configuration

for some B

such that [A +cz.BP]

14 February 1992

LETTERS

(*>, the offset of an attribute occurrence x is o (o < O), if either x is a synthesized attribute occurrence contained in X, +, or x is an inherited attribute occurrence contained in S,,,. The set of input attribute occurrences of state S is INP( S)

= {B’.aI B .a E L4( B) for some B

= {( X.a, o) I X.a E SA( X) such that in an item [A +a*B’/3]

ES}. [B +a,X,2*p]

The superscripts are used to distinguish different occurrences of a grammar symbol following the dot in items of S. In an L-attributed grammar, the inherited attributes of state S can depend ultimately (directly or indirectly) only on the occurrences of synthesized attributes of symbols in LY, and on the occurrences of inherited attributes of A in a kernel item [A + cr. PI of state S [3,81. These occurrences are called input attribute occurrences of state S. Each input attribute occurrence is identified by a pair (x, o), where x is an attribute (synthesized or inherited), and o is the offset that

u((B.a,

ES, o =offset(X.a)}

o) I B.a EU(B)

such that

[B+a*P]

EZGWNEL(S), o = offset( B.a)].

As stated above, this set represents all the values on which the inherited attributes in IN(S) can (ultimately) depend. The semantic expressions are actually used for expressing these dependencies. Definition

3.2. F,(A’.a) is the set of semantic expressions for an inherited attribute occurrence A’.a E IN’(S). It is the smallest set such that 69

Volume

41. Number 2

INFORMATION

PROCESSING

(1) If [B -+ (Y*A’pl E KERNEL(S), and the semantic rule for A.a associated with production B +AP is A.a := expr( a,, a*,. . . , a,), then

EFS(A’.U), where oi = offset for all i = 1, 2, . . . , II (according to Definition 3.1). (2) If [B + *A’/31E S, and this item is directly derived from an item [C -+ y. B”6] of state S, and the semantic rule for A.u associated with production B -+ AD is A.u :=expr(B.a,,

B.a, ,..., B.u,),

then expr(e,,

e2... %) E Fs(A’a)

for all ei E Fs(B”.ai), where i = 1, 2, . . . , n. However, the LR parsing method does not provide sufficient information for distinguishing different occurrences of an inherited attribute of an LR state. Hence, the sets F, have to be combined for the purpose of attribute evaluation during parsing: E,(A.u) is the set of semantic expressions for an inherited attribute A.u E ZN(S). It is the set Definition

3.3.

E,( A.u) = u F,( A’.u), t

where the union is for all t such that A’ is an occurrence of symbol A following the dot in an item of S. When a state S is pushed on the stack during parsing, the values of its inherited attributes can be obtained as results of the evaluation of semantic expressions in the sets E,. For any state S, and any attribute a E IN(S), the semantic expression has to be uniquely defined. Hence, each set E,(u) has to be a one-element set. Following [7], we call the class of matching attribute grammars 70

LETTERS

14 February 1992

the MLR-attributed grammars (“Madsen’s-LR-attributed grammars”). Definition 3.4. AG G is MLR(k)-attributed (called MLR-attributed for k = l), if

- its underlying CFG is LR(k), - G is L-attributed, - for each state S of the LR(k)-automaton of G, for each attribute a E INS), the set E,(a) contains at most one element. Note. As already mentioned,

this construction of semantic expressions has been “refined” in [8], considering partial states of the LR(k)-automaton. As in [7], we will refer to that class of AGs as the SALR-attributed grammars (“SAssa’s-LR-attributed grammars”). As shown in [7], MLR-AGs are a proper subclass of SALR-AGs. For all inherited attributes in each state S of the LR-automaton, the one-element sets E, of semantic expressions may be computed by an algorithm that checks simultaneously whether or not the given attribute grammar is MLR-attributed. This algorithm can be found in [S].

4. What is computed during evaluation? The semantic expressions are used to compute the values of inherited attributes during LR parsing. For a state S at the top of the parsing stack, there is one semantic expression in E,(u) for each inherited attribute a of state S. All these semantic expressions of state S are evaluated one by one, in some order. In this consecutive evaluation, some computation may be repeated several times, as the following example shows. Example 4.1. Let attribute grammar G, have the following productions and semantic rules:

z-+x X-+&4 A+Bb B + Cc B+d C-g

X.ui A.ui B.ui C.ui

:= k := X.ai :=f( A.ai) := B.ai

Volume

INFORMATION

41, Number 2

PROCESSING

In state S=([x~a.A],[A~.Bb],[B~.Cc], [B + .dl, [C + the sets E, for inherited attributes E,(A.ai)

= {(X&i,

E,(B.ai)

= {f((X.ai,

E,(C.ai)

= { f(( X&i, - 1))).

-gl}>

in IN(S) are

-l)}, -l))},

G, is MLR-attributed. In order to compute the values of all inherited attributes of state S, the three semantic expressions in E,(A.ai), E,(B.ui), and E,(C.ui) are evaluated. Regardless of the order of these evaluations, the function f is computed twice with the same parameter. Obviously, the second computation is redundant, since the result is already available. As the function f may be complicated, such redundant computations should be avoided.

The elimination of some redundant computations may be achieved by considering the ECLRattributed grammars [9]. Inherited attributes of the attribute grammar can be partitioned into disjoint equivalence classes EC,, EC,, . . . , EC,,. Each equivalence class EC, is a nonempty subset of the set of inherited attributes of AG such that in each state S the set E.S(ECi)

=

U

~EEC,~INW

Es(a)

contains at most one semantic expression, provided that for any pair of inherited input attribute occurrences (a,, oi), (u2, 02) EZNP(S), (a,, oi) = (a,, 02), if oi =02, and both a, and u2 belong to one equivalence class ECj, 1 Q j < n. As shown in [7], the class of MLR-attributed grammars is a proper subclass of the ECLR-attributed grammars. Having partitioned the set ZA of inherited attributes into equivalence classes, all attributes in an equivalence class are processed as a single inherited attribute. In this way, the attribute evaluation is simplified considerably, and many redundant computations are avoided. Nevertheless, it is a rather difficult task to find the optimal

14 February 1992

LETTERS

partition of the inherited attributes of a given attribute grammar. As mentioned in [9], the equivalence classes may be computed using a graphcolouring algorithm, and finding an optimal solution turns out to be an NP-complete problem. Alternatively, the partition may be provided by the user. In this case, however, the user must deal with too many implementation details, and his partition may be far from optimal. Considering AG G, from Example 4.1, one can get two equivalence classes EC, = {X.ui, A.ui}, EC, = {B.ui, C.ui}, and the sets of semantic expressions E,(EC,) = {(EC,, - l)), and - 1))). Consequently, the EJEC,) = (f((EC,, function f is evaluated only once. However, not in all cases does this approach remove all the redundant computations. In Example 4.2 below, inherited attributes A,.ui, B.ui, and C.ui of state S, cannot appear together in a single equivalence class. Moreover, the method is not able to eliminate any of the three executions of g((Y.ui, - 1)) in state S,, since they occur in different semantic expressions. 4.2. Let attribute grammar G, have the following productions and semantic rules:

Example

z-+x

X.ui := k,

Z+Y

Y.ui := k,

X+uAIb

A,.ui :=f( X.ui)

Y--j bA,u

A,.ui

A,

B.ui :=A,.ui

+BC

:= g( Y.ui)

A,+Cd

C.ui := A,.ui

A,+Bx

B.ui :=A,.ui

&+CY B-h c+z

C.ui := A,ui + 2

+ 1

In states S,={[X+u*A,b],

[A,+

.Bc],

[AI+

-Cd],

[B + -hl, [C + .z]},

and S,= ([Y+b.A,u],

[A*-’

-Box], [AZ-+ [B +

Ty],

*hl, [C + *zl}, 71

Volume

41. Number 2

INFORMATION

PROCESSING

the sets of semantic expressions are: E,1(A,.ai)

= {f((X.ai,

-l))}.

E&M)

= {f((X.ai,

-l))},

E&.ai)

= { f(( X.ai,

- 1))) )

E&.ai)

= { g(( Y.ui, - 1)) + 2) )

&(A,.4 E&Lui)

= fg((Y.4 = {g((Y.ui,

-l>>},

-1))

+ 1).

In this case, the introduction of equivalence classes does not exclude all the redundant computations, even if we use partial states, according to [81. It has already been suggested that there are two reasons for this: (1) Even though the equivalence classes are constructed in ECLR-attributed grammars, it is done globally. The partition of inherited attributes has to be correct with respect to all LR states. Hence, in a particular state, two inherited attributes need not belong to one equivalence class, even if their semantic expressions are equivalent. (2) The semantic expressions are defined in terms of input attribute occurrences only. It means that “total substitutions” are performed. Consequently, a subexpression may be valuated repeatedly in several different semantic expressions. In the following section, we present an optimization that excludes the redundant computations in the evaluation of inherited attributes. Unlike in the ECLR-attributed grammars, the equivalence classes are determined for the set of inherited attributes of each particular LR state. Further, when inherited attributes of an LR state are evaluated, the results of formerly computed semantic expressions are used instead of their re-evaluation. This is enabled by defining the ordering of semantic expressions in each state, and by evaluating them in the prescribed order.

LETTERS

tributes of a state. The separation leads to an indirect access to semantic expressions, and this allows us to avoid completely the redundant computations. Instead of sets Es, the expressions of a state S are now kept in a so-called semantic sequence that defines an order of these semantic expressions. Consequently, in the construction of a semantic expression in the sequence, the values of preceding expressions may be introduced instead of their multiple copies. Elements of the semantic sequence are then assigned to inherited attributes of the state using a mapping function. Hence, any semantic expression need not be kept in the semantic sequence (and evaluated during parsing) more than once. 5.1. Let S be a state of the LR(k)-automaton of attribute grammar G. The semantic sequence of this state is EXs = (e,, e2,. . . , ems)--a sequence of semantic expressions. The length of this sequence is ms. The domain of an expression ei (i = 1, 2,. . . , ms) is the set Definition

~i=INP(S)U{ual(j)lj=1,2

redundant

computations

We propose to separate the semantic expressions, and their assignment to the inherited at72

,..., i-l].

The ith semantic expression e, in EXs will be denoted by EXs[i]. EXs is a proper semantic sequence of state S, if EX,[i] # EXJ j] for all i fj such that 1 < i,j
5. Removing

14 February 1992

Volume

INFORMATION

41. Number 2

PROCESSING

of 11, 2,. . .) m,}). EX, is the shortest proper semantic sequence such that for each A’.a E IN’(S), AM$A’.a) is the smallest set satisfying: (1) If [B + a -A’/?] E KERNEL(S), and the semantic rule for A.a associated with production B -+ aA/ is A.a := expr(a,, u2,. . . , anI, then for some z, such that 1 =zz < m,,

and z E AM$A’.u), where oi = offset for all i=l,2 , . . . , n (according to Definition 3.1). (2) If [B + *A’@] E S, and this item is directly derived from an item [C + y . B”6] E S, and (a) the semantic rule for A.u associated with B + AP is the copy rule A.u := B.u, then AM;(B”.u)

cAM;(A’.u),

(b) the semantic rule for A.u associated with B-A/I is A.u :=expr(B.u,, B.u, ,..., B.u,)(and does not match case (a)), then for each (d,, dz,...,

d,) E AM;( B”.u,) x ...

x AM;( B”.u,)

xAM;(B”.u,),

there is max(d,, d,, . . . , d,)
=expr(ual(d,),

uul(d,),...,uul(d,)),

and z E AMi( A’.u). For the same reasons as in Section 3 (Definition 3.31, we have to combine the mapping functions for inherited attribute occurrences to obtain mappings for the inherited attributes of an LR state. Definition 5.3. Let (EX,, AMi) be the semantic information of state S, according to Definition 5.2. The complete semantic information of S is the pair (EXs, AM,), where AM, is the mapping function AM, : IN(S) + 2t1,27...,m~),and for each A.u E ZNW, AMs( A.u) = u AM;( A’.u), I

where the union is for all t such that A’ is an occurrence of symbol A following the dot in an item of S.

LETTERS

14 February 1992

The use of complete semantic information in the evaluation of inherited attributes is rather straightforward. The semantic expressions in EXs are evaluated one after another, using the values of input attribute occurrences of S, and/or the values of formerly computed semantic expressions in EXs (substituting the elements uuZ(j)). The value of any inherited attribute of state S is then determined by the mapping AM,. Obviously, the evaluation is correct, if for each A.u E IN(S), the value assigned is unique-i.e. AMs(A.u) contains just one element. In this case, AM, defines a partition of the set IN(S), as mentioned at the end of Section 4. This requirement is equal to the definition of MLR-attributed grammars (Definition 3.4). Theorem 5.4. AG G is MLR(k)-attributed if and only if - its underlying CFG is LR(k), - G is L-attributed, - for each state S of the LR(k)-automaton of G with the complete semantic information (EX,, AM,), for each attribute a E IN(S), the set AM,(a) contains at most one element. Proof. The single semantic expressions in the complete semantic information (EX,, AM,) are constructed in the same way as the semantic expressions in sets Es. Only the substitutions required by Definition 3.2 are replaced by introducing vu1 elements according to Definition 5.2. Hence, a set E,(u) contains more than one element if and only if AM,(u) contains more than one element. 0

In comparison to the use of sets of semantic expressions (Es), the complete semantic information allows a more efficient attribute evaluation, since each computation in a state S is performed at most once. Moreover, if the length of the semantic sequence of state S is m,, it is sufficient to store with S in the parsing stack only m, attribute values, and significant space savings are achieved as well. The following example shows that m, may even be less than the number of values stored with state S, if equivalence classes are introduced according to 191. 73

Volume

41. Number 2

INFORMATION

PROCESSING

LETTERS

14 February 1992

5.5. In AG G, from Example 4.2, the complete semantic information of states S, and S, is (EX,,, AMs,> and (EXs2, AM.& respectively, where m,, = 1, ms2 = 3, and

Output: Determination

EX,,[l]

begin for each LR state S do ms := 0; {EX, is the empty sequence} for each a E Z/V(S) do AM,(u) := 6; set each item i E S to unmarked; for each item k E KERNEL(S) do Truverse(k of S); endfor; output m,, EX,, and AM,; endfor; end. procedure Traverse(item i of state S); begin if i is marked then exit; {let i = [B --‘a .Ap]} for each A.u E LA(A) do (let A.u := expr(u,, u2,. . . , a,) be the semantic rule for the evaluation of A.u in production B -+ a A/3} if i E KERNEL(S) then X:= expr((u,, offset(u (a,, offset( . . . 7 (a,, offdu,))); elsif expr is the identity (A.u := B.u) then X := EX,[ p], where p E Ah4JB.u); else x := expr(vul(d,), v&f,), . . . ) vul(d,)), where di E AhI,( i = 1,. . . , n; endif; if EX.Jj]=X for some jE{l,...,m,} then

Example

=f((

X&i, -I)),

EX,*[l] =g((Y.ui,

-l)),

~&(A,.@

= (II,

AM&?.ai)

= {1))

AM,I(C.ai)

= {I})

AM&4,.ui)

= {l},

EX,*[2] = uul( 1) + 1,

[email protected])

= (2) )

EX,J3]

AM&.ui)

= {3}.

= vul( 1) + 2,

Notice that m,, = 1, while any partition into equivalence classes results in at least two (equal) semantic expressions in state S,.

Although the ECLR-attributed grammars properly include the MLR-AGs, the equivalence classes have been introduced in 191 mainly in order to improve the time and space efficiency of attribute evaluation. However, the efficiency achieved in this way tightly depends on the partition of the inherited attributes into equivalence classes. It has already been mentioned that the computation of an optimal partition for a given AG is an NP-complete problem. Unlike these difficulties, the optimization by means of complete semantic information does not require any additional work in comparison to the construction of semantic expressions described in Section 3. The following algorithm checks whether a given AG is MLR-attributed, and computes the complete semantic information for all states of the LR(k)-automaton. This algorithm is a modification of the algorithm for computation of the sets Es of semantic expressions, presented in [81 (Algorithm 2).

5.6. Checking MLR-attributed properties, and (if satisfied) computing the pairs (EX,, AM,) of the complete semantic information.

Algorithm

Input: An L-attributed 74

grammar G.

of whether G is MLR-attributed or not, and computation of the complete semantic information (EX,, AM,) for each state S of the LR(k)-automaton of grammar G.

p:=j;

else :-m, + 1; Assam,] :=X; p := m,; endif; if AM,( A.u) G {p} then AM,(A.u) := {p}; else

message (G is not MLR-attributed); exit; endif; endfor;

mark item i;

Volume

41, Number

2

INFORMATION

PROCESSING

LETTERS

14 February

1992

for each &tern directly derived from i do TraverseC ditem of S 1; endfor; end Traverse;

many discussions on LR-attributed grammars, and Albert Nijmeijer for polishing the English.

6. Concluding

References

remarks

An optimization has been proposed for onepass attribute evaluation during LR parsing based on the construction of semantic expressions. This optimization excludes redundant computations in the evaluation of inherited attributes. Also, the number of attribute values stored in the stack during parsing is minimized. A more efficient attribute evaluation is achieved by means of a simple rearrangement of the common construction of semantic expressions so that the user (or the parser generator) is spared any additional effort. Although we have shown this optimization only for the class of MLR-attributed grammars, it is also applicable to other methods that use semantic expressions for the evaluation of inherited attributes, like SALR and ECLR-AGs. In fact the complete semantic information proposed may be considered as a linearized form of (parts of) the evaluation graph suggested in [5].

Acknowledgment

The author wants to thank Rieks op den Akker and Henk Alblas for their kind guidance, and for

Aho, R. Sethi and J.D. Ullman, Compilers, Principles, Techniques and Tools (Addison-Wesley, Reading, MA, 1986). 121A.V. Aho and J.D. Ullman, The Theory of Parsing, Translation and Compiling, Vols. 1 and 2 (Prentice-Hall, Englewood Cliffs, NJ, 1972). Attribute influenced LR [31 M.D. Jones and M. Madsen, parsing, in: N.D. Jones, ed., Proc. of the Aarhus Workshop on Semantics - Directed Compiler Generation (Springer, Berlin, 1980) 393-407. of context-free languages, Math. [41 D.E. Knuth, Semantics Systems Theory 2 (1968) 127-145; Correction, ibidem 5 (1971) 95. and R.E. Stearns, Atbl P.M. Lewis, D.J. Rosenkrantz tributed translations, J. Comput. System Sci. 9 (1974) 279307. Parsing attribute grammars, M.Sc. Thesis, 161 M. Madsen, Dept. of Computer Science, University of Aarhus, Aarhus, 1990. [71 R. Op den Akker, B. Melichar and J. Tarhio, The hierarchy of LR-attributed grammars, in: P. Deransart and M. Jourdan, eds., Attribute Grammars and their Applications, Proc. Internat. Conf WAGA, Paris, Lecture Notes in Computer Science 461 (Springer, Paris, 1990) 13-28. to w M. Sassa, H. Ishizuka and I. Nakata, A contribution LR-attributed grammars, J. Inform. Process. 8 (3) (1985) 196-206. [91 M. Sassa, HY. Ishizuka and I. Nakata, ECLR-attributed grammars: A practical class of LR-attributed grammars, Inform. Process. Lett. 24 (1987) 31-41.

111A.V.

75