Skip to content

Commit

Permalink
Final Push for Project
Browse files Browse the repository at this point in the history
  • Loading branch information
CStre committed Dec 13, 2023
1 parent 9bcf4ae commit 8fae19c
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 36 deletions.
Binary file modified .stack-work/dist/x86_64-linux/Cabal-3.6.3.0/build/app/app
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/home/streitmancm/project/calculator/monomer-starter.cabal:
hash: 14383bd07cdb67a1da3673e0399b8f55ce970057ceeb54621f37430f836b84c1
/home/streitmancm/project/calculator/package.yaml:
hash: e72bb2a6bdc91a97957bd068dd86b4abf36386612965fae74ffbc670494e44ab
hash: 6b099376f0bb6d51078aad7cf712b175e3d88225b354e3c280dad230cb1a3571
/home/streitmancm/project/calculator/src/Main.hs:
hash: 54dce14ef9fc877f377e901bf00b55a92952e01d6bf08ea6ed82ad7531ce25e3
hash: 178a5739fa3a6a21c64feaf03e7226b4c5b3ee815a7e89294bb1cf9d63baf029
/usr/include/stdc-predef.h:
hash: cb08cd5d4cc059a90833ac48a284d25016e8d56ded8ad4cd98d8ac59cc5053f3
Binary file not shown.
Binary file modified .stack-work/stack.sqlite3
Binary file not shown.
8 changes: 4 additions & 4 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ dependencies:
- lens
- monomer
- text
- text-show
- deepseq
- split
- directory >=1.3 && <1.4
- text-show # Added
- deepseq # Added
- split # Added
- directory >=1.3 && <1.4 # Added this for the appending file

executables:
app:
Expand Down
42 changes: 19 additions & 23 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ import qualified Monomer.Lens as L -- (19) For more lens op
import Monomer.Event.Lens (HasRightShift(rightShift)) -- (20) For handling specific event-related lens operations in Monomer, possibly a dependency.
import System.Directory (doesFileExist) -- (21) For checking the existence of files, used in 'appendToFile', 'readValidInputs'.
import System.IO (writeFile) -- (22) For writing data to files, used in 'appendToFile', 'readValidInputs'.
import Monomer.Main.Platform (defaultWindowSize) -- (23) This is used to define the size of the window
import Monomer.Main.Types (MainWindowState) -- (24) This is used to define the size of the window
import Monomer.Core.WidgetTypes
import Monomer.Main.UserUtil




Expand All @@ -67,8 +64,8 @@ import Monomer.Main.UserUtil
-----------------------------------------------------------------------------
-}
data AppModel = AppModel {
_currentInput :: Text,
_shouldExit :: Bool
_currentInput :: Text, -- For current input
_shouldExit :: Bool -- For the exit event
} deriving (Eq, Show)

makeLenses 'AppModel
Expand All @@ -93,9 +90,8 @@ data AppEvent = AddDigit Char -- Digit is added to expression
| HistoryDown -- This is used to look down from memory
| ToggleFun -- Toggle for the special Polonsky Mode
| SetInput String -- Used to set the input to a specific thing
| ExitApp --
| CloseApp --
| InitiateExit
| ExitApp -- Used with the done buttom to display a Goodbye! message and start the timer
| InitiateExit -- Called by the ExitApp event and closes the program
deriving (Eq, Show)

