module Compiler where import qualified AbstractSyntaxTree as AST data Command = Const Int -- Load integer const | Add | Sub | Mult | Div deriving Show compile :: AST.AST -> [Command] compile = reverse . compile' where compile' ast = case ast of AST.Scalar i -> [Const i] AST.Operation AST.Add left right -> Add : compile' left ++ compile' right AST.Operation AST.Sub left right -> Sub : compile' left ++ compile' right AST.Operation AST.Mult left right -> Mult : compile' left ++ compile' right AST.Operation AST.Div left right -> Div : compile' left ++ compile' right