3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; This file is part of Mes.
8 ;;; Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
23 ;;; copy of mes/read-0.mes, comment-out read-input-file
29 ;; (define car (make-function 'car 0))
30 ;; (define cdr (make-function 'cdr 1))
31 ;; (define cons (make-function 'cons 1))
34 ;; * use case/cond, expand
37 ;; * read characters, quote, strings
40 (read-word (read-byte) '() (current-module)))
42 (define (read-input-file)
45 (cons x (helper (read)))))
48 (define-macro (cond . clauses)
49 (list 'if (null? clauses) *unspecified*
50 (if (null? (cdr clauses))
51 (list 'if (car (car clauses))
52 (list (cons 'lambda (cons '() (cons (car (car clauses)) (cdr (car clauses))))))
54 (if (eq? (car (cadr clauses)) 'else)
55 (list 'if (car (car clauses))
56 (list (cons 'lambda (cons '() (car clauses))))
57 (list (cons 'lambda (cons '() (cons *unspecified* (cdr (cadr clauses)))))))
58 (list 'if (car (car clauses))
59 (list (cons 'lambda (cons '() (car clauses))))
60 (cons 'cond (cdr clauses)))))))
62 (define (eat-whitespace)
64 ((eq? (peek-byte) 9) (read-byte) (eat-whitespace))
65 ((eq? (peek-byte) 10) (read-byte) (eat-whitespace))
66 ((eq? (peek-byte) 13) (read-byte) (eat-whitespace))
67 ((eq? (peek-byte) 32) (read-byte) (eat-whitespace))
68 ((eq? (peek-byte) 59) (begin (read-line-comment (read-byte))
70 ((eq? (peek-byte) 35) (begin (read-byte)
71 (if (eq? (peek-byte) 33) (begin (read-byte)
72 (read-block-comment (read-byte))
76 (define (read-block-comment c)
77 (if (eq? c 33) (if (eq? (peek-byte) 35) (read-byte)
78 (read-block-comment (read-byte)))
79 (read-block-comment (read-byte))))
81 ;; (define (read-hex c)
83 ;; (read-line-comment (read-byte))))
85 (define (read-line-comment c)
87 (read-line-comment (read-byte))))
91 (if (eq? (peek-byte) 41) (begin (read-byte) '())
93 (if (eq? w '.) (car (read-list a))
94 (cons w (read-list a))))
95 (read-word (read-byte) '() a))))
97 ;;(define (read-string))
99 (define (lookup-char c a)
100 (lookup (cons (integer->char c) '()) a))
102 (define (read-word c w a)
105 ((eq? c 10) (if (null? w) (read-word (read-byte) '() a)
107 ((eq? c 32) (read-word 10 w a))
108 ((eq? c 34) (if (null? w) (read-string)
109 (begin (unread-byte c) (lookup w a))))
111 ((eq? (peek-byte) 33) (begin (read-byte)
112 (read-block-comment (read-byte))
113 (read-word (read-byte) w a)))
114 ((eq? (peek-byte) 40) (read-byte) (list->vector (read-list a)))
115 ((eq? (peek-byte) 92) (read-byte) (read-character))
116 ((eq? (peek-byte) 120) (read-byte) (read-hex))
117 (else (read-word (read-byte) (append2 w (cons (integer->char c) '())) a))))
118 ((eq? c 39) (if (null? w) (cons (lookup (cons (integer->char c) '()) a)
119 (cons (read-word (read-byte) w a) '()))
120 (begin (unread-byte c) (lookup w a))))
121 ((eq? c 40) (if (null? w) (read-list a)
122 (begin (unread-byte c) (lookup w a))))
123 ((eq? c 41) (if (null? w) (cons (lookup (cons (integer->char c) '()) a)
124 (cons (read-word (read-byte) w a) '()))
125 (begin (unread-byte c) (lookup w a))))
127 ((eq? (peek-byte) 64) (begin (read-byte)
129 (lookup (symbol->list 'unquote-splicing) a)
130 (cons (read-word (read-byte) w a) '()))))
131 (else (cons (lookup-char c a) (cons (read-word (read-byte) w a)
133 ((eq? c 96) (cons (lookup-char c a) (cons (read-word (read-byte) w a) '())))
134 ((eq? c 59) (read-line-comment c) (read-word 10 w a))
135 (else (read-word (read-byte) (append2 w (cons (integer->char c) '())) a))))
138 ;; ;;(display 'program=) (display p) (newline)
139 ;; (begin-env p (current-module)))
140 ;; (read-input-file))