-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.fs
40 lines (36 loc) · 1.26 KB
/
Program.fs
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
open System.IO
open InterpreterTypes
open ProjectParser
open ProjectInterpreter
exception ParseFailureException of (int * string) option
[<EntryPoint>]
let main argv =
try
let s = argv.[0]
let lines = File.ReadLines s |> List.ofSeq
match parseComplete lines with
| ParseFailure onum ->
let oline = Option.map (fun x -> x, lines.[x-1]) onum
raise (ParseFailureException oline)
| ParseSuccess dlist ->
//let s2 = (prettyprint dlist)
//printfn "%s" s2
//printfn "%O" dlist
match runMain dlist with
| ValInt i ->
printfn "Program exited with return code %i" i
| _ ->
printfn "Program exited with non-integer return code"
0 // return an integer exit code*)
with
| ParseFailureException oline ->
let oval =
match oline with
| None -> "Cannot parse input"
| Some (num, line) -> sprintf "Invalid syntax on line %i:\n\t%s" num (line.Trim())
printfn "%s" oval
1
| InterpreterException s ->
printfn "Interpreter exception \"%s\"" s
1
//| _ -> printfn "Usage: dotnet run <s>"; 1