This commit is contained in:
Oleg Sobolev 2025-12-30 06:53:05 +03:00
parent 6f4a835e54
commit ef7dc3603d
5 changed files with 50 additions and 2 deletions

View file

@ -15,8 +15,20 @@ run source = do
Left (SyntaxError s) -> putStrLn s
Right statements -> runStatements statements
runEval :: String -> IO ()
runEval source = do
let tokensMaybe = scanTokensFromSource source
object <- case tokensMaybe of
Left UnexpectedCharacterError -> putStrLn "Unexpected character" >> return NullObject
Right tokens -> do
let exprMaybe = parseExpression tokens
case exprMaybe of
Left (SyntaxError s) -> putStrLn s >> return NullObject
Right statements -> eval statements
print object
repl :: IO ()
repl = putStr ">> " >> hFlush stdout >> getLine >>= run
repl = putStr ">> " >> hFlush stdout >> getLine >>= runEval
main :: IO ()
main = getArgs >>= fs