diff --git a/coursework/part1/.gitignore b/coursework/part1/.gitignore index ac40320..e99c740 100644 --- a/coursework/part1/.gitignore +++ b/coursework/part1/.gitignore @@ -1,3 +1,4 @@ .stack-work/ *~ -!task_part1.txt \ No newline at end of file +!task_part1.txt +!expressions.txt \ No newline at end of file diff --git a/coursework/part1/app/Main.hs b/coursework/part1/app/Main.hs index e33fb1d..08dbdca 100644 --- a/coursework/part1/app/Main.hs +++ b/coursework/part1/app/Main.hs @@ -3,4 +3,10 @@ module Main (main) where import Lib main :: IO () -main = putStrLn "temp" +main = do + putStrLn "Введите имя файла:" + fileName <- getLine + content <- readFile fileName + let expressions = lines content + putStrLn $ concatMap processExpression expressions + \ No newline at end of file diff --git a/coursework/part1/expressions.txt b/coursework/part1/expressions.txt new file mode 100644 index 0000000..f2453cd --- /dev/null +++ b/coursework/part1/expressions.txt @@ -0,0 +1,6 @@ +100 * 100 +40 + 30 +50 / 2 +5 / 2 +62 - 32 +78 - 500 \ No newline at end of file diff --git a/coursework/part1/src/Lib.hs b/coursework/part1/src/Lib.hs index 6b8389f..796a737 100644 --- a/coursework/part1/src/Lib.hs +++ b/coursework/part1/src/Lib.hs @@ -96,7 +96,7 @@ processExpression s = case runParser expression s of show a ++ " " ++ operationToString op ++ " " ++ show b ++ " = " ++ - show (calculateExpression (a, op, b)) + show (calculateExpression (a, op, b)) ++ "\n" _ -> err where err = error $ "Unable to parse the following expression: \"" ++ s ++ "\"" \ No newline at end of file