- Up - | Next >> |
First, we define the grammar rules. We distinguish phrasal rules like NP -> DET N
involving only non-terminals, and lexical rules like DET -> the
which are normally stated in a lexicon.
declare RULES = [
<Phrasal Rules>
<Lexical Rules>]
What you see above is the definition of a named chunk of code. The name of this chunk is Grammar Rules
and it uses two other named chunks, respectively called Phrasal Rules
and Lexical Rules
. The idea is that wherever a named chunk is used, it stands for the corresponding chunk of code stipulated in its definition, i. e. this chunk of code is substituted in its place.
Using code chunks allows us to present and discuss a program in small bits that are easier to understand. We will use this form of program presentation throughout the remainder of the course. It was invented by Donald Knuth under the name of Literate Programming. In the HTML version of the course, wherever a named chunk is used, you can click on it to jump to its definition. In the printed version, you should use the trailing reference number to lookup the definition.
A rule C -> C1 ... Cn
is represented by the record:
o(cat:C subcat:[C1 ... Cn])
In the rules below vi
stands for verb intransitive, vt
for verb transitive, and vd
for verb ditransitive.
o(cat:s subcat:[np vp])
o(cat:np subcat:[det n])
o(cat:np subcat:[pn])
o(cat:np subcat:[np pp])
o(cat:vp subcat:[vi])
o(cat:vp subcat:[vt np])
o(cat:vp subcat:[vd np np])
o(cat:vp subcat:[vp pp])
o(cat:pp subcat:[prep np])
The lexicon contains rules where the subcat list consists of a single terminal category:
o(cat:pn subcat:[john])
o(cat:pn subcat:[mary])
o(cat:det subcat:[the])
o(cat:n subcat:[man])
o(cat:vi subcat:[runs])
o(cat:vt subcat:[likes])
o(cat:vt subcat:[sees])
o(cat:prep subcat:['with'])
o(cat:n subcat:[telescope])
- Up - | Next >> |