diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-03 22:57:10 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-03 22:57:10 +0200 |
| commit | 2b0b62b44a87536597050c525322c7bcc745bdb2 (patch) | |
| tree | 56ee143d427c66cb1f0583c07beec5f181abc983 /src/parser/Expr.hs | |
| parent | 5e7d3a5ff586ac75b768a9a1c1f2d5b80960e821 (diff) | |
| download | computorv2-2b0b62b44a87536597050c525322c7bcc745bdb2.tar.gz computorv2-2b0b62b44a87536597050c525322c7bcc745bdb2.tar.bz2 computorv2-2b0b62b44a87536597050c525322c7bcc745bdb2.zip | |
Added polynom solver from computorv1, Added matrix multipilcation
Diffstat (limited to 'src/parser/Expr.hs')
| -rw-r--r-- | src/parser/Expr.hs | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/parser/Expr.hs b/src/parser/Expr.hs index 6a721f8..221d669 100644 --- a/src/parser/Expr.hs +++ b/src/parser/Expr.hs @@ -1,4 +1,4 @@ -module Parser.Expr where +module Parser.Expr (exprP) where import Control.Applicative @@ -6,20 +6,6 @@ import Parser.Core import Expr -imaginaryP :: Parser Expr -imaginaryP = Imaginary <$> (floatP <* char 'i') - -rationalP :: Parser Expr -rationalP = Rational <$> floatP - --- Parse a matrix in the following format: --- [ [a, b]; [c, d] ] -matrixP :: Parser Expr -matrixP = Matrix <$> brackets (matrixRowP `sepBy` (char ';')) - where matrixRowP = brackets (exprP `sepBy` (char ',')) - brackets = between "[" "]" - - -- Parse expression separated by one infix operator of the operator list operatorChoiceChain :: Parser a -> [Parser (a -> a -> a)] -> Parser a operatorChoiceChain x operators = x `chainl1` choice operators @@ -42,12 +28,19 @@ termP = operatorChoiceChain factorP factorP :: Parser Expr factorP = choice [ parenthesizedExprP , imaginaryP - , rationalP + , Rational <$> floatP , matrixP - , functionP - , variableP + , Function <$> labelP <*> parenthesizedExprP + , Variable <$> labelP ] `chainl1` (infixOp "^" Exp) + where + parenthesizedExprP = parenthesis exprP + + imaginaryP = Imaginary <$> (floatP <|> pure 1.0) <* char 'i' - where variableP = Variable <$> alphaStringP - functionP = Function <$> alphaStringP <*> parenthesizedExprP - parenthesizedExprP = parenthesis exprP + -- Parse a matrix in the following format: + -- [ [a, b]; [c, d] ] + matrixP :: Parser Expr + matrixP = Matrix <$> brackets (matrixRowP `sepBy` (char ';')) + where matrixRowP = brackets (exprP `sepBy` (char ',')) + brackets = between "[" "]" |
