Created
October 11, 2016 20:17
-
-
Save jg/0338169fe95998a0f4714c0b674277d8 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
-- arithmetic operators: | |
data AExpr = Var String Info | |
| IntConst Integer Info | |
| Neg AExpr Info | |
| ABinary ABinOp AExpr AExpr Info | |
deriving (Show, Eq) | |
aExpression :: Parser AExpr | |
aExpression = buildExpressionParser aOperators aTerm | |
bExpression :: Parser BExpr | |
bExpression = buildExpressionParser bOperators bTerm | |
aOperators = [ [prefix "-" Neg] | |
, [binary "*" (ABinary Multiply) AssocLeft] | |
, [binary "/" (ABinary Divide) AssocLeft] | |
, [binary "+" (ABinary Add) AssocLeft] | |
, [binary "-" (ABinary Subtract) AssocLeft] | |
] | |
bOperators = [ [prefix "not" (Not)] | |
, [binary "and" (BBinary And) AssocLeft] | |
, [binary "or" (BBinary Or) AssocLeft] | |
] | |
binary name fun assoc = Infix (do{ reservedOp name; pos <- getPosition; return fun (getInfo pos)}) assoc | |
prefix name fun = Prefix (do{ reservedOp name; pos <- getPosition; return fun (getInfo pos)}) | |
postfix name fun = Postfix (do{ reservedOp name; pos <- getPosition; return fun (getInfo pos)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment