view exercises/src/FormParser1.hs @ 30:8bf7ca2663d2

Advanced AdditionParser
author Markus Kaiser <markus.kaiser@in.tum.de>
date Sat, 12 Jan 2013 14:36:43 +0000
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)"