From 3692629264303700cc647dd8cc75cfcd2b7cafaf Mon Sep 17 00:00:00 2001 From: Arity-T Date: Sun, 8 Dec 2024 20:00:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20Main,=20=D0=BD=D0=BE=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D0=B0=20=D1=81=20do-=D0=BD=D0=BE=D1=82=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coursework/part1/.gitignore | 3 ++- coursework/part1/app/Main.hs | 8 +++++++- coursework/part1/expressions.txt | 6 ++++++ coursework/part1/src/Lib.hs | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 coursework/part1/expressions.txt 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