@@ -11,10 +11,8 @@ import SourceSyntax.Declaration (Assoc(..))
1111import Text.Parsec
1212import Parse.Helpers
1313
14−type OpTable = [(Int, Assoc, String)]
15−
1614preludeTable :: OpTable
17−preludeTable =
15+preludeTable = Map.fromList $ map (\(lvl,assoc,op) -> (op, (lvl,assoc)))
1816 [ (9, R, ".")
1917 , (8, R, "^")
2018 , (7, L, "*"), (7, L, "/"), (7, L, "mod"), (7, L, "div"), (7, L, "rem")
@@ -29,24 +27,22 @@ preludeTable =
2927 ]
3028
3129opLevel :: OpTable -> String -> Int
32−opLevel table op = Map.findWithDefault 9 op dict
33− where dict = Map.fromList (map (\(lvl,_,op) -> (op,lvl)) table)
30+opLevel table op = fst $ Map.findWithDefault (9,R) op table
3431
3532opAssoc :: OpTable -> String -> Assoc
36−opAssoc table op = Map.findWithDefault R op dict
37− where dict = Map.fromList (map (\(_,assoc,op) -> (op,assoc)) table)
33+opAssoc table op = snd $ Map.findWithDefault (9,R) op table
3834
3935hasLevel :: OpTable -> Int -> (String, LExpr t v) -> Bool
4036hasLevel table n (op,_) = opLevel table op == n
4137
42−binops :: OpTable
43− -> IParser (LExpr t v)
38+binops :: IParser (LExpr t v)
4439 -> IParser (LExpr t v)
4540 -> IParser String
4641 -> IParser (LExpr t v)
47−binops table term last anyOp =
42+binops term last anyOp =
4843 do e <- term
49− split (table ++ preludeTable) 0 e =<< nextOps
44+ table <- getState
45+ split (Map.union preludeTable table) 0 e =<< nextOps
5046 where
5147 nextOps = choice [ commitIf (whitespace >> anyOp) $ do
5248 whitespace ; op <- anyOp ; whitespace