22.3 Sample Grammar

Here is a sample grammar, packaged as a functor that exports Lexicon and Rules.

<Grammar Functor>=
functor 
export 
   Lexicon Rules
define 
   
<Lexicon> 
   
<Rules> 
end

The lexicon is extremely simple but has nonetheless a number feature in order to illustrate agreement constraints.

<Lexicon>= >>
Lex =
lex(
   the:
      [det   #fun {$} det(phon:the number:_) end]
   a:
      [det   #fun {$} det(phon:a number:singular) end]
   john:
      [np    #fun {$} np(phon:john number:singular) end]
   man:
      [n     #fun {$} n(phon:man number:singular) end]
   men:
      [n     #fun {$} n(phon:men number:plural) end]
   woman:
      [n     #fun {$} n(phon:woman number:singular) end]
   women:
      [n     #fun {$} n(phon:women number:plural) end]
   'with':
      [prep  #fun {$} prep(phon:'with'end]
   telescope:
      [n     #fun {$} np(phon:telescope number:singular) end]
   saw:
      [v     #fun {$} v(phon:saw number:_) end]
   sees:
      [v     #fun {$} v(phon:see number:singular) end]
   likes:
      [v     #fun {$} v(phon:likes number:singular) end 
       n     #fun {$} n(phon:likes number:plural  ) end]
   like:
      [v     #fun {$} v(phon:like number:plural) end]
   )

<Lexicon>= <<
fun {Lexicon Word} Lex.Word end

Verb and subject, as well as determiner and noun, must agree in number. We also copy the number feature upward whenever necessary.

<Rules>=
Rules =
[rule(s [np vp]
      fun {$ Args}
         Args.1^number=Args.2^number
         s(Args.1 Args.2)
      end)
 rule(np [det n]
      fun {$ Args}
         Args.1^number=Args.2^number
         np(number:Args.2^number Args.1 Args.2)
      end)
 rule(np [n]
      fun {$ Args}
         Args.1^number=plural
         np(number:plural Args.1)
      end)
 rule(np [np pp]
      fun {$ Args}
         np(number:Args.1^number Args.1 Args.2)
      end)
 rule(vp [v np]
      fun {$ Args}
         vp(number:Args.1^number Args.1 Args.2)
      end)
 rule(vp [vp pp]
      fun {$ Args}
         vp(number:Args.1^number Args.1 Args.2)
      end)
 rule(pp [prep np]
      fun {$ Args}
         pp(Args.1 Args.2)
      end)
 rule(vp [v]
      fun {$ Args}
         vp(number:Args.1^number Args.1)
      end)
]


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)