-- Haskel data types for the abstract syntax. -- Generated by the BNF converter. {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE PatternSynonyms #-} -- | The abstract syntax of language Calc. module AbsCalc where import qualified Prelude as T (Integer) import qualified Prelude as C ( Eq , Ord , Show , Read , Functor , Foldable , Traversable , Int, Maybe(..) ) type Exp = Exp' BNFC'Position data Exp' a = EAdd a (Exp' a) (Exp' a) -- ^ Exp ::= Exp "+" Exp1 | EDiv a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 "/" Exp2 | EInt a T.Integer -- ^ Exp ::= Integer | EMul a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 "*" Exp2 | ESub a (Exp' a) (Exp' a) -- ^ Exp ::= Exp "-" Exp1 deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) -- | Start position (line, column) of something. type BNFC'Position = C.Maybe (C.Int, C.Int) pattern BNFC'NoPosition :: BNFC'Position pattern BNFC'NoPosition = C.Nothing pattern BNFC'Position :: C.Int -> C.Int -> BNFC'Position pattern BNFC'Position line col = C.Just (line, col) -- | Get the start position of something. class HasPosition a where hasPosition :: a -> BNFC'Position instance HasPosition Exp where hasPosition = \case EAdd p _ _ -> p EDiv p _ _ -> p EInt p _ -> p EMul p _ _ -> p ESub p _ _ -> p