From 37e52bff39a1fe4d442cb253773252030c1cab8a Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 12 Mar 2020 14:23:01 +0100 Subject: Basic expression parsing --- src/expr.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/expr.hs (limited to 'src/expr.hs') 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 ++ " )" -- cgit