From 9acf5c0fc91d7e348c794c8b8181d4e56f393925 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 22 Jul 2016 19:56:18 -0700 Subject: 3129 Degenerate 'parser' that handles just atoms of one character. --- 067stream.mu | 10 ++++++++++ lambda-to-mu.mu | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/067stream.mu b/067stream.mu index db7c189a..e55d5986 100644 --- a/067stream.mu +++ b/067stream.mu @@ -18,6 +18,16 @@ def rewind-stream in:address:stream -> in:address:stream [ *in <- put *in, index:offset, 0 ] +def read in:address:stream -> result:character, in:address:stream [ + local-scope + load-ingredients + idx:number <- get *in, index:offset + s:address:array:character <- get *in, data:offset + result <- index *s, idx + idx <- add idx, 1 + *in <- put *in, index:offset, idx +] + def read-line in:address:stream -> result:address:array:character, in:address:stream [ local-scope load-ingredients diff --git a/lambda-to-mu.mu b/lambda-to-mu.mu index bfdc0e9d..9afe1ed3 100644 --- a/lambda-to-mu.mu +++ b/lambda-to-mu.mu @@ -124,3 +124,32 @@ scenario cell-operations-on-pair [ 11 <- 0 # rest is nil ] ] + +def parse in:address:array:character -> out:address:cell [ + local-scope + load-ingredients + s:address:stream <- new-stream in + out, s <- parse s +] + +def parse in:address:stream -> out:address:cell, in:address:stream [ + local-scope + load-ingredients + b:address:buffer <- new-buffer 30 + c:character, in <- read in + b <- append b, c + s:address:array:character <- buffer-to-array b + out <- new-atom s +] + +scenario parse-atom [ + local-scope + s:address:array:character <- new [a] + x:address:cell <- parse s + s2:address:array:character, 10:boolean/raw <- maybe-convert *x, atom:variant + 11:array:character/raw <- copy *s2 + memory-should-contain [ + 10 <- 1 # parse result is an atom + 11:array:character <- [a] + ] +] -- cgit 1.4.1-2-gfad0