smaller exx

This commit is contained in:
aarne
2005-04-20 19:55:00 +00:00
parent 2ccda07860
commit 4015cd095d
6 changed files with 39 additions and 46 deletions

View File

@@ -7,10 +7,10 @@ fun
UseV : V -> VP ; UseV : V -> VP ;
ComplTV : TV -> NP -> VP ; ComplTV : TV -> NP -> VP ;
UseA : A -> VP ; UseA : A -> VP ;
This, That, Def, Indef : CN -> NP ;
ModA : A -> CN -> CN ; ModA : A -> CN -> CN ;
Bird, Boy, Man, Louse, Snake, Worm : CN ; This, That, Def, Indef : CN -> NP ;
Big, Green, Rotten, Thick, Warm : A ; Boy, Louse, Snake, Worm : CN ;
Green, Rotten, Thick, Warm : A ;
Laugh, Sleep, Swim : V ; Laugh, Sleep, Swim : V ;
Eat, Kill, Wash : TV ; Eat, Kill, Wash : TV ;
} }

View File

@@ -11,13 +11,10 @@ lin
Def cn = {s = "the" ++ cn.s} ; Def cn = {s = "the" ++ cn.s} ;
Indef cn = {s = "a" ++ cn.s} ; Indef cn = {s = "a" ++ cn.s} ;
ModA a cn = {s = a.s ++ cn.s} ; ModA a cn = {s = a.s ++ cn.s} ;
Bird = {s = "bird"} ;
Boy = {s = "boy"} ; Boy = {s = "boy"} ;
Louse = {s = "louse"} ; Louse = {s = "louse"} ;
Man = {s = "man"} ;
Snake = {s = "snake"} ; Snake = {s = "snake"} ;
Worm = {s = "worm"} ; Worm = {s = "worm"} ;
Big = {s = "big"} ;
Green = {s = "green"} ; Green = {s = "green"} ;
Rotten = {s = "rotten"} ; Rotten = {s = "rotten"} ;
Thick = {s = "thick"} ; Thick = {s = "thick"} ;

View File

@@ -11,13 +11,10 @@ lin
Def cn = {s = "il" ++ cn.s} ; Def cn = {s = "il" ++ cn.s} ;
Indef cn = {s = "un" ++ cn.s} ; Indef cn = {s = "un" ++ cn.s} ;
ModA a cn = {s = cn.s ++ a.s} ; ModA a cn = {s = cn.s ++ a.s} ;
Bird = {s = "uccello"} ;
Boy = {s = "ragazzo"} ; Boy = {s = "ragazzo"} ;
Louse = {s = "pidocchio"} ; Louse = {s = "pidocchio"} ;
Man = {s = "uomo"} ;
Snake = {s = "serpente"} ; Snake = {s = "serpente"} ;
Worm = {s = "verme"} ; Worm = {s = "verme"} ;
Big = {s = "grande"} ;
Green = {s = "verde"} ; Green = {s = "verde"} ;
Rotten = {s = "marcio"} ; Rotten = {s = "marcio"} ;
Thick = {s = "grosso"} ; Thick = {s = "grosso"} ;

View File

