3 export GUILE_AUTO_COMPILE=0
4 exec ${GUILE-guile} -L $(pwd)/guile -e '(nyacc)' -s "$0" "$@"
7 ;;; Mes --- The Maxwell Equations of Software
8 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; This file is part of GNU Guix.
12 ;;; Mes is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
17 ;;; Mes is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
25 ;; The Maxwell Equations of Software -- John McCarthy page 13
26 ;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
30 GUILE='~/src/guile-1.8/build/pre-inst-guile --debug -q' guile/nyacc.scm
33 ;; Tcalc.scm - calculator
35 ;; Copyright (C) 2015 Matthew R. Wette
37 ;; Copying and distribution of this file, with or without modification,
38 ;; are permitted in any medium without royalty provided the copyright
39 ;; notice and this notice are preserved. This file is offered as-is,
40 ;; without any warranty.
45 (use-modules (ice-9 syncase))
46 (use-modules (ice-9 optargs))))
48 (define-module (nyacc)
49 #:use-module (nyacc lalr)
50 #:use-module (nyacc lex)
51 #:use-module (nyacc parse)
52 #:use-module (ice-9 rdelim)
53 #:use-module (ice-9 pretty-print)
58 (prec< (left "+" "-") (left "*" "/"))
62 (expr "+" expr ($$ (+ $1 $3)))
63 (expr "-" expr ($$ (- $1 $3)))
64 (expr "*" expr ($$ (* $1 $3)))
65 (expr "/" expr ($$ (/ $1 $3)))
67 ($fixed ($$ (string->number $1)))
68 ($float ($$ (string->number $1)))
69 ("(" expr ")" ($$ $2))))))
71 (define simple-mach (make-lalr-machine simple-spec))
73 ;; (use-modules (nyacc bison))
74 ;; (define simple-mach (make-lalr-machine/bison simple-spec))
76 (define match-table (assq-ref simple-mach 'mtab))
78 (define gen-lexer (make-lexer-generator match-table))
80 (define parse (make-lalr-parser simple-mach))
82 (define demo-string "2 + 2")
84 (define (main arguments)
87 (display (with-input-from-string demo-string
88 (lambda () (parse (gen-lexer)))))