Started working on a simple compiler.
This commit is contained in:
parent
0ae5a9cee0
commit
b389e397b6
2 changed files with 37 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue