summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/tutorial/gf-tutorial2.txt28
-rw-r--r--examples/unix/Char.gf51
-rw-r--r--examples/unix/CharEng.gf52
-rw-r--r--examples/unix/CharUni.gf67
-rw-r--r--examples/unix/Unix.gf45
-rw-r--r--examples/unix/UnixEng.gf19
-rw-r--r--examples/unix/UnixUni.gf19
7 files changed, 255 insertions, 26 deletions
diff --git a/doc/tutorial/gf-tutorial2.txt b/doc/tutorial/gf-tutorial2.txt
index 43602d23b..a1226d7cd 100644
--- a/doc/tutorial/gf-tutorial2.txt
+++ b/doc/tutorial/gf-tutorial2.txt
@@ -1857,7 +1857,7 @@ they can be used as arguments. For example:
-- e.g. (StreetAddress 10 "Downing Street") : Address
```
-
+The linearization type is ``{s : Str}`` for all these categories.
==More concepts of abstract syntax==
@@ -1922,16 +1922,30 @@ documents:
However, to give a flavour of both using and writing resource grammars,
we have created a miniature resource, which resides in the
subdirectory [``resource`` resource]. Its API consists of the following
-modules:
-- [Syntax resource/Syntax.gf]: syntactic structures, language-independent
-- [LexEng resource/LexEng.gf]: lexical paradigms, English
-- [LexIta resource/LexIta.gf]: lexical paradigms, Italian
+three modules:
+
+[Syntax resource/Syntax.gf] - syntactic structures, language-independent:
+```
+
+```
+[LexEng resource/LexEng.gf] - lexical paradigms, English:
+```
+
+```
+[LexIta resource/LexIta.gf] - lexical paradigms, Italian:
+```
+
+```
Only these three modules should be ``open``ed in applications.
The implementations of the resource are given in the following four modules:
-- [MorphoEng resource/MorphoEng.gf],
- [MorphoIta resource/MorphoIta.gf]: low-level morphology
+
+[MorphoEng resource/MorphoEng.gf],
+```
+
+```
+[MorphoIta resource/MorphoIta.gf]: low-level morphology
- [SyntaxEng resource/SyntaxEng.gf].
[SyntaxIta resource/SyntaxIta.gf]: definitions of syntactic structures
diff --git a/examples/unix/Char.gf b/examples/unix/Char.gf
new file mode 100644
index 000000000..f10284587
--- /dev/null
+++ b/examples/unix/Char.gf
@@ -0,0 +1,51 @@
+abstract Char = {
+
+ cat
+ [Chr] {1} ; Chr ; Letter ;
+
+ fun
+ C_dot : Chr ;
+ C_pipe : Chr ;
+ C_hyphen : Chr ;
+ CSmall : Letter -> Chr ;
+ CCap : Letter -> Chr ;
+ CC : Letter -> Chr ;
+
+ CDig_0 : Chr ;
+ CDig_1 : Chr ;
+ CDig_2 : Chr ;
+ CDig_3 : Chr ;
+ CDig_4 : Chr ;
+ CDig_5 : Chr ;
+ CDig_6 : Chr ;
+ CDig_7 : Chr ;
+ CDig_8 : Chr ;
+ CDig_9 : Chr ;
+
+ L_a : Letter ;
+ L_b : Letter ;
+ L_c : Letter ;
+ L_d : Letter ;
+ L_e : Letter ;
+ L_f : Letter ;
+ L_g : Letter ;
+ L_h : Letter ;
+ L_i : Letter ;
+ L_j : Letter ;
+ L_k : Letter ;
+ L_l : Letter ;
+ L_m : Letter ;
+ L_n : Letter ;
+ L_o : Letter ;
+ L_p : Letter ;
+ L_q : Letter ;
+ L_r : Letter ;
+ L_s : Letter ;
+ L_t : Letter ;
+ L_u : Letter ;
+ L_v : Letter ;
+ L_w : Letter ;
+ L_x : Letter ;
+ L_y : Letter ;
+ L_z : Letter ;
+}
diff --git a/examples/unix/CharEng.gf b/examples/unix/CharEng.gf
new file mode 100644
index 000000000..39d9b9d16
--- /dev/null
+++ b/examples/unix/CharEng.gf
@@ -0,0 +1,52 @@
+concrete CharEng of Char = open Prelude in {
+
+lin
+ BaseChr c = c ;
+ ConsChr = infixSS "," ;
+
+ C_dot = ss "dot" ;
+ C_pipe = ss "pipe" ;
+ C_hyphen = ss (variants {"dash" ; "hyphen" ; "minus"}) ;
+ CSmall = prefixSS "small" ;
+ CCap = prefixSS "capital" ;
+ CC c = c ;
+
+ CDig_0 = ss "0" ;
+ CDig_1 = ss "1" ;
+ CDig_2 = ss "2" ;
+ CDig_3 = ss "3" ;
+ CDig_4 = ss "4" ;
+ CDig_5 = ss "5" ;
+ CDig_6 = ss "6" ;
+ CDig_7 = ss "7" ;
+ CDig_8 = ss "8" ;
+ CDig_9 = ss "9" ;
+
+ L_a = ss "A" ;
+ L_b = ss "B" ;
+ L_c = ss "C" ;
+ L_d = ss "D" ;
+ L_e = ss "E" ;
+ L_f = ss "F" ;
+ L_g = ss "G" ;
+ L_h = ss "H" ;
+ L_i = ss "I" ;
+ L_j = ss "J" ;
+ L_k = ss "K" ;
+ L_l = ss "L" ;
+ L_m = ss "M" ;
+ L_n = ss "N" ;
+ L_o = ss "O" ;
+ L_p = ss "P" ;
+ L_q = ss "Q" ;
+ L_r = ss "R" ;
+ L_s = ss "S" ;
+ L_t = ss "T" ;
+ L_u = ss "U" ;
+ L_v = ss "V" ;
+ L_w = ss "W" ;
+ L_x = ss "X" ;
+ L_y = ss "Y" ;
+ L_z = ss "Z" ;
+
+} \ No newline at end of file
diff --git a/examples/unix/CharUni.gf b/examples/unix/CharUni.gf
new file mode 100644
index 000000000..0e6628657
--- /dev/null
+++ b/examples/unix/CharUni.gf
@@ -0,0 +1,67 @@
+concrete CharUni of Char = open Prelude in {
+
+param
+ LForm = LCap | LSma ;
+
+oper
+ chr : Str -> Str -> {s : LForm => Str} = \c,C -> {
+ s = table {
+ LCap => C ;
+ LSma => c
+ }
+ } ;
+
+lincat
+ Letter = {s : LForm => Str} ;
+
+lin
+ BaseChr c = c ;
+ ConsChr = infixSS "&+" ;
+
+ C_dot = ss "." ;
+ C_pipe = ss "|" ;
+ C_hyphen = ss "-" ;
+ CSmall c = ss (c.s ! LSma) ;
+ CCap c = ss (c.s ! LCap) ;
+ CC c = ss (c.s ! LSma) ;
+
+ CDig_0 = ss "0" ;
+ CDig_1 = ss "1" ;
+ CDig_2 = ss "2" ;
+ CDig_3 = ss "3" ;
+ CDig_4 = ss "4" ;
+ CDig_5 = ss "5" ;
+ CDig_6 = ss "6" ;
+ CDig_7 = ss "7" ;
+ CDig_8 = ss "8" ;
+ CDig_9 = ss "9" ;
+
+
+ L_a = chr "a" "A" ;
+ L_b = chr "b" "B" ;
+ L_c = chr "c" "C" ;
+ L_d = chr "d" "D" ;
+ L_e = chr "e" "E" ;
+ L_f = chr "f" "F" ;
+ L_g = chr "g" "G" ;
+ L_h = chr "h" "H" ;
+ L_i = chr "i" "I" ;
+ L_j = chr "j" "J" ;
+ L_k = chr "k" "K" ;
+ L_l = chr "l" "L" ;
+ L_m = chr "m" "M" ;
+ L_n = chr "n" "N" ;
+ L_o = chr "o" "O" ;
+ L_p = chr "p" "P" ;
+ L_q = chr "q" "Q" ;
+ L_r = chr "r" "R" ;
+ L_s = chr "s" "S" ;
+ L_t = chr "t" "T" ;
+ L_u = chr "u" "U" ;
+ L_v = chr "v" "V" ;
+ L_w = chr "w" "W" ;
+ L_x = chr "x" "X" ;
+ L_y = chr "y" "Y" ;
+ L_z = chr "z" "Z" ;
+
+}
diff --git a/examples/unix/Unix.gf b/examples/unix/Unix.gf
index c1ddd742b..ea5e2c2af 100644
--- a/examples/unix/Unix.gf
+++ b/examples/unix/Unix.gf
@@ -1,24 +1,43 @@
-abstract Unix = {
+abstract Unix = Char ** {
cat
- S ;
- Line ;
- Command ;
- File ;
+ S ; -- whole command line
+ Command ; -- one command
+ File ; -- file name
+ Word ; -- string e.g. in grep
+ [Word] {1} ; --
fun
- Pipe : Command -> S -> S ;
- Comm : Command -> S ;
+
+-- Catch-all: command dictated letter by letter.
+
+ CommWords : [Word] -> Command ;
+
+-- General command-line structure.
+
+ Redirect : S -> File -> S ; -- cs >f
+ Pipe : S -> Command -> S ; -- cs | c
+ Comm : Command -> S ; -- c
+
+--- This would be cool, but is it supported by speech recognition?
+--- CommOpt : (c : Command) -> [Option c] -> S ; -- c -o -k
WhatTime : Command ;
WhatDate : Command ;
WhereNow : Command ;
- Remove : File -> Command ;
- Copy : File -> File -> Command ;
- Linecount : File -> Command ;
- Wordcount : File -> Command ;
+ Remove : File -> Command ;
+ Copy : File -> File -> Command ;
+ Linecount : File -> Command ;
+ Wordcount : File -> Command ;
+ Grep : Word -> File -> Command ;
+ Cat : File -> Command ;
+
+ It : File ; -- no file name - contents received from pipe
+
+ FileChars : [Chr] -> File ;
+ WordChars : [Chr] -> Word ;
- Name : String -> File ;
- It : File ;
+ FileSuffix : Word -> File ; -- *suff
+ FilePrefix : Word -> File ; -- pref*
}
diff --git a/examples/unix/UnixEng.gf b/examples/unix/UnixEng.gf
index 3bed08bc5..5b0ca944f 100644
--- a/examples/unix/UnixEng.gf
+++ b/examples/unix/UnixEng.gf
@@ -1,8 +1,8 @@
--# -path=.:prelude
-concrete UnixEng of Unix = open Prelude in {
+concrete UnixEng of Unix = CharEng ** open Prelude in {
- flags unlexer=textlit ; lexer=textlit ;
+ flags lexer=text ;
{-
lincat
@@ -13,6 +13,9 @@ concrete UnixEng of Unix = open Prelude in {
-}
lin
+ CommWords w = w ;
+
+ Redirect = infixSS (optStr "and" ++ ["write the result to"]) ;
Pipe = infixSS "then" ;
Comm c = c ;
@@ -23,8 +26,18 @@ concrete UnixEng of Unix = open Prelude in {
Copy x y = ss ("copy" ++ x.s ++ "to" ++ y.s) ;
Linecount = prefixSS ["how many lines has"] ;
Wordcount = prefixSS ["how many words has"] ;
+ Grep x y = ss (["show the lines containing"] ++ x.s ++ "in" ++ y.s) ;
+ Cat = prefixSS ["show the contents of"] ;
- Name x = x ;
It = ss "it" ;
+ FileChars = prefixSS (optStr ["the file"]) ;
+ WordChars = prefixSS (optStr ["the word"]) ;
+
+ FileSuffix = prefixSS ["all files ending with"] ;
+ FilePrefix = prefixSS ["all files beginning with"] ;
+
+ BaseWord w = w ;
+ ConsWord = infixSS "space" ;
+
}
diff --git a/examples/unix/UnixUni.gf b/examples/unix/UnixUni.gf
index e0898853f..b1b220824 100644
--- a/examples/unix/UnixUni.gf
+++ b/examples/unix/UnixUni.gf
@@ -1,8 +1,8 @@
--# -path=.:prelude
-concrete UnixUni of Unix = open Prelude in {
+concrete UnixUni of Unix = CharUni ** open Prelude in {
- flags unlexer=codelit ; lexer=codelit ;
+ flags unlexer=bind ;
{-
lincat
@@ -13,6 +13,9 @@ concrete UnixUni of Unix = open Prelude in {
-}
lin
+ CommWords w = w ;
+
+ Redirect = infixSS ">" ;
Pipe = infixSS "|" ;
Comm c = c ;
@@ -23,8 +26,18 @@ concrete UnixUni of Unix = open Prelude in {
Copy x y = ss ("cp" ++ x.s ++ y.s) ;
Linecount = prefixSS ["wc -l"] ;
Wordcount = prefixSS ["wc -w"] ;
+ Grep x y = ss ("grep" ++ x.s ++ y.s) ;
+ Cat = prefixSS "cat" ;
- Name x = x ;
It = ss [] ;
+ FileChars c = c ;
+ WordChars c = c ;
+
+ FileSuffix = prefixSS ["* &+"] ;
+ FilePrefix = postfixSS ["&+ *"] ;
+
+ BaseWord w = w ;
+ ConsWord = cc2 ;
+
}