-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
module Main (main) where | ||
|
||
import Interpreter.Interpreter | ||
import Options.Applicative | ||
import Parser.Program | ||
import Text.Parsec (parse) | ||
|
||
developProgram :: String | ||
developProgram = | ||
-- "int i = 1; int j = 2; int l = 3 + 4; int k = i + j + l; k = k * 0;" | ||
-- "void test(int i, int k) { }" | ||
-- "print()" | ||
"int main() { print(\"Test\"); }" | ||
-- TODO: replace with either | ||
data Options = Options (Maybe String) (Maybe FilePath) | ||
|
||
parseOptions :: Parser Options | ||
parseOptions = | ||
Options | ||
<$> optional | ||
( strOption | ||
( long "inline" | ||
<> short 'i' | ||
<> metavar "STRING" | ||
<> help "Inline string to parse and interpret" | ||
) | ||
) | ||
<*> optional (argument str (metavar "PATH")) | ||
|
||
main :: IO () | ||
main = do | ||
let result = parse parseProgram "" developProgram | ||
opts <- execParser $ info (parseOptions <**> helper) fullDesc | ||
processOptions opts | ||
|
||
processOptions :: Options -> IO () | ||
processOptions (Options Nothing (Just path)) = do | ||
contents <- readFile path | ||
runPeter contents | ||
processOptions (Options (Just inlineSourceCode) Nothing) = | ||
runPeter inlineSourceCode | ||
processOptions _ = | ||
putStrLn "Arguments: provided file path OR inline source code" | ||
|
||
runPeter :: String -> IO () | ||
runPeter sourceCode = do | ||
let result = parse parseProgram "" sourceCode | ||
case result of | ||
Left err -> putStrLn $ "Parse error: " ++ show err | ||
Right program -> do | ||
putStrLn "Parsed program:" | ||
-- putStrLn "Parsed program:" | ||
print program | ||
interpret program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void main() { | ||
print("Hello, World!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("Hello, World!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters