diff --git a/language.cabal b/language.cabal index fc1c2fe..adac1c5 100644 --- a/language.cabal +++ b/language.cabal @@ -12,7 +12,7 @@ build-type: Simple extra-doc-files: CHANGELOG.md -extra-source-fiels: +extra-source-files: Grammar.cf @@ -30,12 +30,13 @@ executable language Grammar.Par Grammar.Print Grammar.Skel + Compiler Interpreter hs-source-dirs: src build-depends: - base ^>=4.16.3.0 + base ^>=4.17.0.0 , mtl , containers , either diff --git a/src/Compiler.hs b/src/Compiler.hs index e69de29..011544c 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -0,0 +1,34 @@ +module Compiler where + +import Control.Applicative (Applicative) +import Control.Monad.Except (Except, MonadError (throwError), + liftEither) +import Data.Either.Combinators (maybeToRight) +import Data.Map (Map) +import qualified Data.Map as Map +import Grammar.Abs +import Grammar.Print (printTree) +import Grammar.Par (myLexer,pProgram) +import System.Exit (exitFailure) + +compileFile :: String -> IO () +compileFile file = do + input <- readFile file + case pProgram (myLexer input) of + Left err -> do + putStrLn "SYNTAX ERROR" + putStrLn err + exitFailure + Right cor -> do + putStrLn $ printTree cor + compile cor + +data Compiler = Compiler + { data :: [LLVMIr] } + +data LLVMIr = + + + +compile :: Program -> IO () +compile p = print "hej" \ No newline at end of file