{- Copyright 2010 Dominique Devriese This file is part of the grammar-combinators library. The grammar-combinators library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Foobar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Foobar. If not, see . -} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NoMonomorphismRestriction #-} import Text.GrammarCombinators.Parser.LL1 import Text.GrammarCombinators.Parser.RealLL1 import Text.GrammarCombinators.Parser.LL1TH import Text.GrammarCombinators.TH.Base import Text.GrammarCombinators.TH.RealLL1 import Text.GrammarCombinators.TH.FoldLoops import Text.GrammarCombinators.Parser.Packrat import Text.GrammarCombinators.Parser.RecursiveDescent import Text.GrammarCombinators.Base import Text.GrammarCombinators.Test.LL1Grammar import Data.Time.Clock test1 = "((1+3)+(3+9))" printgram :: ProcessingContextFreeGrammar SFNode Char NodeResult printgram = applyProcessor grammar printer parseTestLL1 :: String -> Maybe (NodeResult S) parseTestLL1 = parseLL1 printgram (calcLL1Table grammar) S testLL1 str = case parseTestLL1 str of Just (NRS s) -> s Nothing -> "" compTable :: LL1Table SFNode Char compTable = $(prepareLL1TableTH grammar) parseTestLL1Opt :: String -> Maybe (NodeResult S) parseTestLL1Opt = parseLL1 printgram compTable S testLL1Opt str = case parseTestLL1Opt str of Just (NRS s) -> s Nothing -> "" parsePR = parsePackrat printgram S testPR str = case parsePR str of Parsed (NRS s) _ -> s parseRD = parseRecDec printgram S testRD str = case parseRD str of Just (NRS s) -> s tableRLL1 = $(liftRealLL1Table $ prepareLL1Parser grammar) parseRLL1 = parseRealLL1 printgram tableRLL1 S testRLL1 str = case parseRLL1 str of Just (NRS s) -> s genTestS 0 = "5" genTestS i = "(3+" ++ genTestS (i-1) ++ ")" testidxs = [100..199] tests = [genTestS i | i <- testidxs] printTests = mapM_ (\s -> putStr s >> putStr "\n") tests usermain = do printTests -- make sure all tests are precomputed t0 <- getCurrentTime mapM_ (putStr . show . length . testLL1) tests putStr "\n" t1 <- getCurrentTime mapM_ (putStr . show . length . testPR) tests putStr "\n" t2 <- getCurrentTime mapM_ (putStr . show . length . testLL1Opt) tests putStr "\n" t3 <- getCurrentTime mapM_ (putStr . show . length . testRD) tests putStr "\n" t4 <- getCurrentTime mapM_ (putStr . show . length . testRLL1) tests putStr "\n" t5 <- getCurrentTime putStr "ll1 time: " putStr $ show (diffUTCTime t1 t0) putStr "\n" putStr "PR time: " putStr $ show (diffUTCTime t2 t1) putStr "\n" putStr "LL1 opt time: " putStr $ show (diffUTCTime t3 t2) putStr "\n" putStr "RD time: " putStr $ show (diffUTCTime t4 t3) putStr "\n" putStr "RealLL1 time: " putStr $ show (diffUTCTime t5 t4) putStr "\n" main = usermain profmain = do mapM_ (putStr . show . length . testLL1) tests putStr "\n" mapM_ (putStr . show . length . testLL1Opt) tests