{-
Expand Down Expand Up @@ -154,7 +150,7 @@ tokenize str@(c:cs)
else if last num == '.' -- Check for dot not followed by a number.
then Num (read (num ++ "0")) : tokenize rest
else Num (read num) : tokenize rest
| c == '.' = [ErrorToken "[Error 303]: Decimal point preceding a function or symbol { .f(x) or .!}"] -- Case .f(x): Decimal point directly before a function or symbol.
| c == '.' = [ErrorToken "[Error 303]: Decimal point preceding function or symbol { .f(x) or .!}"] -- Case .f(x): Decimal point directly before a function or symbol.
| isSpace c = tokenize cs
| c == '+' = Op '+' : tokenize cs
| c == '-' = Op '-' : tokenize cs
Expand Down Expand Up @@ -226,7 +222,7 @@ parseProduct tokens =
(Op '÷' : rest2) -> let (num2, rest3) = parseProduct rest2 in (num1 / num2, rest3)
(Mod : rest2) ->
case parseFactor rest2 of -- Handle modulo operation
(num2, rest3) | num2 == 0 -> (0, [ErrorToken "[Error 102]: Division by zero in mod not possible { x%0 }"])
(num2, rest3) | num2 == 0 -> (0, [ErrorToken "[Error 102]: Division by zero mod not possible { x%0 }"])
| otherwise -> (fromIntegral (floor num1 `mod` floor num2), rest3)
_ -> (num1, rest1) -- No multiplication, division, or modulo, return current results

Expand All @@ -250,8 +246,8 @@ parseFactor tokens = case tokens of
let (expResult, restAfterExp) = parseExpr rest'
in case restAfterExp of
(Op ')' : restFinal) -> (n ** expResult, restFinal)
_ -> (0, [ErrorToken "[Error 104]: Missing closing parenthesis for exponent operator { x^(x }"])
_ -> (0, [ErrorToken "[Error 205]: Expected opening parenthesis after exponent operator { x^ }"])
_ -> (0, [ErrorToken "[Error 104]: Missing parenthesis for exponent operator { x^(x_ }"])
_ -> (0, [ErrorToken "[Error 205]: Expected parenthesis after exponent operator { x^_ }"])
(Op '-' : Num n : Fact : rest) -> (0, [ErrorToken "[Error 106]: Factorial not defined for negative numbers"]) -- Check for ex. -_!
(Num n : Fact : rest) -> case factorial (round n) of -- Check for ex. _!
Just factResult -> (fromIntegral factResult, rest)
Expand Down Expand Up @@ -366,11 +362,11 @@ parseLogOrLnWithBase f defaultBase tokens = case tokens of
let (secondNum, finalRest) = parseFactor secondNumRest
in case finalRest of
(Op ')' : rest') -> (f firstNum secondNum, rest') -- Apply the log function with two arguments.
_ -> (0, [ErrorToken "[Error 211]: Missing closing parenethesis after log with base { log(x,y }"])
_ -> (0, [ErrorToken "[Error 211]: Closing parenethesis after log with base { log(x,y }"])
-- Case for one argument: log(x) or ln(x).
(Op ')' : rest') -> (f defaultBase firstNum, rest') -- Apply the log function with the default base.
_ -> (0, [ErrorToken "[Error 212]: Missing comma or closing parenthesis after { log(x or ln(x }"])
_ -> (0, [ErrorToken "[Error 113]: Expected pair of parenthesis after log/ln { log x,y }"])
_ -> (0, [ErrorToken "[Error 212]: Comma or parenthesis after { log(x or ln(x }"])
_ -> (0, [ErrorToken "[Error 113]: Pair of parenthesis after log/ln { log x,y }"])

------------ Expression Number 2 ------------
-- Parses square root expressions, handling both regular and nth roots.
Expand All @@ -385,11 +381,11 @@ parseSqrtWithBase tokens = case tokens of
let (secondNum, finalRest) = parseExpr secondNumRest
in case finalRest of
(Op ')' : rest') -> (secondNum ** (1 / firstNum), rest') -- nth root of secondNum
_ -> (0, [ErrorToken "[Error 213]: Missing closing parenthesis/comma after sqrt with base { √(x,y }"])
_ -> (0, [ErrorToken "[Error 213]: Missing parenthesis/comma after sqrt { √(x,y_ }"])
-- Case for regular square root: √(x).
(Op ')' : rest') -> (sqrt firstNum, rest') -- Regular square root
_ -> (0, [ErrorToken "[Error 214]: Missing closing parenthesis after sqrt { √(x }"])
_ -> (0, [ErrorToken "[Error 115]: Missing opening parenthesis after sqrt { √ x,y }"])
_ -> (0, [ErrorToken "[Error 214]: Missing parenthesis after sqrt { √(x_ }"])
_ -> (0, [ErrorToken "[Error 115]: Missing parenthesis after sqrt { √_x,y }"])

------------ Expression Number 3 ------------
-- Handle implicit multiplication around a parenthesis
Expand Down Expand Up @@ -455,7 +451,7 @@ funModeMarker = " !!!Polonsky Mode!!!" -- Used to identify Polonsky Mode.
------------ Expression Number 13 ------------
-- Defines styling settings for text elements in the UI.
inputTextStyle :: [StyleState]
inputTextStyle = [textColor black, textSize 30] -- Sets text color, size, and font.
inputTextStyle = [textColor black, textSize 15] -- Sets text color, size, and font.

{-
-----------------------------------------------------------------------------
Expand All @@ -481,7 +477,7 @@ evaluateExpression input =
resultString = eval tokens -- Evaluate the tokens.
in case readMaybe resultString :: Maybe Double of
Just result -> if result > upperLimit
then "[Error 100]: Too big!" -- Check if result exceeds the upper limit.
then "[Error 101]: Too big!" -- Check if result exceeds the upper limit.
else formatOutput result -- Format the result for display.
Nothing -> resultString -- If it's not a number, it's an error message

Expand Down Expand Up @@ -539,7 +535,7 @@ buildUI wenv model = widgetTree where
vSpacer 10,
hstack [button "0" (AddDigit '0') `styleBasic` wideCircularButtonStyle, hSpacer 10, button "." (AddOperation '.') `styleBasic` circularButtonStyle, hSpacer 10, button "=" Calculate `styleBasic` orangeCircularButtonStyle],
vSpacer 20,
hstack [hSpacer 130, button "Done" ExitApp `styleBasic` exitButton, hSpacer 100]
hstack [ hSpacer 130, button "Done" ExitApp `styleBasic` exitButton, hSpacer 100]
]

-- Define different button layouts for standard and fun mode.
Expand All @@ -554,7 +550,7 @@ buildUI wenv model = widgetTree where
vSpacer 10,
hstack [button "cmem" ClearMem `styleBasic` redCircularButtonStyle, hSpacer 10, button "Λ" HistoryDown `styleBasic` redCircularButtonStyle, hSpacer 10, button "V" HistoryUp `styleBasic` redCircularButtonStyle, hSpacer 10, button "=" Calculate `styleBasic` orangeCircularButtonStyle],
vSpacer 20,
hstack [hSpacer 130, button "Done" ExitApp `styleBasic` exitButton, hSpacer 100]
hstack [ hSpacer 130, button "Done" ExitApp `styleBasic` exitButton, hSpacer 100]
]

------------ Expression Number 3 ------------
Expand Down
19 changes: 12 additions & 7 deletions validInputs.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
25-6
2-3
-1log(5)
5×9
45log(5)
5×9
89-3÷6
28!
8×8
6%9
-8%-3
6.3!
6.3333!
π×e
1!
0!
8×8
64-6
58÷6

0 comments on commit 8fae19c

Please sign in to comment.