diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-12 16:19:55 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-13 12:30:49 +0100 |
| commit | e0ade28ab642c043501493fe7192b626a6a68115 (patch) | |
| tree | 7bfa065b5f80f6c245137244cb37d8691c02f488 /src/expr.hs | |
| parent | 37e52bff39a1fe4d442cb253773252030c1cab8a (diff) | |
| download | computorv2-e0ade28ab642c043501493fe7192b626a6a68115.tar.gz computorv2-e0ade28ab642c043501493fe7192b626a6a68115.tar.bz2 computorv2-e0ade28ab642c043501493fe7192b626a6a68115.zip | |
Caveman parsing working
(brain hurty)
Diffstat (limited to 'src/expr.hs')
| -rw-r--r-- | src/expr.hs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/expr.hs b/src/expr.hs index 3cada63..ccc0e36 100644 --- a/src/expr.hs +++ b/src/expr.hs @@ -1,15 +1,24 @@ module Expr where +import Imag +import Matrix + -- data X = Expr | Imag | Matrix -data Expr = Expr Term Expr | ExprSingle Term +-- class ExprElement where +-- subExpr :: ExprElement a => a -> a +-- composed :: ExprElement a -> a -> (a, a) + +data AExpr = AExpr Term AExpr | AExprSingle Term data Term = Term Factor Term | TermSingle Factor data Factor = Factor Base Factor | FactorSingle Base -data Base = Base Expr | BaseSingle Float +data Base = Base AExpr | BaseSingle Expr -instance Show Expr where - show (ExprSingle t) = show t - show (Expr t e) = show t ++ " + " ++ show e +data Expr = ExprF Float | ExprI Imag | ExprM (Matrix AExpr) + +instance Show AExpr where + show (AExprSingle t) = show t + show (AExpr t e) = show t ++ " + " ++ show e instance Show Term where show (TermSingle f) = show f @@ -21,4 +30,12 @@ instance Show Factor where instance Show Base where show (BaseSingle x) = show x - show (Base e) = "( " ++ show e ++ " )" + show (Base e) = "(" ++ show e ++ ")" + +instance Show Expr where + show (ExprF f) = show f + show (ExprI i) = show i + show (ExprM m) = show m + +-- eval :: Expr -> Float +-- eval |
