view exercises/src/FormParser1.hs @ 27:a316877ed3d9

week 11
author Markus Kaiser <markus.kaiser@in.tum.de>
date Wed, 09 Jan 2013 21:00:13 +0100
parents
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)"