From f496c49263c0eecd9e7288d8aeea48fac489bb5d Mon Sep 17 00:00:00 2001 From: aarne Date: Thu, 12 May 2005 16:12:03 +0000 Subject: [PATCH] index and tutorial --- doc/gf-index.html | 17 +++- doc/tutorial/Fish.gf | 4 + doc/tutorial/FishEng.gf | 5 + doc/tutorial/Gatherer.gf | 5 + doc/tutorial/Gatherer.gif | Bin 0 -> 12415 bytes doc/tutorial/GathererEng.gf | 5 + doc/tutorial/Mushrooms.gf | 4 + doc/tutorial/MushroomsEng.gf | 5 + doc/tutorial/Neolithic.gf | 5 + doc/tutorial/NeolithicEng.gf | 6 ++ doc/tutorial/gf-tutorial2.html | 168 +++++++++++++++++++++++++++++---- 11 files changed, 201 insertions(+), 23 deletions(-) create mode 100644 doc/tutorial/Fish.gf create mode 100644 doc/tutorial/FishEng.gf create mode 100644 doc/tutorial/Gatherer.gf create mode 100644 doc/tutorial/Gatherer.gif create mode 100644 doc/tutorial/GathererEng.gf create mode 100644 doc/tutorial/Mushrooms.gf create mode 100644 doc/tutorial/MushroomsEng.gf create mode 100644 doc/tutorial/Neolithic.gf create mode 100644 doc/tutorial/NeolithicEng.gf diff --git a/doc/gf-index.html b/doc/gf-index.html index 340f64f44..01397554b 100644 --- a/doc/gf-index.html +++ b/doc/gf-index.html @@ -12,20 +12,27 @@

Version 2.1

November 8, 2004. + +

+ +Version 2.2 scheduled to be released May 16, 2005! See +highlights. +

News

- May 9, 2005. PhD Thesis by diff --git a/doc/tutorial/Fish.gf b/doc/tutorial/Fish.gf new file mode 100644 index 000000000..c404115e9 --- /dev/null +++ b/doc/tutorial/Fish.gf @@ -0,0 +1,4 @@ +abstract Fish = { + cat Fish ; + fun Salmon, Perch : Fish ; +} diff --git a/doc/tutorial/FishEng.gf b/doc/tutorial/FishEng.gf new file mode 100644 index 000000000..560f6cda4 --- /dev/null +++ b/doc/tutorial/FishEng.gf @@ -0,0 +1,5 @@ +concrete FishEng of Fish = { + lin + Salmon = {s = "salmon"} ; + Perch = {s = "perch"} ; +} diff --git a/doc/tutorial/Gatherer.gf b/doc/tutorial/Gatherer.gf new file mode 100644 index 000000000..254a46ec0 --- /dev/null +++ b/doc/tutorial/Gatherer.gf @@ -0,0 +1,5 @@ +abstract Gatherer = Paleolithic, Fish, Mushrooms ** { + fun + UseFish : Fish -> CN ; + UseMushroom : Mushroom -> CN ; +} \ No newline at end of file diff --git a/doc/tutorial/Gatherer.gif b/doc/tutorial/Gatherer.gif new file mode 100644 index 0000000000000000000000000000000000000000..758b8ea8b3443763579e1a02a9776e18e114c82b GIT binary patch literal 12415 zcmZ?wbhEHb%wQ5`oXEiN|Nnmm5c!XRfkE*n3nK#q6N3%|0|Ns{o`LCqOaIE#Z}}I` z*>bCU^SwR4`P&|OOncV3?A57l@3@bD^11%4_xZ1L-~aLRaJ3&<^s&Q7Yx7liBl$r zRTo~HUH<=IKud>!-7>xH_B};G4o*L2?7H*M;FRa;y%w*}?*5;k(U+2$MBJP_^43)42iJDsrhI?dAUOEDI(xoi@b5)<;*-LaON6wNEJaqiZ({Js8 zeo=3aM&{r9%kEsL;w`L<)z$MdR;|lp z*PQ7I2wggbNu^Gp#wQllUB@SKJWM{~Dp0efgNN&3@~cllSp2Bs)bc@}N${eF(+xou z`QYi(g+RfR2U3q3EgXW1f4Uu5x_ArN9Xu42ILcg(u(Eb?Fes=9G6;yMC^0lS{SaUj z6k%vcat67Dy9qt@E^$bluGhQWft zi-CZp{!} zf4Zx~AG=qTBWJ14TBUt^m%hwtE^63Cbn!+og#Lp{e3v7~6@IvXocKWbD4gNm)Gs2>X%|$ZaswmL z1YGF=m4=d_9Fu3IbVtTSM_b zhFOvjvzCC&(gvH=57vib)<*@9tDb&q{|JuP@*p4d%)ueV38{5Iy!n}7{@>jrffQq9u_cED|U zx0MjaM2JdAo&O(F>9Y$$E#EW|EgUXJHpt#>z>j`xmyb506262lY zSi%<+`+513z{c746v2{xh9JZf(hx6!BBN;cWU!G)mAzvp#I66q!Mj}=q6br1J4Bg0 z#MSZ;W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`~+oW`w`L^_J;e2 zRRz3&;9Gky%*IomqMhKS1%LUWbmElBAWxkJO}c{nx$3bnU9hH~!6{Ewi0W8R8F>2_ z+?$>42)C?P1+?V#={I&L4eI<0gPP5yJEua1Z|fzV_J9KAD$?LeC%CI~Cr`x;Je3U6 zqzPW7Q?3bWg+m4iIzWmbYa2jI*)MTH`f@!Yu+=$5m$KwL`!g5Jf;F5oRX-X+SD|RA zuPvMSV+Q9cDHce_ujo?Ndhl=us1>v1su47jL5p3rd Edition, for GF version 2.2 or later -

