view exercises/src/FormParser1.hs @ 39:9a7b9e0c9eb0 default tip

week 15 tutorial
author Markus Kaiser <markus.kaiser@in.tum.de>
date Fri, 08 Feb 2013 00:06:20 +0100
parents a316877ed3d9
children
line wrap: on
line source

{- A simpleminded parser for a subset of formulas not containing | (or)
   Does not allow spaces in formulas.
-}

module FormParser1 (form) where

import Form
import Parser

form :: Parser Char Form
form  =
  form1 *** optional (item '&' *** form >>> snd) >>> andF
  where andF(f1, Just f2) = f1 :&: f2
        andF(f1, Nothing) = f1

-- form1 does not allow &
form1 :: Parser Char Form
form1  =
  item '~' *** form1 >>> (Not . snd) |||
  item 'T' >>> const T |||
  item 'F' >>> const F |||
  identifier >>> Var |||
  enclose '(' ')' form

test = form "(x1&~T)&~a&~((F&d2)&~d2&d1)"