Visualizer kinda works.
[jars.git] / parse.scm
1 (import (chicken irregex))
2
3 (define (string->instr str)
4   (let ((idx 0)
5         (l (string-length str))
6         (whitespace-irx (irregex "[ \t]*"))
7         (newline-irx (irregex "\n"))
8         (comment-irx (irregex ";[^\n]*")))
9     (define (accept-token irx mandatory)
10       (let ((wsmatch (irregex-match whitespace-irx (substr str idx))))
11         (set! idx (+ idx (irregex-match-end-index wsmatch)))) ;Skip leading whitespace
12       (let ((res (irregex-match irx (substring str idx))))
13         (if res
14             (begin
15               (set! idx (+ idx (irregex-match-end-index res)))
16               (irregex-match-substring res))
17             (if mandatory
18                 (error "Unexpected token at input string index" idx)
19                 #f))))
20     (define (accept-token-string token-str mandatory)
21       (accept-token (irregex token-str) mandatory))
22     (define (load-file)
23       (let loop ()
24         (if (line)
25             (loop))))
26     (define (line)
27       (or (accept-token comment-irx #f)
28           (accept-token newline-irx #f)
29           (and(accept-token newline-irx #t))))
30     (define (instruction)
31       (and (opcode)
32            (accept-token period-irx #t)
33            (accept-modifier)))))
34