File tree 2 files changed +16
-16
lines changed
2 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ bool = (reserved "True" >> return (Lit (LBool True)))
36
36
fix :: Parser Expr
37
37
fix = do
38
38
reservedOp " fix"
39
- x <- aexp
39
+ x <- expr
40
40
return (Fix x)
41
41
42
42
lambda :: Parser Expr
@@ -71,11 +71,11 @@ letrecin = do
71
71
ifthen :: Parser Expr
72
72
ifthen = do
73
73
reserved " if"
74
- cond <- aexp
74
+ cond <- expr
75
75
reservedOp " then"
76
- tr <- aexp
76
+ tr <- expr
77
77
reserved " else"
78
- fl <- aexp
78
+ fl <- expr
79
79
return (If cond tr fl)
80
80
81
81
aexp :: Parser Expr
91
91
<|> variable
92
92
93
93
term :: Parser Expr
94
- term = Ex. buildExpressionParser table aexp
94
+ term = aexp >>= \ x ->
95
+ (many1 aexp >>= \ xs -> return (foldl App x xs))
96
+ <|> return x
95
97
96
98
infixOp :: String -> (a -> a -> a ) -> Ex. Assoc -> Op a
97
99
infixOp x f = Ex. Infix (reservedOp x >> return f)
@@ -111,9 +113,7 @@ table = [
111
113
]
112
114
113
115
expr :: Parser Expr
114
- expr = do
115
- es <- many1 term
116
- return (foldl1 App es)
116
+ expr = Ex. buildExpressionParser table term
117
117
118
118
type Binding = (String , Expr )
119
119
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ bool = (reserved "True" >> return (Lit (LBool True)))
36
36
fix :: Parser Expr
37
37
fix = do
38
38
reservedOp " fix"
39
- x <- aexp
39
+ x <- expr
40
40
return (Fix x)
41
41
42
42
lambda :: Parser Expr
@@ -71,11 +71,11 @@ letrecin = do
71
71
ifthen :: Parser Expr
72
72
ifthen = do
73
73
reserved " if"
74
- cond <- aexp
74
+ cond <- expr
75
75
reservedOp " then"
76
- tr <- aexp
76
+ tr <- expr
77
77
reserved " else"
78
- fl <- aexp
78
+ fl <- expr
79
79
return (If cond tr fl)
80
80
81
81
aexp :: Parser Expr
91
91
<|> variable
92
92
93
93
term :: Parser Expr
94
- term = Ex. buildExpressionParser table aexp
94
+ term = aexp >>= \ x ->
95
+ (many1 aexp >>= \ xs -> return (foldl App x xs))
96
+ <|> return x
95
97
96
98
infixOp :: String -> (a -> a -> a ) -> Ex. Assoc -> Op a
97
99
infixOp x f = Ex. Infix (reservedOp x >> return f)
@@ -111,9 +113,7 @@ table = [
111
113
]
112
114
113
115
expr :: Parser Expr
114
- expr = do
115
- es <- many1 term
116
- return (foldl1 App es)
116
+ expr = Ex. buildExpressionParser table term
117
117
118
118
type Binding = (String , Expr )
119
119
You can’t perform that action at this time.
0 commit comments