+

Aarne Ranta -

aarne@cs.chalmers.se -

+ +

+ +12 May 2005 + @@ -29,12 +32,13 @@ The term GF is used for different things:

  • a program used for working with grammars
  • a programming language in which grammars can be written -
  • a theory about the concepts of grammars and languages +
  • a theory about grammars and languages

-This tutorial is about the GF program and the GF programming language. +This tutorial is primarily about the GF program and +the GF programming language. It will guide you

  • to use the GF program @@ -43,8 +47,9 @@ It will guide you
+ -

The GF program

+

Getting the GF program

The program is open-source free software, which you can download from the GF Homepage:
@@ -60,8 +65,8 @@ There you can download
  • grammar libraries and examples If you want to compile GF from source, you need Haskell and Java -compilers. But normally you don't have to compile, and you don't -need to know Haskell or Java to use GF. +compilers. But normally you don't have to compile, and you definitely +don't need to know Haskell or Java to use GF.

    @@ -127,7 +132,7 @@ you imported. Try parsing something else, and you fail > p "hello world" No success in cf parsing no tree found -

    +
    @@ -183,6 +188,7 @@ generate ten strings with one and the same command: To generate all sentence that a grammar can generate, use the command generate_trees = gt.
    +  > generate_trees | l
       this louse laughs
       this louse sleeps
       this louse swims
    @@ -197,12 +203,13 @@ You get quite a few trees but not all of them: only up to a given
     depth of trees. To see how you can get more, use the
     help = h command,
     
    -  h gr
    +  help gr
     
    Quiz. If the command gt generated all trees in your grammar, it would never terminate. Why? +

    More on pipes; tracing

    @@ -509,10 +516,38 @@ Each module is compiled into a .gfc file. Import PaleolithicEng.gf and try what happens
    -
    +  > i PaleolithicEng.gf
     
    -Nothing more than before, except that the GFC files -are generated. +The GF program does not only read the file +PaleolithicEng.gf, but also all other files that it +depends on - in this case, Paleolithic.gf. + +

    + +For each file that is compiles, a .gfc file +is generated. The GFC format (="GF Canonical") is the +"machine code" of GF, which is faster to process than +GF source files. When reading a module, GF knows whether +to use an existing .gfc file or to generate +a new one, by looking at modification times. + + + + +

    Multilingual grammar

    + +The main advantage of separating abstract from concrete syntax is that +one abstract syntax can be equipped with many concrete syntaxes. +A system with this property is called a multilingual grammar. + +

    + +Multilingual grammars can be used for applications such as +translation. Let us buid an Italian concrete syntax for +Paleolithic and then test the resulting +multilingual grammar. + + @@ -554,17 +589,39 @@ lin Import without first emptying

    -
    +  > i PaleolithicEng.gf
    +  > i PaleolithicIta.gf
     
    Try generation now:
    +  > gr | l
    +  un pidocchio uccide questo ragazzo
     
    +  > gr | l -lang=PaleolithicEng
    +  that louse eats a louse
     
    Translate by using a pipe:
    -
    +  > p -lang=PaleolithicEng "the boy eats the snake" | l -lang=PaleolithicIta
    +  il ragazzo mangia il serpente
     
    -Inspect the shell state (print_options = po): + + + +

    The multilingual shell state

    + +A GF shell is at any time in a state, which +contains a multilingual grammar. One of the concrete +syntaxes is the "main" one, which means that parsing and linearization +are performed by using it. By default, the main concrete syntax is the +last-imported one. As we saw on previous slide, the lang flag +can be used to change the linearization and parsing grammar. + +

    + +To see what the multilingual grammar is (as well as some other +things), you can use the command +print_options = po:

       > print_options
       main abstract :     Paleolithic
    @@ -574,11 +631,86 @@ Inspect the shell state (print_options = po):
     
     
     
    -

    Extending the grammar

    +

    Extending a grammar

    -Neolithic: fire, wheel, think,... +The module system of GF makes it possible to extend a +grammar in different ways. The syntax of extension is +shown by the following example. +
    +  abstract Neolithic = Paleolithic ** {
    +    fun
    +      Fire, Wheel : CN ;
    +      Think : V ;
    +  }
    +
    +Parallel to the abstract syntax, extensions can +be built for concrete syntaxes: +
    +  concrete NeolithicEng of Neolithic = PaleolithicEng ** {
    +    lin
    +      Fire  = {s = "fire"} ;
    +      Wheel = {s = "wheel"} ;
    +      Think = {s = "thinks"} ;
    +  }
    +
    +The effect of extension is that all of the contents of the extended +and extending module are put together. + +

    Multiple inheritance

    + +Specialized vocabularies can be represented as small grammars that +only do "one thing" each, e.g. +
    +  abstract Fish = {
    +    cat Fish ;
    +    fun Salmon, Perch : Fish ;
    +  }
    +
    +  abstract Mushrooms = {
    +    cat Mushroom ;
    +    fun Cep, Agaric : Mushroom ;
    +  }
    +
    +They can afterwards be combined in bigger grammars by using +multiple inheritance, i.e. extension of several grammars at the +same time: +
    +  abstract Gatherer = Paleolithic, Fish, Mushrooms ** {
    +    fun 
    +      UseFish     : Fish     -> CN ;
    +      UseMushroom : Mushroom -> CN ;
    +    }
    +
    + + + + +

    Visualizing module structure

    + +When you have created all the abstract syntaxes and +one set of concrete syntaxes needed for Gatherer, +your grammar consists of eight GF modules. To see how their +dependences look like, you can use the command +visualize_graph = vg, +
    +  > visualize_graph
    +
    +and the graph will pop up in a separate window. It can also +be printed out into a file, e.g. a .gif file that +can be included in an HTML document +
    +  > pm -printer=graph | wf Gatherer.dot
    +  > ! dot -Tgif Gatherer.dot > Gatherer.gif
    +
    +The latter command is a Unix command, issued from GF by using the +shell escape symbol !. The resulting graph is shown below. + +

    + + + \ No newline at end of file