@@ -108,10 +108,10 @@ representation, and shows a new prompt when it is ready.
You can use GF for <b>parsing</b>: You can use GF for <b>parsing</b>:
<pre> <pre>
> parse "the boy eats a snake" > parse "the boy eats a snake"
Mks_0 (Mks_6 Mks_10) (Mks_2 Mks_23 (Mks_7 Mks_13)) Mks_0 (Mks_6 Mks_9) (Mks_2 Mks_20 (Mks_7 Mks_11))
> parse "the snake eats a boy" > parse "the snake eats a boy"
Mks_0 (Mks_6 Mks_13) (Mks_2 Mks_23 (Mks_7 Mks_10)) Mks_0 (Mks_6 Mks_11) (Mks_2 Mks_20 (Mks_7 Mks_9))
</pre> </pre>
The <tt>parse</tt> (= <tt>p</tt>) command takes a <b>string</b> The <tt>parse</tt> (= <tt>p</tt>) command takes a <b>string</b>
(in double quotes) and returns an <b>abstract syntax tree</b> - the thing (in double quotes) and returns an <b>abstract syntax tree</b> - the thing
@@ -137,7 +137,7 @@ You can also use GF for <b>linearizing</b>
(<tt>linearize = l</tt>). This is the inverse of (<tt>linearize = l</tt>). This is the inverse of
parsing, taking trees into strings: parsing, taking trees into strings:
<pre> <pre>
> linearize Mks_0 (Mks_6 Mks_13) (Mks_2 Mks_23 (Mks_7 Mks_10)) > linearize Mks_0 (Mks_6 Mks_11) (Mks_2 Mks_20 (Mks_7 Mks_9))
the snake eats a boy the snake eats a boy
</pre> </pre>
What is the use of this? Typically not that you type in a tree at What is the use of this? Typically not that you type in a tree at
@@ -153,7 +153,7 @@ Or, more efficiently, feed random generation into parsing by using
a <b>pipe</b>. a <b>pipe</b>.
<pre> <pre>
> gr | l > gr | l
this man is big this worm is warm
</pre> </pre>
@@ -164,16 +164,16 @@ Random generation can be quite amusing. So you may want to
generate ten strings with one and the same command: generate ten strings with one and the same command:
<pre> <pre>
> gr -number=10 | l > gr -number=10 | l
this boy is green
a snake laughs a snake laughs
that man laughs the rotten boy is thick
the man swims a boy washes this worm
this man is warm a boy is warm
a louse is rotten this green warm boy is rotten
that worm washes a man the green thick green louse is rotten
a boy swims that boy is green
a snake laughs this thick thick boy laughs
a man washes this man a boy is green
this louse kills the boy
</pre> </pre>
@@ -183,13 +183,15 @@ generate ten strings with one and the same command:
To generate <i>all</i> sentence that a grammar To generate <i>all</i> sentence that a grammar
can generate, use the command <tt>generate_trees = gt</tt>. can generate, use the command <tt>generate_trees = gt</tt>.
<pre> <pre>
this boy laughs this louse laughs
this boy sleeps this louse sleeps
this boy swims this louse swims
this louse is green
this louse is rotten
... ...
a worm is rotten a boy is rotten
a worm is thick a boy is thick
a worm is warm a boy is warm
</pre> </pre>
You get quite a few trees but not all of them: only up to a given You get quite a few trees but not all of them: only up to a given
<b>depth</b> of trees. To see how you can get more, use the <b>depth</b> of trees. To see how you can get more, use the
@@ -215,9 +217,9 @@ The intermediate results in a pipe can be observed by putting the
want to see: want to see:
<pre> <pre>
> gr -tr | l -tr | p > gr -tr | l -tr | p
Mks_0 (Mks_6 Mks_13) (Mks_1 Mks_20) Mks_0 (Mks_7 Mks_10) (Mks_1 Mks_18)
the snake laughs a louse sleeps
Mks_0 (Mks_6 Mks_13) (Mks_1 Mks_20) Mks_0 (Mks_7 Mks_10) (Mks_1 Mks_18)
</pre> </pre>
This facility is good for test purposes: for instance, you This facility is good for test purposes: for instance, you
may want to see if a grammar is <b>ambiguous</b>, i.e. may want to see if a grammar is <b>ambiguous</b>, i.e.
@@ -256,27 +258,27 @@ which rule, you can use the <tt>print_grammar = pg</tt> command
with the <tt>printer</tt> flag set to <tt>cf</tt> (which means context-free): with the <tt>printer</tt> flag set to <tt>cf</tt> (which means context-free):
<pre> <pre>
> print_grammar -printer=cf > print_grammar -printer=cf
Mks_10. CN ::= "boy" ; Mks_10. CN ::= "louse" ;
Mks_11. CN ::= "man" ; Mks_11. CN ::= "snake" ;
Mks_12. CN ::= "louse" ; Mks_12. CN ::= "worm" ;
Mks_13. CN ::= "snake" ;
Mks_14. CN ::= "worm" ;
Mks_8. CN ::= A CN ; Mks_8. CN ::= A CN ;
Mks_9. CN ::= "bird" ; Mks_9. CN ::= "boy" ;
Mks_4. NP ::= "this" CN ; Mks_4. NP ::= "this" CN ;
Mks_18. A ::= "thick" ; Mks_15. A ::= "thick" ;
...
</pre> </pre>
A syntax tree such as A syntax tree such as
<pre> <pre>
Mks_4 (Mks_8 Mks_18 Mks_14) Mks_4 (Mks_8 Mks_15 Mks_12)
this thick worm this thick worm
</pre> </pre>
encodes the sequence of grammar rules used for building the encodes the sequence of grammar rules used for building the
expression. If you look at this tree, you will notice that <tt>Mks_4</tt> expression. If you look at this tree, you will notice that <tt>Mks_4</tt>
is the label of the rule prefixing <tt>this</tt> to a common noun, is the label of the rule prefixing <tt>this</tt> to a common noun,
<tt>Mks_18</tt> is the label of the adjective <tt>thick</tt>, <tt>Mks_15</tt> is the label of the adjective <tt>thick</tt>,
and so on. and so on.
<!-- NEW --> <!-- NEW -->
<h4>The labelled context-free format</h4> <h4>The labelled context-free format</h4>
@@ -574,7 +576,7 @@ Inspect the shell state (<tt>print_options = po</tt>):
<!-- NEW --> <!-- NEW -->
<h4>Extending the grammar</h4> <h4>Extending the grammar</h4>
Neolithic Neolithic: fire, wheel, think,...

View File

@@ -7,13 +7,10 @@ That. NP ::= "that" CN ;
Def. NP ::= "the" CN ; Def. NP ::= "the" CN ;
Indef. NP ::= "a" CN ; Indef. NP ::= "a" CN ;
ModA. CN ::= A CN ; ModA. CN ::= A CN ;
Bird. CN ::= "bird" ;
Boy. CN ::= "boy" ; Boy. CN ::= "boy" ;
Man. CN ::= "man" ;
Louse. CN ::= "louse" ; Louse. CN ::= "louse" ;
Snake. CN ::= "snake" ; Snake. CN ::= "snake" ;
Worm. CN ::= "worm" ; Worm. CN ::= "worm" ;
Big. A ::= "big" ;
Green. A ::= "green" ; Green. A ::= "green" ;
Rotten. A ::= "rotten" ; Rotten. A ::= "rotten" ;
Thick. A ::= "thick" ; Thick. A ::= "thick" ;

View File

@@ -2,7 +2,7 @@ S ::= NP VP ;
VP ::= V | TV NP | "is" A ; VP ::= V | TV NP | "is" A ;
NP ::= ("this" | "that" | "the" | "a") CN ; NP ::= ("this" | "that" | "the" | "a") CN ;
CN ::= A CN ; CN ::= A CN ;
CN ::= "bird" | "boy" | "man" | "louse" | "snake" | "worm" ; CN ::= "boy" | "louse" | "snake" | "worm" ;
A ::= "big" | "green" | "rotten" | "thick" | "warm" ; A ::= "green" | "rotten" | "thick" | "warm" ;
V ::= "laughs" | "sleeps" | "swims" ; V ::= "laughs" | "sleeps" | "swims" ;
TV ::= "eats" | "kills" | "washes" ; TV ::= "eats" | "kills" | "washes" ;