Created
February 11, 2015 22:45
-
-
Save hasufell/54c68fc61e938df59c43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Grammar where | |
data Expr a = Plus (Expr a) (Term a) | |
| Minus (Expr a) (Term a) | |
| ExprTerm (Term a) | |
data Term a = Mult (Term a) (Factor a) | |
| Div (Term a) (Factor a) | |
| TermFactor (Factor a) | |
data Factor a = Constant a | |
| FactorExpr (Expr a) | |
runExpr :: Expr Double -> Double | |
runExpr (Plus expr term) = runExpr expr + runTerm term | |
runExpr (Minus expr term) = runExpr expr - runTerm term | |
runExpr (ExprTerm term) = runTerm term | |
runTerm :: Term Double -> Double | |
runTerm (Mult term fac) = runTerm term * runFac fac | |
runTerm (Div term fac) = runTerm term / runFac fac | |
runTerm (TermFactor fac) = runFac fac | |
runFac :: Factor Double -> Double | |
runFac (Constant a) = a | |
runFac (FactorExpr expr) = runExpr expr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment