diff --git a/examples/C/README.rst b/examples/C/README.rst index b2d828b1..22929270 100644 --- a/examples/C/README.rst +++ b/examples/C/README.rst @@ -11,8 +11,7 @@ This directory contains different grammars related to the C language: Developed by Ulf Persson is 2003 as part of a BSc thesis at Chalmers University of Technology ``C_with_delimiters.cf`` - Modified Ansi C grammar to make use of ``delimiter`` pragmas (used in the CNF - backend). + Modified Ansi C grammar to make use of ``delimiter`` pragmas. And some example programs: diff --git a/source/BNFC.cabal b/source/BNFC.cabal index 0c9bac8c..09740460 100644 --- a/source/BNFC.cabal +++ b/source/BNFC.cabal @@ -61,18 +61,6 @@ Source-repository this subdir: source tag: v2.8.4 -Library - hs-source-dirs: runtime, src - default-language: Haskell2010 - Build-Depends: base>=4.8 && <5, array - exposed-modules: - Algebra.RingUtils - Data.Pair - Data.Matrix.Quad - Data.Matrix.Class - Parsing.Chart - Parsing.TestProgram - Executable bnfc default-language: Haskell2010 Build-Depends: @@ -111,7 +99,6 @@ Executable bnfc -- BNFC core BNFC.Utils BNFC.CF - BNFC.ToCNFCore BNFC.Regex BNFC.TypeChecker BNFC.GetCF @@ -124,7 +111,6 @@ Executable bnfc BNFC.Backend.Common.StrUtils BNFC.Options BNFC.PrettyPrint - Data.Pair -- Documentation backends BNFC.Backend.Latex @@ -132,7 +118,6 @@ Executable bnfc -- Haskell backend BNFC.Backend.Haskell - BNFC.Backend.Haskell.ToCNF BNFC.Backend.Haskell.CFtoTemplate BNFC.Backend.Haskell.CFtoAlex3 BNFC.Backend.Haskell.CFtoHappy @@ -276,7 +261,6 @@ Test-suite unit-tests -- BNFC core BNFC.Utils BNFC.CF - BNFC.ToCNFCore BNFC.Regex BNFC.TypeChecker BNFC.GetCF @@ -289,7 +273,6 @@ Test-suite unit-tests BNFC.Backend.Common.StrUtils BNFC.Options BNFC.PrettyPrint - Data.Pair -- Documentation backends BNFC.Backend.Latex @@ -297,7 +280,6 @@ Test-suite unit-tests -- Haskell backend BNFC.Backend.Haskell - BNFC.Backend.Haskell.ToCNF BNFC.Backend.Haskell.CFtoTemplate BNFC.Backend.Haskell.CFtoAlex3 BNFC.Backend.Haskell.CFtoHappy diff --git a/source/changelog b/source/changelog index b4e74564..c5cddddd 100644 --- a/source/changelog +++ b/source/changelog @@ -1,5 +1,5 @@ 2.9.0 Andreas Abel - * Haskell: removed options --alex1, --alex2, --sharestrings, and --profile + * Haskell: removed options --alex1, --alex2, --sharestrings, --profile, and --cnf * C#: backend removed 2.8.4 Andreas Abel October 2020 diff --git a/source/runtime/Algebra/RingUtils.hs b/source/runtime/Algebra/RingUtils.hs deleted file mode 100644 index 23e06ffc..00000000 --- a/source/runtime/Algebra/RingUtils.hs +++ /dev/null @@ -1,74 +0,0 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} - -module Algebra.RingUtils - ( module Prelude - , AbelianGroup(..) - , AbelianGroupZ(..) - , Ring(..) - , RingP(..) - , Pair(..), select, onlyLeft, onlyRight - , O(..) - , sum - , mulDefault - , module Data.Pair - ) - where - -import qualified Prelude as P -import Prelude hiding ( (+), (*), splitAt, sum ) -import Control.Applicative -import Data.Pair - -class AbelianGroup a where - zero :: a - (+) :: a -> a -> a - -instance AbelianGroup Int where - zero = 0 - (+) = (P.+) - -class AbelianGroup a => AbelianGroupZ a where - isZero :: a -> Bool - -instance AbelianGroupZ Int where - isZero x = x == 0 - -class AbelianGroupZ a => Ring a where - (*) :: a -> a -> a - -class (AbelianGroupZ a) => RingP a where - mul :: Bool -> a -> a -> Pair a --- mul _ x y = pure $ x * y - -mulDefault x y = leftOf (mul False x y) - -onlyLeft x = x :/: [] -onlyRight x = [] :/: x - -select p = if p then onlyRight else onlyLeft - -newtype O f g a = O {fromO :: f (g a)} - deriving (AbelianGroup, AbelianGroupZ, Show) - -instance (Functor f,Functor g) => Functor (O f g) where - fmap f (O x) = O (fmap (fmap f) x) - -instance AbelianGroup a => AbelianGroup (Pair a) where - zero = (zero:/:zero) - (a:/:b) + (x:/:y) = (a+x) :/: (b+y) - -instance AbelianGroupZ a => AbelianGroupZ (Pair a) where - isZero (a:/:b) = isZero a && isZero b - -instance Ring Int where - (*) = (P.*) - -infixl 7 * -infixl 6 + - -sum :: AbelianGroup a => [a] -> a -sum = foldr (+) zero - -instance AbelianGroup Bool where - zero = False - (+) = (||) diff --git a/source/runtime/BNFC/Runtime/CYKSparse.hs b/source/runtime/BNFC/Runtime/CYKSparse.hs deleted file mode 100644 index e1710d53..00000000 --- a/source/runtime/BNFC/Runtime/CYKSparse.hs +++ /dev/null @@ -1,85 +0,0 @@ -module BNFC.Runtime.CYKSparse where - -import Data.Array.IArray -import Data.List -import Data.Char -import Data.Maybe -import GHC.Exts - - --- Sparse triangle matrices. -data Chart a = - Single a | - Merge { - mergeSize :: !Int, - here :: Array Int [(Int,a)], -- parses starting in left, ending in right. - left :: Chart a, - right :: Chart a - } -- invariant : mergeSize = size left + size right - deriving Show - --- | Size of a chart -size :: Chart a -> Int -size (Single _) = 1 -size (Merge s _ _ _) = s - - --- | Everything that starts at a given position -startingAt = startingAt' True - --- | Things that start at a given position. Flag=False means not to take anything from the left subtree. -startingAt' :: Bool -> Int -> Chart a -> [(Int,a)] -startingAt' _ 0 (Single nt) = [(1,nt)] -startingAt' _ e (Single nt) = [] -startingAt' lookLeft s (Merge n h l r) - | s >= n = [] - | s >= size l = map (shift (size l)) (startingAt (s-size l) r) - | lookLeft = (h ! s) ++ (startingAt s l) - | otherwise = h ! s - where shift i (x,y) = (x+i,y) - --- | Merge two charts. -merge (*) l r = result - where - result = Merge n h l r - n = size l + size r - h = listArray (0,size l-1) $ - map (\start -> concatMap (init . chainsFrom) (startingAt start l)) - -- the last element is the one taken from the left - -- part; so drop it. - [0..size l - 1] - -- chainsFrom :: (Int,Set (AST nt tok)) -> [(Int,Set (AST nt tok))] - chainsFrom (mid,nts1) = [x | - (end,nts2) <- startingAt' False mid result, - -- we don't want things included in the - -- left part: merging those would - -- return things included in the left - -- part again. - let nts = nts1 * nts2, - not (null nts), - x <- chainsFrom (end,nts) - ] ++ [(mid,nts1)] - -- it's tempting to sort the above list by large ends first, but - -- that would destroy laziness. Things will be "more or less" sorted anyway. - - -type AST cat = (cat,Any) - - - -mkTree :: (posn -> tok -> [(cat,Any)]) -> - (cat -> cat -> [(cat, Any -> Any -> Any)]) -> [(posn,tok)] -> Chart [AST cat] -mkTree tokens combine ts = sweeps (map unitChart ts) - where - sweeps [] = error "can't parse the empty string, sorry" - sweeps [p] = p - sweeps ps = sweeps (pairs ps) - - pairs [] = [] - pairs [p] = [p] - pairs (p:q:ps) = (merge mul p q) : pairs ps - - mul p q = [(c',f x1 x2) | (c1,x1) <- p, (c2,x2) <- q, (c',f) <- combine c1 c2] - - -- unitChart :: (Posn,tok) -> Chart [AST cat] - unitChart (posn,tok) = Single (tokens posn tok) diff --git a/source/runtime/Data/Matrix/CYK.hs b/source/runtime/Data/Matrix/CYK.hs deleted file mode 100644 index 70d8a539..00000000 --- a/source/runtime/Data/Matrix/CYK.hs +++ /dev/null @@ -1,64 +0,0 @@ -module CYK where - -import Data.Monoid -import Data.Array.IArray -import Data.List -import Control.Monad - -import Prelude () -import Prelude.YAP -import CNF -import Examples -import Chart - - -data Chart a = - Single a | - Merge { - mergeSize :: Int, - here :: (Array (Int,Int) a), - left :: Chart a, - right :: Chart a - } -- invariant : size = size left + size right - deriving Show - -size (Single _) = 1 -size (Merge s _ _ _) = s - - -access start end w | start < 0 = error "start<0" - | start >= size w = error "start>=n" - | end <= 0 = error "end<=0" - | end > size w = error "end>n" - | start >= end = error "start>=end" - | otherwise = access' start end w - - -access' 0 1 (Single x) = x -access' start end (Merge n h l r) - | end <= size l = access start end l - | start >= size l = access (start - size l) (end - size l) r - | otherwise = h ! (start,n-end) - -showW w = forM_ [1..n] $ \end -> do - forM_ [0..end-1] $ \start -> - putStr (show (access start end w) ++ " ") - putStrLn "" - where n = size w - - -merge l r = result - where - x i j = access i j result - result = Merge n h l r - n = size l + size r - h = array ((0,0),(size l-1, size r-1)) - [((start,n-end), nub [c | k <- [start+1..end-1], c <- x start k * x k end]) - | start <- [0..size l-1], - end <- [size l+1..n] - ] - - -instance IsChart Chart where - single nt = Single nt - (<>) = merge diff --git a/source/runtime/Data/Matrix/Class.hs b/source/runtime/Data/Matrix/Class.hs deleted file mode 100644 index 07988bb0..00000000 --- a/source/runtime/Data/Matrix/Class.hs +++ /dev/null @@ -1,81 +0,0 @@ -{-# LANGUAGE FlexibleInstances #-} - -module Data.Matrix.Class where - -import Prelude () -import Algebra.RingUtils -import Control.Applicative hiding ((<|>)) - - -fingerprint m = [[ if isZero (at i j m) then ' ' else 'X' | i <- [0..x-1] ] | j <- [0..y-1]] - where x = countColumns m - y = countRows m - -(f *** g) (x,y) = (f x,g y) - -data Dimension - = XD - | YD - deriving (Eq,Show) - -quad a b c d = (a <|> b) <-> (c <|> d) - - -nextDim XD = YD -nextDim YD = XD - -type Extent = (Int,Int) - -ext XD (x,y) = x -ext YD (x,y) = y - -glueExt XD (x1,y1) (x2,y2) = (x1+x2,y1) -glueExt YD (x1,y1) (x2,y2) = (x1,y1+y2) - -splitExt XD k (x,y) = ((k,y),(x-k,y)) -splitExt YD k (x,y) = ((x,k),(x,y-k)) - -class Matrix m where - at :: AbelianGroupZ a => Int -> Int -> m a -> a - extent :: m a -> Extent - -- | Sigleton matrix - singleton :: AbelianGroupZ a => a -> m a - glue :: AbelianGroup a => Dimension -> m a -> m a -> m a - split :: AbelianGroupZ a => Dimension -> Int -> m a -> (m a, m a) - zeroMatrix :: AbelianGroup a => Int -> Int -> m a - -instance Matrix m => Matrix (O Pair m) where - at i j (O (x :/: y)) = at i j x + at i j y - extent (O (x :/: y)) = extent x -- union with y - glue d (O p) (O q) = O $ glue d <$> p <*> q - split d k (O (x :/: y)) = (O $ ax :/: ay, O $ bx :/: by) - where (ax,bx) = split d k x - (ay,by) = split d k y - zeroMatrix x y = O $ pure (zeroMatrix x y) - singleton x = O $ pure (singleton x) -- Attention: on both sides always! - - -(<|>) :: (AbelianGroup a, Matrix m) => m a -> m a -> m a -(<|>) = glue XD - -(<->) :: (AbelianGroup a, Matrix m) => m a -> m a -> m a -(<->) = glue YD - -countColumns, countRows :: Matrix m => m a -> Int -countColumns = ext XD . extent -countRows = ext YD . extent - -chopLastColumn, chopFirstRow, chopFirstColumn, chopLastRow, lastColumn, firstRow :: (AbelianGroupZ a, Matrix m) => m a -> m a -chopFirstRow = snd . split YD 1 -chopFirstColumn = snd . split XD 1 -chopLastColumn x = fst . split XD (countColumns x - 1) $ x -firstRow = fst . split YD 1 -lastColumn x = snd . split XD (countColumns x - 1) $ x - -chopLastRow x = fst . split YD (countRows x - 1) $ x - - - - - - diff --git a/source/runtime/Data/Matrix/Quad.hs b/source/runtime/Data/Matrix/Quad.hs deleted file mode 100644 index 8e0aee29..00000000 --- a/source/runtime/Data/Matrix/Quad.hs +++ /dev/null @@ -1,299 +0,0 @@ -{-# LANGUAGE GADTs, DataKinds, ScopedTypeVariables, KindSignatures #-} - -module Data.Matrix.Quad where - -import Prelude () -import Data.List (splitAt,intercalate) -import Control.Applicative -import Algebra.RingUtils hiding (O,concat) -import Data.Traversable -import Data.Foldable - -data Shape = Bin Shape Shape | Leaf - -data Shape' :: Shape -> * where - Bin' :: !Int -> Shape' s -> Shape' s' -> Shape' (Bin s s') - Leaf' :: Shape' Leaf - -data SomeShape where - S :: Shape' s -> SomeShape - -data Mat :: Shape -> Shape -> * -> * where - Quad :: !(Mat x1 y1 a) -> !(Mat x2 y1 a) -> - !(Mat x1 y2 a) -> !(Mat x2 y2 a) -> - Mat (Bin x1 x2) (Bin y1 y2) a - Zero :: Mat x y a - One :: !a -> Mat Leaf Leaf a - Row :: Mat x1 Leaf a -> Mat x2 Leaf a -> Mat (Bin x1 x2) Leaf a - Col :: Mat Leaf y1 a -> Mat Leaf y2 a -> Mat Leaf (Bin y1 y2) a - -data Vec :: Shape -> * -> * where - Z :: Vec s a - O :: a -> Vec Leaf a - (:!) :: Vec s a -> Vec s' a -> Vec (Bin s s') a - - -row Zero Zero = Zero -row x y = Row x y - -col :: Mat Leaf y1 a -> Mat Leaf y2 a -> Mat Leaf (Bin y1 y2) a -col Zero Zero = Zero -col x y = Col x y - -quad Zero Zero Zero Zero = Zero -quad a b c d = Quad a b c d - -one :: AbelianGroupZ a => a -> Mat Leaf Leaf a -one x | isZero x = Zero - | otherwise = One x - -(.+.) :: AbelianGroupZ a => Mat x y a -> Mat x y a -> Mat x y a -Zero .+. x = x -x .+. Zero = x -Quad a b c d .+. Quad a' b' c' d' = quad (a .+. a') (b .+. b') (c .+. c') (d .+. d') -One x .+. One x' = one (x + x') -Row x y .+. Row x' y' = row (x .+. x') (y .+. y') -Col x y .+. Col x' y' = col (x .+. x') (y .+. y') - -instance AbelianGroupZ a => AbelianGroup (Mat x y a) where - (+) = (.+.) - zero = Zero - -mult :: RingP a => Bool -> Mat x y a -> Mat z x a -> Mat z y (Pair a) -mult p a b = a & b where - infixl 7 & - (&) :: RingP a => Mat x y a -> Mat z x a -> Mat z y (Pair a) - Zero & x = Zero - x & Zero = Zero - One x & One x' = one (mul p x x') - One x & Row a b = row (One x & a) (One x & b) - Col a b & One x = col (a & One x) (b & One x) - Row a b & Col a' b' = a & a' + b & b' - Col a b & Row a' b' = quad (a & a') (a & b') (b & a') (b & b') - Row a b & Quad a' b' c' d' = row (a & a' + b & c') (a & b' + b & d') - Quad a b c d & Col a' c' = col (a & a' + b & c') (c & a' + d & c') - Quad a b c d & Quad a' b' c' d' = - quad (a & a' + b & c') (a & b' + b & d') - (c & a' + d & c') (c & b' + d & d') - - -- REDUNANT CLAUSE: - x & y = error $ "mult:" ++ intercalate "; " [showR x,showR y] - --- a variant of traverse. The constraint prevents to just use traverse. -trav :: AbelianGroupZ a => Mat y x (Pair a) -> Pair (Mat y x a) -trav Zero = pure Zero -trav (Quad a b c d) = quad <$> trav a <*> trav b <*> trav c <*> trav d -trav (One x) = one <$> x -trav (Col a b) = col <$> trav a <*> trav b -trav (Row a b) = row <$> trav a <*> trav b - -q0 :: Mat (Bin x x') (Bin y y') a -q0 = Quad Zero Zero Zero Zero - -closeDisjointP :: RingP a => Bool -> Mat x x a -> Mat y x (Pair a) -> Mat y y a -> Pair (Mat y x a) -closeDisjointP p l c r = close l c r - where close :: RingP a => Mat x x a -> Mat y x (Pair a) -> Mat y y a -> Pair (Mat y x a) - close l Zero r = Zero :/: Zero - close Zero x Zero = trav x -- if x = One x', we are in this case - close (Quad a11 a12 Zero a22) (Quad c11 c12 c21 c22) (Quad b11 b12 Zero b22) = quad <$> x11 <*> x12 <*> x21 <*> x22 - where x21 = close a22 c21 b11 - x11 = close a11 (a12 & rightOf x21 + c11) b11 - x22 = close a22 (leftOf x21 & b12 + c22) b22 - x12 = close a11 (a12 & rightOf x22 + leftOf x11 & b12 + c12) b22 - close Zero (Quad c11 c12 c21 c22) (Quad b11 b12 Zero b22) = close q0 (Quad c11 c12 c21 c22) (Quad b11 b12 Zero b22) - close (Quad a11 a12 Zero a22) (Quad c11 c12 c21 c22) Zero = close (Quad a11 a12 Zero a22) (Quad c11 c12 c21 c22) q0 - close (Quad a11 a12 Zero a22) (Col c1 c2) (Zero) = col <$> x1 <*> x2 - where x2 = close a22 c2 Zero - x1 = close a11 (mult p a12 (rightOf x2) + c1) Zero - close Zero (Row c1 c2) (Quad b11 b12 Zero b22) = row <$> x1 <*> x2 - where x1 = close Zero c1 b11 - x2 = close Zero (mult p (leftOf x1) b12 + c2) b22 - close a c b = error $ "closeDisjointP:" ++ intercalate "; " [showR a,showR c,showR b] - (&) :: RingP a => Mat x y a -> Mat z x a -> Mat z y (Pair a) - (&) = mult p - -showR :: Mat x y a -> String -showR Zero = "0" -showR (One _) = "1" -showR (Row a b) = "("++showR a++"-"++showR b++")" -showR (Col a b) = "("++showR a++"|"++showR b++")" -showR (Quad a b c d) = "#("++ intercalate "," [showR a,showR b,showR c,showR d]++")" - -bin' :: Shape' s -> Shape' s' -> Shape' (Bin s s') -bin' s s' = Bin' (sz' s + sz' s') s s' - -mkShape :: Int -> SomeShape -mkShape 1 = S (bin' Leaf' Leaf') -mkShape 2 = S (bin' (bin' Leaf' Leaf') Leaf') -mkShape n = case (mkShape n'1, mkShape n'2) of - (S x, S y) -> S (bin' x y) - where n'1 = n `div` 2 - n'2 = n - n'1 - 1 - -mkSing :: AbelianGroupZ a => Shape' x -> Shape' y -> a -> Mat x y a -mkSing (Bin' _ x1 x2) (Bin' _ y1 y2) a = quad Zero Zero (mkSing x1 y2 a) Zero -mkSing Leaf' Leaf' a = one a -mkSing Leaf' (Bin' _ y1 y2) a = col Zero (mkSing Leaf' y2 a) -mkSing (Bin' _ x1 x2) Leaf' a = row (mkSing x1 Leaf' a) Zero - -data SomeTri a where - T :: Shape' s -> Pair (Mat s s a) -> SomeTri a - -type Q a = SomeTri a - -mkUpDiag :: AbelianGroupZ a => [a] -> Shape' s -> Mat s s a -mkUpDiag [] Leaf' = Zero -mkUpDiag xs (Bin' _ s s') = Quad (mkUpDiag a s) (mkSing s' s c) Zero (mkUpDiag b s') - where (a,c:b) = splitAt (sz' s - 1) xs - -close :: RingP a => Bool -> Mat s s (Pair a) -> Pair (Mat s s a) -close p Zero = zero -close p (One x) = one <$> x -close p (Quad a11 a12 Zero a22) = quad' x11 (closeDisjointP p (leftOf x11) a12 (rightOf x22)) zero x22 - where x11 = close (not p) a11 - x22 = close (not p) a22 - -mkTree :: RingP a => [Pair a] -> SomeTri a -mkTree xs = case mkShape (length xs) of - S s -> T s (close True $ mkUpDiag xs s) - -quad' a b c d = quad <$> a <*> b <*> c <*> d - -mergein :: RingP a => Bool -> SomeTri a -> Pair a -> SomeTri a -> SomeTri a -mergein p (T y a) c (T x b) = T (bin' y x) (quad' a (closeDisjointP p (leftOf a) c' (rightOf b)) zero b) - where c' = mkSing x y c - --- | A variant of zipWith on vectors -zw :: (AbelianGroup a, AbelianGroup b) => (a -> b -> c) -> Vec y a -> Vec y b -> Vec y c -zw f Z Z = Z -zw f Z (a :! b) = zw f (Z :! Z) (a :! b) -zw f (a :! b) Z = zw f (a :! b) (Z :! Z) -zw f Z (O x) = O $ f zero x -zw f (O x) Z = O $ f x zero -zw f (O x) (O y) = O (f x y) -zw f (a :! b) (a' :! b') = zw f a a' :! zw f b b' - --- | Lookup in a vector -lk :: AbelianGroup a => Int -> Shape' x -> Vec x a -> a -lk n _ Z = zero -lk 0 Leaf' (O x) = x -lk i (Bin' _ s s') (x :! x') - | i < sz' s = lk i s x - | otherwise = lk (i - sz' s) s' x' - --- | Linearize a matrix -lin' :: AbelianGroup a => Mat x y a -> Vec y (Vec x a) -lin' Zero = Z -lin' (One a) = O (O a) -lin' (Row a b) = zw (:!) (lin' a) (lin' b) -lin' (Col a b) = lin' a :! lin' b -lin' (Quad a b c d) = zw (:!) (lin' a) (lin' b) :!zw (:!) (lin' c) (lin' d) - --- | Contents of a vector -contents :: Shape' x -> Vec x a -> [(Int,a)] -contents s Z = [] -contents s (O a) = [(0,a)] -contents (Bin' _ s s') (xs :! xs') = contents s xs ++ map (first (+sz' s)) (contents s' xs') - - -first f (a,b) = (f a,b) -second f (a,b) = (a,f b) - -instance AbelianGroup a => AbelianGroup (Vec x a) where - zero = Z - (+) = zw (+) - -data Path :: Shape -> * where - Here :: Path Leaf - Low :: Path s -> Path (Bin s s') - High :: Path s -> Path (Bin s' s) - -(<||>) :: Maybe (a,Path x) -> Maybe (a,Path x') -> Maybe (a,Path (Bin x x')) -x <||> y = (second High <$> y) <|> (second Low <$> x) - --- | What is, and where is the rightmost non-zero element on a given --- line of the matrix? -rightmostOnLine :: Path y -> Mat x y a -> Maybe (a,Path x) -rightmostOnLine _ Zero = Nothing -rightmostOnLine Here (One x) = Just (x,Here) -rightmostOnLine Here (Row a b) = rightmostOnLine Here a <||> rightmostOnLine Here b -rightmostOnLine (Low p) (Col a b) = rightmostOnLine p a -rightmostOnLine (High p) (Col a b) = rightmostOnLine p b -rightmostOnLine (Low p) (Quad a b _ _) = rightmostOnLine p a <||> rightmostOnLine p b -rightmostOnLine (High p) (Quad _ _ a b) = rightmostOnLine p a <||> rightmostOnLine p b - --- | Is this the rightmost path? -isRightmost :: Path x -> Bool -isRightmost (Low _) = False -isRightmost (Here) = True -isRightmost (High x) = isRightmost x - -results' :: AbelianGroup a => Mat y y a -> Path y -> [(Path y, a, Path y)] -results' m y | isRightmost y = [] - | otherwise = (y,a,x) : results' m x - where Just (a,x) = rightmostOnLine y m - -results :: AbelianGroupZ a => SomeTri a -> [(Int, a, Int)] -results (T s (m :/: m')) = [(fromPath s x,a,fromPath s y) | (x,a,y) <- results' (m+m') (leftMost s)] - -leftMost :: Shape' s -> Path s -leftMost Leaf' = Here -leftMost (Bin' _ s _) = Low $ leftMost s - -fromPath :: Shape' y -> Path y -> Int -fromPath _ Here = 0 -fromPath (Bin' _ s s') (Low x) = fromPath s x -fromPath (Bin' _ s s') (High x) = sz' s + fromPath s' x - - -root' :: AbelianGroup a => Mat x y a -> a -root' Zero = zero -root' (One x) = x -root' (Quad _ a _ _) = root' a -root' (Col a _) = root' a -root' (Row _ a) = root' a - -root (T _ (m :/: m')) = root' m + root' m' - -single x = T Leaf' (one <$> x) - -square2 x = T (bin' Leaf' Leaf') $ quad' zero (one <$> x) zero zero - -square3 p x y = T (bin' (bin' Leaf' Leaf') (Leaf')) - (quad' (quad' zero (one <$> x) zero zero) (Col <$> (one <$> mul p (leftOf x) (rightOf y)) <*> (one <$> y)) zero zero) - - -sz' :: Shape' s -> Int -sz' Leaf' = 1 -sz' (Bin' x l r) = x -- sz' l + sz' r - - -(|+|) = zipWith (++) -(-+-) = (++) - --- TODO: reimplement using lin' -lin :: AbelianGroup a => Shape' x -> Shape' y -> Mat x y a -> [[a]] -lin x y Zero = replicate (sz' y) $ replicate (sz' x) zero -lin _ _ (One x) = [[x]] -lin (Bin' _ x x') (Bin' _ y y') (Quad a b c d) = (lin x y a |+| lin x' y b) -+- (lin x y' c |+| lin x' y' d) -lin Leaf' (Bin' _ y y') (Col a b) = lin Leaf' y a -+- lin Leaf' y' b -lin (Bin' _ x x') Leaf' (Row a b) = (lin x Leaf' a) |+| (lin x' Leaf' b) - -sparse :: AbelianGroup a => Shape' x -> Shape' y -> Mat x y a -> [(Int,Int,a)] -sparse x y Zero = [] -sparse _ _ (One x) = [(0,0,x)] -sparse (Bin' _ x x') (Bin' _ y y') (Quad a b c d) = sparse x y a ++ shiftX x (sparse x' y b) ++ shiftY y (sparse x y' c) ++ shiftX x (shiftY y(sparse x' y' d)) -sparse Leaf' (Bin' _ y y') (Col a b) = sparse Leaf' y a ++ shiftY y (sparse Leaf' y' b) -sparse (Bin' _ x x') Leaf' (Row a b) = sparse x Leaf' a ++ shiftX x (sparse x' Leaf' b) - -shiftX x0 as = [(x+sz' x0,y,a) | (x,y,a) <- as] -shiftY y0 as = [(x,y+sz' y0,a) | (x,y,a) <- as] - -fingerprint (T s (m :/: m')) = zipWith (zipWith c) (lin s s m) (lin s s m') - where c x y = case (isZero x,isZero y) of - (True , True) -> ' ' - (True , False) -> '>' - (False , True) -> '<' - (False , False) -> 'X' - -scatterplot (T s (m :/: m')) = concat [show x ++ " " ++ show y ++ "\n" | (x,y,_) <- sparse s s m ++ sparse s s m'] diff --git a/source/runtime/Parsing/CNF.hs b/source/runtime/Parsing/CNF.hs deleted file mode 100644 index 1ad373bc..00000000 --- a/source/runtime/Parsing/CNF.hs +++ /dev/null @@ -1,154 +0,0 @@ -{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, - TypeSynonymInstances, FlexibleInstances #-} -module CNF where --- Tools for grammars in CNF (or Bin). - -import qualified Prelude as P -import Data.List (nub,partition) -import Zero -import Control.Applicative -import Data.Traversable -import Control.Monad (join) - -trans :: Eq a => [(a,a)] -> [(a,a)] -trans xys = iter [] xys - where - iter rel [] = - rel - - iter rel (xy:xys) | xy `elem` rel = - iter rel xys - - iter rel (xy@(x,y):xys) = - iter (xy:rel) (new ++ xys) - where - new = [ (a,y) | (a,b) <- rel, b==x ] - ++ [ (x,b) | (a,b) <- rel, y==a ] - -class Token tok where - -- | For printing - tokToString :: tok -> String - - -class (Eq nt, Token token, Eq token, Bounded nt, Enum nt) - => Grammar nt token | nt -> token where - -- | All NTs generating a given token - tokNT :: token -> [nt] - -- | productions a b = All NTs producing "a b" - productions :: nt -> nt -> [nt] - - startcats :: [nt] - - allNTs :: [nt] - allNTs = [minBound .. maxBound] - - merges :: [(nt,nt)] - merges = - [ (x,y) - | x <- allNTs - , y <- allNTs - , not (null (x `productions` y)) - ] - -- (a,b) in lefts, iff a can be on the left spine of a valid parse tree with b at the top - -- (a,b) in rights, iff a can be on the right spine of a valid parse tree with b at the top - lefts :: [(nt,nt)] - lefts = - trans [ (a,c) - | a <- allNTs - , b <- allNTs - , c <- a `productions` b - ] - rights :: [(nt,nt)] - rights = - trans [ (b,c) - | a <- allNTs - , b <- allNTs - , c <- a `productions` b - ] - -- (a,b) in leftNbs, iff a as a left neighbour of b is a valid reason to keep b alive - -- (a,b) in rightNbs, iff b as a right neighbour of a is a valid reason to keep a alive - leftNbs, rightNbs :: [(nt,nt)] - leftNbs = - nub - [ (a,b) - | (c,b) <- merges - , (a,c') <- rights - , c == c' - ] - - rightNbs = - nub - [ (a,b) - | (a,c) <- merges - , (b,c') <- lefts - , c == c' - ] - - -- a in leftEdge, iff a should be kept alive on the left-edge of a chart - -- a in rightEdge, iff a should be kept alive on the right-edge of a chart - leftEdge, rightEdge :: [nt] - leftEdge = - nub - [ b - | (a,b) <- merges - ] - - rightEdge = - nub - [ a - | (a,b) <- merges - ] - - -class (Eq nt, Token token, Eq token, Bounded nt, Enum nt) - => GrammarP nt token | nt -> token where - -- | All NTs generating a given token - tokNTP :: Bool -> token -> Pair [nt] - tokNTP _ = pure . tokNTN - tokNTN :: token -> [nt] - -- | productions a b = All NTs producing "a b" - productionsP :: Bool -> nt -> nt -> Pair [nt] - productionsP _ x y = pure $ productionsN x y - productionsN :: nt -> nt -> [nt] - - -data AST cat token = L cat token - | B cat (AST cat token) (AST cat token) - deriving (Eq) - --- | Linearisation of an AST. -lin (L _ s) = tokToString s -lin (B _ x y) = lin x ++ " " ++ lin y - --- | Category of an AST -cat (L x _) = x -cat (B x _ _) = x - - -instance (GrammarP nt token, Show nt) => Show (AST nt token) where - show = sho - -sho (L x t) = show x ++ "=" ++ tokToString t -sho (B x s t) = show x ++ "{" ++ sho s ++ "," ++ sho t ++ "}" - - -type Set a = [a] - - --- Sets form an abelian group -instance AbelianGroup (Set a) where - zero = [] - (+) = (++) - -instance AbelianGroupZ (Set a) where - isZero = null - --- Sets of ASTs form a ring, lifting the production rules. -instance Grammar nt token => Ring (Set (AST nt token)) where - xs * ys = [B c x y | x <- xs, y <- ys, c <- productions (cat x) (cat y)] - -instance GrammarP nt token => RingP (Set (AST nt token)) where - mul p xs ys = join <$> sequenceA [map (\z -> B z x y) <$> productionsP p (cat x) (cat y) | x <- xs, y <- ys] - - - diff --git a/source/runtime/Parsing/Chart.hs b/source/runtime/Parsing/Chart.hs deleted file mode 100644 index 5fd6859f..00000000 --- a/source/runtime/Parsing/Chart.hs +++ /dev/null @@ -1,76 +0,0 @@ -{-# LANGUAGE NoMonomorphismRestriction, TypeSynonymInstances, FlexibleInstances #-} - -module Parsing.Chart where - -import Data.Array -import Data.Maybe -import Prelude () -import Data.Traversable (sequenceA) -import Control.Applicative ((<$>),(<*>),pure) -import Control.Monad(join) - -import Data.List (splitAt) -import Algebra.RingUtils -import qualified Data.Matrix.Quad as Q -import Data.Matrix.Class - -fingerprint = Q.fingerprint - -{- -mkTreeHelp alt s = sweeps (map single s) - where - sweeps [] = error "can't parse the empty string, sorry" - sweeps [p] = p - sweeps ps = sweeps (pairs ps alts) - - pairs [] _ = [] - pairs [p] _ = [p] - pairs (p:q:ps) (b:bs) = (merging b p q) : pairs ps bs - - alts = cycle alt - -} - --- mkTree2 :: (AbelianGroupZ (c a), RingP a, IsChart c) => Bool -> [Pair a] -> c a -mkTree2 :: RingP a => Bool -> [Pair a] -> Q.Q a -mkTree2 p [] = error "can't parse the empty string, sorry" -mkTree2 p [x] = Q.square2 x -mkTree2 p [x,y] = Q.square3 p x y -mkTree2 p leaves = Q.mergein p (mkTree2 False xs) y (mkTree2 True zs) - where (xs,y:zs) = splitAt n2 leaves - n2 = length leaves `div` 2 - - --- mkTree :: (RingP a, IsChart c) => [Pair a] -> c a -mkTree = mkTree2 False -- mkTreeHelp [False,True] -mkTree' = mkTree2 True -- mkTreeHelp [True,False] - - -type Set a = [a] - --- Sets form an abelian group -instance AbelianGroup (Set a) where - zero = [] - (+) = (++) - -instance AbelianGroupZ (Set a) where - isZero = null - -type MT2 a = Q.Q a - -genXPM xs@(h:_) = unlines $ - ["! XPM2", - -- - show width ++ " " ++ show height ++ " 4 1", - "X c cyan", - "< c blue", - "> c red", - " c black" - ] ++ - xs - where width = length h - height = length xs - -root = Q.root -mergein a c b = Q.mergein a c b -single x = Q.single x - diff --git a/source/runtime/Parsing/TestProgram.hs b/source/runtime/Parsing/TestProgram.hs deleted file mode 100644 index 0868c484..00000000 --- a/source/runtime/Parsing/TestProgram.hs +++ /dev/null @@ -1,84 +0,0 @@ -{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-} -module Parsing.TestProgram where - -import System.IO ( stdin, hGetContents ) -import System.Environment ( getArgs, getProgName ) - -import GHC.Exts -import Control.Monad -import Control.Applicative (pure) -import Parsing.Chart hiding (fingerprint,mkTree) -import Data.Matrix.Quad -import Data.Pair -import Algebra.RingUtils - -type Verbosity = Int - -putStrV :: Verbosity -> String -> IO () -putStrV v s = if v > 1 then putStrLn s else return () - - -mainTest :: forall category token. - (RingP [(category,Any)], Eq category) => - ((category,Any) -> String) -> - (Bool -> token -> Pair [(category,Any)]) -> - (String -> [token]) -> - (token -> (Int,Int)) -> - (category -> String) -> - (category -> [category]) -> - IO () -mainTest showAst cnfToksToCat myLLexer getTokPos describe follows = - do args <- getArgs - case args of - [] -> hGetContents stdin >>= run "stdin" 2 - "-s":fs -> mapM_ (runFile 0) fs - fs -> mapM_ (runFile 2) fs - - where - neighbors a b = b `elem` follows a - showResults :: [(category,Any)] -> IO () - showResults x = do - putStrLn $ show (length x) ++ " results" - forM_ x $ \(cat,ast) -> do - putStrLn $ describe cat - putStrLn $ showAst (cat,ast) - - runFile v f = putStrLn f >> readFile f >>= run f v - run f v s = - do case rs of - [(_,x,_)] -> showResults x - _ -> do let errs = pairs rs - best = minimum $ map quality errs - mapM_ (putStrLn . showErr ts) $ filter (\x -> quality x == best) errs - when (v >= 2) $ do - writeFile (f ++ ".xpm") (genXPM $ fingerprint chart) - let scatt = scatterplot chart - putStrLn $ "Scatterplot data size:" ++ show (length scatt) - writeFile (f ++ ".data") scatt - where ts = myLLexer s - chart = mkTree $ zipWith cnfToksToCat (cycle [False,True]) ts - rs = results chart - - showTokPos :: (Int,Int) -> String - showTokPos (l,c) = show l ++ "," ++ show (c-1) - - showPos :: [token] -> Int -> String - showPos ts x = showTokPos (getTokPos $ ts !! x) - - showErr ts ((_,x',p),(_,y',_)) = - showPos ts p ++ ": cannot combine " ++ showBestCat x' ++ " with " ++ showBestCat y' - - quality (a@(_,x',p),b@(_,y',_)) = (or [ neighbors x y | x <- map fst x', y <- map fst y'], - (resSz a) Prelude.+ (resSz b)) - - - showBestCat ((x,_):_) = describe x - -pairs (x:y:xs) = (x,y):pairs (y:xs) -pairs _ = [] - -resSz (i,_,j) = j-i - - - - diff --git a/source/src/BNFC/Backend/Haskell.hs b/source/src/BNFC/Backend/Haskell.hs index 2a110eb8..6863ad93 100644 --- a/source/src/BNFC/Backend/Haskell.hs +++ b/source/src/BNFC/Backend/Haskell.hs @@ -34,7 +34,6 @@ import BNFC.Backend.Haskell.CFtoPrinter import BNFC.Backend.Haskell.CFtoLayout import BNFC.Backend.Haskell.HsOpts import BNFC.Backend.Haskell.MkErrM -import BNFC.Backend.Haskell.ToCNF as ToCNF import BNFC.Backend.Haskell.Utils import BNFC.Backend.Txt2Tag import BNFC.Backend.XML @@ -72,8 +71,8 @@ makeHaskell opts cf = do Ctrl.when (hasLayout cf) $ mkfile (layoutFile opts) $ cf2Layout (tokenText opts) layMod lexMod cf - -- Generate Happy parser and matching test program unless --cnf. - Ctrl.unless (cnf opts) $ do + -- Generate Happy parser and matching test program. + do mkfile (happyFile opts) $ cf2Happy parMod absMod lexMod (glr opts) (tokenText opts) (functor opts) cf -- liftIO $ printf "%s Tested with Happy 1.15\n" (happyFile opts) @@ -92,12 +91,6 @@ makeHaskell opts cf = do 1 -> makeXML opts False cf _ -> return () - -- CNF backend. Currently does not make use of layout. - Ctrl.when (cnf opts) $ do - mkfile (cnfTablesFile opts) $ ToCNF.generate opts cf - mkfile (cnfTestFile opts) $ ToCNF.genTestFile opts cf - mkfile (cnfBenchFile opts) $ ToCNF.genBenchmark opts - -- Generate Agda bindings for AST, Printer and Parser. Ctrl.when (agda opts) $ makeAgda time opts cf @@ -112,12 +105,8 @@ _oldMakefile -> Doc -- ^ Content of the makefile. _oldMakefile opts makeFile = vcat [ Makefile.mkRule "all" [] $ concat $ - [ [ unwords $ [ "happy -gca" ] ++ glrParams ++ [ happyFile opts ] | not (cnf opts) ] + [ [ unwords $ [ "happy -gca" ] ++ glrParams ++ [ happyFile opts ] ] , [ "alex -g " ++ alexFile opts ] - , [ if cnf opts - then unwords [ "ghc --make", cnfTestFile opts, "-o", cnfTestFileExe opts ] - else unwords [ "ghc --make", tFile opts, "-o", tFileExe opts ] - ] ] , cleanRule opts , distCleanRule opts makeFile @@ -165,7 +154,7 @@ distCleanRule opts makeFile = Makefile.mkRule "distclean" ["clean"] $ , agdaLibFile -- IOLib.agda , agdaMainFile -- Main.agda , (\ opts -> dir ++ lang opts ++ ".dtd") - ] -- TODO: clean up cnf files + ] -- Files that have no .bak variant , map (\ (file, ext) -> mkFile withLang file ext opts) [ ("Test" , "") @@ -206,9 +195,9 @@ makefile opts makeFile = vcat -- from the Makefile. Thus, we have to drop the rule for -- reinvokation of bnfc. , when (isDefault outDir opts) $ bnfcRule - , unless (cnf opts) $ happyRule + , happyRule , alexRule - , if cnf opts then testCNFRule else testParserRule + , testParserRule , when (agda opts) $ agdaRule , vcat [ "# Rules for cleaning generated files." , "" ] , cleanRule opts @@ -231,8 +220,7 @@ makefile opts makeFile = vcat , Makefile.mkRule "all" tgts [] ] where - tgts | cnf opts = [ cnfTestFileExe opts ] - | otherwise = concat $ + tgts = concat $ [ [ tFileExe opts ] , [ "Main" | agda opts ] ] @@ -245,7 +233,7 @@ makefile opts makeFile = vcat recipe = unwords [ "bnfc", printOptions opts{ make = Nothing } ] tgts = unwords . concat $ [ alexEtc - , if cnf opts then [ cnfTestFile opts ] else [ happyFile opts, tFile opts ] + , [ happyFile opts, tFile opts ] , when (agda opts) agdaFiles ] alexEtc = map ($ opts) [ errFile, alexFile, printerFile ] @@ -280,12 +268,6 @@ makefile opts makeFile = vcat , printerFile ] - -- | Rule to build CNF test parser. - testCNFRule :: Doc - testCNFRule = Makefile.mkRule (cnfTestFileExe opts) deps [ "ghc --make $< -o $@" ] - where - deps = [ cnfTestFile opts {- must be first! -} , alexFileHs opts ] - -- | Rule to build Agda parser. agdaRule :: Doc agdaRule = Makefile.mkRule "Main" deps [ "agda --no-libraries --ghc --ghc-flag=-Wwarn $<" ] diff --git a/source/src/BNFC/Backend/Haskell/HsOpts.hs b/source/src/BNFC/Backend/Haskell/HsOpts.hs index 2aab6438..b5d69264 100644 --- a/source/src/BNFC/Backend/Haskell/HsOpts.hs +++ b/source/src/BNFC/Backend/Haskell/HsOpts.hs @@ -41,18 +41,6 @@ xmlFileM = mkMod withLang "XML" composOpFile = mkFile noLang "ComposOp" "hs" composOpFileM = mkMod noLang "ComposOp" --- Files created by the CNF variant - -cnfTablesFile, cnfTablesFileM - , cnfTestFile, cnfTestFileExe - , cnfBenchFile - :: Options -> String -cnfTablesFile = mkFile withLang "CnfTables" "hs" -cnfTablesFileM = mkMod withLang "CnfTables" -cnfTestFile = mkFile withLang "Test" "hs" -- WAS: TestCNF, but just naming it Test is easier for testsuite -cnfTestFileExe = mkFile withLang "Test" "" -cnfBenchFile = mkFile withLang "BenchCNF" "hs" - -- Files created by the Agda backend agdaASTFile diff --git a/source/src/BNFC/Backend/Haskell/ToCNF.hs b/source/src/BNFC/Backend/Haskell/ToCNF.hs deleted file mode 100644 index 01020e03..00000000 --- a/source/src/BNFC/Backend/Haskell/ToCNF.hs +++ /dev/null @@ -1,280 +0,0 @@ -{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, CPP #-} -{- - Copyright (C) 2012 Authors: - Jean-Philippe Bernardy. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA --} - -{-# LANGUAGE OverloadedStrings #-} - -module BNFC.Backend.Haskell.ToCNF (generate, genTestFile, genBenchmark) where - -{- - -Construction of CYK tables. The algorithm follows: - -Lange, Martin; Leiß, Hans (2009), "To CNF or not to CNF? An Efficient -Yet Presentable Version of the CYK Algorithm", Informatica Didactica - --} -import BNFC.ToCNFCore -import BNFC.CF hiding (App,Exp) -import BNFC.Backend.Haskell.HsOpts -#if __GLASGOW_HASKELL__ < 710 -import Control.Applicative hiding (Const) -#endif -import qualified Data.Map as Map -#if !(MIN_VERSION_base(4,11,0)) -import Data.Monoid -#endif -import Data.Pair -import Text.PrettyPrint.HughesPJ hiding (first,(<>)) - --- Code generation - -incomment x = "{-" <> x <> "-}" - -generate :: Options -> CF -> Doc -generate opts cf0 = vcat $ - [ header opts - , genShowFunction cf0 - , genCatTags cf1 - , genDesc cf1 descriptions - , genNeighborSet neighbors - , genCombTable units $ onRules (filter (not . isUnitRule)) cf - , genTokTable units cf - , incomment $ vcat $ - [ "Normalised grammar:" - , text $ show cf - , "Unit relation:" - , prettyUnitSet units - ] - ] - where - (cf1, cf, units, descriptions, neighbors) = toCNF cf0 - -class Pretty a where - pretty :: a -> Doc - -instance (Pretty k, Pretty v) => Pretty (Set k v) where - pretty s = sep [pretty k <> " --> " <> pretty v | (k,x) <- Map.assocs s, v <- x] - -instance Pretty (Either Cat String) where - pretty (Left x) = text $ show x - pretty (Right x) = quotes $ text x - -instance Pretty String where - pretty = text - -prettyUnitSet units = vcat $ - [ prettyExp f <> " : " <> catTag cat <> " --> " <> text (show cat') - | (cat, x) <- Map.assocs units - , (f, cat') <- x - ] - -header opts = vcat $ - [ "{-# LANGUAGE MagicHash, FlexibleInstances #-}" - , "" - , "module " <> text (cnfTablesFileM opts) <> " where" - , "" - , "import GHC.Prim" - , "import Control.Applicative hiding (Const)" - , "" - , "import Algebra.RingUtils" - , "import Parsing.Chart ()" - , "" - , "import " <> text (absFileM opts) - , "import " <> text (alexFileM opts) - , "import " <> text ( printerFileM opts) - , "" - , "readInteger :: String -> Integer" - , "readInteger = read" - , "" - , "readDouble :: String -> Double" - , "readDouble = read" - , "" - , "instance RingP [(CATEGORY,a)] where" - , " mul p a b = trav [ map (app tx ty) l :/: map (app tx ty) r | (x, tx) <- a, (y, ty) <- b, let l:/:r = combine p x y ]" - , " where " - , " trav :: [Pair [a]] -> Pair [a]" - , " trav [] = pure []" - , " trav (x:xs) = (++) <$> x <*> trav xs" - , " app tx ty (z, f) = (z, f tx ty)" - , "" - ] - -genShowFunction cf = - hang "showAst (cat, ast) = case cat of " 6 $ vcat $ - [ vcat - [ hsep [ catTag (Left cat), "->", "printTree", parens ("(unsafeCoerce# ast) ::" <+> text (show cat)) ] - | cat <- filter isDataOrListCat $ reallyAllCats cf - ] - , "_ -> \"Unprintable category\"" - ] - -genCatTags :: CFG Exp -> Doc -genCatTags cf = vcat - [ "data CATEGORY = " <> punctuate' " |" cs - , " deriving (Eq, Ord, Show)" - ] - where - cs = map catTag $ allSyms cf - -genDesc :: CFG Exp -> CatDescriptions -> Doc -genDesc cf descs = vcat $ - [ "describe " <> catTag s <> " = " <> text (show (descOf s)) - | s <- allSyms cf - ] - where - descOf :: Either Cat String -> String - descOf (Right x) = "token " <> x - descOf (Left x) = maybe (show x) render $ Map.lookup x descs - -genCombTable :: UnitRel Cat -> CFG Exp -> Doc -genCombTable units cf = vcat - [ "combine :: Bool -> CATEGORY -> CATEGORY -> Pair [(CATEGORY, a -> a -> a)]" - , genCombine units cf - , "combine _ _ _ = pure []" - ] - -allSyms :: CFG Exp -> [Either Cat String] -allSyms cf = concat $ - [ map Left $ reallyAllCats cf - , map (Left . TokenCat) $ literals cf - , map (Right . fst) $ cfTokens cf - ] - -ppPair (x, y) = parens $ hsep [ x <> comma, y ] - -unsafeCoerce' = app' (Con "unsafeCoerce#") - -prettyPair (x :/: y) = sep [ x, ":/:", y ] - -prettyListFun xs = parens $ sep (map (<> "$") xs) <> "[]" - - -genCombine :: UnitRel Cat -> CFG Exp -> Doc -genCombine units cf = vcat $ map genEntry $ group' $ map (alt units) (cfgRules cf) - where - genEntry :: ((RHSEl,RHSEl),[(Cat,Exp)]) -> Doc - genEntry ((r1,r2),cs) = hsep $ - [ "combine p", catTag r1, catTag r2, equals - , prettyPair (genList <$> splitOptim (Left . fst) cf cs) - ] - mkLam body = "\\ x y -> " <> body - genList xs = prettyListFun $ - [ p $ ppPair (catTag . Left $ x, mkLam . prettyExp . unsafeCoerce' $ y) - | ((x, y), p) <- xs - ] - -alt :: UnitRel Cat -> Rul Exp -> ((RHSEl,RHSEl),[(Cat,Exp)]) -alt units (Rule f (WithPosition _ c) [r1, r2] _) = ((r1, r2), initial:others) - where - initial = (c, f `appMany` args) - others = [ (c', f' `app'` (f `appMany` args)) - | (f',c') <- lookupMulti (Left c) units - ] - args = map (unsafeCoerce' . Con) $ [ "x" | isCat r1 ] ++ [ "y" | isCat r2 ] -alt _ _ = error "Only works with binary rules" - - - -genTokTable :: UnitRel Cat -> CFG Exp -> Doc -genTokTable units cf = vcat - [ "tokenToCats :: Bool -> Token -> Pair [(CATEGORY,a)]" - , vcat $ map (genSpecEntry cf units) $ tokInfo cf - , vcat $ map (genTokEntry cf units) $ cfTokens cf - , "tokenToCats p t = error (\"unknown token: \" ++ show t)" - ] - -tokInfo cf = concat $ - [ [ (catChar , "TC", Con "head") - , (catString , "TL", Id) - , (catInteger, "TI", Con "readInteger") - , (catDouble , "TD", Con "readDouble") - ] - , [ (catIdent,"TV", Con "Ident") | hasIdent cf ] - , [ (t, "T_" <> text t, Con t) | (t, _) <- tokenPragmas cf ] - ] - -genTokCommon cf xs = prettyPair (gen <$> splitOptim fst cf xs) - where gen ys = prettyListFun [ p (ppPair (catTag x, y)) | ((x, y), p) <- ys ] - -genSpecEntry cf units (tokName, constrName, fun) = - "tokenToCats p (PT (Pn _ l c) (" <> constrName <> " x)) = " <> genTokCommon cf xs - where - xs = map (second (prettyExp . (\ f -> unsafeCoerce' (f `app'` tokArgs)))) $ - (Left $ TokenCat tokName, fun) : [ (Left c, f `after` fun) | (f, c) <- lookupMulti (Left $ TokenCat tokName) units ] - tokArgs | isPositionCat cf tokName = Con "((l, c), x)" - | otherwise = Con "x" - -genTokEntry cf units (tok,x) = - " -- " <> text tok $$ - "tokenToCats p (PT posn (TS _ " <> int x <> ")) = " <> genTokCommon cf xs - where - xs = (Right tok, tokVal) : - [ (Left c, prettyExp (unsafeCoerce' f)) | (f, c) <- lookupMulti (Right tok) units ] - tokVal = "error" <> (text $ show $ "cannot access value of token: " ++ tok) - -ppList = brackets . punctuate' ", " - -genNeighborSet ns = vcat $ - [ vcat [ hsep [ "neighbors", catTag x, equals, ppList (map catTag y) ] | (x, y) <- ns ] - , "neighbors _ = []" - ] - ------------------------- --- Test file generation - -genTestFile :: Options -> CF -> Doc -genTestFile opts _ = vcat $ - [ "module Main where" - , "" - , "import Parsing.TestProgram" - , "import" <+> text (alexFileM opts) - , "import" <+> text (cnfTablesFileM opts) - , "" - , "main = mainTest showAst tokenToCats tokens tokenLineCol describe neighbors" - ] - - -genBenchmark opts = vcat $ - [ "import Control.Applicative" - , "import GHC.Exts" - , "import System.Environment ( getArgs )" - , "" - , "import Criterion.Main" - , "" - , "import Algebra.RingUtils" - , "import Parsing.Chart" - , "" - , "import" <+> text (alexFileM opts) <+> "as Lexer" - , "import" <+> text (cnfTablesFileM opts) <+> "as Parser" - , "" - , "type T = [(CATEGORY,a)]" - , "" - , "pLGrammar :: [Pair T] -> MT2 T" - , "pLGrammar = mkTree" - , "" - , "main = do" - , " f:_ <- getArgs" - , " s <- readFile f" - , " let ts = zipWith tokenToCats (cycle [False, True]) (Lexer.tokens s)" - , " (ts1, x:ts2) = splitAt (length ts `div` 2) ts" - , " cs = [mkTree ts1, mkTree' ts2]" - , " work [c1, c2] = show $ map fst $ root $ mergein False c1 x c2" - , " defaultMain [bench f $ nf work cs] -- note the hack!!!" - ] diff --git a/source/src/BNFC/GetCF.hs b/source/src/BNFC/GetCF.hs index fa9fd802..9658a6bb 100644 --- a/source/src/BNFC/GetCF.hs +++ b/source/src/BNFC/GetCF.hs @@ -201,7 +201,7 @@ die msg = do getCF :: SharedOptions -> Abs.Grammar -> Err CF getCF opts (Abs.Grammar defs0) = do - let (defs,inlineDelims)= if cnf opts then (defs0,id) else removeDelims defs0 + let (defs,inlineDelims)= removeDelims defs0 (pragma,rules0) = partitionEithers $ concat $ mapM transDef defs `runTrans` opts rules = inlineDelims rules0 reservedWords = nub [t | r <- rules, isParsable r, Right t <- rhsRule r, not $ all isSpace t] diff --git a/source/src/BNFC/Options.hs b/source/src/BNFC/Options.hs index 3a24459f..5bb397af 100644 --- a/source/src/BNFC/Options.hs +++ b/source/src/BNFC/Options.hs @@ -122,7 +122,6 @@ data SharedOptions = Options , tokenText :: TokenText -- ^ Options @--bytestrings@, @--string-token@, and @--text-token@. , glr :: HappyMode -- ^ Happy option @--glr@. , xml :: Int -- ^ Options @--xml@, generate DTD and XML printers. - , cnf :: Bool -- ^ Option @--cnf@. Generate CNF-like tables? , agda :: Bool -- ^ Option @--agda@. Create bindings for Agda? --- OCaml specific , ocamlParser :: OCamlParser -- ^ Option @--menhir@ to switch to @Menhir@. @@ -156,7 +155,6 @@ defaultOptions = Options , tokenText = StringToken , glr = Standard , xml = 0 - , cnf = False , agda = False -- OCaml specific , ocamlParser = OCamlYacc @@ -216,7 +214,6 @@ printOptions opts = unwords . concat $ , [ "--glr" | glr opts == GLR ] , [ "--xml" | xml opts == 1 ] , [ "--xmlt" | xml opts == 2 ] - , [ "--cnf" | cnf opts ] , [ "--agda" | agda opts ] -- C# options: , [ "--vs" | visualStudio opts ] @@ -362,10 +359,7 @@ specificOptions = , ( Option [] ["xmlt"] (NoArg (\o -> o {xml = 2})) "DTD and an XML printer, another encoding" , haskellTargets ) - -- CNF and Agda do not support the GADT syntax - , ( Option [] ["cnf"] (NoArg (\o -> o {cnf = True})) - "Use the CNF parser instead of happy" - , [TargetHaskell] ) + -- Agda does not support the GADT syntax , ( Option [] ["agda"] (NoArg (\o -> o { agda = True, tokenText = TextToken })) "Also generate Agda bindings for the abstract syntax" , [TargetHaskell] ) @@ -581,6 +575,7 @@ classifyUnknownOption = \case "--alex2" -> supportRemovedIn290 $ "Alex version 2" "--alex3" -> obsolete s@"--sharestrings" -> optionRemovedIn290 s + s@"--cnf" -> optionRemovedIn290 s "--csharp" -> supportRemovedIn290 "C#" "--profile" -> supportRemovedIn290 "permutation profiles" _ -> unknown diff --git a/source/src/BNFC/ToCNFCore.hs b/source/src/BNFC/ToCNFCore.hs deleted file mode 100644 index 2d96a2e6..00000000 --- a/source/src/BNFC/ToCNFCore.hs +++ /dev/null @@ -1,315 +0,0 @@ -{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, CPP #-} -{-# LANGUAGE RecordWildCards #-} -{- - Copyright (C) 2012 Authors: - Jean-Philippe Bernardy. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA --} - -{-# LANGUAGE OverloadedStrings #-} - -module BNFC.ToCNFCore (toCNF, isCat, group', catTag, punctuate', onRules, isUnitRule, splitOptim, second, lookupMulti, - Set, CatDescriptions, UnitRel, RHSEl, Exp(..), prettyExp, appMany, app',after) where - -{- - -Construction of CYK tables. The algorithm follows: - -Lange, Martin; Leiß, Hans (2009), "To CNF or not to CNF? An Efficient -Yet Presentable Version of the CYK Algorithm", Informatica Didactica - --} - -import BNFC.CF hiding (App,Exp) -import Control.Monad.RWS -#if __GLASGOW_HASKELL__ < 710 -import Control.Applicative hiding (Const) -#endif - -import Data.Bifunctor (second) -import Data.Char (isAlphaNum, ord) -import Data.Function (on) -import Data.Functor (($>)) -import Data.List (nub, sortBy, sort) -import Data.Map (Map) -import qualified Data.Map as Map -import Data.Pair - -import Text.PrettyPrint.HughesPJ hiding (first, (<>)) - -onRules ::([Rul f] -> [Rul g]) -> CFG f -> CFG g -onRules f cfg@CFG{..} = cfg { cfgRules = f cfgRules } - -toCNF :: IsFun a => CFG a - -> (CFG Exp, CFG Exp, UnitRel Cat, CatDescriptions, - [(Either Cat String, [Either Cat String])]) -toCNF cf0 = (cf1,cf2,units,descriptions,neighbors) - where cf01 = funToExp . onRules (filter isParsable) $ cf0 - (rules',descriptions) = toBin (cfgRules cf01) - cf1 = cf01 { cfgRules = rules' } - cf2 = delNull cf1 - units = unitSet cf2 - neighbors = neighborSet cf2 - -funToExp :: IsFun a => CFG a -> CFG Exp -funToExp = fmap toExp - -toExp :: IsFun a => a -> Exp -toExp f | isCoercion f = Id - | otherwise = Con $ funName f - -isCat (Right _) = False -isCat (Left _) = True - - -group0 :: Eq a => [(a,[b])] -> [(a,[b])] -group0 [] = [] -group0 ((a,bs):xs) = (a,bs ++ concatMap snd ys) : group0 zs - where (ys,zs) = span (\x -> fst x == a) xs - -group' :: Ord a => [(a,[b])] -> [(a,[b])] -group' = group0 . sortBy (compare `on` fst) - -catTag :: Either Cat String -> Doc -catTag (Left c) = "CAT_" <> text (concatMap escape (show c)) -catTag (Right t) = "TOK_" <> text (concatMap escapeToken t) - -escape c | isAlphaNum c || c == '_' = [c] -escape '[' = "" -escape ']' = "_List" -escape '{' = "OPEN_" -escape '}' = "CLOS_" -escape '@' = "BIN_" -escape c = show (ord c) ++ "_" - -escapeToken c | isAlphaNum c || c == '_' = [c] -escapeToken '(' = "LPAREN_" -escapeToken ')' = "RPAREN_" -escapeToken '[' = "LBRACKET_" -escapeToken ']' = "RBRACKET_" -escapeToken '{' = "LBRACE_" -escapeToken '}' = "RBRACE_" -escapeToken '~' = "TILDE_" -escapeToken '^' = "CARET_" -escapeToken '*' = "STAR_" -escapeToken '+' = "PLUS_" -escapeToken '-' = "DASH_" -escapeToken '/' = "SLASH_" -escapeToken '.' = "DOT_" -escapeToken ',' = "COMMA_" -escapeToken ';' = "SEMI_" -escapeToken ':' = "COLON_" -escapeToken '=' = "EQ_" -escapeToken '<' = "LT_" -escapeToken '>' = "GT_" -escapeToken '&' = "AMP_" -escapeToken '|' = "BAR_" -escapeToken '%' = "PERCENT_" -escapeToken '?' = "QUESTION_" -escapeToken '!' = "BANG_" --- add more if you have fun --- or fall back to ASCII code: -escapeToken c = show (ord c) ++ "_" - -punctuate' p = cat . punctuate p --------------------------------------------------------------- --- BIN: make sure no rule has more than 2 symbols on the rhs - -allocateCatName = do - n <- get - put (1+n) - return $ show n - -toBin :: [Rul Exp] -> ([Rul Exp], CatDescriptions) -toBin cf = (a,w) - where (a,_,w) = runRWS (concat <$> forM cf toBinRul) () 0 - -type CatDescriptions = Map Cat Doc - --- | Convert a rule into a number of equivalent rules with at most 2 --- symbols on the rhs. --- Also writes an explanation of what new categories are. -toBinRul :: Rul Exp -> RWS () CatDescriptions Int [Rul Exp] -toBinRul (Rule f cat rhs internal) | length rhs > 2 = do - cat' <- liftM Cat allocateCatName - r' <- toBinRul $ Rule f (cat $> cat') p internal - tell $ Map.singleton cat' (int (length p) <> "-prefix of " <> prettyExp f <> " " <> parens (prettyRHS p)) - return $ Rule (Con "($)") cat [Left cat',l] internal - : r' - where l = last rhs - p = init rhs -toBinRul r = return [r] - -prettyRHS = hcat . punctuate " " . map (either (text . show) (quotes . text)) - ---------------------------- --- Fixpoint utilities - -x ∪ y = sort $ nub (x ++ y) - -lookupMulti cat nullset = maybe [] id (Map.lookup cat nullset) - -type Set k x = Map k [x] - -fixpointOnGrammar :: (Show k, Show x,Ord k, Ord x) => String -> (Set k x -> Rul f -> Set k x) -> CFG f -> Set k x -fixpointOnGrammar name f cf = case fixn 100 step Map.empty of - Left x -> error $ "Could not find fixpoint of " ++ name ++". Last iteration:\n" ++ show x - Right x -> x - where step curSet = Map.unionsWith (∪) (map (f curSet) (cfgRules cf)) - -fixn :: Eq a => Int -> (a -> a) -> a -> Either a a -fixn 0 _ x = Left x -fixn n f x = if x' == x then Right x else fixn (n-1) f x' - where x' = f x - -------------------------------------------------------- --- DEL : make sure no rule has 0 symbol on the rhs - -type Nullable = Set Cat Exp - -cross :: [[a]] -> [[a]] -cross [] = [[]] -cross (x:xs) = [y:ys | y <- x, ys <- cross xs] - -nullRule :: Nullable -> Rul Exp -> (Cat,[Exp]) -nullRule nullset (Rule f c rhs _) = (wpThing c, map (appMany f) (cross (map nulls rhs))) - where nulls (Right _) = [] - nulls (Left cat) = lookupMulti cat nullset - -nullSet :: CFG Exp -> Nullable -nullSet = fixpointOnGrammar "nullable" (\s r -> uncurry Map.singleton (nullRule s r)) - --- | Replace nullable occurences by nothing, and adapt the function consequently. -delNullable :: Nullable -> Rul Exp -> [Rul Exp] -delNullable nullset r@(Rule f cat rhs internal) = case rhs of - [] -> [] - [_] -> [r] - [r1,r2] -> [r] ++ [Rule (app' f x) cat [r2] internal | x <- lk' r1] - ++ [Rule (app2 (isCat r1) f x) cat [r1] internal | x <- lk' r2] - _ -> error $ "Panic:" ++ show r ++ "should have at most two elements." - where lk' (Right _) = [] - lk' (Left cat) = lookupMulti cat nullset - -delNull :: CFG Exp -> CFG Exp -delNull cf = onRules (concatMap (delNullable (nullSet cf))) cf - - ---------------- --- UNIT - -type UnitRel cat = Set (Either cat String) (Exp,cat) - --- (c,(f,c')) ∈ unitSet ⇒ f : c → c' - -unitSet :: CFG Exp -> UnitRel Cat -unitSet = fixpointOnGrammar "unit set" unitRule - -unitRule unitSet (Rule f (WithPosition _ c) [r] _internal) = Map.singleton r $ - (f,c) : [(g `appl` f,c') | (g,c') <- lookupMulti (Left c) unitSet] - where appl = case r of - Left _ -> after - Right _ -> app' -unitRule _ _ = Map.empty - -isUnitRule (Rule _ _ [_] _) = True -isUnitRule _ = False - - ------------------------- --- Left/Right occurences -type RHSEl = Either Cat String - -isOnLeft, isOnRight :: RHSEl -> Rul f -> Bool -isOnLeft c (Rule _ _ [c',_] _) = c == c' -isOnLeft _ _ = False - -isOnRight c (Rule _ _ [_,c'] _) = c == c' -isOnRight _ _ = False - -isEntryPoint cf el = either (`elem` allEntryPoints cf) (const False) el - -occurs :: (RHSEl -> Rul f -> Bool) -> RHSEl -> CFG f -> Bool -occurs where_ el cf = any (where_ el) (cfgRules cf) - -splitLROn :: (a -> RHSEl) -> CFG f -> [a] -> Pair [a] -splitLROn f cf xs = filt <*> pure xs - where filt = filter (\c -> occurs isOnLeft (f c) cf || isEntryPoint cf (f c)) :/: - filter (\c -> occurs isOnRight (f c) cf) - -isSpecial (Left (Cat ('@':'@':_))) = True -isSpecial _ = False - -optim :: (a -> RHSEl) -> Pair [a] -> Pair [(a,Doc -> Doc)] -optim f (x:/:y) = map modif x :/: map modif' y - where modif a | isSpecial (f a) = (a,\x -> "(if not p then (" <> x <> ":) else id)") - | otherwise = (a,rob) - modif' a | isSpecial (f a) = (a,\x -> "(if p then (" <> x <> ":) else id)") - | otherwise = (a,rob) - rob x = "("<> x <> ":)" - - -splitOptim f cf xs = optim f $ splitLROn f cf $ xs - - ---------------------------- --- Error reporting - --- leftOf C = ⋃ { {X} ∪ leftOf X | C ::= X B ∈ Grammar or C ::= X ∈ Grammar } -leftRight pos s (Rule _ c rhs _) = Map.singleton (show c) (lkCat x s) - where x = pos rhs - -lkCat (Right t) _ = [Right t] -lkCat (Left c) s = Left c:lookupMulti (show c) s - --- neighbors A B = ∃ A' B'. P ::= A' B' & A ∈ rightOf A' & B ∈ leftOf B -neighborSet cf = map (second (nub . sort)) $ group' [(x',lkCat y leftSet) | Rule _ _ [x,y] _ <- cfgRules cf, x' <- lkCat x rightSet] - where leftSet = fixpointOnGrammar "left set" (leftRight head) cf - rightSet = fixpointOnGrammar "right set" (leftRight last) cf - -data Exp = Id -- identity function - | Con String -- constructor or variable - | App Exp Exp - | Exp `After` Exp - | App2 Exp Exp - deriving (Eq,Ord) - -prettyExp Id = "id" -prettyExp (Con x) = text x -prettyExp (App f x) = prettyExp f <+> (parens $ prettyExp x) -prettyExp (App2 f x) = "flip" <+> parens (prettyExp f) <+> parens (prettyExp x) -prettyExp (f `After` g) = parens (prettyExp f) <> "." <> parens (prettyExp g) - -instance Show Exp where show = render . prettyExp - --- | Apply in 2nd position if the flag is true, otherwise apply normally. -app2 True f x = App2 f x -app2 False f x = app' f x - -infixl `app'` -app' :: Exp -> Exp -> Exp -app' (f `After` g) x = app' f (app' g x) -app' Id x = x -app' (App2 f y) x = (f `app'` x) `app'` y -app' (Con "($)") f = f --- app' (Con "const") f = f -app' f x = App f x - -after :: Exp -> Exp -> Exp -after Id f = f -after f Id = f -after f g = f `After` g - -appMany f args = foldl app' f args diff --git a/source/src/Data/Pair.hs b/source/src/Data/Pair.hs deleted file mode 100644 index e65c35c9..00000000 --- a/source/src/Data/Pair.hs +++ /dev/null @@ -1,19 +0,0 @@ -{-# LANGUAGE CPP #-} -module Data.Pair where - -#if __GLASGOW_HASKELL__ < 710 -import Control.Applicative -#endif - -infixl 2 :/: - -data Pair a = (:/:) {leftOf :: a, rightOf :: a} - deriving (Show) - -instance Functor Pair where - fmap f (a :/: b) = f a :/: f b - -instance Applicative Pair where - pure a = a :/: a - (f :/: g) <*> (a :/: b) = f a :/: g b - diff --git a/testing/Main.hs b/testing/Main.hs index 04368c55..5bf1d966 100644 --- a/testing/Main.hs +++ b/testing/Main.hs @@ -4,7 +4,6 @@ import Test.Framework (htfMain) import qualified SucceedLBNFTests import qualified FailLBNFTests -import qualified HaskellCnfTests import qualified ParameterizedTests import qualified PygmentsTests import qualified RegressionTests @@ -27,6 +26,5 @@ main = do RegressionTests.all : ParameterizedTests.layoutTest : OutputParser.tests : - HaskellCnfTests.all : PygmentsTests.all : [] diff --git a/testing/bnfc-system-tests.cabal b/testing/bnfc-system-tests.cabal index 008a3e5b..ab4d0df2 100644 --- a/testing/bnfc-system-tests.cabal +++ b/testing/bnfc-system-tests.cabal @@ -57,7 +57,6 @@ executable bnfc-system-tests -- Modules included in this executable, other than Main. other-modules: SucceedLBNFTests FailLBNFTests - HaskellCnfTests OutputParser ParameterizedTests PygmentsTests diff --git a/testing/src/HaskellCnfTests.hs b/testing/src/HaskellCnfTests.hs deleted file mode 100644 index c35eb5b1..00000000 --- a/testing/src/HaskellCnfTests.hs +++ /dev/null @@ -1,35 +0,0 @@ -module HaskellCnfTests (all) where - -import Prelude hiding (all) --- import Shelly - -import ParameterizedTests hiding (all) -import TestUtils - -cnf :: TestParameters -cnf = haskellParameters - { tpName = "Haskell/CNF" - , tpBnfcOptions = ["--haskell", "--cnf"] - , tpBuild = tpMake - } - --- cnfOld :: TestParameters --- cnfOld = TP --- { tpName = "Haskell/CNF" --- , tpBnfcOptions = ["--haskell", "--cnf"] --- , tpBuild = tpMake --- , tpRunTestProg = --- (\ _lang args -> do --- bin <- canonicalize $ "." "TestCNF" --- -- This naive approach does not work: ("TestCNF" <> lang) --- -- Because the Haskell backend does some manipulation of names --- -- to conform with Haskell module name syntax. --- cmd bin args --- ) --- } - --- The CNF backend does not exactly work like other backend and some tests are --- not applicable as-is. We create a restricted test suite just for it. -all :: Test -all = makeTestSuite "Haskell/CNF" - [ exampleTests cnf, exitCodeTest cnf ] diff --git a/testing/src/TestData.hs b/testing/src/TestData.hs index 63bd5d00..b12dc9f2 100644 --- a/testing/src/TestData.hs +++ b/testing/src/TestData.hs @@ -47,7 +47,7 @@ exampleGrammars = map (fmap prefix) $ , fmap ("prolog" ) $ Example "Prolog.cf" [ "small.pl", "simpsons.pl" ] , fmap ("C" ) $ Example "C.cf" [ "runtime.c", "koe2.c" ] , fmap ("C" ) $ Example "C4.cf" [ "koe2.c" ] - , fmap ("C" ) $ Example "C_with_delimiters.cf" [ "small.c" ] -- "core.c" fails with CNF!!! + , fmap ("C" ) $ Example "C_with_delimiters.cf" [ "small.c", "core.c" ] , fmap ("Javalette" ) $ Example "JavaletteLight.cf" [ "koe.jll" ] , fmap ("LBNF" ) $ Example "LBNF.cf" [ "LBNF.cf" ] , fmap ("Java" ) $ Example' (Excluded ["antlr"]) "java.cf" []