From 4573d104425a79b8b00ebcccb2e94c62275285ea Mon Sep 17 00:00:00 2001 From: krasimir Date: Tue, 14 Oct 2008 08:00:50 +0000 Subject: the new optimized incremental parser and the common subexpression elimination optimization in PMCFG --- src/PGF.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/PGF.hs') diff --git a/src/PGF.hs b/src/PGF.hs index c078bf3bf..347b52ccc 100644 --- a/src/PGF.hs +++ b/src/PGF.hs @@ -77,6 +77,7 @@ import Data.Char import qualified Data.Map as Map import Data.Maybe import System.Random (newStdGen) +import Control.Monad --------------------------------------------------- -- Interface @@ -211,7 +212,7 @@ parse pgf lang cat s = Just cnc -> case parser cnc of Just pinfo -> if Map.lookup (mkCId "erasing") (cflags cnc) == Just "on" then Incremental.parse pinfo (mkCId cat) (words s) - else case parseFCFG "bottomup" pinfo (mkCId cat) (words s) of + else case parseFCFG "topdown" pinfo (mkCId cat) (words s) of Ok x -> x Bad s -> error s Nothing -> error ("No parser built for language: " ++ lang) @@ -259,9 +260,10 @@ startCat pgf = lookStartCat pgf complete pgf from cat input = let (ws,prefix) = tokensAndPrefix input state0 = initState pgf from cat - state = foldl Incremental.nextState state0 ws - compls = Incremental.getCompletions state prefix - in [unwords (ws++[c]) ++ " " | c <- Map.keys compls] + in case foldM Incremental.nextState state0 ws of + Nothing -> [] + Just state -> let compls = Incremental.getCompletions state prefix + in [unwords (ws++[c]) ++ " " | c <- Map.keys compls] where tokensAndPrefix :: String -> ([String],String) tokensAndPrefix s | not (null s) && isSpace (last s) = (words s, "") -- cgit v1.2.3