@@ -11,10 +11,8 @@ import SourceSyntax.Declaration (Assoc(..))
11import Text.Parsec
11import Text.Parsec
12import Parse.Helpers
12import Parse.Helpers
14−type OpTable = [(Int, Assoc, String)]
16preludeTable :: OpTable
14preludeTable :: OpTable
17−preludeTable =
15+preludeTable = Map.fromList $ map (\(lvl,assoc,op) -> (op, (lvl,assoc)))
18 [ (9, R, ".")
16 [ (9, R, ".")
19 , (8, R, "^")
17 , (8, R, "^")
20 , (7, L, "*"), (7, L, "/"), (7, L, "mod"), (7, L, "div"), (7, L, "rem")
18 , (7, L, "*"), (7, L, "/"), (7, L, "mod"), (7, L, "div"), (7, L, "rem")
@@ -29,24 +27,22 @@ preludeTable =
31opLevel :: OpTable -> String -> Int
29opLevel :: OpTable -> String -> Int
32−opLevel table op = Map.findWithDefault 9 op dict
30+opLevel table op = fst $ Map.findWithDefault (9,R) op table
33− where dict = Map.fromList (map (\(lvl,_,op) -> (op,lvl)) table)
35opAssoc :: OpTable -> String -> Assoc
32opAssoc :: OpTable -> String -> Assoc
36−opAssoc table op = Map.findWithDefault R op dict
33+opAssoc table op = snd $ Map.findWithDefault (9,R) op table
37− where dict = Map.fromList (map (\(_,assoc,op) -> (op,assoc)) table)
39hasLevel :: OpTable -> Int -> (String, LExpr t v) -> Bool
35hasLevel :: OpTable -> Int -> (String, LExpr t v) -> Bool
40hasLevel table n (op,_) = opLevel table op == n
36hasLevel table n (op,_) = opLevel table op == n
43− -> IParser (LExpr t v)
38+binops :: IParser (LExpr t v)
44 -> IParser (LExpr t v)
39 -> IParser (LExpr t v)
45 -> IParser String
40 -> IParser String
46 -> IParser (LExpr t v)
41 -> IParser (LExpr t v)
47−binops table term last anyOp =
42+binops term last anyOp =
48 do e <- term
43 do e <- term
49− split (table ++ preludeTable) 0 e =<< nextOps
45+ split (Map.union preludeTable table) 0 e =<< nextOps
51 nextOps = choice [ commitIf (whitespace >> anyOp) $ do
47 nextOps = choice [ commitIf (whitespace >> anyOp) $ do
52 whitespace ; op <- anyOp ; whitespace
48 whitespace ; op <- anyOp ; whitespace