-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
25 lines (23 loc) · 863 Bytes
/
Main.hs
File metadata and controls
25 lines (23 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Main where
import System.Environment (getArgs)
import Lexer (tokenize)
import Parser (parse)
import SemanticAnalyzer (analyze)
import CodeGenerator (generate)
main :: IO ()
main = do
args <- getArgs
case args of
[inputFile] -> do
contents <- readFile inputFile
let tokens = tokenize contents
case parse tokens of
Left error -> putStrLn $ "Parse error: " ++ error
Right ast -> do
case analyze ast of
Left error -> putStrLn $ "Semantic error: " ++ error
Right _ -> do
let code = generate ast
writeFile (inputFile ++ ".js") code
putStrLn "Compilation successful!"
_ -> putStrLn "Usage: fofi-compiler <input-file>"