summaryrefslogtreecommitdiff
path: root/grammars/resource/english/Syntax.gf
blob: 07f4c7358d466154dd8123f276e6c627147ba662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
--1 A Small English Resource Syntax
--
-- Aarne Ranta 2002
--
-- This resource grammar contains definitions needed to construct 
-- indicative, interrogative, and imperative sentences in English.
--
-- The following files are presupposed:

resource Syntax = Morpho ** open Prelude, (CO = Coordination) in {

--2 Common Nouns
--
-- Simple common nouns are defined as the type $CommNoun$ in $morpho.Deu.gf$.

--3 Common noun phrases

-- To the common nouns of morphology,
-- we add natural gender (human/nonhuman) which is needed in syntactic
-- combinations (e.g. "man who runs" - "program which runs").

oper
  CommNoun = CommonNoun ** {g : Gender} ;

  CommNounPhrase = CommNoun ;

  noun2CommNounPhrase : CommNoun -> CommNounPhrase = \man ->
    man ;

  cnGen : CommonNoun -> Gender -> CommNoun = \cn,g ->
    cn ** {g = g} ;

  cnHum : CommonNoun -> CommNoun = \cn ->
    cnGen cn Hum ;
  cnNoHum : CommonNoun -> CommNoun = \cn ->
    cnGen cn NoHum ;

--2 Noun phrases
--
-- The worst case is pronouns, which have inflection in the possessive forms. 
-- Proper names are a special case.

  NounPhrase : Type = Pronoun ;

  nameNounPhrase : ProperName -> NounPhrase = \john -> 
    {s = \\c => john.s ! toCase c ; n = Sg ; p = P3} ;

--2 Determiners
--
-- Determiners are inflected according to the nouns they determine.
-- The determiner is not inflected.
  Determiner : Type = {s : Str ; n : Number} ;

  detNounPhrase : Determiner -> CommNounPhrase -> NounPhrase = \every, man -> 
    {s = \\c => every.s ++ man.s ! every.n ! toCase c ; 
     n = every.n ; 
     p = P3
    } ;

  mkDeterminer : Number -> Str -> Determiner = \n,det -> 
    {s = det ; 
     n = n
    } ;

  everyDet = mkDeterminer Sg "every" ;
  allDet   = mkDeterminer Pl "all" ;
  mostDet  = mkDeterminer Pl "most" ;
  aDet     = mkDeterminer Sg artIndef ;
  plDet    = mkDeterminer Pl [] ;
  theSgDet = mkDeterminer Sg "the" ;
  thePlDet = mkDeterminer Pl "the" ;
  anySgDet = mkDeterminer Sg "any" ;
  anyPlDet = mkDeterminer Pl "any" ;

  whichSgDet = mkDeterminer Sg "which" ;
  whichPlDet = mkDeterminer Pl "which" ;

  whichDet = whichSgDet ; --- API

  indefNoun : Number -> CommNoun -> Str = \n,man -> 
    (indefNounPhrase n man).s ! NomP ;

  indefNounPhrase : Number -> CommNounPhrase -> NounPhrase = \n,man -> 
    {s = \\c => case n of {
                       Sg => artIndef ++ man.s ! n ! toCase c ; 
                       Pl => man.s ! n ! toCase c
                       } ;
     n = n ; p = P3
    } ;

  defNounPhrase : Number -> CommNounPhrase -> NounPhrase = \n,car -> 
    {s = \\c => artDef ++ car.s ! n ! toCase c ; n = n ; p = P3} ;

-- Genitives of noun phrases can be used like determiners, to build noun phrases.
-- The number argument makes the difference between "my house" - "my houses".
--
-- We have the variation "the car of John / the car of John's / John's car"

  npGenDet : Number -> NounPhrase -> CommNounPhrase -> NounPhrase = 
    \n,john,car -> 
      {s = \\c => variants {
             artDef ++ car.s ! n ! Nom ++ "of" ++ john.s ! GenSP ; 
             john.s ! GenP ++ car.s ! n ! toCase c
             } ;
       n = n ; 
       p = P3
      } ;

-- *Bare plural noun phrases* like "men", "good cars", are built without a 
-- determiner word.

  plurDet : CommNounPhrase -> NounPhrase = \cn -> 
    {s = \\c => cn.s ! plural ! toCase c ; 
     p = P3 ; 
     n = Pl
    } ;

-- Constructions like "the idea that two is even" are formed at the
-- first place as common nouns, so that one can also have "a suggestion that...".

  nounThatSentence : CommNounPhrase -> Sentence -> CommNounPhrase = \idea,x -> 
    {s = \\n,c => idea.s ! n ! c ++ "that" ++ x.s ; 
     g = idea.g
    } ;


--2 Adjectives
--
-- Adjectival phrases have a parameter $p$ telling if they are prefixed ($True$) or 
-- postfixed (complex APs). 

  AdjPhrase : Type = Adjective ** {p : Bool} ;

  adj2adjPhrase : Adjective -> AdjPhrase = \new -> new ** {p = True} ;

  simpleAdjPhrase : Str -> AdjPhrase = \French ->
    adj2adjPhrase (simpleAdj French) ;


--3 Comparison adjectives
--
-- Each of the comparison forms has a characteristic use:
--
-- Positive forms are used alone, as adjectival phrases ("big").

  positAdjPhrase : AdjDegr -> AdjPhrase = \big -> 
    adj2adjPhrase (ss (big.s ! Pos)) ;

-- Comparative forms are used with an object of comparison, as
-- adjectival phrases ("bigger then you").

  comparAdjPhrase : AdjDegr -> NounPhrase -> AdjPhrase = \big, you ->
    {s = big.s ! Comp ++ "than" ++ you.s ! NomP ; 
     p = False
    } ;

-- Superlative forms are used with a modified noun, picking out the
-- maximal representative of a domain ("the biggest house").

  superlNounPhrase : AdjDegr -> CommNoun -> NounPhrase = \big, house ->
    {s = \\c => "the" ++ big.s ! Sup ++ house.s ! Sg ! toCase c ; 
     n = Sg ; 
     p = P3
    } ;


--3 Two-place adjectives
--
-- A two-place adjective is an adjective with a preposition used before
-- the complement.

  Preposition = Str ;

  AdjCompl = Adjective ** {s2 : Preposition} ;

  complAdj : AdjCompl -> NounPhrase -> AdjPhrase = \related,john ->
    {s = related.s ++ related.s2 ++ john.s ! AccP ; 
     p = False
    } ;


--3 Modification of common nouns
--
-- The two main functions of adjective are in predication ("John is old")
-- and in modification ("an old man"). Predication will be defined
-- later, in the chapter on verbs.
--
-- Modification must pay attention to pre- and post-noun
-- adjectives: "big car"/"car bigger than X"

  modCommNounPhrase : AdjPhrase -> CommNounPhrase -> CommNounPhrase = \big, car -> 
    {s = \\n => if_then_else (Case => Str) big.p 
           (\\c => big.s ++ car.s ! n ! c)
           (table {Nom => car.s ! n ! Nom ++ big.s ; Gen => variants {}}) ;
     g = car.g
    } ;


--2 Function expressions

-- A function expression is a common noun together with the
-- preposition prefixed to its argument ("mother of x").
-- The type is analogous to two-place adjectives and transitive verbs.

  Function = CommNounPhrase ** {s2 : Preposition} ;

-- The application of a function gives, in the first place, a common noun:
-- "mother/mothers of John". From this, other rules of the resource grammar 
-- give noun phrases, such as "the mother of John", "the mothers of John",
-- "the mothers of John and Mary", and "the mother of John and Mary" (the
-- latter two corresponding to distributive and collective functions,
-- respectively). Semantics will eventually tell when each
-- of the readings is meaningful.

  appFunComm : Function -> NounPhrase -> CommNounPhrase = \mother,john -> 
    {s = \\n => table {
            Gen => nonExist ; --- ?
            _ => mother.s ! n ! Nom ++ mother.s2 ++ john.s ! GenSP 
            } ;
     g = mother.g
    } ;

-- It is possible to use a function word as a common noun; the semantics is
-- often existential or indexical.

  funAsCommNounPhrase : Function -> CommNounPhrase = 
    noun2CommNounPhrase ;

-- The following is an aggregate corresponding to the original function application
-- producing "John's mother" and "the mother of John". It does not appear in the
-- resource grammar API any longer.

  appFun : Bool -> Function -> NounPhrase -> NounPhrase = \coll, mother,john -> 
    let {n = john.n ; nf = if_then_else Number coll Sg n} in 
    variants {
      defNounPhrase nf (appFunComm mother john) ;
      npGenDet nf john mother
      } ;

-- The commonest case is functions with the preposition  "of".

  funOf : CommNoun -> Function = \mother -> 
    mother ** {s2 = "of"} ;

  funOfReg : Str -> Gender -> Function = \mother,g -> 
    funOf (nounReg mother ** {g = g}) ;

-- Two-place functions add one argument place.

  Function2 = Function ** {s3 : Preposition} ;

-- There application starts by filling the first place.

  appFun2 : Function2 -> NounPhrase -> Function = \train, paris ->
    {s  = \\n,c => train.s ! n ! c ++ train.s2 ++ paris.s ! AccP ;
     g  = train.g ;
     s2 = train.s3
    } ;


--2 Verbs
--
--3 Verb phrases
--
-- Verb phrases are discontinuous: the two parts of a verb phrase are
-- (s) an inflected verb, (s2) infinitive and complement.
-- For instance: "doesn't" - "walk" ; "isn't" - "old" ; "is" - "a man"
-- There's also a parameter telling if the verb is an auxiliary:
-- this is needed in question.

  VerbPhrase = VerbP3 ** {s2 : Number => Str ; isAux : Bool} ;

-- From the inflection table, we selecting the finite form as function 
-- of person and number:

  indicVerb : VerbP3 -> Person -> Number -> Str = \v,p,n -> case n of {
    Sg => v.s ! Indic p ;
    Pl => v.s ! Indic P2
    } ;

-- A simple verb can be made into a verb phrase with an empty complement.
-- There are two versions, depending on if we want to negate the verb.
-- N.B. negation is *not* a function applicable to a verb phrase, since
-- double negations with "don't" are not grammatical.

  predVerb : Bool -> Verb -> VerbPhrase = \b,walk ->
    if_then_else VerbPhrase b 
      {s = \\v => walk.s ! v ++ walk.s1 ;
       s2 = \\_ => [] ; 
       isAux = False
      }
      {s  = \\v => contractNot (verbP3Do.s ! v) ; 
       s2 = \\_ => walk.s ! InfImp ++ walk.s1 ;
       isAux = True
      } ;

-- Sometimes we want to extract the verb part of a verb phrase.

  verbOfPhrase : VerbPhrase -> VerbP3 = \v -> {s = v.s} ;

-- Verb phrases can also be formed from adjectives ("is old"),
-- common nouns ("is a man"), and noun phrases ("ist John").
-- The third rule is overgenerating: "is every man" has to be ruled out
-- on semantic grounds.

  predAdjective : Bool -> Adjective -> VerbPhrase = \b,old ->
    {s = beOrNotBe b ;
     s2 = \\_ => old.s ;
     isAux = True
    } ;

  predCommNoun : Bool -> CommNoun -> VerbPhrase = \b,man ->
    {s = beOrNotBe b ;
     s2 = \\n => indefNoun n man ;
     isAux = True
    } ;

  predNounPhrase : Bool -> NounPhrase -> VerbPhrase = \b,john ->
    {s = beOrNotBe b ;
     s2 = \\_ => john.s ! NomP ;
     isAux = True
    } ;

-- We use an auxiliary giving all forms of "be".

  beOrNotBe : Bool -> (VForm => Str) = \b -> 
    if_then_else (VForm => Str) b 
      verbBe.s
      (table {
        InfImp   => contractNot "do" ++ "be" ;
        Indic P1 => "am" ++ "not" ;
        v        => contractNot (verbBe.s ! v)
        }) ;

--3 Transitive verbs
--
-- Transitive verbs are verbs with a preposition for the complement,
-- in analogy with two-place adjectives and functions.
-- One might prefer to use the term "2-place verb", since
-- "transitive" traditionally means that the inherent preposition is empty.
-- Such a verb is one with a *direct object*.

  TransVerb : Type = Verb ** {s3 : Preposition} ;

-- The rule for using transitive verbs is the complementization rule.
-- Particles produce free variation: before or after the complement 
-- ("I switch on the TV" / "I switch the TV on").

  complTransVerb : Bool -> TransVerb -> NounPhrase -> VerbPhrase = 
    \b,lookat,john ->
    let {lookatjohn = bothWays lookat.s1 (lookat.s3 ++ john.s ! AccP)} in
    if_then_else VerbPhrase b 
      {s = lookat.s ; 
       s2 = \\_ => lookatjohn ; 
       isAux = False}
      {s = \\v => contractNot (verbP3Do.s ! v) ; 
       s2 = \\_ => lookat.s ! InfImp ++ lookatjohn ;
       isAux = True} ;


-- Verbs that take direct object and a  particle:
  mkTransVerbPart : VerbP3 -> Str -> TransVerb = \turn,off -> 
    {s = turn.s ; s1 = off ; s3 = []} ;

-- Verbs that take prepositional object, no particle:
  mkTransVerb : VerbP3 -> Str -> TransVerb = \wait,for -> 
    {s = wait.s ; s1 = [] ; s3 = for} ;

-- Verbs that take direct object, no particle:
  mkTransVerbDir : VerbP3 -> TransVerb = \love -> 
    mkTransVerbPart love [] ;

-- Transitive verbs with accusative objects can be used passively. 
-- The function does not check that the verb is transitive.
-- Therefore, the function can also be used for "he is swum", etc.
-- The syntax is the same as for adjectival predication.

  passVerb : Bool -> Verb -> VerbPhrase = \b,love ->
    predAdjective b (adj2adjPhrase (ss (love.s ! PPart))) ;

-- Transitive verbs can be used elliptically as verbs. The semantics
-- is left to applications. The definition is trivial, due to record
-- subtyping.

  transAsVerb : TransVerb -> Verb = \love -> 
    love ;

-- *Ditransitive verbs* are verbs with three argument places.
-- We treat so far only the rule in which the ditransitive
-- verb takes both complements to form a verb phrase.

  DitransVerb = TransVerb ** {s4 : Preposition} ; 

  mkDitransVerb : Verb -> Preposition -> Preposition -> DitransVerb = \v,p1,p2 -> 
    v ** {s3 = p1 ; s4 = p2} ;

  complDitransVerb : 
    Bool -> DitransVerb -> NounPhrase -> NounPhrase -> VerbPhrase = 
    \b,give,you,beer ->
      let {
        youbeer = give.s1 ++ give.s3 ++ you.s ! AccP ++ give.s4 ++ beer.s ! AccP
      } in
      if_then_else VerbPhrase b 
      {s = give.s ; 
       s2 = \\_ => youbeer ;
       isAux = False
      }
      {s = \\v => contractNot (verbP3Do.s ! v) ; 
       s2 = \\_ => give.s ! InfImp ++ youbeer ;
       isAux = True
      } ;


--2 Adverbials
--
-- Adverbials are not inflected (we ignore comparison, and treat
-- compared adverbials as separate expressions; this could be done another way).
-- We distinguish between post- and pre-verbal adverbs.

  Adverb : Type = SS ** {p : Bool} ;

  advPre  : Str -> Adverb = \seldom -> ss seldom ** {p = False} ;
  advPost : Str -> Adverb = \well   -> ss well   ** {p = True} ;

-- N.B. this rule generates the cyclic parsing rule $VP#2 ::= VP#2$
-- and cannot thus be parsed.

  adVerbPhrase : VerbPhrase -> Adverb -> VerbPhrase = \sings, well ->
    let {postp = orB well.p sings.isAux} in
    {
     s = \\v => (if_then_else Str postp [] well.s) ++ sings.s ! v ;
     s2 = \\n => sings.s2 ! n ++ (if_then_else Str postp well.s []) ;
     isAux = sings.isAux
    } ;

  advAdjPhrase : SS -> AdjPhrase -> AdjPhrase = \very, good ->
    {s = very.s ++ good.s ;
     p = good.p
    } ;

-- Adverbials are typically generated by prefixing prepositions.
-- The rule for creating locative noun phrases by the preposition "in"
-- is a little shaky, since other prepositions may be preferred ("on", "at").

  prepPhrase : Preposition -> NounPhrase -> Adverb = \on, it ->
    advPost (on ++ it.s ! AccP) ;

  locativeNounPhrase : NounPhrase -> Adverb = 
    prepPhrase "in" ;

-- This is a source of the "mann with a telescope" ambiguity, and may produce
-- strange things, like "cars always" (while "cars today" is OK).
-- Semantics will have to make finer distinctions among adverbials.
--
-- N.B. the genitive case created in this way would not make sense.

  advCommNounPhrase : CommNounPhrase -> Adverb -> CommNounPhrase = \car,today ->
   {s = \\n => table {
      Nom => car.s ! n ! Nom ++ today.s ; 
      Gen => nonExist
      } ;
    g = car.g
   } ;


--2 Sentences
--
-- Sentences are not inflected in this fragment of English without tense.

  Sentence : Type = SS ;

-- This is the traditional $S -> NP VP$ rule. It takes care of
-- agreement between subject and verb. Recall that the VP may already
-- contain negation. 

  predVerbPhrase : NounPhrase -> VerbPhrase -> Sentence = \john,walks ->
    ss (john.s ! NomP ++ indicVerb (verbOfPhrase walks) john.p john.n ++ 
        walks.s2 ! john.n) ;


-- This is a macro for simultaneous predication and complementization.

  predTransVerb : Bool -> NounPhrase -> TransVerb -> NounPhrase -> Sentence = 
    \b,you,see,john -> 
    predVerbPhrase you (complTransVerb b see john) ;


--3 Sentence-complement verbs
--
-- Sentence-complement verbs take sentences as complements.

  SentenceVerb : Type = Verb ;

-- To generate "says that John walks" / "doesn't say that John walks":

  complSentVerb : Bool -> SentenceVerb -> Sentence -> VerbPhrase = 
    \b,say,johnruns ->
    let {thatjohnruns = optStr "that" ++ johnruns.s} in
    if_then_else VerbPhrase b 
      {s  = say.s ; 
       s2 = \\_ => thatjohnruns ; 
       isAux = False}
      {s  = \\v => contractNot (verbP3Do.s ! v) ; 
       s2 = \\_ => say.s ! InfImp ++ thatjohnruns ;
       isAux = True} ;


--2 Sentences missing noun phrases
--
-- This is one instance of Gazdar's *slash categories*, corresponding to his
-- $S/NP$.
-- We cannot have - nor would we want to have - a productive slash-category former.
-- Perhaps a handful more will be needed.
--
-- Notice that the slash category has a similar relation to sentences as
-- transitive verbs have to verbs: it's like a *sentence taking a complement*.
-- However, we need something more to distinguish its use in direct questions:
-- not just "you see" but ("whom") "do you see".
--
-- The particle always follows the verb, but the preposition can fly:
-- "whom you make it up with" / "with whom you make it up".

  SentenceSlashNounPhrase = {s : Bool => Str ; s2 : Preposition} ;

  slashTransVerb : Bool -> NounPhrase -> TransVerb -> SentenceSlashNounPhrase = 
    \b,You,lookat ->
    let {you   = You.s ! NomP ;
         looks = indicVerb {s = lookat.s} You.p You.n ;
         look  = lookat.s ! InfImp ;
         do    = indicVerb verbP3Do You.p You.n ;
         dont  = contractNot do ;
         up    = lookat.s1
        } in
    {s  = table {
            True  => if_then_else Str b do dont ++ you ++ look ++ up ; 
            False => you ++ if_then_else Str b looks (dont ++ look) ++ up
            } ;
     s2 = lookat.s3   
    } ;


--2 Relative pronouns and relative clauses
--
-- As described in $types.Eng.gf$, relative pronouns are inflected in 
-- gender (human/nonhuman), number, and case.
--
-- We get the simple relative pronoun ("who"/"which"/"whom"/"whose"/"that"/$""$)
-- from $morpho.Eng.gf$.

  identRelPron : RelPron = relPron ;

  funRelPron : Function -> RelPron -> RelPron = \mother,which -> 
    {s = \\g,n,c => "the" ++ mother.s ! n ! Nom ++ 
                    mother.s2 ++ which.s ! g ! n ! GenSP
    } ;

-- Relative clauses can be formed from both verb phrases ("who walks") and
-- slash expressions ("whom you see", "on which you sit" / "that you sit on"). 

  RelClause : Type = {s : Gender => Number => Str} ;

  relVerbPhrase : RelPron -> VerbPhrase -> RelClause = \who,walks ->
    {s = \\g, n => who.s ! g ! n ! NomP ++ 
                   indicVerb (verbOfPhrase walks) P3 n ++ walks.s2 ! n
    } ;

  relSlash : RelPron -> SentenceSlashNounPhrase -> RelClause = \who,yousee ->
    {s = \\g,n => 
           let {youSee = yousee.s ! False} in
           variants {
             who.s ! g ! n ! AccP ++ youSee ++ yousee.s2 ;
             yousee.s2 ++ who.s ! g ! n ! GenSP ++ youSee
             }
    } ;

-- A 'degenerate' relative clause is the one often used in mathematics, e.g.
-- "number x such that x is even".

  relSuch : Sentence -> RelClause = \A ->
    {s = \\_,_ => "such" ++ "that" ++ A.s} ;

-- The main use of relative clauses is to modify common nouns.
-- The result is a common noun, out of which noun phrases can be formed
-- by determiners. No comma is used before these relative clause.

  modRelClause : CommNounPhrase -> RelClause -> CommNounPhrase = \man,whoruns ->
    {s = \\n,c => man.s ! n ! c ++ whoruns.s ! man.g ! n ;
     g = man.g
    } ;


--2 Interrogative pronouns
--
-- If relative pronouns are adjective-like, interrogative pronouns are
-- noun-phrase-like. 

  IntPron : Type = {s : NPForm => Str ; n : Number} ; 

-- In analogy with relative pronouns, we have a rule for applying a function
-- to a relative pronoun to create a new one. 

  funIntPron : Function -> IntPron -> IntPron = \mother,which -> 
    {s = \\c => "the" ++ mother.s ! which.n ! Nom ++ mother.s2 ++ which.s ! GenSP ;
     n = which.n
    } ;

-- There is a variety of simple interrogative pronouns:
-- "which house", "who", "what".

  nounIntPron : Number -> CommNounPhrase -> IntPron = \n, car ->
    {s = \\c => "which" ++ car.s ! n ! toCase c ; 
     n = n
    } ; 

  intPronWho : Number -> IntPron = \num -> {
    s = table {
      NomP  => "who" ;
      AccP  => variants {"who" ; "whom"} ;
      GenP  => "whose" ;
      GenSP => "whom"
      } ;
    n = num
  } ;

  intPronWhat : Number -> IntPron = \num -> {
    s = table {
      GenP  => "what's" ;
      _ => "what"
      } ;
    n = num
  } ;


--2 Utterances

-- By utterances we mean whole phrases, such as 
-- 'can be used as moves in a language game': indicatives, questions, imperative,
-- and one-word utterances. The rules are far from complete.
--
-- N.B. we have not included rules for texts, which we find we cannot say much
-- about on this level. In semantically rich GF grammars, texts, dialogues, etc, 
-- will of course play an important role as categories not reducible to utterances.
-- An example is proof texts, whose semantics show a dependence between premises
-- and conclusions. Another example is intersentential anaphora.

  Utterance = SS ;
  
  indicUtt : Sentence -> Utterance = \x -> ss (x.s ++ ".") ;
  interrogUtt : Question -> Utterance = \x -> ss (x.s ! DirQ ++ "?") ;


--2 Questions
--
-- Questions are either direct ("are you happy") or indirect 
-- ("if/whether you are happy").

param 
  QuestForm = DirQ | IndirQ ;

oper
  Question = SS1 QuestForm ;

--3 Yes-no questions 
--
-- Yes-no questions are used both independently 
-- ("does John walk" / "if John walks")
-- and after interrogative adverbials 
-- ("why does John walk" / "why John walks").
-- 
-- It is economical to handle with all these cases by the one
-- rule, $questVerbPhrase'$. The word ("ob" / "whether") never appears
-- if there is an adverbial.

  questVerbPhrase : NounPhrase -> VerbPhrase -> Question = 
    questVerbPhrase' False ;

  questVerbPhrase' : Bool -> NounPhrase -> VerbPhrase -> Question = 
    \adv,john,walk ->
    {s = table {
      DirQ   => if_then_else Str walk.isAux 
                  (indicVerb (verbOfPhrase walk) john.p john.n ++
                   john.s ! NomP ++ walk.s2 ! john.n) 
                  (indicVerb verbP3Do john.p john.n ++ 
                   john.s ! NomP ++ walk.s ! InfImp ++ walk.s2 ! john.n) ;
      IndirQ => if_then_else Str adv [] (variants {"if" ; "whether"}) ++ 
                (predVerbPhrase john walk).s
      }
    } ;



--3 Wh-questions
--
-- Wh-questions are of two kinds: ones that are like $NP - VP$ sentences,
-- others that are line $S/NP - NP$ sentences.

  intVerbPhrase : IntPron -> VerbPhrase -> Question = \who,walk ->
    {s = \\_ => who.s ! NomP ++ indicVerb (verbOfPhrase walk) P3 who.n ++ 
                walk.s2 ! who.n 
    } ;

  intSlash : IntPron -> SentenceSlashNounPhrase -> Question = \who,yousee ->
    {s = \\q =>
           let {youSee = case q of {
                  DirQ   => yousee.s ! True ; 
                  IndirQ => yousee.s ! False
                  }
           } in
           variants {
             who.s ! AccP ++ youSee ++ yousee.s2 ;
             yousee.s2 ++ who.s ! GenSP ++ youSee
             } 
    } ;

--3 Interrogative adverbials
--
-- These adverbials will be defined in the lexicon: they include
-- "when", "where", "how", "why", etc, which are all invariant one-word
-- expressions. In addition, they can be formed by adding prepositions
-- to interrogative pronouns, in the same way as adverbials are formed
-- from noun phrases. 

  IntAdverb = SS ;

  prepIntAdverb : Preposition -> IntPron -> IntAdverb = \at, whom ->
    ss (at ++ whom.s ! AccP) ;

-- A question adverbial can be applied to anything, and whether this makes
-- sense is a semantic question.

  questAdverbial : IntAdverb -> NounPhrase -> VerbPhrase -> Question = 
    \why, you, walk ->
    {s = \\q => why.s ++ (questVerbPhrase' True you walk).s ! q} ;


--2 Imperatives
--
-- We only consider second-person imperatives. 

  Imperative = SS1 Number ;

  imperVerbPhrase : VerbPhrase -> Imperative = \walk -> 
    {s = \\n => walk.s ! InfImp ++ walk.s2 ! n} ;

  imperUtterance : Number -> Imperative -> Utterance = \n,I ->
    ss (I.s ! n ++ "!") ;

--2 Sentence adverbials
--
-- This class covers adverbials such as "otherwise", "therefore", which are prefixed
-- to a sentence to form a phrase.

  advSentence : SS -> Sentence -> Utterance = \hence,itiseven ->
    ss (hence.s ++ itiseven.s ++ ".") ;


--2 Coordination
--
-- Coordination is to some extent orthogonal to the rest of syntax, and
-- has been treated in a generic way in the module $CO$ in the file
-- $coordination.gf$. The overall structure is independent of category,
-- but there can be differences in parameter dependencies.
--
--3 Conjunctions
--
-- Coordinated phrases are built by using conjunctions, which are either
-- simple ("and", "or") or distributed ("both - and", "either - or").
--
-- The conjunction has an inherent number, which is used when conjoining
-- noun phrases: "John and Mary are..." vs. "John or Mary is..."; in the
-- case of "or", the result is however plural if any of the disjuncts is.

  Conjunction = CO.Conjunction ** {n : Number} ;
  ConjunctionDistr = CO.ConjunctionDistr ** {n : Number} ;

--3 Coordinating sentences
--
-- We need a category of lists of sentences. It is a discontinuous
-- category, the parts corresponding to 'init' and 'last' segments
-- (rather than 'head' and 'tail', because we have to keep track of the slot between
-- the last two elements of the list). A list has at least two elements.

  ListSentence : Type = SD2 ;

  twoSentence : (_,_ : Sentence) -> ListSentence = CO.twoSS ;

  consSentence : ListSentence -> Sentence -> ListSentence =
    CO.consSS CO.comma ;

-- To coordinate a list of sentences by a simple conjunction, we place
-- it between the last two elements; commas are put in the other slots,
-- e.g. "du rauchst, er trinkt und ich esse".

  conjunctSentence : Conjunction -> ListSentence -> Sentence = \c,xs ->
    ss (CO.conjunctX c xs) ;

-- To coordinate a list of sentences by a distributed conjunction, we place
-- the first part (e.g. "either") in front of the first element, the second
-- part ("or") between the last two elements, and commas in the other slots.
-- For sentences this is really not used.

  conjunctDistrSentence : ConjunctionDistr -> ListSentence -> Sentence = 
    \c,xs ->
    ss (CO.conjunctDistrX c xs) ;

--3 Coordinating adjective phrases
--
-- The structure is the same as for sentences. The result is a prefix adjective
-- if and only if all elements are prefix.

  ListAdjPhrase : Type = SD2 ** {p : Bool} ;

  twoAdjPhrase : (_,_ : AdjPhrase) -> ListAdjPhrase = \x,y ->
    CO.twoStr x.s y.s ** {p = andB x.p y.p} ;

  consAdjPhrase : ListAdjPhrase -> AdjPhrase -> ListAdjPhrase =  \xs,x ->
    CO.consStr CO.comma xs x.s ** {p = andB xs.p x.p} ;

  conjunctAdjPhrase : Conjunction -> ListAdjPhrase -> AdjPhrase = \c,xs ->
    ss (CO.conjunctX c xs) ** {p = xs.p} ;

  conjunctDistrAdjPhrase : ConjunctionDistr -> ListAdjPhrase -> AdjPhrase = 
    \c,xs ->
    ss (CO.conjunctDistrX c xs) ** {p = xs.p} ;


--3 Coordinating noun phrases
--
-- The structure is the same as for sentences. The result is either always plural
-- or plural if any of the components is, depending on the conjunction.

  ListNounPhrase : Type = {s1,s2 : NPForm => Str ; n : Number ; p : Person} ;

  twoNounPhrase : (_,_ : NounPhrase) -> ListNounPhrase = \x,y ->
    CO.twoTable NPForm x y ** {n = conjNumber x.n y.n ; p = conjPerson x.p y.p} ;

  consNounPhrase : ListNounPhrase -> NounPhrase -> ListNounPhrase =  \xs,x ->
    CO.consTable NPForm CO.comma xs x ** 
       {n = conjNumber xs.n x.n ; p = conjPerson xs.p x.p} ;

  conjunctNounPhrase : Conjunction -> ListNounPhrase -> NounPhrase = \c,xs ->
    CO.conjunctTable NPForm c xs ** {n = conjNumber c.n xs.n ; p = xs.p} ;

  conjunctDistrNounPhrase : ConjunctionDistr -> ListNounPhrase -> NounPhrase = 
    \c,xs ->
    CO.conjunctDistrTable NPForm c xs ** {n = conjNumber c.n xs.n ; p = xs.p} ;

-- We have to define a calculus of numbers of persons. For numbers,
-- it is like the conjunction with $Pl$ corresponding to $False$.

  conjNumber : Number -> Number -> Number = \m,n -> case <m,n> of {
    <Sg,Sg> => Sg ;
    _ => Pl 
    } ;

-- For persons, we let the latter argument win ("either you or I am absent"
-- but "either I or you are absent"). This is not quite clear.

  conjPerson : Person -> Person -> Person = \_,p -> 
    p ;



--2 Subjunction
--
-- Subjunctions ("when", "if", etc) 
-- are a different way to combine sentences than conjunctions.
-- The main clause can be a sentences, an imperatives, or a question,
-- but the subjoined clause must be a sentence.
--
-- There are uniformly two variant word orders, e.g. 
-- "if you smoke I get angry"
-- and "I get angry if you smoke".

  Subjunction = SS ;

  subjunctSentence : Subjunction -> Sentence -> Sentence -> Sentence = 
    \if, A, B -> 
    ss (subjunctVariants if A.s B.s) ;

  subjunctImperative : Subjunction -> Sentence -> Imperative -> Imperative = 
    \if, A, B -> 
    {s = \\n => subjunctVariants if A.s (B.s ! n)} ;

  subjunctQuestion : Subjunction -> Sentence -> Question -> Question = 
    \if, A, B ->
    {s = \\q => subjunctVariants if A.s (B.s ! q)} ;

  subjunctVariants : Subjunction -> Str -> Str -> Str = \if,A,B ->
    variants {if.s ++ A ++ "," ++ B ; B ++ "," ++ if.s ++ A} ;

  subjunctVerbPhrase : VerbPhrase -> Subjunction -> Sentence -> VerbPhrase =
    \V, if, A -> 
    adVerbPhrase V (advPost (if.s ++ A.s)) ;

--2 One-word utterances
-- 
-- An utterance can consist of one phrase of almost any category, 
-- the limiting case being one-word utterances. These
-- utterances are often (but not always) in what can be called the
-- default form of a category, e.g. the nominative.
-- This list is far from exhaustive.

  useNounPhrase : NounPhrase -> Utterance = \john ->
    postfixSS "." (defaultNounPhrase john) ;

  useCommonNounPhrase : Number -> CommNounPhrase -> Utterance = \n,car -> 
    useNounPhrase (indefNounPhrase n car) ;

  useRegularName : SS -> NounPhrase = \john -> 
    nameNounPhrase (nameReg john.s) ;

-- Here are some default forms.

  defaultNounPhrase : NounPhrase -> SS = \john -> 
    ss (john.s ! NomP) ;

  defaultQuestion : Question -> SS = \whoareyou ->
    ss (whoareyou.s ! DirQ) ;

  defaultSentence : Sentence -> Utterance = \x -> 
    x ;

} ;