2025-12-09 17:23:54 +03:00
|
|
|
import Lox.Scanner
|
2025-12-25 18:41:04 +03:00
|
|
|
import Lox.Parser
|
|
|
|
|
import Lox.Interpreter
|
2025-12-25 19:00:01 +03:00
|
|
|
import System.IO
|
2025-12-09 17:23:54 +03:00
|
|
|
|
|
|
|
|
run :: String -> IO ()
|
2025-12-29 23:57:15 +03:00
|
|
|
run source = do
|
|
|
|
|
let tokensMaybe = scanTokensFromSource source
|
|
|
|
|
case tokensMaybe of
|
|
|
|
|
Left UnexpectedCharacterError -> putStrLn "Unexpected character"
|
|
|
|
|
Right tokens -> do
|
2025-12-30 01:27:01 +03:00
|
|
|
let stmtMaybe = parse tokens
|
|
|
|
|
case stmtMaybe of
|
2025-12-29 23:57:15 +03:00
|
|
|
Left ExpectedExpressionError -> putStrLn "Expected expression"
|
|
|
|
|
Left MismatchedParenthesesError -> putStrLn "Mismatched parentheses"
|
2025-12-30 01:27:01 +03:00
|
|
|
Left ExpectedSemicolonError -> putStrLn "Expected semicolon"
|
|
|
|
|
Right statements -> runStatements statements
|
2025-12-09 17:23:54 +03:00
|
|
|
|
2025-12-02 23:26:17 +03:00
|
|
|
main :: IO ()
|
2025-12-25 19:00:01 +03:00
|
|
|
main = putStr ">> " >> hFlush stdout >> getLine >>= run
|