This commit is contained in:
aarne
2005-10-05 19:02:19 +00:00
parent 5b828bb83d
commit e475a71e88
13 changed files with 104 additions and 26 deletions

View File

@@ -14,6 +14,17 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2
<p> <p>
5/10 (AR) Printing missing linearization rules:
<tt>pm -printer=missing</tt>. Command <tt>g = grep</tt>,
which works in a way similar to Unix grep.
<p>
5/10 (PL) Printing graphs with function and category dependencies:
<tt>pg -printer=functiongraph</tt>, <tt>pg -printer=typegraph</tt>.
<p>
20/9 (AR) Added optimization by <b>common subexpression elimination</b>. 20/9 (AR) Added optimization by <b>common subexpression elimination</b>.
It works on GFC modules and creates <tt>oper</tt> definitions for It works on GFC modules and creates <tt>oper</tt> definitions for
subterms that occur more than once in <tt>lin</tt> definitions. These subterms that occur more than once in <tt>lin</tt> definitions. These

View File

@@ -1,3 +1,4 @@
-- # -path=.:prelude
--# -path=.:../../lib/prelude --# -path=.:../../lib/prelude
-- Toy English phrasing of C programs. Intended use is with -- Toy English phrasing of C programs. Intended use is with

View File

@@ -1,4 +1,5 @@
--# -path=.:../../lib/resource/abstract:../../lib/resource/english:../../lib/prelude --# -path=.:resource/english:resource/abstract:prelude
-- # -path=.:../../lib/resource/abstract:../../lib/resource/english:../../lib/prelude
concrete StoneageEng of Stoneage concrete StoneageEng of Stoneage
= open SyntaxEng, ResourceEng, ParadigmsEng, SwadeshLexEng, = open SyntaxEng, ResourceEng, ParadigmsEng, SwadeshLexEng,
StoneageResEng in { StoneageResEng in {

View File

@@ -1,3 +1,4 @@
-- # -path=.:resource/abstract:prelude:resource/swedish:resource/scandinavian
--# -path=.:../../lib/resource/abstract:../../lib/prelude:../../lib/resource/swedish:../../lib/resource/scandinavian --# -path=.:../../lib/resource/abstract:../../lib/prelude:../../lib/resource/swedish:../../lib/resource/scandinavian
concrete StoneageSwe of Stoneage concrete StoneageSwe of Stoneage
= open SyntaxSwe, ResourceSwe, ParadigmsSwe, VerbsSwe, SwadeshLexSwe, StoneageResSwe in { = open SyntaxSwe, ResourceSwe, ParadigmsSwe, VerbsSwe, SwadeshLexSwe, StoneageResSwe in {
@@ -30,7 +31,7 @@ lin
Know = PresVasV2 know_V ; Know = PresVasV2 know_V ;
Smell s o = PresCl (SPredV2 s (dirV2 känna_V) (DefOneNP Smell s o = PresCl (SPredV2 s (dirV2 känna_V) (DefOneNP
(AdvCN (UseN (mk2N "lukt" "lukter")) (AdvCN (UseN (mk2N "lukt" "lukter"))
(PrepNP possess_Prep o)))) ; (AdvPP (PrepNP possess_Prep o))))) ;
Fear = PresVasV2 fear_V ; Fear = PresVasV2 fear_V ;
Kill = PresVasV2 kill_V ; Kill = PresVasV2 kill_V ;
Fight s o = PresCl (AdvCl (SPredV s fight_V) (AdvPP (PrepNP with_Prep o))) ; Fight s o = PresCl (AdvCl (SPredV s fight_V) (AdvPP (PrepNP with_Prep o))) ;

View File

@@ -1,5 +1,7 @@
--# -path=.:../abstract:../../prelude --# -path=.:../abstract:../../prelude
-- # -path=.:resource/english:resource/abstract:prelude
concrete LangEng of Lang = concrete LangEng of Lang =
RulesEng, RulesEng,
ClauseEng, ClauseEng,

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/09/20 09:32:56 $ -- > CVS $Date: 2005/10/05 20:02:19 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.44 $ -- > CVS $Revision: 1.45 $
-- --
-- The top-level compilation chain from source file to gfc\/gfr. -- The top-level compilation chain from source file to gfc\/gfr.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -106,7 +106,7 @@ compileModule opts1 st0 file = do
ps0 <- ioeIO $ pathListOpts opts fpath ps0 <- ioeIO $ pathListOpts opts fpath
let ps1 = if (useFileOpt && not useLineOpt) let ps1 = if (useFileOpt && not useLineOpt)
then (map (prefixPathName fpath) ps0) then (ps0 ++ map (prefixPathName fpath) ps0)
else ps0 else ps0
ps <- ioeIO $ extendPathEnv gfLibraryPath gfGrammarPathVar ps1 ps <- ioeIO $ extendPathEnv gfLibraryPath gfGrammarPathVar ps1
let ioeIOIf = if oElem beVerbose opts then ioeIO else (const (return ())) let ioeIOIf = if oElem beVerbose opts then ioeIO else (const (return ()))

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/07/01 08:16:32 $ -- > CVS $Date: 2005/10/05 20:02:19 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.42 $ -- > CVS $Revision: 1.43 $
-- --
-- GF shell command interpreter. -- GF shell command interpreter.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -51,7 +51,7 @@ import GF.Grammar.PrGrammar
import Control.Monad (foldM,liftM) import Control.Monad (foldM,liftM)
import System (system) import System (system)
import System.Random (newStdGen) ---- import System.Random (newStdGen) ----
import Data.List (nub) import Data.List (nub,isPrefixOf)
import GF.Data.Zipper ---- import GF.Data.Zipper ----
import GF.Data.Operations import GF.Data.Operations
@@ -269,6 +269,8 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
CSystemCommand s -> justOutput opts (system s >> return ()) sa CSystemCommand s -> justOutput opts (system s >> return ()) sa
CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa
----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa ----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa
CGrep ms -> changeArg (AString . unlines . filter (grep ms) . lines . prCommandArg) sa
CSetFlag -> changeState (addGlobalOptions opts0) sa CSetFlag -> changeState (addGlobalOptions opts0) sa
---- deprec! CSetLocalFlag lang -> changeState (addLocalOptions lang opts0) sa ---- deprec! CSetLocalFlag lang -> changeState (addLocalOptions lang opts0) sa
@@ -327,6 +329,11 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
then (putStrLn ("Warning: discontinuous category" +++ prt_ c)) then (putStrLn ("Warning: discontinuous category" +++ prt_ c))
else (return ()) else (return ())
grep ms s = (if oElem beVerbose opts then not else id) $ grepv ms s --- -v
grepv ms s = case s of
_:cs -> isPrefixOf ms s || grepv ms cs
_ -> isPrefixOf ms s
-- commands either change the state or process the argument, but not both -- commands either change the state or process the argument, but not both
-- some commands just do output -- some commands just do output

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/09/20 09:32:56 $ -- > CVS $Date: 2005/10/05 20:02:19 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.13 $ -- > CVS $Revision: 1.14 $
-- --
-- Help on shell commands. Generated from HelpFile by 'make help'. -- Help on shell commands. Generated from HelpFile by 'make help'.
-- PLEASE DON'T EDIT THIS FILE. -- PLEASE DON'T EDIT THIS FILE.
@@ -115,7 +115,6 @@ txtHelpFile =
"\n options:" ++ "\n options:" ++
"\n -utf8 apply UTF8 encoding to the tokens in the grammar" ++ "\n -utf8 apply UTF8 encoding to the tokens in the grammar" ++
"\n -utf8id apply UTF8 encoding to the identifiers in the grammar" ++ "\n -utf8id apply UTF8 encoding to the identifiers in the grammar" ++
"\n -graph print module dependency graph in 'dot' format" ++
"\n examples:" ++ "\n examples:" ++
"\n pm | wf Letter.gfcm -- print the grammar into the file Letter.gfcm" ++ "\n pm | wf Letter.gfcm -- print the grammar into the file Letter.gfcm" ++
"\n pm -printer=graph | wf D.dot -- then do 'dot -Tps D.dot > D.ps'" ++ "\n pm -printer=graph | wf D.dot -- then do 'dot -Tps D.dot > D.ps'" ++
@@ -203,6 +202,14 @@ txtHelpFile =
"\n examples:" ++ "\n examples:" ++
"\n tt -lexer=codelit \"2*(x + 3)\" -- a favourite lexer for program code" ++ "\n tt -lexer=codelit \"2*(x + 3)\" -- a favourite lexer for program code" ++
"\n" ++ "\n" ++
"\ng, grep: g String1 String2" ++
"\n Grep the String1 in the String2. String2 is read line by line," ++
"\n and only those lines that contain String1 are returned." ++
"\n flags:" ++
"\n -v return those lines that do not contain String1." ++
"\n examples:" ++
"\n pg -printer=cf | grep \"mother\" -- show cf rules with word mother" ++
"\n" ++
"\ncc, compute_concrete: cc Term" ++ "\ncc, compute_concrete: cc Term" ++
"\n Compute a term by concrete syntax definitions. Uses the topmost" ++ "\n Compute a term by concrete syntax definitions. Uses the topmost" ++
"\n resource module (the last in listing by command po) to resolve " ++ "\n resource module (the last in listing by command po) to resolve " ++
@@ -505,13 +512,16 @@ txtHelpFile =
"\n -optimize=all first try parametrize then do values with the rest" ++ "\n -optimize=all first try parametrize then do values with the rest" ++
"\n -optimize=none no optimization" ++ "\n -optimize=none no optimization" ++
"\n" ++ "\n" ++
"\n-parser, parsing strategy. The default is chart. If -cfg or -mcfg are selected, only bottomup and topdown are recognized." ++ "\n-parser, parsing strategy. The default is chart. If -cfg or -mcfg are" ++
"\n selected, only bottomup and topdown are recognized." ++
"\n -parser=chart bottom-up chart parsing" ++ "\n -parser=chart bottom-up chart parsing" ++
"\n -parser=bottomup a more up to date bottom-up strategy" ++ "\n -parser=bottomup a more up to date bottom-up strategy" ++
"\n -parser=topdown top-down strategy" ++ "\n -parser=topdown top-down strategy" ++
"\n -parser=old an old bottom-up chart parser" ++ "\n -parser=old an old bottom-up chart parser" ++
"\n" ++ "\n" ++
"\n-printer, format in which the grammar is printed. The default is gfc." ++ "\n-printer, format in which the grammar is printed. The default is" ++
"\n gfc. Those marked with M are (only) available for pm, the rest" ++
"\n for pg." ++
"\n -printer=gfc GFC grammar" ++ "\n -printer=gfc GFC grammar" ++
"\n -printer=gf GF grammar" ++ "\n -printer=gf GF grammar" ++
"\n -printer=old old GF grammar" ++ "\n -printer=old old GF grammar" ++
@@ -535,6 +545,15 @@ txtHelpFile =
"\n -printer=fa_graphviz a finite automaton with labelled edges" ++ "\n -printer=fa_graphviz a finite automaton with labelled edges" ++
"\n -printer=regular a regular grammar in a simple BNF" ++ "\n -printer=regular a regular grammar in a simple BNF" ++
"\n -printer=unpar a gfc grammar with parameters eliminated" ++ "\n -printer=unpar a gfc grammar with parameters eliminated" ++
"\n -printer=functiongraph abstract syntax functions in 'dot' format" ++
"\n -printer=typegraph abstract syntax categories in 'dot' format" ++
"\n -printer=gfcm M gfcm file (default for pm)" ++
"\n -printer=header M gfcm file with header (for GF embedded in Java)" ++
"\n -printer=graph M module dependency graph in 'dot' (graphviz) format" ++
"\n -printer=missing M the missing linearizations of each concrete" ++
"\n -printer=gfc-prolog M gfc in prolog format (also pg)" ++
"\n -printer=mcfg-prolog M mcfg in prolog format (also pg)" ++
"\n -printer=cfg-prolog M cfg in prolog format (also pg)" ++
"\n" ++ "\n" ++
"\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++ "\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++
"\n" ++ "\n" ++

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/06/20 16:14:20 $ -- > CVS $Date: 2005/10/05 20:02:20 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.25 $ -- > CVS $Revision: 1.26 $
-- --
-- parsing GF shell commands. AR 11\/11\/2001 -- parsing GF shell commands. AR 11\/11\/2001
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -133,6 +133,7 @@ pCommand ws = case ws of
"st" : s -> aTerm CShowTerm s "st" : s -> aTerm CShowTerm s
"!" : s -> aUnit (CSystemCommand (unwords s)) "!" : s -> aUnit (CSystemCommand (unwords s))
"sc" : s -> aUnit (CSystemCommand (unwords s)) "sc" : s -> aUnit (CSystemCommand (unwords s))
"g" : f : s -> aString (CGrep (unquote f)) s
"sf" : l : [] -> aUnit (CSetLocalFlag (language l)) "sf" : l : [] -> aUnit (CSetLocalFlag (language l))
"sf" : [] -> aUnit CSetFlag "sf" : [] -> aUnit CSetFlag

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/07/01 08:16:32 $ -- > CVS $Date: 2005/10/05 20:02:20 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.39 $ -- > CVS $Revision: 1.40 $
-- --
-- The datatype of shell commands and the list of their options. -- The datatype of shell commands and the list of their options.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -64,6 +64,7 @@ data Command =
| CPutString | CPutString
| CShowTerm | CShowTerm
| CSystemCommand String | CSystemCommand String
| CGrep String
| CSetFlag | CSetFlag
| CSetLocalFlag Language | CSetLocalFlag Language
@@ -193,6 +194,7 @@ optionsOfCommand co = case co of
CShowTerm -> flags "printer" CShowTerm -> flags "printer"
CShowTreeGraph -> opts "c f g o" CShowTreeGraph -> opts "c f g o"
CSystemCommand _ -> none CSystemCommand _ -> none
CGrep _ -> opts "v"
CPrintGrammar -> both "utf8" "printer lang" CPrintGrammar -> both "utf8" "printer lang"
CPrintMultiGrammar -> both "utf8 utf8id" "printer" CPrintMultiGrammar -> both "utf8 utf8id" "printer"

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/10/05 11:56:42 $ -- > CVS $Date: 2005/10/05 20:02:20 $
-- > CVS $Author: peb $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.76 $ -- > CVS $Revision: 1.77 $
-- --
-- A database for customizable GF shell commands. -- A database for customizable GF shell commands.
-- --
@@ -63,6 +63,7 @@ import GF.Data.Zipper
import GF.UseGrammar.Statistics import GF.UseGrammar.Statistics
import GF.UseGrammar.Morphology import GF.UseGrammar.Morphology
import GF.UseGrammar.Information
import GF.API.GrammarToHaskell import GF.API.GrammarToHaskell
-----import GrammarToCanon (showCanon, showCanonOpt) -----import GrammarToCanon (showCanon, showCanonOpt)
-----import qualified GrammarToGFC as GFC -----import qualified GrammarToGFC as GFC
@@ -307,6 +308,7 @@ customMultiGrammarPrinter =
,(strCI "header", const (MC.prCanonMGr . unoptimizeCanon)) ,(strCI "header", const (MC.prCanonMGr . unoptimizeCanon))
,(strCI "cfgm", prCanonAsCFGM) ,(strCI "cfgm", prCanonAsCFGM)
,(strCI "graph", visualizeCanonGrammar) ,(strCI "graph", visualizeCanonGrammar)
,(strCI "missing", const missingLinCanonGrammar)
-- to prolog format: -- to prolog format:
,(strCI "gfc-prolog", CnvProlog.prtSMulti) ,(strCI "gfc-prolog", CnvProlog.prtSMulti)

View File

@@ -5,16 +5,19 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/05/30 18:39:45 $ -- > CVS $Date: 2005/10/05 20:02:20 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.6 $ -- > CVS $Revision: 1.7 $
-- --
-- information on module, category, function, operation, parameter,... -- information on module, category, function, operation, parameter,...
-- AR 16\/9\/2003. -- AR 16\/9\/2003.
-- uses source grammar -- uses source grammar
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.UseGrammar.Information (showInformation) where module GF.UseGrammar.Information (
showInformation,
missingLinCanonGrammar
) where
import GF.Grammar.Grammar import GF.Grammar.Grammar
import GF.Infra.Ident import GF.Infra.Ident
@@ -25,6 +28,7 @@ import GF.CF.PPrCF
import GF.Compile.ShellState import GF.Compile.ShellState
import GF.Grammar.PrGrammar import GF.Grammar.PrGrammar
import GF.Grammar.Lookup import GF.Grammar.Lookup
import GF.Grammar.Macros (zIdent)
import qualified GF.Canon.GFC as GFC import qualified GF.Canon.GFC as GFC
import qualified GF.Canon.AbsGFC as AbsGFC import qualified GF.Canon.AbsGFC as AbsGFC
@@ -141,3 +145,11 @@ ownConstants = map fst . filter isOwn . tree2list where
AnyInd _ _ -> False AnyInd _ _ -> False
_ -> True _ -> True
missingLinCanonGrammar :: GFC.CanonGrammar -> String
missingLinCanonGrammar cgr =
unlines $ concat [prt_ c : missing js | (c,js) <- concretes] where
missing js = map ((" " ++) . prt_) $ filter (not . flip isInBinTree js) abstract
abstract = err (const []) (map fst . tree2list . jments) $ lookupModMod cgr absId
absId = maybe (zIdent "") id $ greatestAbstract cgr
concretes = [(cnc,jments mo) |
cnc <- allConcretes cgr absId, Ok mo <- [lookupModMod cgr cnc]]

View File

@@ -86,7 +86,6 @@ pm, print_multigrammar: pm
options: options:
-utf8 apply UTF8 encoding to the tokens in the grammar -utf8 apply UTF8 encoding to the tokens in the grammar
-utf8id apply UTF8 encoding to the identifiers in the grammar -utf8id apply UTF8 encoding to the identifiers in the grammar
-graph print module dependency graph in 'dot' format
examples: examples:
pm | wf Letter.gfcm -- print the grammar into the file Letter.gfcm pm | wf Letter.gfcm -- print the grammar into the file Letter.gfcm
pm -printer=graph | wf D.dot -- then do 'dot -Tps D.dot > D.ps' pm -printer=graph | wf D.dot -- then do 'dot -Tps D.dot > D.ps'
@@ -174,6 +173,14 @@ tt, test_tokenizer: tt String
examples: examples:
tt -lexer=codelit "2*(x + 3)" -- a favourite lexer for program code tt -lexer=codelit "2*(x + 3)" -- a favourite lexer for program code
g, grep: g String1 String2
Grep the String1 in the String2. String2 is read line by line,
and only those lines that contain String1 are returned.
flags:
-v return those lines that do not contain String1.
examples:
pg -printer=cf | grep "mother" -- show cf rules with word mother
cc, compute_concrete: cc Term cc, compute_concrete: cc Term
Compute a term by concrete syntax definitions. Uses the topmost Compute a term by concrete syntax definitions. Uses the topmost
resource module (the last in listing by command po) to resolve resource module (the last in listing by command po) to resolve
@@ -476,13 +483,16 @@ q, quit: q
-optimize=all first try parametrize then do values with the rest -optimize=all first try parametrize then do values with the rest
-optimize=none no optimization -optimize=none no optimization
-parser, parsing strategy. The default is chart. If -cfg or -mcfg are selected, only bottomup and topdown are recognized. -parser, parsing strategy. The default is chart. If -cfg or -mcfg are
selected, only bottomup and topdown are recognized.
-parser=chart bottom-up chart parsing -parser=chart bottom-up chart parsing
-parser=bottomup a more up to date bottom-up strategy -parser=bottomup a more up to date bottom-up strategy
-parser=topdown top-down strategy -parser=topdown top-down strategy
-parser=old an old bottom-up chart parser -parser=old an old bottom-up chart parser
-printer, format in which the grammar is printed. The default is gfc. -printer, format in which the grammar is printed. The default is
gfc. Those marked with M are (only) available for pm, the rest
for pg.
-printer=gfc GFC grammar -printer=gfc GFC grammar
-printer=gf GF grammar -printer=gf GF grammar
-printer=old old GF grammar -printer=old old GF grammar
@@ -506,6 +516,15 @@ q, quit: q
-printer=fa_graphviz a finite automaton with labelled edges -printer=fa_graphviz a finite automaton with labelled edges
-printer=regular a regular grammar in a simple BNF -printer=regular a regular grammar in a simple BNF
-printer=unpar a gfc grammar with parameters eliminated -printer=unpar a gfc grammar with parameters eliminated
-printer=functiongraph abstract syntax functions in 'dot' format
-printer=typegraph abstract syntax categories in 'dot' format
-printer=gfcm M gfcm file (default for pm)
-printer=header M gfcm file with header (for GF embedded in Java)
-printer=graph M module dependency graph in 'dot' (graphviz) format
-printer=missing M the missing linearizations of each concrete
-printer=gfc-prolog M gfc in prolog format (also pg)
-printer=mcfg-prolog M mcfg in prolog format (also pg)
-printer=cfg-prolog M cfg in prolog format (also pg)
-startcat, like -cat, but used in grammars (to avoid clash with keyword cat) -startcat, like -cat, but used in grammars (to avoid clash with keyword cat)