This commit is contained in:
NikolajDanger
2022-05-15 12:54:29 +02:00
parent 383332077b
commit ba22cff91f
222 changed files with 23320 additions and 0 deletions

View File

@ -0,0 +1,27 @@
open System.Text
open FSharp.Text.Lexing
open FSharp.Text.Parsing
(* Both lex and parse a program. *)
let parse (s : string) =
Parser.Prog Lexer.Token
<| LexBuffer<_>.FromBytes (Encoding.UTF8.GetBytes s)
(* Continually evaluate user expressions. *)
let loop () =
let mutable running = true
while running do
printf "Input an expression: "
try
let program = System.Console.ReadLine()
if program = "exit"
then
running <- false
else
printfn "Parse result: %A" (parse program)
with
| Failure msg -> printfn "%s" msg
| :? System.ArgumentNullException ->
running <- false
loop ()