aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/Assignment.hs (renamed from src/parser/assignment.hs)0
-rw-r--r--src/parser/Core.hs (renamed from src/parser/core.hs)5
-rw-r--r--src/parser/Expr.hs (renamed from src/parser/expr.hs)29
-rw-r--r--src/parser/Statement.hs (renamed from src/parser/statement.hs)0
4 files changed, 16 insertions, 18 deletions
diff --git a/src/parser/assignment.hs b/src/parser/Assignment.hs
index bb782f5..bb782f5 100644
--- a/src/parser/assignment.hs
+++ b/src/parser/Assignment.hs
diff --git a/src/parser/core.hs b/src/parser/Core.hs
index b622634..b22bcf4 100644
--- a/src/parser/core.hs
+++ b/src/parser/Core.hs
@@ -50,8 +50,9 @@ satisfyChar f = Parser p
p (c:cs) = if f c then Just (c, cs)
else Nothing
--- sepBy :: Parser b -> Parser a -> Parser [a]
--- sepBy sep x = (:) <$> x <*> (many (sep *> x))
+sepBy :: Parser b -> Parser a -> Parser [a]
+sepBy sep x = (:) <$> x <*> (many (sep *> x))
+
-- sepByMap :: (b -> a -> a) -> Parser b -> Parser a -> Parser [a]
-- sepByMap f sep x = (:) <$> x <*> (many (f <$> sep <*> x))
diff --git a/src/parser/expr.hs b/src/parser/Expr.hs
index b84362d..5ba4be7 100644
--- a/src/parser/expr.hs
+++ b/src/parser/Expr.hs
@@ -3,30 +3,31 @@ module Parser.Expr where
import Control.Applicative
import Parser.Core
-import Atom
import Expr
imaginaryP :: Parser Atom
-imaginaryP = AImaginary <$> (floatP <* char 'i')
+imaginaryP = Imaginary <$> (floatP <* char 'i')
rationalP :: Parser Atom
-rationalP = ARational <$> floatP
+rationalP = Rational <$> floatP
-termOpP :: Parser (Expr -> Expr -> Expr)
-termOpP = infixOp "+" Add <|> infixOp "-" Sub
-
-factorOpP :: Parser (Expr -> Expr -> Expr)
-factorOpP = infixOp "*" Mul <|> infixOp "/" Div <|> infixOp "%" Mod
-
-expOpP :: Parser (Expr -> Expr -> Expr)
-expOpP = infixOp "^" Exp
+matrixP :: Parser Atom
+matrixP = Matrix <$> (char '[' *> sepBy (char ';') matrixRowP <* char ']')
+ where matrixRowP = char '[' *> sepBy (char ',') exprP <* char ']'
exprP :: Parser Expr
exprP = termP `chainl1` termOpP
+ where termOpP = infixOp "+" Add <|> infixOp "-" Sub
termP :: Parser Expr
termP = factorP `chainl1` factorOpP
+ where factorOpP = infixOp "**" Dot <|> infixOp "*" Mul <|> infixOp "/" Div <|> infixOp "%" Mod
+
+factorP :: Parser Expr
+factorP = endpointP `chainl1` expOpP
+ where expOpP = infixOp "^" Exp
+ endpointP = parenthesisExprP <|> (EAtom <$> atomP) <|> functionP <|> variableP
variableP :: Parser Expr
variableP = Variable <$> alphaStringP
@@ -34,12 +35,8 @@ variableP = Variable <$> alphaStringP
functionP :: Parser Expr
functionP = Function <$> alphaStringP <*> parenthesisExprP
-factorP :: Parser Expr
-factorP = endpointP `chainl1` expOpP
- where endpointP = parenthesisExprP <|> (EAtom <$> atomP) <|> functionP <|> variableP
-
parenthesisExprP :: Parser Expr
parenthesisExprP = parenthesize exprP
atomP :: Parser Atom
-atomP = imaginaryP <|> rationalP
+atomP = imaginaryP <|> rationalP <|> matrixP
diff --git a/src/parser/statement.hs b/src/parser/Statement.hs
index 74f7f01..74f7f01 100644
--- a/src/parser/statement.hs
+++ b/src/parser/Statement.hs