COMPILING TRACE & UNIFICATION GRAMMAR FOR PARSING AND 
GENERATION 
Hans Ulrich Block 
Siemens AG, Corporate Research, ZFE IS INF 23 
Otto Hahn-Ring 6 
D-8000 Miinchen 83 
Germany 
block@ztivax.uucp 
ABSTRACT 
This paper presents Trace & Unification Gram- 
mar (TUG), a declarative and reversible grammar 
formalism that brings together Unification Gram- 
mar (uG) and ideas of Government & Binding 
Theory (GB) in an undogmatic way. A grammar 
compiler is presented that transforms a grammar 
written in the TUG formalism into two different 
forms, one being useful for parsing, the other be- 
ing useful for generation. 
1 INTRODUCTION 
During the last years there has been a growing 
interest in NL systems that can be used for both 
parsing and generation. The invention of unifica- 
tion grammar that allows for a declarative descrip- 
tion of language made it possible to use the same 
grammar for both tasks. The main goal of a gram- 
mar then is to describe a relation between nor- 
malized (semantic) representations and language 
strings. A grammar that can be used in both di- 
rections is called "reversible". 
We can distinguish three levels of reversibility. 
On the first level, not only the same grammar is 
used for parsing and generation, but also the in- 
terpreter for parsing and generation is reversible. 
This approach is taken in Shieber (1988). Besides 
elegance the approach has the advantage that the 
reversibility is guaranteed. Further advantages are 
mentioned in Neumann (1991). As a disadvantage, 
it is yet unclear whether and how these systems 
can be made efficient. 
On the second level we find systems where the 
same reversible grammar is processed by two dif- 
ferent interpreters, one for parsing, one for gener- 
ation. The advantage of these systems is that the 
grammar can be changed and tested easily, which 
helps to shorten the development cycle. The dis- 
advantage again is that grammar interpreters are 
usually too slow to be used in realistic systems. 
On the third level we finally find systems, where 
the linguistic description is given in a reversible 
declarative grammar. This grammar is then com- 
piled into two different forms, one being usefull 
only for parsing, the other only for generation. 
Whereas here we have to face the disadvantage 
that compiling can take some time and therefore 
prolongs the development cycle, the advantage lies 
in the efficient processing that can be achieved 
with compiled grammars. Strzalkowski (1990) and 
Strzalkowski/Peng (1990) describe a compiler that 
transforms a grammar originally written for pars- 
ing into an efficient generator. 
In the follwing section I will present a system of 
the third type and show by means of which com- 
piling methods a grammar written in a perspicious 
formalism, TRACE AND UNIFICATION GRAMMAR 
(TUG) can be transformed to fast parsers and gen- 
erators. The proposed compilers and their mod- 
ular architecture have the further advantage that 
most of their parts can be used also for other for- 
malisms than the one described, e.g. DCGS. 
The whole system is part of a polyfunctional 
linguistic processor for German called LINGUISTIC 
KERNEL PROCESSOR (LKP). The LKP contains a 
grammar of German with broad coverage. The 
grammar describes the relation between a subset 
of German and a subset of QLF, the intermedi- 
ate semantic form that is used in the Care Lan- 
guage Engine of SRI Cambridge (Alshawi 1990). 
The LKP has been implemented in PROLOG. Pars- 
ing and Generation of a sentence up to 15 words 
normally takes between 1 and 10 seconds, with a 
strong tendency to the lower bound. 
i00 
2 FORMALISM 
The design of Trace and Unification Grammar 
has been guided by the following goals: 
i 
• Perspicuity. We are convinced that the gen- 
erality, coverage , reliability and development 
speed of a grammar are a direct function of 
its perspicuity, just as programming in Pas- 
cal is less errorprone than programming in as- 
sembler. In the optimal case, the grammar 
writer shoul d be freed of reflections on how 
to code things best for processing but should 
only be guided by linguistic criteria. These 
goals led for .example to the introduction of 
unrestricted disjunction into the TUG formal- 
ism. 
• Compatibility to GB Theory. It was a ma- 
jor objective bf the LKP to base the grammar 
on well undo;stood and motivated grounds. 
As most of the newer linguistic descriptions 
on German ate in the framework of GB theory, 
TUG was designed to be somehow compatible 
with this theory though it was not our goal 
to "hardwire" every Gs principle. 
• Efficiency. :As the LKP is supposed to be 
the basis of products for interactive usage of 
natural langu~age, efficiency is a very impor- 
tant goal. Making efficiency a design goal of 
the formalism led e.g. to the introduction of 
feature types 'and the separation of the move- 
ment rules int~ head movement and argument 
movement. 
The basis of TUG is formed by a context free 
grammar that is augmented by PATR n-style fea- 
ture equations. Besides this basis, the main 
features of TUG are feature typing, mixing of 
attribute-value-pair and (PROLOG-) term unifica- 
tion, flexible macros, unrestricted disjunction and 
special rule types !for argument and head move- 
ment. 
2.1 BASIC FEATURES 
As a very simple example we will look at the 
TUG version of the example grammar in Shieber 
(1984). 
~type definition 
s => f. 
np => f(agr:agrmnt). 
vp => f(agr:agrmnt). 
v => f(agr:agrmnt). 
agrnmt => f(number:number,person:person). 
number => {slngular,plural}. 
person => {first,second,third}. 
rules 
s ---> np, vp \[ 
np:agr = vp:agr. 
vp ---> v, np I 
vp:agr = v:agr. 
lexicon 
lexicon('Uther',np) I 
agr:number = singular, 
agr:person = third. 
lexicon('Arthur',np) I 
agr:number = singular, 
agr:person = third. 
lexicon(knights,v) I 
agr:number = singular, 
agr:person = third. 
lexicon(knight,v) \[ 
( agr:number = singular0 
( agr:person = first 
; agr:person = second 
) 
agr:number = plural 
). 
The two main differences to PATR II in the ba- 
sic framwork are that first, TUG is leas flexible in 
that it has a "hard" contextfree backbone, whereas 
in PATR II categories of the context free part are 
placeholders for feature structures, their names 
boeing taken as the value of the cat feature in 
the structure. Second, TUG has a strict typing. 
For a feature path to be well defined, each of its 
attributes has to be declared in the type definition. 
Besides defined attribute-value-pairs, TUO al- 
lows for the mixing of attribute-value-pair unifica- 
tion with arbitrary structures like PROLOG terms 
using a back-quote notation. This can be re- 
garded as the unificational variant of the BUILDQ 
operation known from ATNS. As an example con- 
sider the following lexicon entry of each that con- 
structs a predicate logic notation out of dot :base, 
i01 
det:scope and det:var. 
lexicon(each,det) I 
det:sem = 
'all(de~:var,det:base -> 
det:scope) 
During our work on the German grammar we 
found that this feature was very useful for the con- 
struction of semantic forms. 
TUG provides templates for a clearer organiza- 
tion of the grammar. The agreement in the above 
mentioned grammar might have been formulated 
like this: 
agree(X,Y) short_for 
X:agr = Y:agr. 
s ---> np, vp I 
agree(np,vp). 
TUG allows for arbitrary disjunction of feature 
equations. Disjunctions and Conjunction may be 
mixed freely. Besides well known cases as in the 
entry for knight above, we found many cases where 
disjunctions of path equations are useful, e.g. for 
the description of the extraposed relative clauses*. 
2.2 MOVEMENT RULES 
Further to these more standard uG-features, 
TUG provides special rule formats for the de- 
scription of discontinuous dependencies, so called 
"movement rules". Two main types of movement 
are distinguished: argument movement and head 
movement. The format and processing of argu- 
ment movement rules is greatly inspired by Chen 
e.a. (1988) and Chen (1990), the processing of 
head movement is based on GPSG like slash fea- 
tures. 
Head Movement 
A head movement rule defines a relation be- 
tween two positions in a parse tree, one is the land- 
ing site, the other the trace position. Head move- 
ment is constrained by the condition that the trace 
is the head of a specified sister (the root node) of 
1Block/Sclunid (1991) describes our processing tech- 
nique for disjunctions. 
the landing site 2. Trace and Antecedent are iden- 
tical with the exception that the landing site con- 
tains overt material, the trace does'nt. Suppose, 
that v is the head of vk, vk the head of vp and vp 
the head of s, then only the first of the following 
structures is a correct head movement, the second 
is excluded because np is not head of vp, the third 
because antecedent and trace are unequal. 
Is, v~ Is ... \[vp ... 
\[vk ... trace(v), ...\]...\]...\]...\] 
Is' npt \[s ... \[vp trace(nph ... 
\[vk "" v ...\]...\],..\] 
Is, np~ \[s ... \[vp ... 
\[vk "" trace(vh ...\]...\].,.\]...\] 
To formulate head movement in TUG the follow- 
ing format is used. First, a head definition defines 
which category is the head of which other. 
v is_head_of vk. 
vk is_head_of vp. 
vp is_head_of s. 
Second, the landing site is defined by a rule like 
S j ---> V+S \] .,. 
To include recursive rules in the head path, 
heads are defined by the following head definitions. 
In a structure \[M D, ... D,\] D~ is the head of14 
if either Di is_head_of 14 is defined or D~ has the 
same category as 14 and either Di is_head_of X or 
X is_head_of Dt is defined for any category X. 
Head movement rules are very well suited for 
a concise description of the positions of the finite 
verb in German (sentence initial, second and final) 
as in 
Hat~ der Mann der Frau das Buch gegeben t~ ? 
Hast the man the woman the book given tt 
Der Mann hat~ der Frau das Buch gegeben 
The man hast the woman the book given ti 
... daft der Mann der Frau das Buch gegeben hat 
... that the man the woman the book given has 
All that is needed are the head definitions and 
the rule that introduces the landing site 3. 
~Here, "head of" is a transitive relation s.t. if x is head 
of y and y is head of z then x is head of z. 
SEven though verb movement is not supposed to be a 
topic for English grammar, one might think of describing 
English Subj-Aux inversion in terms of head movement. 
Peter hao been reading a book 
Has~ Peter ti been reading a book 
102 
I 
Argument Movement 
Argument movement rules describe a relation 
between a landing site and a trace. The trace is 
always c-commanded by the landing site, its an- 
tecedent. Two different traces are distinguished, 
anaphoric traces and variable traces. Anaphoric 
traces must find their antecedent within the same 
bounding node, variable trace binding is con- 
strained by subjacency, e.a. the binding of 
the trace to its antecedent must not cross two 
bounding nodes.' Anaphoric traces are found 
for example in English passive constructions 
Is \[np The book' of this author\]/ was read ti\] 
whereas variable graces are usually found in wh- 
constructions and~ topicalization. Similar to the 
proposal in Chen e.a. (1988), argument movement 
is coded in TUG by a rule that describes the land- 
ing site, as for example in 
s2 ---> np:ante<trace(var,np:tracs), sll 
ante:fx = trace:fx, 
This rule states that np: ante 4 is the antecedent 
of an np-trace that is dominated by sl. This rule 
describes a leftward movement. Following Chen's 
proposal, TUG also provides for rightward move- 
ment rules, though these are not needed in the 
German grammar. A rightward movement rule 
might look like this. 
s2 ---> sl, traCe(var,np:trace)>np:an~e \[ 
ante:fx = trace:fx, 
The first argument in the trace-term indicates 
whether the landing site is for a variable (vat) 
or for an anaphoric (ana) trace. Other than head 
movement, where trace and antecedent are by def- 
inition identical, the feature sharing of argument 
traces with their 'antecedents has to be defined 
in the grammar by feature equations (ante:fx = 
trace: fx .... ). ~,Furthermore, it is not necessary 
that the antecedent and the trace have the same 
syntactic category. A rule for pronoun fronting in 
German might e.g. look like this: 
spr ---> pron<trace(ana0np), s \[ ... 
4The notation Cat :Index is used to distinguish two or 
more occurrences of the same category in the same rule in 
the equation part. :ante and :trace are arbitrary names 
used as index to refer to the two different nps. 
The current version of the formalisms requires 
that the grammar contains a declaration on which 
categories are possible traces. In such a declara- 
tion it is possible to assign features to a trace, for 
example marking it as empty: 
erace(np) I np:e~pty = yes. 
Bounding nodes have to be declared as such in 
the grammar by statements of the form 
bounding_node(np). 
bounding_node(s) \[ s:tense = yes. 
As in the second case, bounding nodes may 
be defined in terms of category symbols and 
features 5. Typical long distance movement phe- 
nomena are described within this formalism as in 
GB by trace hopping. Below is a grammar frag- 
ment to describe the sentence Which books~ do you 
think ti John knows ti Mary did'nt understand ti: 
bounding_node(s). 
bounding_node(rip). 
sl ---> np<trace(vax,np), s I 
s ---> np, vp \[ ... 
s ---> aux, np, vp \[ ... 
np ---> propernoun \[ ... 
np ---> det, n \[ 
vp ---> v, sl \[ ... 
vp ---> v, np \[ ... 
trace(rip). 
The main difference of argument movement to 
other approaches for the description of discontinu- 
ities like extraposition grammars (Pereira 1981) 
is that argument movement is not restricted to 
nested rule application. This makes the approach 
especially atractive for a scrambling analysis of the 
relative free word order in the German Mittel/eld 
as in 
Ihml hatj das Buchk keiner ti tk gegeben tj. 
3 PROCESSING TRACE & 
UNIFICATION GRAMMAR 
TUG can be processed by a parser and a genera- 
tor. Before parsing and generation, the grammar 
is compiled to a more efficient form. 
5Currently, only conjunction of equations is allowed in 
the definition of bounding nodes. 
103 
The first compilation step is common to gener- 
ation and parsing. The attribute-value-pair struc- 
ture is transformed to (PROLOG) term structure 
by a TUG-tO-.DCG converter. This transformation 
makes use of the type definitions. As an example 
consider the transformation of the grammar 
a => f(al:tl). 
b => f(al:tl). 
tl => f(a2:t2,a3:t3). 
~2 => {1,2}. 
t3 => {2,3}. 
a ---> b I 
a:al:a3 = 2, 
( a:al:a2 = i; a:al = b:al ). 
It is transformed to the following grammar in a 
DCG like format e. 
a(tl(A,2)) ---> 
\[b(B), {A = 1 ; ~1(A,2) = B}\]. 
The compilation steps following the TUG-to-DCG 
converter are different for parsing and generation. 
3.1 THE PARSER GENERATOR 
In the LKP, a TUG is processed by a Tomita 
parser (Tomita 1986). For usage in that parser the 
result of the TUG-tO-DCG converter is compiled in 
several steps: 
• expansion of head movement rules 
• transformation of argument movement rules 
• elimination of empty productions 
• conversion to LR(K) format 
• computation of LR. tables 
First, head movement rules are eliminated and 
the grammar is expanded by introducing slash 
rules for the head path by the head movement ex- 
pander. Suppose the Tuo-to-DCG converter has 
produced the following fragment: 
eNote that the goal {A " 1 ; 1;1(A.2) ,m B} is inter- 
preted as a constraint and not as a PROLOG goal as in 
DCGs. See Block/Schmld (1991) for the evaluation of the 
constraints. 
v(_) is_head_of vk(_). 
vk(_) is_head_of vp(_). 
vp(_) is_head_of s(_). 
s1(Sl) ---> Iv(v) + sCs)\]. 
s(s) ---> \[...,vp(vP),...\]. 
vp(VP) ---> \[...,vk(VX) .... \]. 
vk(VK) ---> \[...,v(V),...\]. 
Then, the head movement expander introduces 
slash rules ~ along the head-path, thereby introduc- 
ing the empty nonterminals push(X) and pop(X). 
rules solar 
• (s) ---> \[ .... vp(VP),...\]. 
vp(VP) ---> \[...,vk(VX),...\]. 
vk(VZ) ---> \[...,v(V),...\]. 
newly introduced slash rules 
sl(S1) ---> \[v(V), push(v(V)), s_v(S)\]. 
s_v(S) ---> \[...,vp_v(VP),...\]. 
vp_v(VP) ---> \[ .... vk_v(VX) .... \]. 
vk_v(VX) ---> \[ .... v_v(V),...\]. 
v_vCV)---> \[popCvCV))\]. 
empty productions for push and pop 
push(X) ---> \[\]. 
pop(X) ---> \[\]. 
push(X) and pop(X) are "marker rules" 
(Aho/Sethi/Ullman 1986) that invoke the parser 
to push and pop their argument onto and off a 
left-to-right stack. This treatment of head move- 
ment leads to a twofold prediction in the Tomita 
parser. First, the new slash categories will lead to 
LR parsing tables that predict that the verb will be 
missing if rule sl ---> ... has applied. Second, 
the feature structure of the verb is transported to 
the right on the left-to-right stack. Therefore, as 
soon as a v_v is expected, the whole information 
of the verb, e.g. its subcategorization frame, is 
available. This strategy leads to a considerable 
increase in parsing efficiency. 
In the next compilation phase, argument move- 
ment rules are transformed to the internal format. 
For the control of gaps a gap-threadding mecha- 
nism is introduced. Following Chen e.a. (1988), 
the gap features are designed as multisets, thus al- 
lowing crossing binding relations as mentioned in 
section 2. 
7 A slashed category Xl¥ is represented using the under.- 
score character Z_¥. 
104 
I 
To see the effect of this compilation step, take 
the following fragment as output of the head move- 
ment expander. 
boundlng_node(s(_)). 
sl(Si) ---> np(NP)<trace(var,np(Trace)), 
sCs). 
s(S) ---> np(NP), vp(VP). 
vp(VP) ---> v(V). 
vp(VP) ---> v(V), np(NP). 
trace(np(_)). 
The argument movement expander transforms 
this to the followifig grammar. 
sl(Gi,Go0Sl) --~> np(Gi,Gt,NP), 
s(Gs,Go,S) I, 
{cut_trace(trace(var,np(Trace)), 
Gs,Gt)}. 
s(Gi,Go,S) --->!np(Gi,Gt,NP), 
vp(Gt,Go, VP), 
{bound(Gi)}. 
vp(Gi,Go,VP) --~> v(Gi,Go,V). 
vp(Gi,Go,VP) --~> v(Gi,Gt,V), 
np(Gt,Go,NP). 
np(\[trace(_,np(SP))\[G\],G,NP) ---> \[\]. 
i 
The predicates cut_trace/3 and bound/1 are 
defined as in Chen e.a. (1988). 
The next step, the empty production eliminater, 
eliminates all empty productions except those for 
push and pop. This transforms the output of 
the argument movement expander to the follow- 
ing grammar. 
s1(Gi,Go,S1) --i> np(Gi,Gt,NP), 
s(Gs,Go,S), 
{cut_trace(trace(var,np(Trace)), 
Gs,Gt)}. 
sl(\[trace(_,np(NP))\[Gt\],Go,S1) ---> 
s(Gs,Go,S). 
{cut_trace(trace(var,np(Trace)), 
Gs,Gt)}. 
s(Gi,Go,S) --->inp(Gi,Gt,NP), 
vp(Gt,Go,VP), 
{bound(Gi)}. 
s(\[trace(_,np(NP))\[Gt\]0Go,S) ---> 
vp(Gt,Go,VP), 
{bound(Gi)}. 
vp(Gi,Go,VP) ---> v(Gi,Go,V). 
vp(Gi,Go,VP) --~> v(Gi,Gt,V), 
np(Gt,Go,NP). 
vp(Gi,Go,VP) --~> 
v(Gi,\[trace(_,np(SP))\[Go\],V). 
Elimination of empty productions allows for 
a simpler implementation of the Tomita parser, 
which again leads to an increased efficiency. 
The next step, the DcG-to-LRK converter splits 
the grammar rules into a context free and 
a DCG part. A context free rule is repre- 
sented as rule(No,LIIS,RHS), a DCG rule as 
dcg_rule (No, LHS, RHS, Constraint). Rules are 
synchronized by their numbers. After this step 
the above grammar fragment is represented in the 
following format. 
rule(l, sl 0 \[np, s\] ). 
rule (2, s I, \[s\] ). 
rule(S, s, \[np, vp\] ). 
rule (4, s, \[vp\] ). 
rule(S,vp, \[v\] ). 
rule(6,vp, \[v,np\] ). 
dcg_rule(1,sl(Gi,Go,S1), 
\[np(Gi,Ot,NP),s(~s,Go,S)\], 
cut_trace(trace(var,np(Trace)), 
~s,~t)). 
dcg_rule(2,sl(\[trace(_,np(NP))\]Gt\], 
Go,St), 
\[s(Gs,Go,S)\], 
cut_trace(trace(var,np(Trace)), 
Gs,Gt)). 
dcg_rule(3,s(Gi,Go,S), 
\[np(Gi,Gt,NP),vp(Gt,Go,VP)\], 
bound(Gi)). 
dcg_rule(4,s(\[~race(_,np(NP))iGt\], 
Go,S), 
\[vp(Gt,Go,VP)\], 
bo~uad(Gi)). 
dcg_rule(S,vp(Gi,Go,VP), 
\[v(Gi,Gv,V)\], 
( Gv = Go 
; Gv = \[trace(_,np(NP))\[Go\] )). 
dcg_rule(6,vp(Gi,Go,VP), 
\[v(Gi,Gt,V),np(Gt,Go,NP)\], 
true). 
Note that during this step, different rules that 
share the same context free backbone are trans- 
formed to a single context free rule. The differ- 
ence in their feature structure is expressed in a 
disjunction in the Constraint (e.g. rule 5). As 
very often traces occur in optional positions (e.g. 
objects, as in vp ---> v. vp ---> v, np), the 
elimination of empty productions (traces) consid- 
erably reduces the amount of edges the parser has 
to build. 
105 
After these compilation steps the context free 
rules are transformed to YACC format and YACC 
is used to compute the LR parsing table. Finally, 
YACC'S y. output file is transformed to PROLOG. 
3.2THE GENERATOR 
GENERATOR 
For generation with TUG an improved version 
of the semantic-head-driven generator (SHDG) (see 
Shieber e.a. 1990) is used. Before beeing useful 
for generation, the grammar is transformed in the 
following steps: 
• expansion of head movement rules 
* transformation to the semantic head driven 
generator format 
• expansion of movement rules 
• elimination of nonchainrules with uninstanti- 
ated semantics 
• goal reordering and transformation to exe- 
cutable prolog code 
First, the head movement expander transforms 
the head movement rules. As in the parser gen- 
erator, slashed categories are generated along the 
head path, but no push and pop categories are in- 
troduces. Instead, the head movement rule and 
the trace are treated similar to argument move- 
ment. The resulting relevant new rules from the 
example above are: 
newly introduced slash rules 
sl(S1) ---> \[v(V)<trace(var,v_v(V)), 
s_v(S)S. 
s_v(S) ---> \[ .... vp_v(VP),...\]. 
vp_v(VP) ---> \[...,vk_v(VK) .... \]. 
vk_v(VZ) ---> \[...,v_v(V),...\]. 
trace(_,v_v(V)). 
In the next step rule symbols are transformed 
to the node(Cat,S,S0) format needed by the 
semantic-head-driven generator. Thereby disjunc- 
tions on the semantic argument as in the following 
example 
a(Sem) ---> b(BSem), c(CSem), 
(BSem = Sem; CSem = Sam}. 
are unfolded (multiplied out) to different rules. 
The output of this step for the above rule is: 
node(a(Sem),S,SO) ---> 
nods(b(Sem),S,Sl), 
node(c(CSem),S1~SO). 
node(a(Sem),S,SO) ---> 
node(b(SSem),S,Sl), 
node(c(Sem),Sl,SO). 
Obviously, unfolding of semantic disjunctions is 
necessary for a correct choice of the semantic head. 
The next compilation cycle expands the move- 
ment rules. Similar to the parser generator two 
arguments for gap threaddin8 are introduced. The 
filling of the arguments and the transformation of 
the movement rules is different from the parser 
generator. It is a rather complicated operation 
which is sensitive to the semantics control flow. 
Given a rule 
a(A) ---> b(B)<trace(var,b(BT)), c(C)} 
we can distinguish two cases: 
1) The rule is a nonchain rule in the sense of 
Shieber e.a. (1990) or it is a chain rule and the 
antecedent of the trace is the semantic head. In 
this case the antecedent has to be generated prior 
to the trace. A typical example is a predicate logic 
analysis as in: 
node(sl(Sem),S,S0) ---> 
node(np(Sem,SemIn) < 
trace(vax0np(NPSem,NPSem)), 
S,Sl), 
nods(s(SemIn),Sl,SO). 
As the antecedent carries the semantic informa- 
tion, it is expanded at the landing site, while the 
trace is just empty: 
node(sl(Gi,Go,Sem),S,SO) ---> 
node(np(Gi,qt,Sem,SemIn),S,Sl), 
node(s(Gt,Gs,Semln),Sl,SO), 
{cut_trace(trace(var,np(NPSem,NPSem), 
Gs,Gi)}. 
node(np(\[trace(var,np(NPSem,NPSem))lGo\], 
Go,NPSem,NPSem),S,S). 
2) If any element other than the antecedent is 
the semantic head, then this head has to be gen- 
erated prior to the antecedent. As the head might 
contain the trace, it also has to be generated prior 
to its antecedent. Consider the rule: 
node(sl(Sem),S,SO) ---> 
106 
node(np(NPSem)<trace(var,np(NPSem)), 
S,SI), 
node(s(Sem),Sl,S0). 
In this rule s is generated prior to np. Within 
s, the trace of np w'ill be generated. Following the 
suggestion in Shieber e.a. (1990), rules like this 
axe compiled in such a way that an antecedent 
is generated in the~ trace position without linking 
it to the input st,ing. This antecedent is then 
added to the set of gaps together with its starting 
and ending position (coded as a difference list). 
When generation domes to the landing site, the 
antecedent is cut out of the trace set. Thereby 
its starting and ending position is unified with the 
landing site's star( and end positions. The trans- 
lation of the above I rule is: 
node(sl(Gi,Go,Sem),S,SO) ---> 
node(s(Gs,Go,Sem),Sl,SO), 
{cut_~race(trace(vax,np(NPSem),S,S1), 
Gs,Gi)}. 
node(np(\[trace(var,np(NPSem),S,SO)\[Go\], 
Go,NPSem),SX,SX) ---> 
node(np(G,G~NPSem),S,SO). 
In the next steP, a certain class of nonchain 
rules is eliminated from the grammar. One of 
the basic inefficiencies of the semantic-head-driven 
generator in Shiebcr e.a. (1990) has its origin in 
nonchaln rules who~se left-hand-side-semantics is a 
variable. This kin d of nonchain rule often results 
from empty productions or lexicon entries of se- 
mantically empty words. For instance, in a gram- 
mar and lexicon fragment like 
vk(SC)/Sem ---> aux(VKSem,SC,VKSC)/Sem, 
vk(VKSC)/VKSem, 
aux (VKSem, SC, SC)/past (VKSem) ---> \[has\]. 
aux (Sere, SC, \[Subj \[ SC\] )/Sere ---> \[is\]. 
the rule introducing is is a nonchain rule whose 
semantics is a variable and thus cannot be indexed 
properly. Rules like this one are eliminated by a 
partial evaluation technique. For each grammar 
rule that contains the left-hand-side of the rule on 
its right-hand-side/~ a copy of the rule is produced 
where the variables ~ are unified with the left-hand- 
side of the nonchain rule and the corresponding 
right-hand-side element is replaced with the right- 
hand-side of the nonchain rule. E.g. insertion of 
the rule for is into the vk-rule above leads to 
vk(SC)/Sem ---> \[is\], vk(\[Subj I SC\])/Sem. 
which is a normal chain rule. 
A final compilation transforms the rules to exe- 
cutable PROLOG code and sorts the right hand side 
to achieve a proper semantics information flow. 
Suppose that, in the following nonchaln rule the 
first argument of a category is its semantics argu- 
ment. 
node(a(f(Sem)),S,SO) ---> 
node(b(BSem)oS,Sl), 
node(c(CSem,BSem),SI,S2), 
node(d(Sem,CSem),S2,SO). 
The righthand side has to be ordered in such a 
way that all semantics arguments have a chance to 
be instantiated when the corresponding category 
is expanded, as in the following rule: 
node(a(f(Sem)),S,SO) ---> 
node(d(Sem,CSem),S2,SO), 
node(c(CSem,BSem),Sl,S2), 
node(b(BSem),S,S1). 
This ordering is achieved by a bubble-sort like 
mechanism. Elements of the right-hand-side are 
sorted into the new right-hand-side from right to 
left. To insert a new element e, ew into an (already 
sorted) list el ... ei, e,,, is inserted into e, ...ei-1 
if the semantics argument of e, ew is not equal to 
some argument of ei, otherwise it is sorted after 
ei. 
In the final PROLOG code nonchaln rules are in- 
dexed by the functor of their lefthand side's se- 
mantics as in the following example. 
~(Z(Sem),Sxp) :- 
generate(Sem0node(d(Sem,CSem), 
s2,so)), 
genera~e(CSem,node(c(CSem,BSem), 
Sl,S2)), 
generate(BSem,node(b(BSem),S,S1)), 
a(node(a(f(Sem)),S,SO),gxp). 
Chain rules (like e.g. the one that re- 
suits by replacing node(a(fCSem)),S,S0) by 
node(a(Sem),S,S0) in the rule above) are in- 
dexed by their syntactic category: 
d(node(d(Sem),S2,SO),Exp) :- 
link(a(Sem),Exp), 
generate(CSem,node(c(CSem,BSem), 
107 
sl,s2)), 
generate(BSem,node(b(BSem),S,S1)), 
a(node(a(Sem),S,SO),Exp). 
The auxiliary predicates needed for the genera- 
tor then can be reduced to bottom-up termination 
rules C(X,X) for all syntactic category symbols C 
and the predicate for generate/2: 
generate(Sem,Exp) :- 
func~or(Sem,F,A), 
functor(Goal,F,2), 
arg(1,Goal,Sem), 
arg(2,Goal,Exp), 
call(Goal). 
4 CONCLUSION 
We have distinguished three levels of reversibil- 
ity: runtime reversibility, interpretation reversibil- 
ity and compilation reversibility. We then have 
presented Trace & Unification Grammar, a gram- 
mar formalism that tries to bridge the gap be- 
tween uo and GB theory in an undogmatic way 
and have presented a parser generator and a gen- 
erator generator that lead to effient runtime code 
of the grammar both for parsing and for genera- 
tion. No special effort has been invested to opti- 
mize the compilers themselves, so the compilation 
takes about 1.5 secs. per rule or lexicon entry. 
Due to space limitations many details of the com- 
pilation phase could not be discussed. 
The presented grammar formalism has been 
used to describe a relevant subset of German lan- 
guage and a smaller subset of Chinese. The gram- 
mars describe a mapping between German and 
Chinese and QLF expressions. 
ACKNOWLEDGEMENTS 
I would like to thank Ms. Ping Peng and my 
collegues Manfred Gehrke, Rudi Hunze, Steffi 
Schachtl and Ludwig Schmid for many discussions 
on the TUG-formalism. 

REFERENCES 
Aho, A.V., R. Sethi and J.D. Ullman (1986) 
Compilers. Principles, Techniques and Tools. 
Addison-Wesley Publishing Company. 
Alshawi, H. (1990) "Resolving Quasi Logical 
Forms", Computational Linguistics, Vol. 16, 
pp. 133-144. 
Block, H. U. (forthcoming) "Two optimizations 
for Semantic-Head-Driven Generators". 
Block, H. U. and L. A. Schmid (forthcoming) "Us- 
ing Disjunctive Constraints in a Bottom-Up 
Parser". 
Chen, H.-H., I-P. Lin and C.-P. Wu (1988) "A 
new design of Prolog-based bottom-up Pars- 
ing System with Government-Binding The- 
ory", Proc. l~th International Conference 
on Computational Linguistics (COLING-88), 
pp. 112-116. 
Chen, H.-H. (1990) "A Logic-Based Government- 
Binding Parser for Mandarin Chinese", Proc. 
13th International Conference on Computa- 
tional Linguistics (COLING-90), pp. 1-6. 
Neumann, G. (1991) "A Bidirectional Model for 
Natural Language Processing" Proc. 5th 
Conf. of the European Chapter of the ACL 
(EACL-91) pp. 245-250. 
Pereira, F. (1981) "Extraposition Grammar" 
Computational Linguistics Vol. 7, pp. 243- 
256. 
Shieber, S.M. (1984) "The design of a Computer 
Language for Linguistic Information" Proc. 
lOth International Conference on Computa- 
tional Linguistics (COLING-84), pp. 362-366. 
Shieber, S.M. (1988) "A Uniform Architecture for 
Parsing and Generation", Proc. l~th Interna- 
tional Conference on Computational Linguis- 
tics (COLING-88), pp. 614-619. 
Shieber, S.M., G. van Noord, F.C.N. Pereira 
and R.C. Moore (1990). "Semantic-Head- 
Driven Generation". Computational Linguis- 
tics, Vol. 16, pp. 30-43. 
Strzalkowsi, T. and Ping Peng (1990). "Auto- 
mated Inversion of Logic Grammars for Gen- 
eration" Proc. Conf. of the 28th Annual 
Meeting of the ACL, (ACL-90) pp. 212-219. 
Strzalkowsiki, T. (1990). "How to Invert a Nat- 
ural Language Parser into an Efficient Gen- 
erator: An Algorithm for Logic Grammars" 
Proc. 13th International Conference on Com- 
putational Linguistics (COLING-90), pp. 347- 
352. 
Tomita, M. (1986). E~icient Parsing for Natural 
Language: A fast Algorithm for Practical Sys- 
tems. Boston: Kluwer Academic Publishers. 
