22.1.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit bfddd560 authored by Philipp Meyer's avatar Philipp Meyer

Fixed parsing and display of parentheses

parent 1cca0e05
...@@ -137,9 +137,10 @@ termOperatorTable = ...@@ -137,9 +137,10 @@ termOperatorTable =
] ]
termAtom :: Parser Term termAtom :: Parser Term
termAtom = parens term termAtom = (Var <$> ident)
<|> (Const <$> integer) <|> (Const <$> integer)
<|> (Var <$> ident) <|> parens term
<?> "basic term"
term :: Parser Term term :: Parser Term
term = buildExpressionParser termOperatorTable termAtom <?> "term" term = buildExpressionParser termOperatorTable termAtom <?> "term"
...@@ -167,10 +168,11 @@ formOperatorTable = ...@@ -167,10 +168,11 @@ formOperatorTable =
] ]
formAtom :: Parser Formula formAtom :: Parser Formula
formAtom = parens formula formAtom = try linIneq
<|> (reserved "true" *> return FTrue) <|> (reserved "true" *> return FTrue)
<|> (reserved "false" *> return FFalse) <|> (reserved "false" *> return FFalse)
<|> linIneq <|> parens formula
<?> "basic formula"
formula :: Parser Formula formula :: Parser Formula
formula = buildExpressionParser formOperatorTable formAtom <?> "formula" formula = buildExpressionParser formOperatorTable formAtom <?> "formula"
......
...@@ -20,10 +20,10 @@ data Term = Var String ...@@ -20,10 +20,10 @@ data Term = Var String
instance Show Term where instance Show Term where
show (Var x) = x show (Var x) = x
show (Const c) = show c show (Const c) = show c
show (Minus t) = "-(" ++ show t ++ ")" show (Minus t) = "-" ++ show t
show (t :+: u) = show t ++ " + " ++ show u show (t :+: u) = "(" ++ show t ++ " + " ++ show u ++ ")"
show (t :-: u) = show t ++ " - " ++ show u show (t :-: u) = "(" ++ show t ++ " - " ++ show u ++ ")"
show (t :*: u) = "(" ++ show t ++ ") * (" ++ show u ++ ")" show (t :*: u) = show t ++ " * " ++ show u
data Op = Gt | Ge | Eq | Ne | Le | Lt data Op = Gt | Ge | Eq | Ne | Le | Lt
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment