2016-12-12 19:07:17 +00:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-12-12 19:07:17 +00:00
|
|
|
;;;
|
|
|
|
;;; This file is part of Mes.
|
|
|
|
;;;
|
|
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; copy of mes/read-0.mes, comment-out read-input-file
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(begin
|
|
|
|
|
|
|
|
;; (define car (make-function 'car 0))
|
|
|
|
;; (define cdr (make-function 'cdr 1))
|
|
|
|
;; (define cons (make-function 'cons 1))
|
|
|
|
|
|
|
|
;; TODO:
|
|
|
|
;; * use case/cond, expand
|
|
|
|
;; * etc int/char?
|
|
|
|
;; * lookup in Scheme
|
|
|
|
;; * read characters, quote, strings
|
|
|
|
|
|
|
|
(define (read)
|
2016-12-13 18:58:34 +00:00
|
|
|
(read-word (read-byte) (list) (current-module)))
|
2016-12-12 19:07:17 +00:00
|
|
|
|
|
|
|
(define (read-input-file)
|
|
|
|
(define (helper x)
|
|
|
|
(if (null? x) x
|
|
|
|
(cons x (helper (read)))))
|
|
|
|
(helper (read)))
|
|
|
|
|
|
|
|
(define-macro (cond . clauses)
|
2016-12-13 18:58:34 +00:00
|
|
|
(list (quote if) (null? clauses) *unspecified*
|
2016-12-12 19:07:17 +00:00
|
|
|
(if (null? (cdr clauses))
|
2016-12-13 18:58:34 +00:00
|
|
|
(list (quote if) (car (car clauses))
|
|
|
|
(list (cons (quote lambda) (cons (list) (cons (car (car clauses)) (cdr (car clauses))))))
|
2016-12-12 19:07:17 +00:00
|
|
|
*unspecified*)
|
2016-12-13 18:58:34 +00:00
|
|
|
(if (eq? (car (cadr clauses)) (quote else))
|
|
|
|
(list (quote if) (car (car clauses))
|
|
|
|
(list (cons (quote lambda) (cons (list) (car clauses))))
|
|
|
|
(list (cons (quote lambda) (cons (list) (cons *unspecified* (cdr (cadr clauses)))))))
|
|
|
|
(list (quote if) (car (car clauses))
|
|
|
|
(list (cons (quote lambda) (cons (list) (car clauses))))
|
|
|
|
(cons (quote cond) (cdr clauses)))))))
|
2016-12-12 19:07:17 +00:00
|
|
|
|
|
|
|
(define (eat-whitespace)
|
|
|
|
(cond
|
|
|
|
((eq? (peek-byte) 9) (read-byte) (eat-whitespace))
|
|
|
|
((eq? (peek-byte) 10) (read-byte) (eat-whitespace))
|
|
|
|
((eq? (peek-byte) 13) (read-byte) (eat-whitespace))
|
|
|
|
((eq? (peek-byte) 32) (read-byte) (eat-whitespace))
|
|
|
|
((eq? (peek-byte) 59) (begin (read-line-comment (read-byte))
|
|
|
|
(eat-whitespace)))
|
|
|
|
((eq? (peek-byte) 35) (begin (read-byte)
|
|
|
|
(if (eq? (peek-byte) 33) (begin (read-byte)
|
|
|
|
(read-block-comment (read-byte))
|
|
|
|
(eat-whitespace))
|
|
|
|
(unread-byte 35))))))
|
|
|
|
|
|
|
|
(define (read-block-comment c)
|
|
|
|
(if (eq? c 33) (if (eq? (peek-byte) 35) (read-byte)
|
|
|
|
(read-block-comment (read-byte)))
|
|
|
|
(read-block-comment (read-byte))))
|
|
|
|
|
|
|
|
;; (define (read-hex c)
|
|
|
|
;; (if (eq? c 10) c
|
|
|
|
;; (read-line-comment (read-byte))))
|
|
|
|
|
|
|
|
(define (read-line-comment c)
|
|
|
|
(if (eq? c 10) c
|
|
|
|
(read-line-comment (read-byte))))
|
|
|
|
|
|
|
|
(define (read-list a)
|
|
|
|
(eat-whitespace)
|
2016-12-13 18:58:34 +00:00
|
|
|
(if (eq? (peek-byte) 41) (begin (read-byte) (list))
|
2016-12-12 19:07:17 +00:00
|
|
|
((lambda (w)
|
2016-12-13 18:58:34 +00:00
|
|
|
(if (eq? w *dot*) (car (read-list a))
|
2016-12-12 19:07:17 +00:00
|
|
|
(cons w (read-list a))))
|
2016-12-13 18:58:34 +00:00
|
|
|
(read-word (read-byte) (list) a))))
|
2016-12-12 19:07:17 +00:00
|
|
|
|
|
|
|
;;(define (read-string))
|
|
|
|
|
|
|
|
(define (lookup-char c a)
|
2016-12-13 18:58:34 +00:00
|
|
|
(lookup (cons (integer->char c) (list)) a))
|
2016-12-12 19:07:17 +00:00
|
|
|
|
|
|
|
(define (read-word c w a)
|
|
|
|
(cond
|
2016-12-13 18:58:34 +00:00
|
|
|
((eq? c -1) (list))
|
|
|
|
((eq? c 10) (if (null? w) (read-word (read-byte) (list) a)
|
2016-12-12 19:07:17 +00:00
|
|
|
(lookup w a)))
|
|
|
|
((eq? c 32) (read-word 10 w a))
|
|
|
|
((eq? c 34) (if (null? w) (read-string)
|
|
|
|
(begin (unread-byte c) (lookup w a))))
|
|
|
|
((eq? c 35) (cond
|
|
|
|
((eq? (peek-byte) 33) (begin (read-byte)
|
|
|
|
(read-block-comment (read-byte))
|
|
|
|
(read-word (read-byte) w a)))
|
|
|
|
((eq? (peek-byte) 40) (read-byte) (list->vector (read-list a)))
|
|
|
|
((eq? (peek-byte) 92) (read-byte) (read-character))
|
|
|
|
((eq? (peek-byte) 120) (read-byte) (read-hex))
|
2016-12-13 18:58:34 +00:00
|
|
|
(else (read-word (read-byte) (append2 w (cons (integer->char c) (list))) a))))
|
|
|
|
((eq? c 39) (if (null? w) (cons (lookup (cons (integer->char c) (list)) a)
|
|
|
|
(cons (read-word (read-byte) w a) (list)))
|
2016-12-12 19:07:17 +00:00
|
|
|
(begin (unread-byte c) (lookup w a))))
|
|
|
|
((eq? c 40) (if (null? w) (read-list a)
|
|
|
|
(begin (unread-byte c) (lookup w a))))
|
2016-12-13 18:58:34 +00:00
|
|
|
((eq? c 41) (if (null? w) (cons (lookup (cons (integer->char c) (list)) a)
|
|
|
|
(cons (read-word (read-byte) w a) (list)))
|
2016-12-12 19:07:17 +00:00
|
|
|
(begin (unread-byte c) (lookup w a))))
|
|
|
|
((eq? c 44) (cond
|
|
|
|
((eq? (peek-byte) 64) (begin (read-byte)
|
|
|
|
(cons
|
2016-12-13 18:58:34 +00:00
|
|
|
(lookup (symbol->list (quote unquote-splicing)) a)
|
|
|
|
(cons (read-word (read-byte) w a) (list)))))
|
2016-12-12 19:07:17 +00:00
|
|
|
(else (cons (lookup-char c a) (cons (read-word (read-byte) w a)
|
2016-12-13 18:58:34 +00:00
|
|
|
(list))))))
|
|
|
|
((eq? c 96) (cons (lookup-char c a) (cons (read-word (read-byte) w a) (list))))
|
2016-12-12 19:07:17 +00:00
|
|
|
((eq? c 59) (read-line-comment c) (read-word 10 w a))
|
2016-12-13 18:58:34 +00:00
|
|
|
(else (read-word (read-byte) (append2 w (cons (integer->char c) (list))) a))))
|
2016-12-12 19:07:17 +00:00
|
|
|
|
|
|
|
;; ((lambda (p)
|
2016-12-13 18:58:34 +00:00
|
|
|
;; ;;(display (quote program=)) (display p) (newline)
|
2016-12-12 19:07:17 +00:00
|
|
|
;; (begin-env p (current-module)))
|
|
|
|
;; (read-input-file))
|
|
|
|
)
|