summaryrefslogtreecommitdiff
path: root/src-2.9/GF/Canon/AbsToBNF.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-05-20 11:47:44 +0000
committeraarne <aarne@cs.chalmers.se>2008-05-20 11:47:44 +0000
commit31bf84122b21efb444aa8d055472e166ffb90783 (patch)
tree1f051909336f1534346bcccde8dda59beab02f64 /src-2.9/GF/Canon/AbsToBNF.hs
parent74f048dcf41de3540778de54dfa7541fa5b39c46 (diff)
moved all old source code to src-2.9 ; src will be for GF 3 development
Diffstat (limited to 'src-2.9/GF/Canon/AbsToBNF.hs')
-rw-r--r--src-2.9/GF/Canon/AbsToBNF.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src-2.9/GF/Canon/AbsToBNF.hs b/src-2.9/GF/Canon/AbsToBNF.hs
new file mode 100644
index 000000000..e30e836da
--- /dev/null
+++ b/src-2.9/GF/Canon/AbsToBNF.hs
@@ -0,0 +1,38 @@
+module GF.Canon.AbsToBNF where
+
+import GF.Grammar.SGrammar
+import GF.Data.Operations
+import GF.Infra.Option
+import GF.Canon.GFC (CanonGrammar)
+
+-- AR 10/5/2007
+
+abstract2bnf :: CanonGrammar -> String
+abstract2bnf = sgrammar2bnf . gr2sgr noOptions emptyProbs
+
+sgrammar2bnf :: SGrammar -> String
+sgrammar2bnf = unlines . map (prBNFRule . mkBNF) . allRules
+
+prBNFRule :: BNFRule -> String
+prBNFRule = id
+
+type BNFRule = String
+
+mkBNF :: SRule -> BNFRule
+mkBNF (pfun,(args,cat)) =
+ fun ++ "." +++ gfId cat +++ "::=" +++ rhs +++ ";"
+ where
+ fun = gfId (snd pfun)
+ rhs = case args of
+ [] -> prQuotedString (snd pfun)
+ _ -> unwords (map gfId args)
+
+-- good for GF
+gfId i = i
+
+-- good for BNFC
+gfIdd i = case i of
+ "Int" -> "Integer"
+ "String" -> i
+ "Float" -> "Double"
+ _ -> "G" ++ i ++ "_"