Parse multiple instructions

This commit is contained in:
2025-09-07 21:58:37 -06:00
parent 925e486e65
commit 43107e7435
4 changed files with 117 additions and 58 deletions

View File

@@ -3,9 +3,24 @@
#load "Parser.fs"
#load "Lexer.fs"
let parse (s:string) =
s |> System.Text.Encoding.ASCII.GetBytes |> FSharp.Text.Lexing.LexBuffer<byte>.FromBytes |> Parser.instr(Lexer.read)
let mutable failed = false
parse "abc()"
parse "abc(def)"
// parse "abc(def,ghi)"
let parse (s:string) =
let lexbuf = s |> System.Text.Encoding.ASCII.GetBytes |> FSharp.Text.Lexing.LexBuffer<byte>.FromBytes
let msg =
try
sprintf "%A" <| Parser.rung Lexer.read lexbuf
with e ->
let pos = lexbuf.EndPos
let lastToken = System.Text.Encoding.ASCII.GetString lexbuf.Lexeme
failed <- true
sprintf "Parse failed at %d, last token = %A" pos.AbsoluteOffset lastToken
printf "%A -> %s\n" s msg
parse "abc();"
parse "abc(def);"
parse "abc(def,ghi);"
parse "abc(def,ghi) a(b) ;"
if failed then exit 1 else exit 0