diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-12 14:23:01 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-12 15:31:38 +0100 |
| commit | 37e52bff39a1fe4d442cb253773252030c1cab8a (patch) | |
| tree | 9942561e55e3a51947b87c6f35ac5181f3dff71c /src/expr.hs | |
| parent | dbbc2f6798ba77d2ea7d9cce91d3bd1879e467a2 (diff) | |
| download | computorv2-37e52bff39a1fe4d442cb253773252030c1cab8a.tar.gz computorv2-37e52bff39a1fe4d442cb253773252030c1cab8a.tar.bz2 computorv2-37e52bff39a1fe4d442cb253773252030c1cab8a.zip | |
Basic expression parsing
Diffstat (limited to 'src/expr.hs')
| -rw-r--r-- | src/expr.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/expr.hs b/src/expr.hs new file mode 100644 index 0000000..3cada63 --- /dev/null +++ b/src/expr.hs @@ -0,0 +1,24 @@ +module Expr where + +-- data X = Expr | Imag | Matrix + +data Expr = Expr Term Expr | ExprSingle Term +data Term = Term Factor Term | TermSingle Factor +data Factor = Factor Base Factor | FactorSingle Base +data Base = Base Expr | BaseSingle Float + +instance Show Expr where + show (ExprSingle t) = show t + show (Expr t e) = show t ++ " + " ++ show e + +instance Show Term where + show (TermSingle f) = show f + show (Term f t) = show f ++ " * " ++ show t + +instance Show Factor where + show (FactorSingle b) = show b + show (Factor b f) = show b ++ " ^ " ++ show f + +instance Show Base where + show (BaseSingle x) = show x + show (Base e) = "( " ++ show e ++ " )" |
