mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 01:22:51 -06:00
Some tracing and formatting stuff looking for the the stack overflow problem in the FA generation.
This commit is contained in:
@@ -27,9 +27,13 @@ import GF.Speech.FiniteState
|
|||||||
import GF.Speech.Relation
|
import GF.Speech.Relation
|
||||||
import GF.Speech.TransformCFG
|
import GF.Speech.TransformCFG
|
||||||
|
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
cfgToFA :: Options -> CGrammar -> DFA String
|
cfgToFA :: Options -> CGrammar -> DFA String
|
||||||
cfgToFA opts = minimize . compileAutomaton start . makeSimpleRegular
|
cfgToFA opts = minimize . compileAutomaton start . makeSimpleRegular
|
||||||
|
--cfgToFA opts = trfa "minimal" . minimize . trfa "initial" . compileAutomaton start . makeSimpleRegular
|
||||||
where start = getStartCat opts
|
where start = getStartCat opts
|
||||||
|
trfa s fa = trace (s ++ ", states: " ++ show (length (states fa)) ++ ", transitions: " ++ show (length (transitions fa))) fa
|
||||||
|
|
||||||
makeSimpleRegular :: CGrammar -> CFRules
|
makeSimpleRegular :: CGrammar -> CFRules
|
||||||
makeSimpleRegular = makeRegular . removeIdenticalRules . removeEmptyCats . cfgToCFRules
|
makeSimpleRegular = makeRegular . removeIdenticalRules . removeEmptyCats . cfgToCFRules
|
||||||
@@ -69,7 +73,8 @@ compileAutomaton :: Cat_ -- ^ Start category
|
|||||||
-> CFRules
|
-> CFRules
|
||||||
-> NFA Token
|
-> NFA Token
|
||||||
compileAutomaton start g = make_fa s [Cat start] f fa''
|
compileAutomaton start g = make_fa s [Cat start] f fa''
|
||||||
where fa = newFA ()
|
where
|
||||||
|
fa = newFA ()
|
||||||
s = startState fa
|
s = startState fa
|
||||||
(fa',f) = newState () fa
|
(fa',f) = newState () fa
|
||||||
fa'' = addFinalState f fa'
|
fa'' = addFinalState f fa'
|
||||||
@@ -88,7 +93,8 @@ compileAutomaton start g = make_fa s [Cat start] f fa''
|
|||||||
getState x = lookup' x ss
|
getState x = lookup' x ss
|
||||||
niRules = catSetRules g ni
|
niRules = catSetRules g ni
|
||||||
(nrs,rs) = partition (ruleIsNonRecursive ni) niRules
|
(nrs,rs) = partition (ruleIsNonRecursive ni) niRules
|
||||||
in if all (isRightLinear ni) niRules then
|
in if all (isRightLinear ni) niRules
|
||||||
|
then
|
||||||
-- the set Ni is right-recursive or cyclic
|
-- the set Ni is right-recursive or cyclic
|
||||||
let fa'' = foldFuns [make_fa (getState c) xs q1 | CFRule c xs _ <- nrs] fa'
|
let fa'' = foldFuns [make_fa (getState c) xs q1 | CFRule c xs _ <- nrs] fa'
|
||||||
fa''' = foldFuns [make_fa (getState c) xs (getState d) | CFRule c ss _ <- rs,
|
fa''' = foldFuns [make_fa (getState c) xs (getState d) | CFRule c ss _ <- rs,
|
||||||
|
|||||||
@@ -34,10 +34,13 @@ import Data.Char (toUpper,toLower)
|
|||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
faGraphvizPrinter :: Ident -- ^ Grammar name
|
faGraphvizPrinter :: Ident -- ^ Grammar name
|
||||||
-> Options -> CGrammar -> String
|
-> Options -> CGrammar -> String
|
||||||
faGraphvizPrinter name opts cfg =
|
faGraphvizPrinter name opts cfg =
|
||||||
prFAGraphviz $ mapStates (const "") $ cfgToFA opts cfg
|
prFAGraphviz $ mapStates (const "") fa
|
||||||
|
where fa = cfgToFA opts cfg
|
||||||
|
|
||||||
|
|
||||||
-- | Convert the grammar to a regular grammar and print it in BNF
|
-- | Convert the grammar to a regular grammar and print it in BNF
|
||||||
|
|||||||
Reference in New Issue
Block a user