From f1000ca8c3c07f851f1f278fc75fdf7caec9848e Mon Sep 17 00:00:00 2001
From: aarne
-This is a quick reference on GF grammars.
+This is a quick reference on GF grammars. It aims to
+cover all forms of expression available when writing
+grammars. It assumes basic knowledge of GF, which
+can be acquired from the
+GF Tutorial.
Help on GF commands is obtained on line by the
-help command (
-This is a complete example, dividing a grammar
-into three files.
+This is a complete example of a GF grammar divided
+into three modules in files. The grammar recognizes the
+phrases one pizza and two pizzas.
-
-File
One module per file.
File named
A
Abstract syntax (in GF Quick Reference
Aarne Ranta
-Wed Mar 29 13:21:48 2006
+Tue Apr 4 09:41:30 2006
-
-
+
+
h).
+help command (help), and help on invoking
+GF with (gf -help).
A Quick Example
+A complete example
abstract, concrete, and resource.
-Order.gf
+File Order.gf:
abstract Order = {
@@ -83,7 +86,7 @@ File
-Res.gf:
oper regNoun : Str -> {s : Num => Str} =
\dog -> {s = table {
Sg => dog ;
- Pl => dog + "s"
+ _ => dog + "s"
}
} ;
}
@@ -99,7 +102,7 @@ To use this example, do
Modules and files
+Modules and files
Foo.gf contains module named
@@ -163,7 +166,7 @@ Comments have the forms
-- till the end of line
{- any number of lines between -}
- --# reserved for compiler pragmas
+ --# used for compiler pragmas
concrete can be opened like a resource.
@@ -181,7 +184,7 @@ An abstract can be opened like an interface.
Any concrete of it then works as an instance.
Judgements
+Judgements
cat C -- declare category C
cat C (x:A)(y:B x) -- dependent category C
@@ -225,7 +228,7 @@ Judgements can also share RHS:
-Types
+Types
fun):
lincat):
Resource (in oper): all those of concrete, plus
- Tok -- tokens (subset of Str)
+ Tok -- tokens (subtype of Str)
A -> B -- functions from A to B
Int -- integers
Strs -- list of prefixes (for pre)
@@ -268,11 +271,11 @@ Resource (in oper): all those of concrete, plus
As parameter types, one can use any finite type:
-param constants P,
+P defined in param P,
Ints n, and record types of parameter types.
Syntax trees = full function applications
@@ -286,7 +289,7 @@ Syntax trees = full function applications Higher-Order Abstract syntax (HOAS): functions as arguments:
- F a (\y -> b) -- : C if a : A, b : B (x : A),
+ F a (\x -> c) -- : C if a : A, c : C (x : B),
fun F : A -> (B -> C) -> C
@@ -320,7 +323,7 @@ Tables _ => "mouse" -- wildcard pattern } table { - n => regn n "cat" ;-- variable pattern + n => regn n "cat" -- variable pattern } table Num {...} -- table given with arg. type table ["ox"; "oxen"] -- table as course of values @@ -336,7 +339,6 @@ Records
{s = "Liz"; g = Fem} -- record in full form
{s,t = "et"} -- same as {s = "et";t= "et"}
-
{s = "Liz"} ** -- record extension: same as
{g = Fem} {s = "Liz" ; g = Fem}
@@ -392,14 +394,15 @@ Example:
-
These patterns can be used in branches of table and
-case expressions.
+case expressions. Patterns are matched in the order in
+which they appear in the grammar.
C -- atomic param constructor
- C p q -- param constr. appl- to patterns
+ C p q -- param constr. applied to patterns
x -- variable, matches anything
_ -- wildcard, matches anything
"foo" -- string
@@ -414,7 +417,7 @@ These patterns can be used in branches of table and
-
-- lib/prelude/Predef.gf
drop : Int -> Tok -> Tok -- drop prefix of length
@@ -446,7 +449,7 @@ These patterns can be used in branches of table and
-Flags can appear, with growing priority,
@@ -480,13 +483,13 @@ Some common flags used in grammars: optimize=noexpand for resource, if =all too big
-For the full set of values for flag,
-use on-line h -flag.
+For the full set of values for FLAG,
+use on-line h -FLAG.
-Colon-separated lists of directories tried in the +Colon-separated lists of directories searched in the given order:
@@ -499,12 +502,12 @@ when invoked, or as flag to theicommand. The prefix--#is used only in files.-If the variabls
-GF_LIB_PATHis defined, its +If the environment variablsGF_LIB_PATHis defined, its value is automatically prefixed to each directory to extend the original search path.Alternative grammar formats
+Alternative grammar formats
Old GF (before GF 2.0): all judgements in any kinds of modules, @@ -530,7 +533,7 @@ Rules must be one per line. The RHS can be empty.
where the RHS is a regular expression of categories
-and quoted tokens: "foo", T U, T|U, T*, T+, T?, or empty.
+and quoted tokens: "foo", CAT, T U, T|U, T*, T+, T?, or empty.
Rule labels are generated automatically.
@@ -560,7 +563,7 @@ are preprocessed by using a parser given by the flag
and the result is written to foo.gf.
H9>Jc23x(Yie4$Y#DcUcFkSq>(y$jMRGNgPg<`(V|?mQ{)eSv>Wpb~{(RLnRx`hS
zP`G@`qogT^oWJY85&eJRLA~9VuyZZ1b8`#+K6H){li)a=_UTC3@=dlc=WOd*mFshT
z?`)?>ow@8kAG7{j~U>d&T$Q-Jkas9WoA|a?0r2v+At}IG>$a8EigrLxr0M
z+jPNzRT@8~zxS3}KU`pa@cO(f6GGMECNBO~KdmYBhU9ML=ll2n-T!DA$Ij$HjlbU(
zO{!}y%>VH+=U$Lb^`+0#kNnbU{N=_M`o~zQkj?h5+lRx>?#9x$PDox|lAbE}C;W({
zbUKsSpN6zatu6Vj)%)e%-7D^SGtZ})#inU*Q!SHc$WaF&kEudaoj5JKl=to2c%Z{s
zrOvyqb#Z;hrNk@m)z(KV);KdIySgZ)ulN_;a8CI7qJ{Yv&j%ixmb!9f>PrXb-AB)*
zecJeHf6JET@8