Import Nyacc 0.72.0.

* module/nyacc: Import module/nyacc.
This commit is contained in:
Jan Nieuwenhuizen 2016-12-17 22:34:43 +01:00
parent f8bc344dfc
commit a53e09d3e8
30 changed files with 10427 additions and 0 deletions

22
module/nyacc/BUGS Normal file
View file

@ -0,0 +1,22 @@
Copyright (C) 2016 Matthew R. Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
BUG-004 <= next bug id
BUG-003 If using phony prec token then it ends up in match table.
For example, "then" appears in the match table for lang/c99.
=fixed=
BUG-001 In lalr.scm, hashify-machine, if pat contains a rrconf then the output
is unspecified
todo I think this was already fixed
BUG-002 If mach has a conflict and hashify followed by pp-lalr-machine then
error because hashify puts #f, not integer, for pat-v.
fixed fixed pp-lalr-machine to check for #f

18
module/nyacc/ChangeLog Normal file
View file

@ -0,0 +1,18 @@
2016-04-09 Matt Wette <mwette@nautilus>
* bison.scm: new file providing make-lalr-machin/bison. It is
similar to make-lalr-machine but uses external bison program
instead of the default from-scratch lalr code.
2016-03-04 Matt Wette <mwette@nautilus>
* lalr.scm: changed grammar parser to interpret $string as
terminal. This saves typing a quote in front.
Copyright (C) 2015,2016 Matthew R. Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.

54
module/nyacc/README Normal file
View file

@ -0,0 +1,54 @@
nyacc/README
Copyright (C) 2016 Matthew R. Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
strategy for generating parsers and other stuff
guile -s mach.scm -c '(@ (nyacc lang c99 mach) gen-mach-files)'
=> .scm/{actions.scm,tables.scm}
#guild compile
eval-when?
use-case: dist mach-files and parser
dist:
mach.scm
===============================================================================
dev-parser.scm: mach.scm pbody.scm mk-parser.scm
parser.scm: mach.scm pbody.scm mk-parser.scm
expr-parser.scm: mach.scm pbody.scm mk-parser.scm
$ guile -l cppmach.scm -c '(@ (nyacc lang c99 cppmach) gen-cpp-files)'
> cppact.scm cpptab.scm
$ guile -l mach.scm -c '(@ (nyacc lang c99 mach) gen-c99-files)'
> c99act.scm c99tab.scm
$ guile -l mach.scm -c '(@ (nyacc lang c99 mach) gen-c99x-files)'
> c99xact.scm c99xtab.scm
===============================================================================
install:
cpp.go
mach.go
parser.go
xparser.go
pprint.go
util1.go
util1.go
cpp.scm: cppmach.scm
#cppmach.scm (export-files

215
module/nyacc/bison.scm Normal file
View file

@ -0,0 +1,215 @@
;;; nyacc/bison.scm
;;;
;;; Copyright (C) 2016 Matthew R. Wette
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 3 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (nyacc bison)
#:export (make-lalr-machine/bison)
#:use-module (sxml simple)
#:use-module (sxml match)
#:use-module (sxml xpath)
#:use-module (ice-9 pretty-print)
#:use-module ((srfi srfi-1) #:select (fold))
#:use-module ((srfi srfi-43) #:select (vector-for-each vector-map))
#:use-module (nyacc export)
#:use-module (nyacc lalr) ; gen-match-table
)
;; @deffn chew-on-grammar tree lhs-v rhs-v terms => a-list
;; Generate a-list that maps bison rule index to NYACC rule index.
(define (chew-on-grammar tree lhs-v rhs-v terms) ;; bison-rule => nyacc-rule map
;; match rule index, if no match return @code{-1}
;; could be improved by starting with last rule number and wrapping
(define (match-rule lhs rhs)
(let iter ((ix 0))
(if (eqv? ix (vector-length lhs-v)) -1
(if (and (equal? lhs (elt->bison (vector-ref lhs-v ix) terms))
(equal? rhs (vector->list
(vector-map
(lambda (ix val) (elt->bison val terms))
(vector-ref rhs-v ix)))))
ix
(iter (1+ ix))))))
;; this is a fold
(define (rule->index-al tree seed)
(sxml-match tree
;; Skip first bison rule: always $accept.
((rule (@ (number "0")) (lhs "$accept") . ,rest)
(acons 0 0 seed))
;; This matches all others.
((rule (@ (number ,n)) (lhs ,lhs) (rhs (symbol ,rhs) ...))
(acons (string->number n) (match-rule lhs rhs) seed))
(,otherwise seed)))
(fold rule->index-al '() ((sxpath '(// rule)) tree)))
;; @deffn chew-on-automaton tree gx-al bs->ns => a-list
;; This digests the automaton and generated the @code{pat-v} and @code{kis-v}
;; vectors for the NYACC automaton.
(define (chew-on-automaton tree gx-al bs->ns)
(define st-numb
(let ((xsnum (sxpath '(@ number *text*))))
(lambda (state)
(string->number (car (xsnum state))))))
(define (do-state state)
(let* ((b-items ((sxpath '(// item)) state))
(n-items (fold
(lambda (tree seed)
(sxml-match tree
((item (@ (rule-number ,rns) (point ,pts)) . ,rest)
(let ((rn (string->number rns))
(pt (string->number pts)))
(if (and (positive? rn) (zero? pt)) seed
(acons (assq-ref gx-al rn) pt seed))))
(,otherwise (error "broken item")))) '() b-items))
(b-trans ((sxpath '(// transition)) state))
(n-trans (map
(lambda (tree)
(sxml-match tree
((transition (@ (symbol ,symb) (state ,dest)))
(cons* (bs->ns symb) 'shift (string->number dest)))
(,otherwise (error "broken tran")))) b-trans))
(b-redxs ((sxpath '(// reduction)) state))
(n-redxs (map
(lambda (tree)
(sxml-match tree
((reduction (@ (symbol ,symb) (rule "accept")))
(cons* (bs->ns symb) 'accept 0))
((reduction (@ (symbol ,symb) (rule ,rule)))
(cons* (bs->ns symb) 'reduce
(assq-ref gx-al (string->number rule))))
(,otherwise (error "broken redx" tree)))) b-redxs))
)
(list
(st-numb state)
(cons 'kis n-items)
(cons 'pat (append n-trans n-redxs)))))
(let ((xsf (sxpath '(itemset item (@ (rule-number (equal? "0"))
(point (equal? "2")))))))
(let iter ((data '()) (xtra #f) (states (cdr tree)))
(cond
((null? states) (cons xtra data))
((pair? (xsf (car states)))
(iter data (st-numb (car states)) (cdr states)))
(else
(iter (cons (do-state (car states)) data) xtra (cdr states)))))))
;; @deffn atomize symbol => string
;; This is copied from the module @code{(nyacc lalr)}.
(define (atomize terminal) ; from lalr.scm
(if (string? terminal)
(string->symbol (string-append "$:" terminal))
terminal))
;; @deffn make-bison->nyacc-symbol-mapper terminals non-terminals => proc
;; This generates a procedure to map bison symbol names, generated by the
;; NYACC @code{lalr->bison} procedure, (back) to nyacc symbols names.
(define (make-bison->nyacc-symbol-mapper terms non-ts)
(let ((bs->ns-al
(cons*
'("$default" . $default)
'("$end" . $end)
(map (lambda (symb) (cons (elt->bison symb terms) symb))
(append (map atomize terms) non-ts)))))
(lambda (name) (assoc-ref bs->ns-al name))))
;; fix-pa
;; fix parse action
(define (fix-pa pa xs)
(cond
((and (eqv? 'shift (cadr pa))
(> (cddr pa) xs))
(cons* (car pa) (cadr pa) (1- (cddr pa))))
((and (eqv? 'shift (cadr pa))
(= (cddr pa) xs))
(cons* (car pa) 'accept 0))
(else pa)))
;; @deffn fix-is is xs rhs-v
;; Convert xxx
(define (fix-is is xs rhs-v)
(let* ((gx (car is))
(rx (cdr is))
(gl (vector-length (vector-ref rhs-v gx))))
(if (= rx gl) (cons gx -1) is)))
;; @deffn spec->mac-sxml spec
;; Write bison-converted @var{spec} to file, run bison on it, and load
;; the bison-generated automaton as a SXML tree using the @code{-x} option.
(define (spec->mach-sxml spec)
(let* ((basename (tmpnam))
(bisname (string-append basename ".y"))
(xmlname (string-append basename ".xml"))
(tabname (string-append basename ".tab.c")))
(with-output-to-file bisname
(lambda () (lalr->bison spec)))
(system (string-append "bison" " --xml=" xmlname " --output=" tabname
" " bisname))
(let ((sx (call-with-input-file xmlname
(lambda (p) (xml->sxml p #:trim-whitespace? #t)))))
(delete-file bisname)
(delete-file xmlname)
(delete-file tabname)
sx)))
;; @deffn make-lalr-machine/bison spec => mach
;; Make a LALR automaton, consistent with that from @code{make-lalr-machine}
;; using external @code{bison} program.
(define (make-lalr-machine/bison spec)
(let* ((terminals (assq-ref spec 'terminals))
(non-terms (assq-ref spec 'non-terms))
(lhs-v (assq-ref spec 'lhs-v))
(rhs-v (assq-ref spec 'rhs-v))
(s0 (spec->mach-sxml spec))
(sG ((sxpath '(bison-xml-report grammar)) s0))
(sG (if (pair? sG) (car sG) sG))
(sA ((sxpath '(bison-xml-report automaton)) s0))
(sA (if (pair? sA) (car sA) sA))
(pG (chew-on-grammar sG lhs-v rhs-v terminals))
(bsym->nsym (make-bison->nyacc-symbol-mapper terminals non-terms))
(pA (chew-on-automaton sA pG bsym->nsym))
(xs (car pA))
(ns (caadr pA))
(pat-v (make-vector ns #f))
(kis-v (make-vector ns #f))
)
;;(pretty-print sA)
(for-each
(lambda (state)
(let* ((sx (car state))
(sx (if (>= sx xs) (1- sx) sx))
(pat (assq-ref (cdr state) 'pat))
(pat (map (lambda (pa) (fix-pa pa xs)) pat))
(kis (assq-ref (cdr state) 'kis))
(kis (map (lambda (is) (fix-is is xs rhs-v)) kis)))
(vector-set! pat-v sx pat)
(vector-set! kis-v sx kis)))
(cdr pA))
(gen-match-table
(cons*
(cons 'pat-v pat-v)
(cons 'kis-v kis-v)
(cons 'len-v (vector-map (lambda (i v) (vector-length v)) rhs-v))
(cons 'rto-v (vector-copy lhs-v))
spec))))
;; --- last line ---

200
module/nyacc/export.scm Normal file
View file

@ -0,0 +1,200 @@
;;; nyacc/export.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 3 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (nyacc export)
#:export (lalr->bison
lalr->guile
c-char token->bison elt->bison
)
#:use-module ((nyacc lalr) #:select (find-terminal pp-rule))
#:use-module (nyacc lex)
#:use-module (nyacc util)
#:use-module ((srfi srfi-1) #:select (fold))
#:use-module ((srfi srfi-43) #:select (vector-for-each))
#:use-module (ice-9 regex)
)
;; The code below, for exporting to guile and bison, should be moved to
;; an "export" module.
;; terminal:
;; ident-like-string -> caps
;; non-ident-like-string -> ChSeq_#_# ...
;; symbol -> if $, use _, otherwise ???
;; breakdown:
;; 1 terminal, or non-terminal:
;; 2 if non-terminal,
;; replace - with _, replace $ with _
;; 3 if terminal, (output of @code{find-terminal})
;; if symbol, use 2
;; replace char with (c-char .)
;; if length-1 string replace with (c-char .)
;; if like-c-ident string, replace with CAPS
;; otherwise use ChSeq
(define re/g regexp-substitute/global)
(define (chseq->name cs)
(let* ((iseq (string-fold (lambda (c s) (cons* (char->integer c) s)) '() cs))
(tail (string-join (map number->string iseq) "_"))
(name (string-append "ChSeq_" tail)))
name))
;; Convert char to string that works inside single quotes for C.
(define (c-char ch)
(case ch
((#\') "'\\''")
((#\\) "'\\\\'")
((#\newline) "'\\n'")
((#\tab) "'\\t'")
((#\return) "\\r")
(else (string #\' ch #\'))))
(define (token->bison tok)
(cond
((eqv? tok '$error) "error")
((symbol? tok) (symbol->bison tok))
((char? tok) (c-char tok))
((string? tok)
(cond
((like-c-ident? tok) (string-upcase tok))
((= 1 (string-length tok)) (c-char (string-ref tok 0)))
(else (chseq->name tok))))
(else (error "what?"))))
(define (symbol->bison symb)
(let* ((str0 (symbol->string symb))
(str1 (re/g #f "-" str0 'pre "_" 'post))
(str2 (re/g #f "\\$" str1 'pre "_" 'post)))
str2))
(define (elt->bison symb terms)
(let ((term (find-terminal symb terms)))
(if term
(token->bison term)
(symbol->bison symb))))
;; @deffn lalr->bison spec => to current output port
;; needs cleanup: tokens working better but p-rules need fix.
(define (lalr->bison spec . rest)
(define (setup-assc assc)
(fold (lambda (al seed)
(append (x-flip al) seed)) '() assc))
(let* ((port (if (pair? rest) (car rest) (current-output-port)))
(lhs-v (assq-ref spec 'lhs-v))
(rhs-v (assq-ref spec 'rhs-v))
(prp-v (assq-ref spec 'prp-v))
(assc (setup-assc (assq-ref spec 'assc)))
(nrule (vector-length lhs-v))
(terms (assq-ref spec 'terminals)))
;; Generate copyright notice.
(let* ((notice (assq-ref (assq-ref spec 'attr) 'notice))
(lines (if notice (string-split notice #\newline) '())))
(for-each (lambda (l) (fmt port "// ~A\n" l))
lines))
;; Write out the tokens.
(for-each
(lambda (term)
(unless (eqv? term '$error)
(fmt port "%token ~A\n" (token->bison term))))
terms)
;; Write the associativity and prececences.
(let iter ((pl '()) (ppl (assq-ref spec 'prec)))
(cond
((pair? pl)
(fmt port "%~A" (or (assq-ref assc (caar pl)) "precedence"))
(let iter2 ((pl (car pl)))
(unless (null? pl)
(fmt port " ~A" (elt->bison (car pl) terms))
(iter2 (cdr pl))))
(fmt port "\n")
(iter (cdr pl) ppl))
((pair? ppl) (iter (car ppl) (cdr ppl)))))
;; Don't compact tables.
(fmt port "%define lr.default-reduction accepting\n")
;; Provide start symbol.
(fmt port "%start ~A\n%%\n" (elt->bison (assq-ref spec 'start) terms))
;;
(do ((i 1 (1+ i))) ((= i nrule))
(let* ((lhs (vector-ref lhs-v i)) (rhs (vector-ref rhs-v i)))
(fmt port "~A:" (elt->bison lhs terms))
(vector-for-each
(lambda (ix e) (fmt port " ~A" (elt->bison e terms)))
rhs)
(if (zero? (vector-length rhs)) (fmt port " %empty"))
(and=> (vector-ref prp-v i)
(lambda (tok) (fmt port " %prec ~A" (elt->bison tok terms))))
(fmt port " ;\n")))
(newline port)
(values)))
;; @item pp-guile-input spec => to current output port
;; total hack right now
(define (lalr->guile spec . rest)
(let* ((port (if (pair? rest) (car rest) (current-output-port)))
(lhs-v (assq-ref spec 'lhs-v))
(rhs-v (assq-ref spec 'rhs-v))
(act-v (assq-ref spec 'act-v))
(nrule (vector-length lhs-v))
(terms (assq-ref spec 'terminals))
(lhsP #f))
;;
(fmt port "(use-modules (system base lalr))\n")
(fmt port "(define parser\n")
(fmt port " (lalr-parser\n (")
(for-each
(lambda (s)
(if (> (port-column port) 60) (fmt port "\n "))
(cond
((equal? #\; s) (fmt port " C-semi"))
((symbol? s) (fmt port " ~A" s))
(else (fmt port " C-~A" s))))
terms)
(fmt port ")\n")
;;
(do ((i 1 (1+ i))) ((= i nrule))
(let* ((lhs (vector-ref lhs-v i)) (rhs (vector-ref rhs-v i)))
(if #f
(pp-rule 0 i)
(begin
(if lhsP
(if (not (eqv? lhs lhsP))
(fmt port " )\n (~S\n" lhs))
(fmt port " (~S\n" lhs))
(fmt port " (")
(do ((j 0 (1+ j) )) ((= j (vector-length rhs)))
(let ((e (vector-ref rhs j)))
(if (positive? j) (fmt port " "))
(fmt
port "~A"
(cond
((equal? #\; e) (fmtstr "C-semi"))
((char? e) (fmtstr "C-~A" e))
(else e)))
))
(fmt port ") ")
(fmt port ": ~S" `(begin ,@(vector-ref act-v i)))
(fmt port "\n")
(set! lhsP lhs)))))
(fmt port " ))\n")
(fmt port " )\n")
(values)))
;;; --- last line ---

106
module/nyacc/import.scm Normal file
View file

@ -0,0 +1,106 @@
;;; nyacc/import.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 3 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;; Convert guile lalr grammar to nyacc grammar.
;; What is *eoi* for?
(define-module (nyacc import)
#:export-syntax (lalr-parser)
#:export (guile-lalr->nyacc-lalr)
#:use-module ((srfi srfi-1) #:select (fold-right))
)
(define (convert-tree spec0)
(let* ((terms (cons '*eoi* (car spec0)))
(start (caadr spec0))
(wrap-symb
(lambda (s) (cons (if (memq s terms) 'terminal 'non-terminal) s))))
(let iter ((prl1 '()) ; new production rules
(prl0 (cdr spec0)) ; old production rules
(lhs #f) ; LHS
(rhs1-l #f) ; new RHS list
(rhs0-l #f)) ; old RHS list
(cond
((pair? rhs0-l) ;; convert RHS
(iter prl1 prl0 lhs
(cons
(fold-right ;; s1 ... : a => (('terminal . s) ... ('$$ . a))
(lambda (symb seed) (cons (wrap-symb symb) seed))
(list (list '$$ (cdar rhs0-l)))
(caar rhs0-l))
rhs1-l)
(cdr rhs0-l)))
((null? rhs0-l) ;; roll up LHS+RHSs to new rule
(iter (cons (cons lhs (reverse rhs1-l)) prl1) prl0 #f #f #f))
((pair? prl0) ;; next production rule
(iter prl1 (cdr prl0) (caar prl0) '() (cdar prl0)))
(else ;; return spec in preliminary form
(list
'lalr-spec
`(start ,start)
`(grammar ,(reverse prl1))))))))
(define-syntax parse-rhs-list
(syntax-rules (:)
((_ (<rhs0sym> ...) : <rhs0act> <rhs1> ...)
(cons (cons '(<rhs0sym> ...) '<rhs0act>)
(parse-rhs-list <rhs1> ...)))
((_) (list))))
(define-syntax parse-prod-list
(syntax-rules ()
((_ (<lhs> <rhs> ...) <prod1> ...)
(cons (cons '<lhs> (parse-rhs-list <rhs> ...))
(parse-prod-list <prod1> ...)))
((_) (list))))
(define-syntax lalr-parser
(syntax-rules ()
((_ <tokens> <prod0> ...)
(convert-tree
(cons '<tokens> (parse-prod-list <prod0> ...))))))
(define (guile-lalr->nyacc-lalr match-table spec)
(letrec
((mark (lambda (s) (if (symbol? s) `(quote ,s) s)))
(rmt (map (lambda (p) (cons (cdr p) (mark (car p)))) match-table))
(clean
(lambda (dt)
(cond
((null? dt) '())
((pair? dt)
(case (car dt)
((non-terminal) (cdr dt))
((terminal)
(cond
((assq-ref rmt (cdr dt)))
((symbol? (cdr dt)) (simple-format #f "~A" (cdr dt)))
(else (cdr dt))))
((start) dt)
(else
(cons (clean (car dt)) (clean (cdr dt))))))
(else
dt))))
)
(clean spec)))
;;; --- last line ---

2030
module/nyacc/lalr.scm Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,39 @@
C99-007 <= next id
C99-006 06 Aug 2016, M.Wette
code "val = '\0';" gets pprinted to "val = '^@;';"
C99-005 26 Jun 2016, M.Wette
in util2.scm, tree->udecl needs to return "struct" and "union"
entries for stuff like
struct foo { int x; };
C99-004 xdef arg to gen-c-lexer may be too simple
it is currently a predicate. Maybe it should return three values
#f => don't expand
#t => expand
string => use string
C99-003 util2.scm/tree->udict should return declarations in order
=== RESOLVED ===================
C99-001 cpp breaks on the following, I think:
#define ABC 123 /* this is a var */
#if ABC > 100
# error "bla"
#endif
13Apr16 works
C99-002 CPP redesign is not working for ifdef and defined:
#define A 1
#ifdef A
...
breaks because it gets expanded as (if "defined(1)")
see cppbody.scm, near line 133:
((read-c-ident ch) =>
(lambda (iden)
25Jun16 fixed
--- last line ---

View file

@ -0,0 +1,45 @@
nyacc/lang/c99/
Copyright (C) 2015,2016 Matthew R. Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
manifest:
cpp.scm C preprocessor using tables
includes: cppbody.scm cppact.scm,cpptab.scm
cppbody.scm eval-cpp-expr procedure
cppmach.scm CPP expression grammer, machine and act/tab file generation
mach.scm C grammer, machine and act/tab file generation
include: pbody.scm
depends: cpp.scm
parser.scm C file parser, using tables
includes: body.scm, c99act.scm, c99tab.scm
depends: cpp.scm
xparser.scm C expression parser
includes: body.scm, c99xact.scm, c99xtab.scm
depends: cpp.scm
pprint.scm C pretty printer, from SXML output of above parsers
util1.scm utilities merge, remove trees from included files
util2.scm utilities to process information in trees
mach.d/
cppact.scm cpp expression parser actions, generated from cppmach.scm
cpptab.scm cpp expression parser tables, generated from cppmach.scm
c99act.scm parser actions, generated from mach.scm
c99tab.scm C99 parser tables, generated from mach.scm
c99xact.scm expression parser actions, generated from mach.scm
c99xtab.scm C99 expression parser tables, generated from mach.scm
==== cpp ================================
parse-cpp-line line => tree

View file

@ -0,0 +1,423 @@
;;; lang/c99/body.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C parser body, with cpp and tables makes a parser
(define-record-type cpi
(make-cpi-1)
cpi?
(debug cpi-debug set-cpi-debug!) ; debug #t #f
(defines cpi-defs set-cpi-defs!) ; #defines
(incdirs cpi-incs set-cpi-incs!) ; #includes
(tn-dict cpi-tynd set-cpi-tynd!) ; typename dict (("<x>" foo_t ..
;;
;;(typnams cpi-tyns set-cpi-tyns!) ; typedef names
;;
(ptl cpi-ptl set-cpi-ptl!) ; parent typename list
(ctl cpi-ctl set-cpi-ctl!) ; current typename list
;;
;;(typdcls cpi-tdls set-cpi-tdls!) ; typedef decls
)
(define std-dict
'(("time.h" "time_t" "clock_t" "size_t")
("stdio.h" "FILE" "size_t")
("string.h" "size_t")
("stddef.h" "ptrdiff_t" "size_t" "wchar_t")
("inttypes.h"
"int8_t" "uint8_t" "int16_t" "uint16_t" "int32_t" "uint32_t"
"int64_t" "uint64_t" "uintptr_t" "intptr_t" "intmax_t" "uintmax_t"
"int_least8_t" "uint_least8_t" "int_least16_t" "uint_least16_t"
"int_least32_t" "uint_least32_t" "int_least64_t" "uint_least64_t"
"imaxdiv_t")
("stdint.h"
"int8_t" "uint8_t" "int16_t" "uint16_t" "int32_t" "uint32_t"
"int64_t" "uint64_t" "uintptr_t" "intptr_t" "intmax_t" "uintmax_t"
"int_least8_t" "uint_least8_t" "int_least16_t" "uint_least16_t"
"int_least32_t" "uint_least32_t" "int_least64_t" "uint_least64_t")
("stdlib.h" "div_t" "ldiv_t" "lldiv_t" "wchar_t")
("stdarg.h" "va_list")
;;("unistd.h" "div_t" "ldiv_t")
("signal.h" "sig_atomic_t")
("setjmp.h" "jmp_buf")
("float.h" "float_t")
("fenv.h" "fenv_t" "fexcept_t")
("complex.h" "complex" "imaginary")
("wchar.h" "wchar_t" "wint_t" "mbstate_t" "size_t")
("wctype.h" "wctrans_t" "wctype_t" "wint_t")
("math.h")
))
(define (make-cpi debug defines incdirs tn-dict)
(let* ((cpi (make-cpi-1)))
(set-cpi-debug! cpi debug)
(set-cpi-defs! cpi defines)
(set-cpi-incs! cpi incdirs)
(set-cpi-tynd! cpi (append tn-dict std-dict))
(set-cpi-ptl! cpi '()) ; list of lists of strings
(set-cpi-ctl! cpi '()) ; list of strings ?
cpi))
;; Need to have a "CPI" stack to deal with types (re)defined in multiple
;; branches of a #if...#endif statement. If we are in "code" mode then we
;; may be skipping code so need to track when to shift and when not to.
(define *info* (make-fluid #f))
;; given tyns
;; cadr is next level
;; caar is list of sibs
;; search (caar car tyns), then (caar cadr tyns), then ...
;; @deffn typename? name
;; Called by lexer to determine if symbol is a typename.
;; Check current sibling for each generation.
(define (typename? name)
;;(simple-format #t "typename? ~S\n" name)
(let ((cpi (fluid-ref *info*)))
(when #f ;;(string=? name "SpiceInt")
(simple-format #t "tn? ~S ~S\n" (cpi-ctl cpi) (cpi-ptl cpi)))
(if (member name (cpi-ctl cpi)) #t
(let iter ((ptl (cpi-ptl cpi)))
(if (null? ptl) #f
(if (member name (car ptl)) #t
(iter (cdr ptl))))))))
;; @deffn add-typename name
;; Helper for @code{save-typenames}.
(define (add-typename name)
;;(simple-format #t "add-typename ~S\n" name)
(let ((cpi (fluid-ref *info*)))
(set-cpi-ctl! cpi (cons name (cpi-ctl cpi)))
;;(simple-format #t "at: ~S ~S\n" (cpi-ctl cpi) (cpi-ptl cpi))
))
(define (cpi-push) ;; on #if
(let ((cpi (fluid-ref *info*)))
(set-cpi-ptl! cpi (cons (cpi-ctl cpi) (cpi-ptl cpi)))
(set-cpi-ctl! cpi '())
;;(simple-format #t "pu: ~S\n" (cpi-ctl cpi))
))
(define (cpi-shift) ;; on #elif #else
(set-cpi-ctl! (fluid-ref *info*) '()))
(define (cpi-pop) ;; on #endif
(let ((cpi (fluid-ref *info*)))
;;(simple-format #t "po<: ~S ~S\n" (cpi-ctl cpi) (cpi-ptl cpi))
(set-cpi-ctl! cpi (append (cpi-ctl cpi) (car (cpi-ptl cpi))))
(set-cpi-ptl! cpi (cdr (cpi-ptl cpi)))
;;(simple-format #t "po>: ~S ~S\n" (cpi-ctl cpi) (cpi-ptl cpi))
))
(use-modules (ice-9 pretty-print))
;; @deffn find-new-typenames decl
;; Helper for @code{save-typenames}.
;; Given declaration return a list of new typenames (via @code{typedef}).
(define (find-new-typenames decl)
;; like declr->ident in util2.scm
(define (declr->id-name declr)
(case (car declr)
((ident) (sx-ref declr 1))
((init-declr) (declr->id-name (sx-ref declr 1)))
((comp-declr) (declr->id-name (sx-ref declr 1)))
((array-of) (declr->id-name (sx-ref declr 1)))
((ptr-declr) (declr->id-name (sx-ref declr 2)))
((ftn-declr) (declr->id-name (sx-ref declr 1)))
((scope) (declr->id-name (sx-ref declr 1)))
(else (error "coding bug: " declr))))
(let* ((spec (sx-ref decl 1))
(stor (sx-find 'stor-spec spec))
(id-l (sx-ref decl 2)))
(if (and stor (eqv? 'typedef (caadr stor)))
(let iter ((res '()) (idl (cdr id-l)))
(if (null? idl) res
(iter (cons (declr->id-name (sx-ref (car idl) 1)) res)
(cdr idl))))
'())))
;; @deffn save-typenames decl
;; Save the typenames for the lexical analyzer and return the decl.
(define (save-typenames decl)
;; This finds typenames using @code{find-new-typenames} and adds via
;; @code{add-typename}. Then return the decl.
(for-each add-typename (find-new-typenames decl))
decl)
;; ------------------------------------------------------------------------
;; @deffn read-cpp-line ch => #f | (cpp-xxxx)??
;; Given if ch is #\# read a cpp-statement
;; includes BUG: #define ABC 123 /* \n
(define (read-cpp-line ch)
(if (not (eq? ch #\#)) #f
(let iter ((cl '()) (ch (read-char)))
(cond
((eq? ch #\newline) (list->string (reverse cl)))
((eq? ch #\\)
(let ((c2 (read-char)))
(if (eq? c2 #\newline)
(iter cl (read-char))
(iter (cons* c2 ch cl) (read-char)))))
((eq? ch #\/) ;; swallow comments, event w/ newlines
(let ((c2 (read-char)))
(cond
((eqv? c2 #\*)
(let iter2 ((cl2 (cons* #\* #\/ cl)) (ch (read-char)))
(cond
((eq? ch #\*)
(let ((c2 (read-char)))
(if (eqv? c2 #\/)
(iter (cons* #\/ #\* cl2) (read-char)) ;; keep comment
;;(iter cl (read-char)) ;; toss comment
(iter2 (cons #\* cl2) c2))))
(else
(iter2 (cons ch cl2) (read-char))))))
(else
(iter (cons #\/ cl) c2)))))
(else (iter (cons ch cl) (read-char)))))))
;; @deffn find-file-in-dirl file dirl => path
(define (find-file-in-dirl file dirl)
(let iter ((dirl dirl))
(if (null? dirl) #f
(let ((p (string-append (car dirl) "/" file)))
(if (access? p R_OK) p (iter (cdr dirl)))))))
;; @subsubsection CPP If-Else Processing
;; States are
;; @table code
;; @item skip
;; skip code
;; @item skip-look
;; skipping code, but still looking for true at this level
;; @item keep
;; keep code
;; @item keep1
;; NOT USED keep one token and pop skip-stack
;; @item skip-one
;; skip one token and pop skip-stack
;; @end table
;; NOTE: if file mode we usually keep #ifdefs. The lone exception is
;; @code{#if 0}
;; @deffn gen-c-lexer [#:mode mode] => thunk
;; Generate a context-sensitive lexer for the C language.
;; The key-arg @var{mode} can be @code{'code} or @code{'file}. If @code{'code}
;; @enumerate
;; @item
;; CPP defines are expanded (future work)
;; @item
;; CPP if/def is executed
;; @end enumerate
(define (def-xdef? name mode)
(eqv? mode 'code))
;; @deffn gen-c-lexer [#:mode mode] [#:xdef? proc] => thunk
(define gen-c-lexer
;; This gets ugly in order to handle cpp.
;;.need to add support for num's w/ letters like @code{14L} and @code{1.3f}.
;; todo: I think there is a bug wrt the comment reader because // ... \n
;; will end up in same mode... so after
;; int x; // comment
;; the lexer will think we are not at BOL.
(let* ((match-table mtab)
(read-ident read-c-ident)
(read-comm read-c-comm)
;;
(ident-like? (make-ident-like-p read-ident))
;;
(strtab (filter-mt string? match-table)) ; strings in grammar
(kwstab (filter-mt ident-like? strtab)) ; keyword strings =>
(keytab (map-mt string->symbol kwstab)) ; keywords in grammar
(chrseq (remove-mt ident-like? strtab)) ; character sequences
(symtab (filter-mt symbol? match-table)) ; symbols in grammar
(chrtab (filter-mt char? match-table)) ; characters in grammar
;;
(read-chseq (make-chseq-reader chrseq))
(assc-$ (lambda (pair) (cons (assq-ref symtab (car pair)) (cdr pair))))
;;
(t-ident (assq-ref symtab '$ident))
(t-typename (assq-ref symtab 'typename))
(xp1 (sxpath '(cpp-stmt define)))
(xp2 (sxpath '(decl))))
;; mode: 'code|'file
;; xdef?: (proc name mode) => #t|#f : do we expand #define?
;; ppev?: (proc ???) => #t|#f : do we eval-and-honor #if/#else ?
(lambda* (#:key (mode 'code) (xdef? #f))
(let ((bol #t) ; begin-of-line condition
(skip (list 'keep)) ; CPP skip-input stack
(info (fluid-ref *info*)) ; assume make and run in same thread
(pstk '()) ; port stack
(x-def? (or xdef? (lambda (name mode) (eqv? mode 'code)))))
;; Return the first (tval lval) pair not excluded by the CPP.
(lambda ()
(define (eval-flow?)
(eqv? mode 'code))
(define (add-define tree)
(let* ((tail (cdr tree))
(name (car (assq-ref tail 'name)))
(args (assq-ref tail 'args))
(repl (car (assq-ref tail 'repl)))
(cell (cons name (if args (cons args repl) repl))))
(set-cpi-defs! info (cons cell (cpi-defs info)))))
(define (rem-define name)
(set-cpi-defs! info (delete name (cpi-defs info))))
(define (exec-cpp line)
;; Parse the line into a CPP stmt, execute it, and return it.
(let* ((stmt (read-cpp-stmt line))
(perr (lambda (file)
(throw 'parse-error "file not found: ~S" file))))
(case (car stmt)
((include)
(let* ((parg (cadr stmt)) (leng (string-length parg))
(file (substring parg 1 (1- leng)))
(tynd (assoc-ref (cpi-tynd info) file)))
(if tynd
(for-each add-typename tynd)
(let* ((pth (find-file-in-dirl file (cpi-incs info)))
(tree (if pth ; path exists
(or (with-input-from-file pth run-parse)
(throw 'parse-error "~A" pth))
(perr file))))
(for-each add-define (xp1 tree)) ; add def's
;; Attach tree onto "include" statement.
(if (pair? tree) (set! stmt (append stmt (list tree))))
))))
((define)
(add-define stmt))
((undef)
(rem-define (cadr stmt)))
((if) ;; and ifdef, ifndef
(cpi-push)
(if (eval-flow?)
(let* ((defs (cpi-defs info))
(rhs (cpp-expand-text (cadr stmt) defs))
;; rhs = "defined(1)" :(
(exp (parse-cpp-expr rhs))
(val (eval-cpp-expr exp defs)))
(cond
((not val)
(throw 'parse-error "unresolved: ~S" (cadr stmt)))
((zero? val)
(set! skip (cons* 'skip-one 'skip-look skip)))
(else
(set! skip (cons* 'skip-one (car skip) skip)))))))
((elif)
(if (eval-flow?)
(let* ((defs (cpi-defs info))
(rhs (cpp-expand-text (cadr stmt) defs))
(exp (parse-cpp-expr rhs))
(val (eval-cpp-expr exp defs)))
(cond
((not val)
(throw 'parse-error "unresolved: ~S" (cadr stmt)))
((eq? 'keep (car skip))
(set! skip (cons* 'skip-one 'skip (cdr skip))))
((zero? val)
(set! skip (cons* 'skip-one skip)))
((eq? 'skip-look (car skip))
(cpi-shift)
(set! skip (cons* 'skip-one 'keep (cdr skip))))
(else
(cpi-shift)
(set! skip (cons* 'skip-one 'skip (cdr skip))))))
(cpi-shift)))
((else)
(if (eval-flow?)
(cond
((eq? 'skip-look (car skip))
(cpi-shift)
(set! skip (cons* 'skip-one 'keep (cdr skip))))
(else
(set! skip (cons* 'skip-one 'skip (cdr skip)))))
(cpi-shift)))
((endif)
(cpi-pop)
(if (eval-flow?)
(set! skip (cons 'skip-one (cdr skip)))))
((error)
stmt)
(else
(error "unhandled cpp stmt")))
(cons 'cpp-stmt stmt)))
;; Composition of @code{read-cpp-line} and @code{exec-cpp}.
(define (read-cpp ch)
(and=> (read-cpp-line ch) exec-cpp))
(define (read-token)
(let iter ((ch (read-char)))
(cond
((eof-object? ch)
(if (pop-input) (iter (read-char)) (assc-$ '($end . ""))))
((eq? ch #\newline) (set! bol #t) (iter (read-char)))
((char-set-contains? c:ws ch) (iter (read-char)))
(bol
(cond
((read-comm ch bol) => assc-$)
((read-cpp ch) => assc-$)
(else (set! bol #f) (iter ch))))
((read-ident ch) =>
(lambda (name)
(let ((symb (string->symbol name)))
(cond
((and (x-def? name mode)
(expand-cpp-mref name (cpi-defs info)))
=> (lambda (st)
(push-input (open-input-string st))
(iter (read-char))))
((assq-ref keytab symb)
=> (lambda (t) (cons t name)))
((typename? name)
(cons (assq-ref symtab 'typename) name))
(else
(cons (assq-ref symtab '$ident) name))))))
((read-c-num ch) => assc-$)
((read-c-string ch) => assc-$)
((read-c-chlit ch) => assc-$)
((read-comm ch bol) => assc-$)
((read-chseq ch) => identity)
((assq-ref chrtab ch) => (lambda (t) (cons t (string ch))))
((eqv? ch #\\) ;; C allows \ at end of line to continue
(let ((ch (read-char)))
(cond ((eqv? #\newline ch) (iter (read-char))) ;; extend line
(else (unread-char ch) (cons #\\ "\\"))))) ;; parse err
(else (cons ch (string ch))))))
;; Loop between reading tokens and skipping tokens.
;; The use of "delayed pop" is not clean IMO. Cleaner way?
(let loop ((pair (read-token)))
(case (car skip)
((keep) pair)
((skip skip-look) (loop (read-token)))
((skip-one)
(set! skip (cdr skip))
(loop (read-token)))))
)))))
;; --- last line ---

View file

@ -0,0 +1,138 @@
;;; lang/c/cpp.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C preprocessor. This is not complete.
(define-module (nyacc lang c99 cpp)
#:export (parse-cpp-stmt
read-cpp-stmt
parse-cpp-expr
eval-cpp-expr
cpp-expand-text
expand-cpp-mref
)
#:use-module (nyacc parse)
#:use-module (nyacc lex)
#:use-module (nyacc lang util)
#:use-module (rnrs arithmetic bitwise)
)
#|
#define #undef #include #if #ifdef #ifndef #else #endif #elif
#line defined #-operator ##-operator #pragma #error
strategy:
don't expand macro calls -- treat like function calls, but provide dict
todo:
pragma
#-op ##-op
provide dict of #defines
provide util to expand defines
|#
;;.@deffn skip-ws ch
;; Helper for
(define (skip-ws ch)
(if (eof-object? ch) ch
(if (char-set-contains? c:ws ch)
(skip-ws (read-char))
ch)))
;; @deffn cpp-define => #f|???
(define (cpp-define)
;; The (weak?) parse architecture is "unread la argument if no match"
(letrec
((p-cppd ;; parse all
(lambda ()
(let* ((iden (read-c-ident (skip-ws (read-char))))
;;(args (or (p-args (skip-ws (read-char))) '()))
;; "define ABC(ARG)" not the same as "define ABC (ARG)"
(args (or (p-args (read-char)) '()))
(rest (or (p-rest (skip-ws (read-char))) " ")))
(if (pair? args)
`(define (name ,iden) ,(cons 'args args) (repl ,rest))
`(define (name ,iden) (repl ,rest))))))
(p-args ;; parse args
(lambda (la) ;; unread la if no match :(
(if (eq? la #\()
(let iter ((args '()) (la (skip-ws (read-char))))
(cond
((eq? la #\)) (reverse args))
((read-c-ident la) =>
(lambda (arg) (iter (cons arg args) (skip-ws (read-char)))))
((eq? la #\,)
(iter args (skip-ws (read-char))))))
(begin (if (char? la) (unread-char la)) #f)))) ;; CLEANUP
(p-rest ;; parse rest
(lambda (la)
(cond ((char? la) (unread-char la) (drain-input (current-input-port)))
(else #f)))))
(p-cppd)))
;; @deffn cpp-include
;; Parse CPP include statement.
(define (cpp-include)
(let* ((beg-ch (skip-ws (read-char)))
(end-ch (if (eq? beg-ch #\<) #\> #\"))
(path (let iter ((cl (list beg-ch)) (ch (read-char)))
(if (eq? ch end-ch) (list->string (reverse (cons ch cl)))
(iter (cons ch cl) (read-char))))))
`(include ,path)))
;; @deffn read-cpp-stmt line defs => (stmt-type text)
;; Parse a line from a CPP statement and return a parse tree.
;; @example
;; (parse-cpp-stmt "define X 123") => (define "X" "123")
;; (parse-cpp-stmt "if defined(A) && defined(B) && defined(C)"
;; => (if "defined(A) && defined(B) && defined(C)")
;; @end example
;; To evaluate the @code{if} statements use @code{parse-cpp-expr} and
;; @code{eval-cpp-expr}.
(define (read-cpp-stmt line)
(define (rd-ident) (read-c-ident (skip-ws (read-char))))
(define (rd-num) (and=> (read-c-num (skip-ws (read-char))) cdr))
(define (rd-rest) (let ((ch (skip-ws (read-char))))
(if (not (eof-object? ch)) (unread-char ch))
(drain-input (current-input-port))))
(with-input-from-string line
(lambda ()
(let ((cmd (string->symbol (read-c-ident (skip-ws (read-char))))))
(case cmd
((include) (cpp-include))
((define) (cpp-define))
((undef) `(undef ,(rd-ident)))
((ifdef)
`(if ,(string-append "defined(" (rd-ident) ")" (rd-rest))))
((ifndef)
`(if ,(string-append "!defined(" (rd-ident) ")" (rd-rest))))
((if elif else endif line error pragma) (list cmd (rd-rest)))
(else '(unknown "")))))))
(include-from-path "nyacc/lang/c99/mach.d/cpptab.scm")
(include-from-path "nyacc/lang/c99/mach.d/cppact.scm")
(define raw-parser
(make-lalr-parser
(list (cons 'len-v len-v) (cons 'pat-v pat-v) (cons 'rto-v rto-v)
(cons 'mtab mtab) (cons 'act-v act-v))))
;; The included file "cppbody.scm" provides:
;; gen-cpp-lexer
;; parse-cpp-expr
;; eval-cpp-expr
(include-from-path "nyacc/lang/c99/cppbody.scm")
;; --- last line ---

View file

@ -0,0 +1,209 @@
;;; nyacc/lang/c99/cppbody.scm
;;;
;;; Copyright (C) 2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
(define gen-cpp-lexer (make-lexer-generator mtab))
;; @deffn parse-cpp-expr text => tree
;; Given a string returns a cpp parse tree. This is called by
;; @code{parse-cpp-stmt} and @code{eval-cpp-expr}. The latter because the
;; parsed expression may include terms which are cpp-defined
;; and should be evaluated lazy mode.
(define (parse-cpp-expr text)
(with-input-from-string text
(lambda () (raw-parser (gen-cpp-lexer)))))
;; @deffn eval-cpp-expr tree dict => datum
;; Evaluate a tree produced from
;; This should be updated to use @code{expand-cpp-def}. See below.
(use-modules (ice-9 pretty-print))
(define (eval-cpp-expr tree dict)
;;(display "eval-cpp-expr:\n") (pretty-print tree)
(letrec
((tx (lambda (tr ix) (list-ref tr ix)))
(tx1 (lambda (tr) (tx tr 1)))
(ev (lambda (ex ix) (eval-expr (list-ref ex ix))))
(ev1 (lambda (ex) (ev ex 1)))
(ev2 (lambda (ex) (ev ex 2)))
(ev3 (lambda (ex) (ev ex 3)))
#;(parse-and-eval
(lambda (str)
(if (not (string? str)) (throw 'parse-error "cpp-eval"))
(let ((idtr (parse-cpp-expr str)))
(eval-cpp-expr idtr dict))))
(eval-expr
(lambda (tree)
(case (car tree)
;;((ident) (parse-and-eval (assoc-ref dict (tx1 tree))))
((fixed) (string->number (tx1 tree)))
((char) (char->integer (tx1 tree)))
((defined) (if (assoc-ref dict (tx1 tree)) 1 0))
;;
((pre-inc post-inc) (1+ (ev1 tree)))
((pre-dec post-dec) (1- (ev1 tree)))
((pos) (ev1 tree))
((neg) (- (ev1 tree)))
((bw-not) (bitwise-not (ev1 tree)))
((not) (if (zero? (ev1 tree)) 1 0))
((mul) (* (ev1 tree) (ev2 tree)))
((div) (/ (ev1 tree) (ev2 tree)))
((mod) (modulo (ev1 tree) (ev2 tree)))
((add) (+ (ev1 tree) (ev2 tree)))
((sub) (- (ev1 tree) (ev2 tree)))
((lshift) (bitwise-arithmetic-shift-left (ev1 tree) (ev2 tree)))
((rshift) (bitwise-arithmetic-shift-right (ev1 tree) (ev2 tree)))
((lt) (if (< (ev1 tree) (ev2 tree)) 1 0))
((le) (if (<= (ev1 tree) (ev2 tree)) 1 0))
((gt) (if (> (ev1 tree) (ev2 tree)) 1 0))
((ge) (if (>= (ev1 tree) (ev2 tree)) 1 0))
((equal) (if (= (ev1 tree) (ev2 tree)) 1 0))
((noteq) (if (= (ev1 tree) (ev2 tree)) 0 1))
((bw-or) (bitwise-ior (ev1 tree) (ev2 tree)))
((bw-xor) (bitwise-xor (ev1 tree) (ev2 tree)))
((bw-and) (bitwise-and (ev1 tree) (ev2 tree)))
((or) (if (and (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
((and) (if (or (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
((cond-expr) (if (zero? (ev1 tree)) (ev3 tree) (ev2 tree)))
(else (error "incomplete implementation"))))))
(catch 'parse-error
(lambda () (eval-expr tree))
(lambda () #f))))
;; @deffn scan-cpp-input argd used dict for-argl => string
;; Process the replacement text and generate a (reversed) token-list.
;; If for-argl, stop at, and push back, @code{,} or @code{)}.
(define (scan-cpp-input argd dict used for-argl)
;; Works like this: scan tokens (comments, parens, strings, char's, etc).
;; Tokens (i.e., strings) are collected in a (reverse ordered) list (stl)
;; and merged together on return. Lone characters are collected in the
;; list @code{chl}. Once a non-char token is found the character list is
;; converted to a string and added to the string list first, followed by
;; the new token.
;; Turn reverse chl into a string and insert it into the string list stl.
(define (add-chl chl stl)
(if (null? chl) stl (cons (list->string (reverse chl)) stl)))
;; We just scanned "defined", not need to scan the arg to inhibit expansion.
;; E.g., scanned "defined", now scan "(FOO)", and return "defined(FOO)".
(define (scan-defined)
(let iter ((chl '()) (ch (read-char)))
(cond ((eof-object? ch) (throw 'parse-error "bad CPP defined"))
((char=? #\) ch)
(string-append "defined" (list->string (reverse (cons ch chl)))))
(else (iter (cons ch chl) (read-char))))))
;;
(let iter ((stl '()) ; string list (i.e., tokens)
(chl '()) ; char-list (current list of input chars)
(nxt #f) ; next string
(lvl 0) ; level
(ch (read-char))) ; next character
;;(simple-format #t "iter stl=~S chl=~S nxt=~S ch=~S\n" stl chl nxt ch)
(cond
;; have item to add, but first add in char's
(nxt (iter (cons nxt (add-chl chl stl)) '() #f lvl ch))
;; If end of string or see end-ch at level 0, then return.
((eof-object? ch) ;; CHECK (ab++)
(apply string-append (reverse (add-chl chl stl))))
((and for-argl (memq ch '(#\) #\,)) (zero? lvl))
(unread-char ch) (apply string-append (reverse (add-chl chl stl))))
((read-c-comm ch #f) =>
(lambda (cp) (iter stl chl (string-append "/*" (cdr cp) "*/")
lvl (read-char))))
((char=? #\( ch) (iter stl (cons ch chl) nxt (1+ lvl) (read-char)))
((char=? #\) ch) (iter stl (cons ch chl) nxt (1- lvl) (read-char)))
((char=? #\# ch)
(let ((ch (read-char)))
(if (eqv? ch #\#)
(iter (cons "##" stl) chl #f lvl (read-char))
(iter (cons "#" stl) chl #f lvl ch))))
((read-c-string ch) =>
(lambda (st) (iter stl chl st lvl (read-char))))
((read-c-ident ch) =>
(lambda (iden)
;;(simple-format #t " iden=~S\n" iden)
(if (equal? iden "defined")
;; "defined" is a special case
(iter stl chl (scan-defined) lvl (read-char))
;; otherwise ...
(let* ((aval (assoc-ref argd iden)) ; lookup argument
(rval (assoc-ref dict iden))) ; lookup macro def
(cond
((member iden used) ; name used
(iter stl chl iden lvl (read-char)))
(aval ; arg ref
(iter stl chl aval lvl (read-char)))
((string? rval) ; cpp repl
(iter stl chl rval lvl (read-char)))
((pair? rval) ; cpp macro
(let* ((argl (car rval)) (text (cdr rval))
(argv (collect-args argd dict used))
(argd (map cons argl argv))
(newl (expand-cpp-repl text argd dict (cons iden used))))
(iter stl chl newl lvl (read-char))))
(else ; normal identifier
(iter stl chl iden lvl (read-char))))))))
(else
(iter stl (cons ch chl) #f lvl (read-char))))))
(define (collect-args argd dict used)
;;(simple-format #t "collect-args\n")
(if (not (eqv? (read-char) #\()) (throw 'parse-error "collect-args"))
(let iter ((argl (list (scan-cpp-input argd dict used #t))))
(simple-format #t "args: ~S\n" argl)
(let ((ch (read-char)))
(if (eqv? ch #\)) (reverse argl)
(iter (cons (scan-cpp-input argd dict used #t) argl))))))
(define (expand-cpp-repl repl argd dict used)
;;(simple-format #t "expand-cpp-repl repl=~S argd=~S\n" repl argd)
(with-input-from-string repl
(lambda () (scan-cpp-input argd dict used #f))))
;; @deffn cpp-expand-text text dict => string
(define (cpp-expand-text text dict)
;;(simple-format #t "cpp-expand-text: ~S\n" text)
(with-input-from-string text
(lambda () (scan-cpp-input '() dict '() #f))))
;; @deffn expand-cpp-mref ident dict => repl|#f
;; Given an identifier seen in C99 input, this checks for associated
;; definition in @var{dict} (generated from CPP defines). If found,
;; the expansion is returned as a string. If @var{ident} refers
;; to a macro with arguments, then the arguments will be read from the
;; current input.
(define (expand-cpp-mref ident dict . rest)
(let ((used (if (pair? rest) (car rest) '()))
(rval (assoc-ref dict ident)))
(cond
((not rval) #f)
((member ident used) ident)
((string? rval)
(let ((expd (expand-cpp-repl rval '() dict (cons ident used))))
;;(simple-format #t "expand ~S => ~S\n" ident expd)
expd))
((pair? rval)
(let* ((args (car rval)) (repl (cdr rval))
(argv (collect-args '() dict '()))
(argd (map cons args argv))
(expd (expand-cpp-repl repl argd dict (cons ident used))))
;;(simple-format #t "expand ~S => ~S\n" ident expd)
expd)))))
;;; --- last line ---

View file

@ -0,0 +1,142 @@
;;; lang/c99/cppmach.scm
;;;
;;; Copyright (C) 2015,2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C preprocessor expression parser generator
(define-module (nyacc lang c99 cppmach)
#:export (cpp-spec
cpp-mach
dev-parse-cpp-expr dev-eval-cpp-expr
gen-cpp-files)
#:use-module (nyacc lalr)
#:use-module (nyacc parse)
#:use-module (nyacc lex)
#:use-module (nyacc lang util)
#:use-module ((srfi srfi-43) #:select (vector-map))
#:use-module (rnrs arithmetic bitwise)
)
(define cpp-spec
(lalr-spec
(notice lang-crn-lic)
(expect 0)
(start conditional-expression)
(grammar
(conditional-expression
(logical-or-expression)
(logical-or-expression "?" logical-or-expression ":" conditional-expression
($$ `(cond-expr ,$1 ,$3 ,$5))))
(logical-or-expression
(logical-and-expression)
(logical-or-expression "||" logical-and-expression ($$ `(or ,$1 ,$3))))
(logical-and-expression
(bitwise-or-expression)
(logical-and-expression "&&" bitwise-or-expression ($$ `(and ,$1 ,$3))))
(bitwise-or-expression
(bitwise-xor-expression)
(bitwise-or-expression "|" bitwise-xor-expression
($$ `(bitwise-or ,$1 ,$3))))
(bitwise-xor-expression
(bitwise-and-expression)
(bitwise-xor-expression "^" bitwise-and-expression
($$ `(bitwise-xor ,$1 ,$3))))
(bitwise-and-expression
(equality-expression)
(bitwise-and-expression "&" equality-expression
($$ `(bitwise-and ,$1 ,$3))))
(equality-expression
(relational-expression)
(equality-expression "==" relational-expression ($$ `(equal ,$1 ,$3)))
(equality-expression "!=" relational-expression ($$ `(noteq ,$1 ,$3))))
(relational-expression
(shift-expression)
(relational-expression "<" shift-expression ($$ `(lt ,$1 ,$3)))
(relational-expression "<=" shift-expression ($$ `(le ,$1 ,$3)))
(relational-expression ">" shift-expression ($$ `(gt ,$1 ,$3)))
(relational-expression ">=" shift-expression ($$ `(ge ,$1 ,$3))))
(shift-expression
(additive-expression)
(shift-expression "<<" additive-expression ($$ `(lshift ,$1 ,$3)))
(shift-expression ">>" additive-expression ($$ `(rshift ,$1 ,$3))))
(additive-expression
(multiplicative-expression)
(additive-expression "+" multiplicative-expression ($$ `(add ,$1 ,$3)))
(additive-expression "-" multiplicative-expression ($$ `(sub ,$1 ,$3))))
(multiplicative-expression
(unary-expression)
(multiplicative-expression "*" unary-expression ($$ `(mul ,$1 ,$3)))
(multiplicative-expression "/" unary-expression ($$ `(div ,$1 ,$3)))
(multiplicative-expression "%" unary-expression ($$ `(mod ,$1 ,$3))))
(unary-expression
(postfix-expression)
("-" unary-expression ($$ `(neg ,$2)))
("+" unary-expression ($$ `(pos ,$2)))
("!" unary-expression ($$ `(not ,$2)))
("~" unary-expression ($$ `(bitwise-not ,$2)))
("++" unary-expression ($$ `(pre-inc ,$2)))
("--" unary-expression ($$ `(pre-dec ,$2))))
(postfix-expression
(primary-expression)
(postfix-expression "++" ($$ `(post-inc ,$1)))
(postfix-expression "--" ($$ `(post-dec ,$1))))
(primary-expression
;;($ident ($$ `(ident ,$1)))
($fixed ($$ `(fixed ,$1))) ; integer-constant
($chlit ($$ `(char ,$1))) ; char-constant
("defined" "(" $ident ")" ($$ `(defined ,$3)))
("(" expression-list ")" ($$ $2)))
(expression-list
(conditional-expression)
(expression-list "," conditional-expression ($$ $3)))
)))
(define cpp-mach
(compact-machine
(hashify-machine
(make-lalr-machine cpp-spec))))
(define mtab (assq-ref cpp-mach 'mtab))
(define raw-parser (make-lalr-parser cpp-mach))
(include-from-path "nyacc/lang/c99/cppbody.scm")
(define dev-parse-cpp-expr parse-cpp-expr)
(define dev-eval-cpp-expr eval-cpp-expr)
;;; =====================================
;; @item gen-cpp-files [dir] => #t
;; Update or generate the files @quot{cppact.scm} and @quot{cpptab.scm}.
;; If there are no changes to existing files, no update occurs.
(define (gen-cpp-files . rest)
(define (lang-dir path)
(if (pair? rest) (string-append (car rest) "/" path) path))
(define (xtra-dir path)
(lang-dir (string-append "mach.d/" path)))
(write-lalr-actions cpp-mach (xtra-dir "cppact.scm.new"))
(write-lalr-tables cpp-mach (xtra-dir "cpptab.scm.new"))
(let ((a (move-if-changed (xtra-dir "cppact.scm.new")
(xtra-dir "cppact.scm")))
(b (move-if-changed (xtra-dir "cpptab.scm.new")
(xtra-dir "cpptab.scm"))))
(when (or a b)
(system (string-append "touch " (lang-dir "cpp.scm")))
#;(compile-file (lang-dir "cpp.scm"))
)))
;; --- last line ---

View file

@ -0,0 +1,762 @@
;; ./mach.d/c99act.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;;
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;; or any later version published by the Free Software Foundation. See the
;; file COPYING included with the this distribution.
(define act-v
(vector
;; $start => translation-unit-proxy
(lambda ($1 . $rest) $1)
;; translation-unit-proxy => translation-unit
(lambda ($1 . $rest) (tl->list $1))
;; primary-expression => identifier
(lambda ($1 . $rest) `(p-expr ,$1))
;; primary-expression => constant
(lambda ($1 . $rest) `(p-expr ,$1))
;; primary-expression => string-literal
(lambda ($1 . $rest) `(p-expr ,(tl->list $1)))
;; primary-expression => "(" expression ")"
(lambda ($3 $2 $1 . $rest) $2)
;; postfix-expression => primary-expression
(lambda ($1 . $rest) $1)
;; postfix-expression => postfix-expression "[" expression "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-ref ,$3 ,$1))
;; postfix-expression => postfix-expression "(" argument-expression-list...
(lambda ($4 $3 $2 $1 . $rest)
`(fctn-call ,$1 ,(tl->list $3)))
;; postfix-expression => postfix-expression "(" ")"
(lambda ($3 $2 $1 . $rest)
`(fctn-call ,$1 (expr-list)))
;; postfix-expression => postfix-expression "." identifier
(lambda ($3 $2 $1 . $rest) `(d-sel ,$3 ,$1))
;; postfix-expression => postfix-expression "->" identifier
(lambda ($3 $2 $1 . $rest) `(i-sel ,$3 ,$1))
;; postfix-expression => postfix-expression "++"
(lambda ($2 $1 . $rest) `(post-inc ,$1))
;; postfix-expression => postfix-expression "--"
(lambda ($2 $1 . $rest) `(post-dec ,$1))
;; postfix-expression => "(" type-name ")" "{" initializer-list "}"
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(comp-lit ,$2 ,(tl->list $5)))
;; postfix-expression => "(" type-name ")" "{" initializer-list "," "}"
(lambda ($7 $6 $5 $4 $3 $2 $1 . $rest)
`(comp-lit ,$2 ,(tl->list $5)))
;; argument-expression-list => assignment-expression
(lambda ($1 . $rest) (make-tl 'expr-list $1))
;; argument-expression-list => argument-expression-list "," assignment-e...
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; argument-expression-list => arg-expr-hack
(lambda ($1 . $rest) (make-tl 'expr-list $1))
;; argument-expression-list => argument-expression-list "," arg-expr-hack
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; arg-expr-hack => declaration-specifiers abstract-declarator
(lambda ($2 $1 . $rest)
`(param-decl ,(tl->list $1) $2))
;; arg-expr-hack => declaration-specifiers
(lambda ($1 . $rest)
`(param-decl ,(tl->list $1)))
;; unary-expression => postfix-expression
(lambda ($1 . $rest) $1)
;; unary-expression => "++" unary-expression
(lambda ($2 $1 . $rest) `(pre-inc ,$2))
;; unary-expression => "--" unary-expression
(lambda ($2 $1 . $rest) `(pre-dec ,$2))
;; unary-expression => unary-operator cast-expression
(lambda ($2 $1 . $rest) (list $1 $2))
;; unary-expression => "sizeof" unary-expression
(lambda ($2 $1 . $rest) `(sizeof-expr ,$2))
;; unary-expression => "sizeof" "(" type-name ")"
(lambda ($4 $3 $2 $1 . $rest) `(sizeof-type ,$3))
;; unary-operator => "&"
(lambda ($1 . $rest) 'ref-to)
;; unary-operator => "*"
(lambda ($1 . $rest) 'de-ref)
;; unary-operator => "+"
(lambda ($1 . $rest) 'pos)
;; unary-operator => "-"
(lambda ($1 . $rest) 'neg)
;; unary-operator => "~"
(lambda ($1 . $rest) 'bitwise-not)
;; unary-operator => "!"
(lambda ($1 . $rest) 'not)
;; cast-expression => unary-expression
(lambda ($1 . $rest) $1)
;; cast-expression => "(" type-name ")" cast-expression
(lambda ($4 $3 $2 $1 . $rest) `(cast ,$2 ,$4))
;; multiplicative-expression => cast-expression
(lambda ($1 . $rest) $1)
;; multiplicative-expression => multiplicative-expression "*" cast-expre...
(lambda ($3 $2 $1 . $rest) `(mul ,$1 ,$3))
;; multiplicative-expression => multiplicative-expression "/" cast-expre...
(lambda ($3 $2 $1 . $rest) `(div ,$1 ,$3))
;; multiplicative-expression => multiplicative-expression "%" cast-expre...
(lambda ($3 $2 $1 . $rest) `(mod ,$1 ,$3))
;; additive-expression => multiplicative-expression
(lambda ($1 . $rest) $1)
;; additive-expression => additive-expression "+" multiplicative-expression
(lambda ($3 $2 $1 . $rest) `(add ,$1 ,$3))
;; additive-expression => additive-expression "-" multiplicative-expression
(lambda ($3 $2 $1 . $rest) `(sub ,$1 ,$3))
;; shift-expression => additive-expression
(lambda ($1 . $rest) $1)
;; shift-expression => shift-expression "<<" additive-expression
(lambda ($3 $2 $1 . $rest) `(lshift ,$1 ,$3))
;; shift-expression => shift-expression ">>" additive-expression
(lambda ($3 $2 $1 . $rest) `(rshift ,$1 ,$3))
;; relational-expression => shift-expression
(lambda ($1 . $rest) $1)
;; relational-expression => relational-expression "<" shift-expression
(lambda ($3 $2 $1 . $rest) `(lt ,$1 ,$3))
;; relational-expression => relational-expression ">" shift-expression
(lambda ($3 $2 $1 . $rest) `(gt ,$1 ,$3))
;; relational-expression => relational-expression "<=" shift-expression
(lambda ($3 $2 $1 . $rest) `(le ,$1 ,$3))
;; relational-expression => relational-expression ">=" shift-expression
(lambda ($3 $2 $1 . $rest) `(ge ,$1 ,$3))
;; equality-expression => relational-expression
(lambda ($1 . $rest) $1)
;; equality-expression => equality-expression "==" relational-expression
(lambda ($3 $2 $1 . $rest) `(eq ,$1 ,$3))
;; equality-expression => equality-expression "!=" relational-expression
(lambda ($3 $2 $1 . $rest) `(ne ,$1 ,$3))
;; bitwise-and-expression => equality-expression
(lambda ($1 . $rest) $1)
;; bitwise-and-expression => bitwise-and-expression "&" equality-expression
(lambda ($3 $2 $1 . $rest)
`(bitwise-and ,$1 ,$3))
;; bitwise-xor-expression => bitwise-and-expression
(lambda ($1 . $rest) $1)
;; bitwise-xor-expression => bitwise-xor-expression "^" bitwise-and-expr...
(lambda ($3 $2 $1 . $rest)
`(bitwise-xor ,$1 ,$3))
;; bitwise-or-expression => bitwise-xor-expression
(lambda ($1 . $rest) $1)
;; bitwise-or-expression => bitwise-or-expression "|" bitwise-xor-expres...
(lambda ($3 $2 $1 . $rest) `(bitwise-or ,$1 ,$3))
;; logical-and-expression => bitwise-or-expression
(lambda ($1 . $rest) $1)
;; logical-and-expression => logical-and-expression "&&" bitwise-or-expr...
(lambda ($3 $2 $1 . $rest) `(and ,$1 ,$3))
;; logical-or-expression => logical-and-expression
(lambda ($1 . $rest) $1)
;; logical-or-expression => logical-or-expression "||" logical-and-expre...
(lambda ($3 $2 $1 . $rest) `(or ,$1 ,$3))
;; conditional-expression => logical-or-expression
(lambda ($1 . $rest) $1)
;; conditional-expression => logical-or-expression "?" expression ":" co...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(cond-expr ,$1 ,$2 ,$3))
;; assignment-expression => conditional-expression
(lambda ($1 . $rest) $1)
;; assignment-expression => unary-expression assignment-operator assignm...
(lambda ($3 $2 $1 . $rest)
`(assn-expr ,$1 (op ,$2) ,$3))
;; assignment-operator => "="
(lambda ($1 . $rest) $1)
;; assignment-operator => "+="
(lambda ($1 . $rest) $1)
;; assignment-operator => "-="
(lambda ($1 . $rest) $1)
;; assignment-operator => "*="
(lambda ($1 . $rest) $1)
;; assignment-operator => "/="
(lambda ($1 . $rest) $1)
;; assignment-operator => "%="
(lambda ($1 . $rest) $1)
;; assignment-operator => "<<="
(lambda ($1 . $rest) $1)
;; assignment-operator => ">>="
(lambda ($1 . $rest) $1)
;; assignment-operator => "&="
(lambda ($1 . $rest) $1)
;; assignment-operator => "^="
(lambda ($1 . $rest) $1)
;; assignment-operator => "|="
(lambda ($1 . $rest) $1)
;; expression => assignment-expression
(lambda ($1 . $rest) $1)
;; expression => expression "," assignment-expression
(lambda ($3 $2 $1 . $rest)
(if (eqv? 'comma-expr (sx-tag $1))
(append $1 (list $3))
`(comma-expr ,$1 ,$3)))
;; constant-expression => conditional-expression
(lambda ($1 . $rest) $1)
;; declaration => declaration-specifiers init-declarator-list $P1 ";" op...
(lambda ($5 $4 $3 $2 $1 . $rest)
(if (pair? $5) (append $3 (list $5)) $3))
;; declaration => declaration-specifiers ";" opt-code-comment
(lambda ($3 $2 $1 . $rest)
(if (pair? $3)
`(decl ,(tl->list $1) ,(list $3))
`(decl ,(tl->list $1))))
;; $P1 =>
(lambda ($2 $1 . $rest)
(save-typenames
`(decl ,(tl->list $1) ,(tl->list $2))))
;; declaration-specifiers => storage-class-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => storage-class-specifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; declaration-specifiers => type-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => type-specifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; declaration-specifiers => type-qualifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => type-qualifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; declaration-specifiers => function-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => function-specifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; init-declarator-list => init-declarator
(lambda ($1 . $rest)
(make-tl 'init-declr-list $1))
;; init-declarator-list => init-declarator-list "," init-declarator
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; init-declarator => declarator
(lambda ($1 . $rest) `(init-declr ,$1))
;; init-declarator => declarator "=" initializer
(lambda ($3 $2 $1 . $rest) `(init-declr ,$1 ,$3))
;; storage-class-specifier => "auto"
(lambda ($1 . $rest) '(stor-spec (auto)))
;; storage-class-specifier => "extern"
(lambda ($1 . $rest) '(stor-spec (extern)))
;; storage-class-specifier => "register"
(lambda ($1 . $rest) '(stor-spec (register)))
;; storage-class-specifier => "static"
(lambda ($1 . $rest) '(stor-spec (static)))
;; storage-class-specifier => "typedef"
(lambda ($1 . $rest) '(stor-spec (typedef)))
;; type-specifier => "void"
(lambda ($1 . $rest) '(type-spec (void)))
;; type-specifier => fixed-type-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => float-type-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => "_Bool"
(lambda ($1 . $rest)
'(type-spec (fixed-type "_Bool")))
;; type-specifier => complex-type-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => struct-or-union-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => enum-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => typedef-name
(lambda ($1 . $rest) `(type-spec ,$1))
;; fixed-type-specifier => "short"
(lambda ($1 . $rest) '(fixed-type "short"))
;; fixed-type-specifier => "short" "int"
(lambda ($2 $1 . $rest)
'(fixed-type "short int"))
;; fixed-type-specifier => "signed" "short"
(lambda ($2 $1 . $rest)
'(fixed-type "signed short"))
;; fixed-type-specifier => "signed" "short" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "signed short int"))
;; fixed-type-specifier => "int"
(lambda ($1 . $rest) '(fixed-type "int"))
;; fixed-type-specifier => "signed"
(lambda ($1 . $rest) '(fixed-type "signed"))
;; fixed-type-specifier => "signed" "int"
(lambda ($2 $1 . $rest)
'(fixed-type "signed int"))
;; fixed-type-specifier => "long"
(lambda ($1 . $rest) '(fixed-type "long"))
;; fixed-type-specifier => "long" "int"
(lambda ($2 $1 . $rest) '(fixed-type "long int"))
;; fixed-type-specifier => "signed" "long"
(lambda ($2 $1 . $rest)
'(fixed-type "signed long"))
;; fixed-type-specifier => "signed" "long" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "signed long int"))
;; fixed-type-specifier => "long" "long"
(lambda ($2 $1 . $rest)
'(fixed-type "long long"))
;; fixed-type-specifier => "long" "long" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "long long int"))
;; fixed-type-specifier => "signed" "long" "long"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "signed long long"))
;; fixed-type-specifier => "signed" "long" "long" "int"
(lambda ($4 $3 $2 $1 . $rest)
'(fixed-type "signed long long int"))
;; fixed-type-specifier => "unsigned" "short" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "unsigned short int"))
;; fixed-type-specifier => "unsigned" "short"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned short"))
;; fixed-type-specifier => "unsigned" "int"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned int"))
;; fixed-type-specifier => "unsigned"
(lambda ($1 . $rest) '(fixed-type "unsigned"))
;; fixed-type-specifier => "unsigned" "long" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "unsigned long"))
;; fixed-type-specifier => "unsigned" "long"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned long"))
;; fixed-type-specifier => "unsigned" "long" "long" "int"
(lambda ($4 $3 $2 $1 . $rest)
'(fixed-type "unsigned long long int"))
;; fixed-type-specifier => "unsigned" "long" "long"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "unsigned long long"))
;; fixed-type-specifier => "char"
(lambda ($1 . $rest) '(fixed-type "char"))
;; fixed-type-specifier => "signed" "char"
(lambda ($2 $1 . $rest)
'(fixed-type "signed char"))
;; fixed-type-specifier => "unsigned" "char"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned char"))
;; float-type-specifier => "float"
(lambda ($1 . $rest) '(float-type "float"))
;; float-type-specifier => "double"
(lambda ($1 . $rest) '(float-type "double"))
;; float-type-specifier => "long" "double"
(lambda ($2 $1 . $rest)
'(float-type "long double"))
;; complex-type-specifier => "_Complex"
(lambda ($1 . $rest) '(complex-type "_Complex"))
;; complex-type-specifier => "float" "_Complex"
(lambda ($2 $1 . $rest)
'(complex-type "float _Complex"))
;; complex-type-specifier => "double" "_Complex"
(lambda ($2 $1 . $rest)
'(complex-type "double _Complex"))
;; complex-type-specifier => "long" "double" "_Complex"
(lambda ($3 $2 $1 . $rest)
'(complex-type "long double _Complex"))
;; struct-or-union-specifier => "struct" ident-like "{" struct-declarati...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(struct-def ,$2 ,(tl->list $4)))
;; struct-or-union-specifier => "struct" "{" struct-declaration-list "}"
(lambda ($4 $3 $2 $1 . $rest)
`(struct-def ,(tl->list $3)))
;; struct-or-union-specifier => "struct" ident-like
(lambda ($2 $1 . $rest) `(struct-ref ,$2))
;; struct-or-union-specifier => "union" ident-like "{" struct-declaratio...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(union-def ,$2 ,(tl->list $4)))
;; struct-or-union-specifier => "union" "{" struct-declaration-list "}"
(lambda ($4 $3 $2 $1 . $rest)
`(union-def ,(tl->list $3)))
;; struct-or-union-specifier => "union" ident-like
(lambda ($2 $1 . $rest) `(union-ref ,$2))
;; ident-like => identifier
(lambda ($1 . $rest) $1)
;; ident-like => typedef-name
(lambda ($1 . $rest) `(ident ,(cdr $1)))
;; struct-declaration-list => struct-declaration
(lambda ($1 . $rest) (make-tl 'field-list $1))
;; struct-declaration-list => lone-comment
(lambda ($1 . $rest) (make-tl 'field-list $1))
;; struct-declaration-list => struct-declaration-list struct-declaration
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; struct-declaration-list => struct-declaration-list lone-comment
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; struct-declaration => specifier-qualifier-list struct-declarator-list...
(lambda ($4 $3 $2 $1 . $rest)
(if (pair? $4)
`(comp-decl ,(tl->list $1) ,(tl->list $2) ,$4)
`(comp-decl ,(tl->list $1) ,(tl->list $2))))
;; specifier-qualifier-list => type-specifier specifier-qualifier-list
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; specifier-qualifier-list => type-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; specifier-qualifier-list => type-qualifier specifier-qualifier-list
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; specifier-qualifier-list => type-qualifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; struct-declarator-list => struct-declarator
(lambda ($1 . $rest)
(make-tl 'comp-declr-list $1))
;; struct-declarator-list => struct-declarator-list "," struct-declarator
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; struct-declarator => declarator
(lambda ($1 . $rest) `(comp-declr ,$1))
;; struct-declarator => declarator ":" constant-expression
(lambda ($3 $2 $1 . $rest)
`(comp-declr (bit-field ,$1 ,$3)))
;; struct-declarator => ":" constant-expression
(lambda ($2 $1 . $rest)
`(comp-declr (bit-field ,$2)))
;; enum-specifier => "enum" identifier "{" enumerator-list "}"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(enum-def ,$2 ,(tl->list $4)))
;; enum-specifier => "enum" identifier "{" enumerator-list "," "}"
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(enum-def ,$2 ,(tl->list $4)))
;; enum-specifier => "enum" "{" enumerator-list "}"
(lambda ($4 $3 $2 $1 . $rest)
`(enum-def ,(tl->list $3)))
;; enum-specifier => "enum" "{" enumerator-list "," "}"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(enum-def ,(tl->list $3)))
;; enum-specifier => "enum" identifier
(lambda ($2 $1 . $rest) `(enum-ref ,$2))
;; enumerator-list => enumerator
(lambda ($1 . $rest) (make-tl 'enum-def-list $1))
;; enumerator-list => enumerator-list "," enumerator
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; enumerator => identifier
(lambda ($1 . $rest) `(enum-defn ,$1))
;; enumerator => identifier "=" constant-expression
(lambda ($3 $2 $1 . $rest) `(enum-defn ,$1 ,$3))
;; type-qualifier => "const"
(lambda ($1 . $rest) `(type-qual ,$1))
;; type-qualifier => "volatile"
(lambda ($1 . $rest) `(type-qual ,$1))
;; type-qualifier => "restrict"
(lambda ($1 . $rest) `(type-qual ,$1))
;; function-specifier => "inline"
(lambda ($1 . $rest) `(fctn-spec ,$1))
;; declarator => pointer direct-declarator
(lambda ($2 $1 . $rest) `(ptr-declr ,$1 ,$2))
;; declarator => direct-declarator
(lambda ($1 . $rest) $1)
;; direct-declarator => identifier
(lambda ($1 . $rest) $1)
;; direct-declarator => "(" declarator ")"
(lambda ($3 $2 $1 . $rest) `(scope ,$2))
;; direct-declarator => direct-declarator "[" type-qualifier-list assign...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3 ,$4))
;; direct-declarator => direct-declarator "[" type-qualifier-list "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3))
;; direct-declarator => direct-declarator "[" assignment-expression "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3))
;; direct-declarator => direct-declarator "[" "]"
(lambda ($3 $2 $1 . $rest) `(array-of ,$1))
;; direct-declarator => direct-declarator "[" "static" type-qualifier-li...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(array-of
,$1
,(tl->list (tl-insert '(stor-spec "static") $4))
,$5))
;; direct-declarator => direct-declarator "[" type-qualifier-list "stati...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(array-of
,$1
,(tl->list (tl-insert '(stor-spec "static") $3))
,$5))
;; direct-declarator => direct-declarator "[" type-qualifier-list "*" "]"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3 (var-len)))
;; direct-declarator => direct-declarator "[" "*" "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-of ,$1 (var-len)))
;; direct-declarator => direct-declarator "(" parameter-type-list ")"
(lambda ($4 $3 $2 $1 . $rest)
`(ftn-declr ,$1 ,(tl->list $3)))
;; direct-declarator => direct-declarator "(" identifier-list ")"
(lambda ($4 $3 $2 $1 . $rest)
`(ftn-declr ,$1 ,(tl->list $3)))
;; direct-declarator => direct-declarator "(" ")"
(lambda ($3 $2 $1 . $rest)
`(ftn-declr ,$1 (param-list)))
;; pointer => "*" type-qualifier-list
(lambda ($2 $1 . $rest)
`(pointer ,(tl->list $2)))
;; pointer => "*"
(lambda ($1 . $rest) '(pointer))
;; pointer => "*" type-qualifier-list pointer
(lambda ($3 $2 $1 . $rest)
`(pointer ,(tl->list $2) ,$3))
;; pointer => "*" pointer
(lambda ($2 $1 . $rest) `(pointer ,$2))
;; type-qualifier-list => type-qualifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; type-qualifier-list => type-qualifier-list type-qualifier
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; parameter-type-list => parameter-list
(lambda ($1 . $rest) $1)
;; parameter-type-list => parameter-list "," "..."
(lambda ($3 $2 $1 . $rest)
(tl-append $1 '(ellipis)))
;; parameter-list => parameter-declaration
(lambda ($1 . $rest) (make-tl 'param-list $1))
;; parameter-list => parameter-list "," parameter-declaration
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; parameter-declaration => declaration-specifiers declarator
(lambda ($2 $1 . $rest)
`(param-decl ,(tl->list $1) (param-declr ,$2)))
;; parameter-declaration => declaration-specifiers abstract-declarator
(lambda ($2 $1 . $rest)
`(param-decl ,(tl->list $1) (param-declr ,$2)))
;; parameter-declaration => declaration-specifiers
(lambda ($1 . $rest)
`(param-decl ,(tl->list $1)))
;; identifier-list => identifier
(lambda ($1 . $rest) (make-tl 'ident-list $1))
;; identifier-list => identifier-list "," identifier
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; type-name => specifier-qualifier-list abstract-declarator
(lambda ($2 $1 . $rest)
`(type-name ,(tl->list $1) ,$2))
;; type-name => declaration-specifiers
(lambda ($1 . $rest) `(type-name ,(tl->list $1)))
;; abstract-declarator => pointer
(lambda ($1 . $rest) `(abs-declr ,$1))
;; abstract-declarator => pointer direct-abstract-declarator
(lambda ($2 $1 . $rest) `(abs-declr ,$1 ,$2))
;; abstract-declarator => direct-abstract-declarator
(lambda ($1 . $rest) `(abs-declr ,$1))
;; direct-abstract-declarator => "(" abstract-declarator ")"
(lambda ($3 $2 $1 . $rest) `(declr-scope ,$2))
;; direct-abstract-declarator => direct-abstract-declarator "[" type-qua...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-array ,$3 ,$4))
;; direct-abstract-declarator => direct-abstract-declarator "[" type-qua...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-array ,$1 ,$3))
;; direct-abstract-declarator => direct-abstract-declarator "[" assignme...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-array ,$1 ,$3))
;; direct-abstract-declarator => direct-abstract-declarator "[" "]"
(lambda ($3 $2 $1 . $rest) `(declr-array ,$1))
;; direct-abstract-declarator => direct-abstract-declarator "[" "static"...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(declr-array
,$1
,(tl->list (tl-insert '(stor-spec "static") $4))
,$5))
;; direct-abstract-declarator => direct-abstract-declarator "[" "static"...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-array
,$1
,(tl->list (tl-insert '(stor-spec "static") $4))))
;; direct-abstract-declarator => direct-abstract-declarator "[" type-qua...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(declr-array
,$1
,(tl->list (tl-insert '(stor-spec "static") $3))
,$5))
;; direct-abstract-declarator => "[" type-qualifier-list assignment-expr...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-anon-array ,$2 ,$3))
;; direct-abstract-declarator => "[" type-qualifier-list "]"
(lambda ($3 $2 $1 . $rest)
`(declr-anon-array ,$2))
;; direct-abstract-declarator => "[" assignment-expression "]"
(lambda ($3 $2 $1 . $rest)
`(declr-anon-array ,$2))
;; direct-abstract-declarator => "[" "]"
(lambda ($2 $1 . $rest) `(declr-anon-array))
;; direct-abstract-declarator => "[" "static" type-qualifier-list assign...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $3))
,$4))
;; direct-abstract-declarator => "[" "static" type-qualifier-list "]"
(lambda ($4 $3 $2 $1 . $rest)
`(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $3))))
;; direct-abstract-declarator => "[" type-qualifier-list "static" assign...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $2))
,$4))
;; direct-abstract-declarator => direct-abstract-declarator "[" "*" "]"
(lambda ($4 $3 $2 $1 . $rest) `(declr-STAR ,$1))
;; direct-abstract-declarator => "[" "*" "]"
(lambda ($3 $2 $1 . $rest) '(declr-STAR))
;; direct-abstract-declarator => direct-abstract-declarator "(" paramete...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-fctn ,$1 ,(tl->list $3)))
;; direct-abstract-declarator => direct-abstract-declarator "(" ")"
(lambda ($3 $2 $1 . $rest) `(declr-fctn ,$1))
;; direct-abstract-declarator => "(" parameter-type-list ")"
(lambda ($3 $2 $1 . $rest)
`(declr-anon-fctn ,(tl->list $2)))
;; direct-abstract-declarator => "(" ")"
(lambda ($2 $1 . $rest) '(declr-anon-fctn))
;; typedef-name => 'typename
(lambda ($1 . $rest) `(typename ,$1))
;; initializer => assignment-expression
(lambda ($1 . $rest) `(initzer ,$1))
;; initializer => "{" initializer-list "}"
(lambda ($3 $2 $1 . $rest)
`(initzer ,(tl->list $2)))
;; initializer => "{" initializer-list "," "}"
(lambda ($4 $3 $2 $1 . $rest)
`(initzer ,(tl->list $2)))
;; initializer-list => designation initializer
(lambda ($2 $1 . $rest)
(make-tl 'initzer-list $1 $2))
;; initializer-list => initializer
(lambda ($1 . $rest) (make-tl 'initzer-list $1))
;; initializer-list => initializer-list "," designation initializer
(lambda ($4 $3 $2 $1 . $rest)
(tl-append $1 $3 $4))
;; initializer-list => initializer-list "," initializer
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; designation => designator-list "="
(lambda ($2 $1 . $rest) `(desig ,$1))
;; designator-list => designator
(lambda ($1 . $rest) (make-tl 'desgr-list $1))
;; designator-list => designator-list designator
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; designator => "[" constant-expression "]"
(lambda ($3 $2 $1 . $rest) (list 'array-dsgr $2))
;; designator => "." identifier
(lambda ($2 $1 . $rest) (list 'sel-dsgr $2))
;; statement => labeled-statement
(lambda ($1 . $rest) $1)
;; statement => compound-statement
(lambda ($1 . $rest) $1)
;; statement => expression-statement
(lambda ($1 . $rest) $1)
;; statement => selection-statement
(lambda ($1 . $rest) $1)
;; statement => iteration-statement
(lambda ($1 . $rest) $1)
;; statement => jump-statement
(lambda ($1 . $rest) $1)
;; statement => cpp-statement
(lambda ($1 . $rest) $1)
;; labeled-statement => identifier ":" statement
(lambda ($3 $2 $1 . $rest)
`(labeled-stmt ,$1 ,$3))
;; labeled-statement => "case" constant-expression ":" statement
(lambda ($4 $3 $2 $1 . $rest) `(case ,$2 ,$4))
;; labeled-statement => "default" ":" statement
(lambda ($3 $2 $1 . $rest) `(default ,$3))
;; compound-statement => "{" block-item-list "}"
(lambda ($3 $2 $1 . $rest)
`(compd-stmt ,(tl->list $2)))
;; compound-statement => "{" "}"
(lambda ($2 $1 . $rest)
`(compd-stmt (block-item-list)))
;; block-item-list => block-item
(lambda ($1 . $rest)
(make-tl 'block-item-list $1))
;; block-item-list => block-item-list block-item
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; block-item => declaration
(lambda ($1 . $rest) $1)
;; block-item => statement
(lambda ($1 . $rest) $1)
;; expression-statement => expression ";"
(lambda ($2 $1 . $rest) `(expr-stmt ,$1))
;; expression-statement => ";"
(lambda ($1 . $rest) '(expr-stmt))
;; selection-statement => "if" "(" expression ")" statement
(lambda ($5 $4 $3 $2 $1 . $rest) `(if ,$3 ,$5))
;; selection-statement => "if" "(" expression ")" statement "else" state...
(lambda ($7 $6 $5 $4 $3 $2 $1 . $rest)
`(if ,$3 ,$5 ,$7))
;; selection-statement => "switch" "(" expression ")" statement
(lambda ($5 $4 $3 $2 $1 . $rest)
`(switch ,$3 ,$5))
;; iteration-statement => "while" "(" expression ")" statement
(lambda ($5 $4 $3 $2 $1 . $rest)
`(while ,$3 ,$5))
;; iteration-statement => "do" statement "while" "(" expression ")" ";"
(lambda ($7 $6 $5 $4 $3 $2 $1 . $rest)
`(do-while ,$2 ,$5))
;; iteration-statement => "for" "(" initial-clause opt-expression ";" op...
(lambda ($8 $7 $6 $5 $4 $3 $2 $1 . $rest)
`(for ,$3 ,$4 ,$6 ,$8))
;; initial-clause => expression ";"
(lambda ($2 $1 . $rest) $1)
;; initial-clause => ";"
(lambda ($1 . $rest) '(expr))
;; initial-clause => declaration
(lambda ($1 . $rest) $1)
;; opt-expression =>
(lambda $rest '(expr))
;; opt-expression => expression
(lambda ($1 . $rest) $1)
;; jump-statement => "goto" identifier ";"
(lambda ($3 $2 $1 . $rest) `(goto $2))
;; jump-statement => "continue" ";"
(lambda ($2 $1 . $rest) '(continue))
;; jump-statement => "break" ";"
(lambda ($2 $1 . $rest) '(break))
;; jump-statement => "return" expression ";"
(lambda ($3 $2 $1 . $rest) `(return ,$2))
;; jump-statement => "return" ";"
(lambda ($2 $1 . $rest) `(return (expr)))
;; translation-unit => external-declaration
(lambda ($1 . $rest) (make-tl 'trans-unit $1))
;; translation-unit => translation-unit external-declaration
(lambda ($2 $1 . $rest)
(cond ((eqv? 'trans-unit (car $2))
(let* ((t1 (tl-append $1 '(extern-C-begin)))
(t2 (tl-extend t1 (cdr $2)))
(t3 (tl-append t2 '(extern-C-end))))
t3))
(else (tl-append $1 $2))))
;; external-declaration => function-definition
(lambda ($1 . $rest) $1)
;; external-declaration => declaration
(lambda ($1 . $rest) $1)
;; external-declaration => lone-comment
(lambda ($1 . $rest) $1)
;; external-declaration => cpp-statement
(lambda ($1 . $rest) $1)
;; external-declaration => "extern" '$string "{" translation-unit "}"
(lambda ($5 $4 $3 $2 $1 . $rest) (tl->list $4))
;; function-definition => declaration-specifiers declarator declaration-...
(lambda ($4 $3 $2 $1 . $rest)
`(knr-fctn-defn
,(tl->list $1)
,$2
,(tl->list $3)
,$4))
;; function-definition => declaration-specifiers declarator compound-sta...
(lambda ($3 $2 $1 . $rest)
`(fctn-defn ,(tl->list $1) ,$2 ,$3))
;; declaration-list => declaration
(lambda ($1 . $rest) (make-tl $1))
;; declaration-list => declaration-list declaration
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; opt-code-comment =>
(lambda $rest (list))
;; opt-code-comment => code-comment
(lambda ($1 . $rest) $1)
;; identifier => '$ident
(lambda ($1 . $rest) `(ident ,$1))
;; identifier => 'cpp-ident
(lambda ($1 . $rest) `(ident ,$1))
;; constant => '$fixed
(lambda ($1 . $rest) `(fixed ,$1))
;; constant => '$float
(lambda ($1 . $rest) `(float ,$1))
;; constant => '$chlit
(lambda ($1 . $rest) `(char ,$1))
;; string-literal => '$string
(lambda ($1 . $rest) (make-tl 'string $1))
;; string-literal => string-literal '$string
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; code-comment => '$code-comm
(lambda ($1 . $rest) `(comment ,$1))
;; lone-comment => '$lone-comm
(lambda ($1 . $rest) `(comment ,$1))
;; cpp-statement => 'cpp-stmt
(lambda ($1 . $rest) `(cpp-stmt ,$1))
))
;;; end tables

View file

@ -0,0 +1,812 @@
;; ./mach.d/c99tab.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;;
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;; or any later version published by the Free Software Foundation. See the
;; file COPYING included with the this distribution.
(define len-v
#(1 1 1 1 1 3 1 4 4 3 3 3 2 2 6 7 1 3 1 3 2 1 1 2 2 2 2 4 1 1 1 1 1 1 1 4
1 3 3 3 1 3 3 1 3 3 1 3 3 3 3 1 3 3 1 3 1 3 1 3 1 3 1 3 1 5 1 3 1 1 1 1 1
1 1 1 1 1 1 1 3 1 5 3 0 1 2 1 2 1 2 1 2 1 3 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2 2 3 1 1 2 1 2 2 3 2 3 3 4 3 2 2 1 3 2 4 3 1 2 2 1 1 2 1 2 2 3 5 4 2 5
4 2 1 1 1 1 2 2 4 2 1 2 1 1 3 1 3 2 5 6 4 5 2 1 3 1 3 1 1 1 1 2 1 1 3 5 4
4 3 6 6 5 4 4 4 3 2 1 3 2 1 2 1 3 1 3 2 2 1 1 3 2 1 1 2 1 3 5 4 4 3 6 5 6
4 3 3 2 5 4 5 4 3 4 3 3 2 1 1 3 4 2 1 4 3 2 1 2 3 2 1 1 1 1 1 1 1 3 4 3 3
2 1 2 1 1 2 1 5 7 5 5 7 8 2 1 1 0 1 3 2 2 3 2 1 2 1 1 1 1 5 4 3 1 2 0 1 1
1 1 1 1 1 2 1 1 1))
(define pat-v
#(((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8)
(34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24 . 15) (25
. 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139
. 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (46 . 29) (144
. 30) (145 . 31) (146 . 32) (147 . 33) (1 . 34) (94 . 35) (167 . 36) (45
. 37) (107 . 38) (131 . 39) (103 . 40) (99 . 41) (100 . 42) (179 . 43) (
180 . 44)) ((-1 . -234)) ((84 . 83) (5 . 50) (6 . 51) (178 . 84)) ((84 .
81) (5 . 50) (6 . 51) (21 . 1) (135 . 78) (178 . 79) (134 . 82)) ((84 . 77
) (5 . 50) (6 . 51) (21 . 1) (135 . 78) (178 . 79) (134 . 80)) ((-1 . -139
)) ((30 . 76) (-1 . -137)) ((30 . 75) (-1 . -136)) ((-1 . -133)) ((39 . 71
) (37 . 72) (35 . 73) (33 . 74) (-1 . -128)) ((37 . 68) (35 . 69) (31 . 70
) (-1 . -117)) ((-1 . -114)) ((39 . 64) (37 . 65) (35 . 66) (33 . 67) (-1
. -115)) ((37 . 63) (-1 . -110)) ((-1 . -177)) ((-1 . -176)) ((-1 . -175))
((-1 . -174)) ((-1 . -109)) ((-1 . -108)) ((-1 . -107)) ((-1 . -106)) ((
-1 . -105)) ((-1 . -104)) ((-1 . -103)) ((-1 . -102)) ((-1 . -101)) ((-1
. -100)) ((-1 . -99)) ((-1 . -97)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (
30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12)
(39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (
137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (
43 . 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (
147 . 33) (167 . 62) (-1 . -91)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30
. 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39
. 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137
. 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43
. 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147
. 33) (167 . 61) (-1 . -89)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5)
(31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 .
13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 .
20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 .
27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 .
33) (167 . 60) (-1 . -87)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (
31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13)
(23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20)
(138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (
44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 . 33) (
167 . 59) (-1 . -85)) ((94 . -303) (-1 . -303)) ((94 . -302) (-1 . -302))
((143 . 47) (150 . 48) (47 . 49) (5 . 50) (6 . 51) (79 . 52) (92 . 53) (
178 . 54) (123 . 55) (124 . 56) (142 . 57)) ((7 . 46) (-1 . -98)) ((94 .
-286) (-1 . -286)) ((94 . -285) (-1 . -285)) ((94 . -284) (-1 . -284)) ((
94 . -283) (-1 . -283)) ((94 . -281) (-1 . -281)) ((21 . 1) (27 . 2) (28
. 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37
. 11) (36 . 12) (39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 .
18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41
. 25) (42 . 26) (43 . 27) (44 . 28) (46 . 29) (144 . 30) (145 . 31) (146
. 32) (147 . 33) (1 . 34) (94 . 35) (167 . 36) (45 . 37) (107 . 38) (131
. 39) (103 . 40) (99 . 41) (100 . 45) (96 . -1)) ((96 . 0)) ((94 . -282) (
-1 . -282)) ((84 . 124)) ((47 . -93) (82 . -93)) ((149 . 122) (82 . 123) (
47 . -84)) ((93 . 119) (97 . 120) (148 . 121) (94 . -292) (-1 . -292)) ((
-1 . -295)) ((-1 . -294)) ((24 . 15) (25 . 16) (26 . 17) (145 . 116) (122
. 117) (79 . 52) (124 . 118) (-1 . -194)) ((5 . 50) (6 . 51) (79 . 52) (92
. 53) (178 . 54) (123 . 55) (124 . 56) (142 . 115)) ((-1 . -180)) ((90 .
113) (92 . 114) (-1 . -179)) ((5 . 50) (6 . 51) (92 . 53) (178 . 54) (123
. 112)) ((84 . 106) (112 . 107) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 .
5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39
. 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137
. 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43
. 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147
. 33) (167 . 108) (103 . 109) (98 . 110) (58 . 111) (47 . -95) (82 . -95))
((-1 . -98)) ((-1 . -86)) ((-1 . -88)) ((-1 . -90)) ((-1 . -92)) ((-1 .
-111)) ((37 . 105) (-1 . -112)) ((-1 . -116)) ((35 . 103) (37 . 104) (-1
. -119)) ((-1 . -134)) ((-1 . -118)) ((37 . 102) (-1 . -121)) ((30 . 101)
(-1 . -138)) ((37 . 100) (-1 . -126)) ((-1 . -127)) ((35 . 98) (37 . 99) (
-1 . -130)) ((-1 . -135)) ((-1 . -140)) ((-1 . -141)) ((21 . 1) (27 . 2) (
28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (
37 . 11) (36 . 12) (39 . 13) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136
. 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (
145 . 90) (146 . 91) (94 . 35) (130 . 92) (131 . 93) (132 . 94) (133 . 97)
) ((-1 . -150)) ((-1 . -149)) ((84 . 96) (-1 . -145)) ((21 . 1) (27 . 2) (
28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (
37 . 11) (36 . 12) (39 . 13) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136
. 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (
145 . 90) (146 . 91) (94 . 35) (130 . 92) (131 . 93) (132 . 94) (133 . 95)
) ((84 . 89) (-1 . -148)) ((5 . 50) (6 . 51) (178 . 86) (125 . 87) (126 .
88)) ((84 . 85) (-1 . -169)) ((5 . 50) (6 . 51) (178 . 86) (125 . 87) (126
. 226)) ((58 . 225) (83 . -172) (82 . -172)) ((83 . -170) (82 . -170)) ((
83 . 223) (82 . 224)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 .
6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (24
. 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40
. 22) (139 . 23) (140 . 24) (41 . 25) (145 . 90) (146 . 91) (94 . 35) (130
. 92) (131 . 93) (132 . 94) (133 . 222)) ((21 . 1) (27 . 2) (28 . 3) (29
. 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36
. 12) (39 . 13) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137
. 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (145 . 90) (146
. 91) (130 . 221) (-1 . -159)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30
. 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39
. 13) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138
. 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (145 . 90) (146 . 91) (
130 . 220) (-1 . -157)) ((5 . 50) (6 . 51) (79 . 52) (92 . 53) (178 . 54)
(123 . 55) (124 . 56) (59 . 216) (142 . 217) (128 . 218) (129 . 219)) ((94
. -152) (-1 . -152)) ((94 . -151) (-1 . -151)) ((83 . 215) (21 . 1) (27
. 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 .
10) (37 . 11) (36 . 12) (39 . 13) (24 . 15) (25 . 16) (26 . 17) (135 . 18)
(136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25
) (145 . 90) (146 . 91) (130 . 92) (132 . 212) (94 . 35) (131 . 213)) ((21
. 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34
. 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (24 . 15) (25 . 16) (26 . 17)
(135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 .
24) (41 . 25) (145 . 90) (146 . 91) (94 . 35) (130 . 92) (131 . 93) (132
. 94) (133 . 214)) ((83 . 211) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5
) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 .
13) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 .
21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (145 . 90) (146 . 91) (130
. 92) (132 . 212) (94 . 35) (131 . 213)) ((37 . 210) (-1 . -132)) ((-1 .
-129)) ((-1 . -125)) ((-1 . -142)) ((-1 . -122)) ((37 . 209) (-1 . -123))
((-1 . -120)) ((-1 . -113)) ((163 . 141) (162 . 142) (161 . 143) (160 .
144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4
. 151) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (154 . 157) (75 .
158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (
174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33
. 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (165 . 172) (152 .
173) (5 . 50) (6 . 51) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18)
(136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25)
(42 . 26) (43 . 27) (44 . 28) (45 . 58) (46 . 29) (169 . 182) (1 . 34) (8
. 183) (9 . 184) (10 . 185) (11 . 186) (12 . 187) (13 . 188) (14 . 189) (
15 . 190) (18 . 191) (47 . 192) (175 . 193) (84 . 106) (19 . 194) (20 .
195) (178 . 196) (144 . 30) (145 . 31) (146 . 32) (147 . 33) (107 . 197) (
108 . 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (
167 . 108) (106 . 204) (103 . 205) (104 . 206) (105 . 207) (83 . 208)) ((
94 . -289) (-1 . -289)) ((5 . 50) (6 . 51) (79 . 52) (92 . 53) (178 . 54)
(123 . 55) (124 . 56) (142 . 126) (143 . 47) (150 . 48) (47 . 49)) ((-1 .
-290)) ((84 . 106) (112 . 180) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5
) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 .
13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 .
20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 .
27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 .
33) (167 . 108) (103 . 181)) ((163 . 141) (162 . 142) (161 . 143) (160 .
144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4
. 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (
178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 .
176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168)
(85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (84 . 177) (169
. 178) (141 . 179)) ((90 . 113) (92 . 114) (-1 . -178)) ((43 . 139) (89 .
140) (163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 .
146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51)
(156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (
75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 162) (80 . 163) (92 . 164
) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (
173 . 171) (165 . 172) (152 . 173) (169 . 174) (24 . 15) (25 . 16) (26 .
17) (145 . 116) (122 . 175)) ((91 . 132) (5 . 50) (6 . 51) (178 . 133) (
120 . 134) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7)
(33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24 .
15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 .
22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 . 58
) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 . 33) (167 . 135) (118
. 136) (119 . 137) (121 . 138)) ((91 . 131)) ((-1 . -197)) ((79 . 52) (124
. 129) (24 . 15) (25 . 16) (26 . 17) (145 . 130) (-1 . -193)) ((-1 . -196
)) ((94 . -301) (-1 . -301)) ((94 . -293) (-1 . -293)) ((94 . -83) (-1 .
-83)) ((47 . 128)) ((5 . 50) (6 . 51) (79 . 52) (92 . 53) (178 . 54) (123
. 55) (124 . 56) (142 . 126) (143 . 127)) ((21 . 1) (27 . 2) (28 . 3) (29
. 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36
. 12) (39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 .
19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 .
26) (43 . 27) (44 . 28) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 .
33) (1 . 34) (94 . 35) (167 . 36) (45 . 37) (107 . 38) (131 . 39) (103 .
40) (99 . 41) (100 . 42) (179 . 125)) ((83 . 332) (21 . 1) (27 . 2) (28 .
3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 .
11) (36 . 12) (39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18)
(136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25
) (42 . 26) (43 . 27) (44 . 28) (46 . 29) (144 . 30) (145 . 31) (146 . 32)
(147 . 33) (1 . 34) (94 . 35) (167 . 36) (45 . 37) (107 . 38) (131 . 39)
(103 . 40) (99 . 41) (100 . 45)) ((58 . 111) (47 . -95) (82 . -95)) ((47
. -94) (82 . -94)) ((93 . 119) (97 . 120) (148 . 331) (94 . -292) (-1 .
-292)) ((-1 . -195)) ((-1 . -198)) ((-1 . -181)) ((-1 . -192)) ((91 . -206
) (82 . -206)) ((91 . 329) (82 . 330)) ((5 . 50) (6 . 51) (178 . 54) (123
. 55) (142 . 323) (90 . 324) (92 . 325) (79 . 52) (117 . 326) (124 . 327)
(166 . 328) (91 . -205) (82 . -205)) ((82 . -201) (91 . -201)) ((82 . 322)
(91 . -199)) ((91 . 321)) ((24 . 15) (25 . 16) (26 . 17) (145 . 116) (122
. 320)) ((-1 . -185)) ((-1 . -36)) ((79 . 317) (74 . 318) (73 . 319) (-1
. -40)) ((78 . 315) (77 . 316) (-1 . -43)) ((72 . 313) (71 . 314) (-1 .
-46)) ((70 . 309) (69 . 310) (68 . 311) (67 . 312) (-1 . -51)) ((66 . 307)
(65 . 308) (-1 . -54)) ((80 . 306) (-1 . -56)) ((-1 . -299)) ((-1 . -298)
) ((-1 . -297)) ((-1 . -296)) ((64 . 305) (-1 . -58)) ((63 . 304) (-1 .
-60)) ((7 . 303) (-1 . -4)) ((-1 . -3)) ((-1 . -2)) ((62 . 302) (-1 . -62)
) ((-1 . -33)) ((-1 . -32)) ((-1 . -31)) ((-1 . -30)) ((89 . 301) (-1 .
-29)) ((-1 . -28)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159
. 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5
. 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156)
(154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 .
163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169)
(86 . 170) (173 . 171) (165 . 172) (152 . 173) (169 . 182) (175 . 295) (21
. 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34
. 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24 . 15) (25 . 16)
(26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23
) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 . 58) (46 . 29) (
144 . 30) (145 . 296) (146 . 297) (147 . 33) (167 . 298) (130 . 299) (171
. 300)) ((-1 . -6)) ((60 . 293) (61 . 294) (-1 . -64)) ((7 . 148) (2 . 149
) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156
) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174
. 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 291
) (92 . 292)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (
176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 .
161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (
86 . 170) (173 . 171) (92 . 164) (165 . 229) (163 . 290)) ((7 . 148) (2 .
149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 .
156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92
. 287) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 .
171) (165 . 289)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 .
51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (
78 . 161) (79 . 176) (80 . 163) (92 . 287) (174 . 165) (81 . 167) (164 .
168) (85 . 169) (86 . 170) (173 . 171) (165 . 288)) ((90 . 281) (92 . 282)
(88 . 283) (87 . 284) (86 . 285) (85 . 286) (-1 . -22)) ((48 . 269) (49
. 270) (50 . 271) (51 . 272) (52 . 273) (53 . 274) (54 . 275) (55 . 276) (
56 . 277) (57 . 278) (58 . 279) (151 . 280) (-1 . -34)) ((-1 . -66)) ((89
. 268)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158
. 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 .
51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157
) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (80 . 163) (92 . 164) (174
. 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171
) (165 . 172) (152 . 173) (169 . 264) (24 . 15) (25 . 16) (26 . 17) (145
. 130) (89 . 265) (43 . 266) (79 . 267)) ((-1 . -29)) ((163 . 141) (162 .
142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148)
(2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (
176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77
. 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (88 . 257)
(90 . 258) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (114 . 259) (165 . 172) (152 . 173) (115 . 260) (84 . 177) (169 .
178) (141 . 261) (116 . 262) (170 . 263)) ((82 . -235) (83 . -235) (47 .
-235)) ((47 . -96) (82 . -96)) ((94 . -288) (-1 . -288)) ((-1 . -291)) ((
-1 . -79)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (
158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6
. 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 .
157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92
. 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 .
170) (173 . 171) (165 . 172) (152 . 173) (169 . 182) (175 . 255) (47 . 256
)) ((47 . 254)) ((47 . 253)) ((5 . 50) (6 . 51) (178 . 252)) ((92 . 251))
((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (
157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152) (155 . 153)
(176 . 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78
. 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167)
(164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (5
. 50) (6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10 . 185) (11 .
186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (47 . 192) (
175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 . 197) (108
. 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (106 .
250)) ((92 . 249)) ((92 . 248)) ((92 . 247)) ((-1 . -264)) ((47 . 245) (82
. 246)) ((59 . 244)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6
. 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160
) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (85
. 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163 . 141) (162 .
142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (156 .
152) (155 . 153) (154 . 157) (153 . 166) (152 . 230) (127 . 243)) ((59 .
242) (-1 . -2)) ((-1 . -253)) ((-1 . -252)) ((-1 . -251)) ((-1 . -250)) ((
-1 . -249)) ((-1 . -248)) ((-1 . -247)) ((-1 . -262)) ((-1 . -261)) ((-1
. -259)) ((83 . 240) (163 . 141) (162 . 142) (161 . 143) (160 . 144) (159
. 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (
156 . 152) (155 . 153) (176 . 154) (177 . 155) (154 . 157) (75 . 158) (76
. 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165)
(153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (21
. 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 .
9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (165 . 172) (152 . 173) (5 . 50
) (6 . 51) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (
137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (
43 . 27) (44 . 28) (45 . 58) (46 . 29) (169 . 182) (1 . 34) (8 . 183) (9
. 184) (10 . 185) (11 . 186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (
18 . 191) (47 . 192) (175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 .
196) (144 . 30) (145 . 31) (146 . 32) (147 . 33) (107 . 197) (108 . 198) (
109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (167 . 108) (
106 . 204) (103 . 205) (104 . 241)) ((94 . -258) (-1 . -258)) ((-1 . -124)
) ((-1 . -131)) ((-1 . -144)) ((94 . -153) (-1 . -153)) ((94 . -154) (-1
. -154)) ((83 . 239) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6)
(32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (24 .
15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 .
22) (139 . 23) (140 . 24) (41 . 25) (145 . 90) (146 . 91) (130 . 92) (132
. 212) (94 . 35) (131 . 213)) ((-1 . -147)) ((7 . 148) (2 . 149) (3 . 150)
(4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158
) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81
. 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229
) (163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146)
(157 . 147) (156 . 152) (155 . 153) (154 . 157) (153 . 166) (152 . 230) (
127 . 238)) ((59 . 237) (47 . -162) (82 . -162)) ((47 . -160) (82 . -160))
((47 . 235) (82 . 236)) ((-1 . -156)) ((-1 . -158)) ((83 . 234) (21 . 1)
(27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (
35 . 10) (37 . 11) (36 . 12) (39 . 13) (24 . 15) (25 . 16) (26 . 17) (135
. 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41
. 25) (145 . 90) (146 . 91) (130 . 92) (132 . 212) (94 . 35) (131 . 213))
((-1 . -167)) ((83 . 232) (5 . 50) (6 . 51) (178 . 86) (125 . 233)) ((7
. 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 .
155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (
80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 .
171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 . 144
) (159 . 145) (158 . 146) (157 . 147) (156 . 152) (155 . 153) (154 . 157)
(153 . 166) (152 . 230) (127 . 231)) ((82 . 227) (83 . 228)) ((5 . 50) (6
. 51) (178 . 86) (125 . 233) (83 . 410)) ((-1 . -165)) ((-1 . -34)) ((-1
. -81)) ((83 . -173) (82 . -173)) ((-1 . -168)) ((83 . -171) (82 . -171))
((-1 . -146)) ((93 . 119) (97 . 120) (148 . 409) (94 . -292) (-1 . -292))
((5 . 50) (6 . 51) (79 . 52) (92 . 53) (178 . 54) (123 . 55) (124 . 56) (
59 . 216) (142 . 217) (128 . 408)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151
) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 .
159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (
164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163
. 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 .
147) (156 . 152) (155 . 153) (154 . 157) (153 . 166) (152 . 230) (127 .
407)) ((47 . -164) (82 . -164)) ((-1 . -143)) ((94 . -257) (-1 . -257)) ((
-1 . -260)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (
158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152)
(155 . 153) (176 . 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77
. 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166
) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (
152 . 173) (5 . 50) (6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10
. 185) (11 . 186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (
47 . 192) (175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 .
197) (108 . 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 .
203) (106 . 406)) ((59 . 405)) ((163 . 141) (162 . 142) (161 . 143) (160
. 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (
4 . 151) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (154 . 157) (75
. 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (
174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (165 . 172) (152 . 173) (5 . 50) (6 . 51) (169 . 182) (1 . 34) (8
. 183) (9 . 184) (10 . 185) (11 . 186) (12 . 187) (13 . 188) (14 . 189) (
15 . 190) (18 . 191) (47 . 192) (175 . 193) (84 . 106) (19 . 194) (20 .
195) (178 . 196) (107 . 197) (108 . 198) (109 . 199) (110 . 200) (111 .
201) (112 . 202) (113 . 203) (106 . 404)) ((-1 . -263)) ((163 . 141) (162
. 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 .
148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 .
153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159)
(77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153
. 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172
) (152 . 173) (169 . 403)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144
) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 .
151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (
178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 .
176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168)
(85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (169 . 182) (175
. 402)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158
. 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 .
51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157
) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 .
164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170)
(173 . 171) (165 . 172) (152 . 173) (169 . 182) (175 . 401)) ((163 . 141)
(162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7
. 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155
. 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 .
159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (
153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165
. 172) (152 . 173) (169 . 182) (175 . 400)) ((14 . 399)) ((163 . 141) (162
. 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 .
148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 .
153) (176 . 154) (177 . 155) (178 . 156) (21 . 1) (27 . 2) (28 . 3) (29 .
4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 .
12) (39 . 13) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79
. 176) (80 . 163) (92 . 164) (174 . 165) (23 . 14) (24 . 15) (25 . 16) (26
. 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (
140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 . 58) (46 . 29) (153
. 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (144 . 30
) (145 . 31) (146 . 32) (147 . 33) (165 . 172) (152 . 173) (167 . 108) (
169 . 182) (103 . 395) (47 . 396) (175 . 397) (102 . 398)) ((47 . 394)) ((
-1 . -277)) ((-1 . -278)) ((47 . 393) (82 . 246)) ((-1 . -280)) ((5 . 50)
(6 . 51) (178 . 392)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6
. 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160
) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (85
. 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163 . 141) (162 .
142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (156 .
152) (155 . 153) (154 . 157) (153 . 166) (152 . 230) (127 . 391)) ((58 .
-243) (88 . -243) (90 . -243)) ((58 . 389) (88 . 257) (90 . 258) (114 .
390)) ((82 . -239) (83 . -239)) ((163 . 141) (162 . 142) (161 . 143) (160
. 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (
4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155)
(178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79
. 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168
) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (84 . 177) (
169 . 178) (141 . 388)) ((82 . 386) (83 . 387)) ((89 . 385)) ((-1 . -183))
((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146)
(157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156
. 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 .
158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (
174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (165 . 172) (152 . 173) (169 . 384)) ((89 . 383) (-1 . -29)) ((-1
. -184)) ((-1 . -78)) ((-1 . -77)) ((-1 . -76)) ((-1 . -75)) ((-1 . -74))
((-1 . -73)) ((-1 . -72)) ((-1 . -71)) ((-1 . -70)) ((-1 . -69)) ((-1 .
-68)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 .
146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51)
(156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (
75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164
) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (
173 . 171) (165 . 172) (152 . 173) (169 . 382)) ((163 . 141) (162 . 142) (
161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 .
149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 .
154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160)
(78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173)
(169 . 182) (175 . 381)) ((91 . 376) (163 . 141) (162 . 142) (161 . 143)
(160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 .
150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (21 . 1) (27 . 2) (28 . 3) (
29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (
36 . 12) (39 . 13) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (23 .
14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 .
21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28
) (45 . 58) (46 . 29) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 .
161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (144 . 30) (145 . 31) (
146 . 32) (147 . 33) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 .
170) (173 . 171) (165 . 172) (152 . 173) (167 . 377) (168 . 378) (169 .
379) (172 . 380)) ((5 . 50) (6 . 51) (178 . 375)) ((5 . 50) (6 . 51) (178
. 374)) ((-1 . -12)) ((-1 . -13)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30
. 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (
39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (
137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (
43 . 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 296) (146 . 297)
(147 . 33) (167 . 298) (130 . 299) (171 . 373) (163 . 141) (162 . 142) (
161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 .
149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 .
154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160)
(78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173)
(169 . 182) (175 . 295)) ((-1 . -23)) ((-1 . -24)) ((-1 . -25)) ((-1 .
-26)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33
. 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24 . 15)
(25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22)
(139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 . 58) (
46 . 29) (144 . 30) (145 . 296) (146 . 297) (147 . 33) (167 . 298) (130 .
299) (171 . 372) (163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 .
145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 .
50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (
154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 .
163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169)
(86 . 170) (173 . 171) (165 . 172) (152 . 173) (169 . 182) (175 . 295)) ((
163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (
157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156
. 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 .
158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (
174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (165 . 172) (152 . 173) (169 . 182) (175 . 371)) ((7 . 148) (2 .
149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 .
156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (
174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 .
164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 .
145) (158 . 146) (157 . 147) (156 . 152) (155 . 153) (154 . 370)) ((91 .
369) (82 . 246)) ((23 . 14) (42 . 26) (43 . 27) (44 . 28) (45 . 58) (46 .
29) (144 . 30) (147 . 33) (167 . 61) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (
30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12)
(39 . 13) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (
138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (145 . 296) (146 . 297
) (130 . 221) (91 . -89) (79 . -159) (90 . -159) (92 . -159)) ((23 . 14) (
42 . 26) (43 . 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (147 . 33) (
167 . 60) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (
33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (24 . 15) (25 .
16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139
. 23) (140 . 24) (41 . 25) (145 . 296) (146 . 297) (130 . 220) (91 . -87)
(79 . -157) (90 . -157) (92 . -157)) ((91 . -209)) ((90 . 324) (92 . 366)
(79 . 52) (117 . 326) (124 . 367) (166 . 368)) ((91 . 365)) ((-1 . -189))
((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (
177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 .
176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (
173 . 171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160
. 144) (159 . 145) (158 . 146) (157 . 147) (156 . 152) (155 . 364)) ((-1
. -300)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176
. 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161)
(79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86
. 170) (173 . 171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 .
143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (156 . 363)) ((7 .
148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 .
155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (
80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 .
171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 . 144
) (159 . 145) (158 . 146) (157 . 362)) ((7 . 148) (2 . 149) (3 . 150) (4
. 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (
76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229)
(163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 361)) (
(7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177
. 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176)
(80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 .
144) (159 . 360)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 .
51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (
78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 .
169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163 . 141) (162 . 142)
(161 . 143) (160 . 144) (159 . 359)) ((7 . 148) (2 . 149) (3 . 150) (4 .
151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76
. 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167)
(164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163
. 141) (162 . 142) (161 . 143) (160 . 358)) ((7 . 148) (2 . 149) (3 . 150)
(4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158
) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81
. 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229
) (163 . 141) (162 . 142) (161 . 143) (160 . 357)) ((7 . 148) (2 . 149) (3
. 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (
75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 .
165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (
165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 . 356)) ((7 . 148) (2
. 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178
. 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (
174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 .
164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 . 355)) ((7 .
148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 .
155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (
80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 .
171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 354)) ((7 . 148
) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155)
(178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 .
163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171)
(92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 353)) ((7 . 148) (2
. 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178
. 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (
174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 .
164) (165 . 229) (163 . 141) (162 . 352)) ((7 . 148) (2 . 149) (3 . 150) (
4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158)
(76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229)
(163 . 141) (162 . 351)) ((7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50)
(6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159) (77 .
160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 . 168) (
85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163 . 350)) ((7
. 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 .
155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (
80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 .
171) (92 . 164) (165 . 229) (163 . 349)) ((7 . 148) (2 . 149) (3 . 150) (4
. 151) (5 . 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (
76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229)
(163 . 348)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145)
(158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (
6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154
. 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (
92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 .
170) (173 . 171) (165 . 172) (152 . 173) (169 . 347) (24 . 15) (25 . 16) (
26 . 17) (145 . 130)) ((-1 . -190)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4) (
30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12)
(39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (
137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (
43 . 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (
147 . 33) (167 . 135) (118 . 345) (22 . 346)) ((91 . -203) (82 . -203)) ((
163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (
157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156
. 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 .
158) (76 . 159) (77 . 160) (78 . 161) (80 . 163) (92 . 164) (174 . 165) (
153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165
. 172) (152 . 173) (169 . 340) (89 . 341) (43 . 342) (24 . 15) (25 . 16) (
26 . 17) (145 . 116) (122 . 343) (79 . 344)) ((90 . 324) (117 . 326) (166
. 337) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33
. 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24 . 15)
(25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22)
(139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 . 58) (
46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 . 33) (167 . 135) (118 .
136) (119 . 137) (121 . 338) (91 . 339) (5 . 50) (6 . 51) (79 . 52) (92 .
325) (178 . 54) (123 . 55) (124 . 327) (142 . 115)) ((90 . 335) (92 . 336)
(91 . -212) (82 . -212)) ((90 . 324) (117 . 334) (5 . 50) (6 . 51) (92 .
325) (178 . 54) (123 . 112) (91 . -210) (82 . -210)) ((91 . -204) (82 .
-204)) ((-1 . -191)) ((5 . 50) (6 . 51) (178 . 333)) ((94 . -82) (-1 . -82
)) ((94 . -287) (-1 . -287)) ((91 . -207) (82 . -207)) ((90 . 335) (92 .
336) (91 . -211) (82 . -211)) ((43 . 444) (89 . 445) (163 . 141) (162 .
142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148)
(2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (
176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77
. 160) (78 . 161) (79 . 446) (80 . 163) (92 . 164) (174 . 165) (153 . 166)
(81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152
. 173) (169 . 447) (24 . 15) (25 . 16) (26 . 17) (145 . 116) (122 . 448))
((91 . 442) (21 . 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7
) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24
. 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40
. 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 .
58) (46 . 29) (144 . 30) (145 . 31) (146 . 32) (147 . 33) (167 . 135) (118
. 136) (119 . 137) (121 . 443)) ((91 . 441)) ((91 . 440)) ((-1 . -233)) (
(89 . 439)) ((-1 . -224)) ((24 . 15) (25 . 16) (26 . 17) (145 . 116) (122
. 438)) ((43 . 435) (24 . 15) (25 . 16) (26 . 17) (145 . 130) (89 . 436) (
163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (
157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156
. 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 .
158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (
174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173
. 171) (165 . 172) (152 . 173) (169 . 437)) ((89 . 434) (-1 . -29)) ((82
. -202) (91 . -202)) ((91 . -200)) ((89 . 433)) ((-1 . -39)) ((-1 . -38))
((-1 . -37)) ((79 . 317) (74 . 318) (73 . 319) (-1 . -42)) ((79 . 317) (74
. 318) (73 . 319) (-1 . -41)) ((78 . 315) (77 . 316) (-1 . -45)) ((78 .
315) (77 . 316) (-1 . -44)) ((72 . 313) (71 . 314) (-1 . -50)) ((72 . 313)
(71 . 314) (-1 . -49)) ((72 . 313) (71 . 314) (-1 . -48)) ((72 . 313) (71
. 314) (-1 . -47)) ((70 . 309) (69 . 310) (68 . 311) (67 . 312) (-1 . -53
)) ((70 . 309) (69 . 310) (68 . 311) (67 . 312) (-1 . -52)) ((66 . 307) (
65 . 308) (-1 . -55)) ((80 . 306) (-1 . -57)) ((64 . 305) (-1 . -59)) ((63
. 304) (-1 . -61)) ((84 . 431) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5
. 50) (6 . 51) (176 . 154) (177 . 155) (178 . 156) (75 . 158) (76 . 159)
(77 . 160) (78 . 161) (79 . 176) (80 . 163) (174 . 165) (81 . 167) (164 .
168) (85 . 169) (86 . 170) (173 . 171) (92 . 164) (165 . 229) (163 . 432))
((90 . 324) (92 . 366) (79 . 52) (117 . 326) (124 . 367) (166 . 337) (21
. 1) (27 . 2) (28 . 3) (29 . 4) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 .
9) (35 . 10) (37 . 11) (36 . 12) (39 . 13) (23 . 14) (24 . 15) (25 . 16) (
26 . 17) (135 . 18) (136 . 19) (137 . 20) (138 . 21) (40 . 22) (139 . 23)
(140 . 24) (41 . 25) (42 . 26) (43 . 27) (44 . 28) (45 . 58) (46 . 29) (
144 . 30) (145 . 31) (146 . 32) (147 . 33) (167 . 135) (118 . 136) (119 .
137) (121 . 338) (91 . 339)) ((90 . 324) (92 . 366) (117 . 334) (91 . -210
) (82 . -210)) ((91 . -208)) ((-1 . -5)) ((62 . 302) (-1 . -63)) ((59 .
430) (82 . 246)) ((91 . 429)) ((91 . 428)) ((-1 . -11)) ((-1 . -10)) ((-1
. -9)) ((90 . 324) (92 . 366) (79 . 52) (117 . 326) (124 . 367) (166 . 427
) (91 . -21) (82 . -21)) ((91 . -18) (82 . -18)) ((91 . -16) (82 . -16)) (
(91 . 425) (82 . 426)) ((89 . 424) (82 . 246)) ((-1 . -67)) ((-1 . -188))
((89 . 423)) ((-1 . -182)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144
) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 .
151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (
178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 .
176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168)
(85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (84 . 177) (169
. 178) (141 . 420) (88 . 257) (90 . 258) (114 . 259) (115 . 260) (116 .
421) (83 . 422)) ((82 . -236) (83 . -236) (47 . -236)) ((82 . -238) (83 .
-238)) ((-1 . -242)) ((58 . -244) (88 . -244) (90 . -244)) ((89 . 419)) ((
58 . -246) (90 . -246) (88 . -246)) ((-1 . -279)) ((-1 . -276)) ((-1 .
-273)) ((-1 . -272)) ((47 . 418) (82 . 246)) ((163 . 141) (162 . 142) (161
. 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149
) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154
) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78
. 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167
) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (
169 . 182) (175 . 416) (101 . 417) (47 . -274)) ((92 . 415)) ((91 . 414) (
82 . 246)) ((91 . 413) (82 . 246)) ((82 . 246) (91 . 412)) ((-1 . -80)) ((
-1 . -256)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (
158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152)
(155 . 153) (176 . 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77
. 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166
) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (
152 . 173) (5 . 50) (6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10
. 185) (11 . 186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (
47 . 192) (175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 .
197) (108 . 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 .
203) (106 . 411)) ((-1 . -254)) ((47 . -163) (82 . -163)) ((47 . -161) (82
. -161)) ((94 . -155) (-1 . -155)) ((-1 . -166)) ((-1 . -255)) ((163 .
141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 .
147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152) (155 . 153) (176
. 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161)
(79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164
. 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (5 . 50)
(6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10 . 185) (11 . 186) (
12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (47 . 192) (175 .
193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 . 197) (108 . 198)
(109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (106 . 469)) (
(163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (
157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152) (155 . 153)
(176 . 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78
. 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167)
(164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (5
. 50) (6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10 . 185) (11 .
186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (47 . 192) (
175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 . 197) (108
. 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (106 .
468)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 .
146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152) (155
. 153) (176 . 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77 . 160
) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81
. 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 .
173) (5 . 50) (6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10 . 185)
(11 . 186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (47 .
192) (175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 . 197)
(108 . 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (
106 . 467)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (
158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6
. 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 .
157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92
. 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 .
170) (173 . 171) (165 . 172) (152 . 173) (169 . 182) (175 . 466)) ((82 .
246) (47 . -275) (91 . -275)) ((47 . 465)) ((-1 . -271)) ((58 . -245) (90
. -245) (88 . -245)) ((82 . -241) (83 . -241)) ((163 . 141) (162 . 142) (
161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 .
149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 .
154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160)
(78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173)
(84 . 177) (169 . 178) (141 . 464)) ((82 . -237) (83 . -237) (47 . -237))
((-1 . -187)) ((-1 . -7)) ((-1 . -8)) ((21 . 1) (27 . 2) (28 . 3) (29 . 4
) (30 . 5) (31 . 6) (32 . 7) (33 . 8) (34 . 9) (35 . 10) (37 . 11) (36 .
12) (39 . 13) (23 . 14) (24 . 15) (25 . 16) (26 . 17) (135 . 18) (136 . 19
) (137 . 20) (138 . 21) (40 . 22) (139 . 23) (140 . 24) (41 . 25) (42 . 26
) (43 . 27) (44 . 28) (45 . 58) (46 . 29) (144 . 30) (145 . 31) (146 . 32)
(147 . 33) (167 . 377) (168 . 462) (163 . 141) (162 . 142) (161 . 143) (
160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 .
150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177
. 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161)
(79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164
. 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (169 .
463)) ((91 . -20) (82 . -20)) ((84 . 431)) ((84 . 431) (-1 . -27)) ((7 .
148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (176 . 154) (177 .
155) (178 . 156) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (
80 . 163) (174 . 165) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 .
171) (92 . 164) (165 . 229) (163 . 141) (162 . 142) (161 . 143) (160 . 144
) (159 . 145) (158 . 146) (157 . 147) (156 . 152) (155 . 153) (154 . 157)
(153 . 166) (152 . 461)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144)
(159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151
) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178
. 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176)
(80 . 163) (92 . 164) (174 . 165) (88 . 257) (90 . 258) (153 . 166) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (114 . 259) (165 . 172)
(152 . 173) (115 . 260) (84 . 177) (169 . 178) (141 . 261) (116 . 262) (
170 . 460)) ((-1 . -35)) ((-1 . -186)) ((-1 . -229)) ((163 . 141) (162 .
142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148)
(2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (
176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77
. 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166)
(81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152
. 173) (169 . 459)) ((-1 . -222)) ((89 . 458)) ((163 . 141) (162 . 142) (
161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2 .
149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176 .
154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160)
(78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 .
167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173)
(169 . 456) (24 . 15) (25 . 16) (26 . 17) (145 . 130) (89 . 457)) ((-1 .
-223)) ((-1 . -232)) ((-1 . -213)) ((-1 . -231)) ((91 . 455)) ((24 . 15) (
25 . 16) (26 . 17) (145 . 116) (122 . 454)) ((-1 . -217)) ((89 . 453) (-1
. -29)) ((89 . 452)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159
. 145) (158 . 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5
. 50) (6 . 51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156
) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80
. 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169
) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (169 . 449) (24 . 15) (25
. 16) (26 . 17) (145 . 130) (89 . 450) (43 . 451)) ((89 . 480)) ((-1 .
-215)) ((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158
. 146) (157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 .
51) (156 . 152) (155 . 153) (176 . 154) (177 . 155) (178 . 156) (154 . 157
) (75 . 158) (76 . 159) (77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 .
164) (174 . 165) (153 . 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170)
(173 . 171) (165 . 172) (152 . 173) (169 . 479)) ((-1 . -216)) ((-1 . -228
)) ((89 . 477) (24 . 15) (25 . 16) (26 . 17) (145 . 130) (163 . 141) (162
. 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 .
148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 .
153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159)
(77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153
. 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172
) (152 . 173) (169 . 478)) ((-1 . -230)) ((89 . 476)) ((-1 . -226)) ((-1
. -221)) ((89 . 475)) ((83 . 473) (82 . 474)) ((-1 . -65)) ((91 . -19) (82
. -19)) ((91 . -17) (82 . -17)) ((82 . -240) (83 . -240)) ((163 . 141) (
162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7
. 148) (2 . 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 .
153) (176 . 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159)
(77 . 160) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153
. 166) (81 . 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172
) (152 . 173) (169 . 182) (175 . 416) (101 . 472) (91 . -274)) ((91 . 471)
(82 . 246)) ((-1 . -268)) ((-1 . -267)) ((16 . 470) (-1 . -265)) ((163 .
141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 .
147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152) (155 . 153) (176
. 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78 . 161)
(79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167) (164
. 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (5 . 50)
(6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10 . 185) (11 . 186) (
12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (47 . 192) (175 .
193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 . 197) (108 . 198)
(109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (106 . 486)) (
(47 . 485)) ((91 . 484)) ((-1 . -14)) ((83 . 483) (163 . 141) (162 . 142)
(161 . 143) (160 . 144) (159 . 145) (158 . 146) (157 . 147) (7 . 148) (2
. 149) (3 . 150) (4 . 151) (5 . 50) (6 . 51) (156 . 152) (155 . 153) (176
. 154) (177 . 155) (178 . 156) (154 . 157) (75 . 158) (76 . 159) (77 . 160
) (78 . 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81
. 167) (164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 .
173) (84 . 177) (169 . 178) (141 . 420) (88 . 257) (90 . 258) (114 . 259)
(115 . 260) (116 . 421)) ((-1 . -227)) ((-1 . -225)) ((-1 . -219)) ((89 .
482)) ((89 . 481)) ((-1 . -214)) ((-1 . -220)) ((-1 . -218)) ((-1 . -15))
((163 . 141) (162 . 142) (161 . 143) (160 . 144) (159 . 145) (158 . 146) (
157 . 147) (7 . 148) (2 . 149) (3 . 150) (4 . 151) (156 . 152) (155 . 153)
(176 . 154) (177 . 155) (154 . 157) (75 . 158) (76 . 159) (77 . 160) (78
. 161) (79 . 176) (80 . 163) (92 . 164) (174 . 165) (153 . 166) (81 . 167)
(164 . 168) (85 . 169) (86 . 170) (173 . 171) (165 . 172) (152 . 173) (5
. 50) (6 . 51) (169 . 182) (1 . 34) (8 . 183) (9 . 184) (10 . 185) (11 .
186) (12 . 187) (13 . 188) (14 . 189) (15 . 190) (18 . 191) (47 . 192) (
175 . 193) (84 . 106) (19 . 194) (20 . 195) (178 . 196) (107 . 197) (108
. 198) (109 . 199) (110 . 200) (111 . 201) (112 . 202) (113 . 203) (106 .
487)) ((-1 . -269)) ((-1 . -266)) ((-1 . -270))))
(define rto-v
#(#f 180 174 174 174 174 173 173 173 173 173 173 173 173 173 173 172 172
172 172 168 168 165 165 165 165 165 165 164 164 164 164 164 164 163 163
162 162 162 162 161 161 161 160 160 160 159 159 159 159 159 158 158 158
157 157 156 156 155 155 154 154 153 153 152 152 169 169 151 151 151 151
151 151 151 151 151 151 151 175 175 127 103 103 149 167 167 167 167 167
167 167 167 150 150 143 143 147 147 147 147 147 146 146 146 146 146 146
146 146 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140
140 140 140 140 140 140 140 140 140 140 139 139 139 138 138 138 138 137
137 137 137 137 137 134 134 133 133 133 133 132 130 130 130 130 129 129
128 128 128 136 136 136 136 136 126 126 125 125 145 145 145 144 142 142
123 123 123 123 123 123 123 123 123 123 123 123 123 124 124 124 124 122
122 121 121 119 119 118 118 118 120 120 171 171 166 166 166 117 117 117
117 117 117 117 117 117 117 117 117 117 117 117 117 117 117 117 117 117
135 141 141 141 170 170 170 170 116 115 115 114 114 106 106 106 106 106
106 106 113 113 113 112 112 105 105 104 104 111 111 110 110 110 109 109
109 102 102 102 101 101 108 108 108 108 108 179 179 100 100 100 100 100 99
99 98 98 148 148 178 178 177 177 177 176 176 97 131 107))
(define mtab
'((cpp-stmt . 1) ($chlit . 2) ($float . 3) ($fixed . 4) (cpp-ident . 5) (
$ident . 6) ($string . 7) ("return" . 8) ("break" . 9) ("continue" . 10) (
"goto" . 11) ("for" . 12) ("do" . 13) ("while" . 14) ("switch" . 15) (
"else" . 16) (then . 17) ("if" . 18) ("default" . 19) ("case" . 20) (
typename . 21) ("..." . 22) ("inline" . 23) ("restrict" . 24) ("volatile"
. 25) ("const" . 26) ("enum" . 27) ("union" . 28) ("struct" . 29) (
"_Complex" . 30) ("double" . 31) ("float" . 32) ("char" . 33) ("unsigned"
. 34) ("long" . 35) ("signed" . 36) ("int" . 37) (imp . 38) ("short" . 39)
("_Bool" . 40) ("void" . 41) ("typedef" . 42) ("static" . 43) ("register"
. 44) ("extern" . 45) ("auto" . 46) (";" . 47) ("|=" . 48) ("^=" . 49) (
"&=" . 50) (">>=" . 51) ("<<=" . 52) ("%=" . 53) ("/=" . 54) ("*=" . 55) (
"-=" . 56) ("+=" . 57) ("=" . 58) (":" . 59) ("?" . 60) ("||" . 61) ("&&"
. 62) ("|" . 63) ("^" . 64) ("!=" . 65) ("==" . 66) (">=" . 67) ("<=" . 68
) (">" . 69) ("<" . 70) (">>" . 71) ("<<" . 72) ("%" . 73) ("/" . 74) ("!"
. 75) ("~" . 76) ("-" . 77) ("+" . 78) ("*" . 79) ("&" . 80) ("sizeof" .
81) ("," . 82) ("}" . 83) ("{" . 84) ("--" . 85) ("++" . 86) ("->" . 87) (
"." . 88) ("]" . 89) ("[" . 90) (")" . 91) ("(" . 92) ($code-comm . 93) (
$lone-comm . 94) ($error . 95) ($end . 96)))
;;; end tables

View file

@ -0,0 +1,762 @@
;; ./mach.d/c99xact.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;;
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;; or any later version published by the Free Software Foundation. See the
;; file COPYING included with the this distribution.
(define act-v
(vector
;; $start => expression
(lambda ($1 . $rest) $1)
;; translation-unit-proxy => translation-unit
(lambda ($1 . $rest) (tl->list $1))
;; primary-expression => identifier
(lambda ($1 . $rest) `(p-expr ,$1))
;; primary-expression => constant
(lambda ($1 . $rest) `(p-expr ,$1))
;; primary-expression => string-literal
(lambda ($1 . $rest) `(p-expr ,(tl->list $1)))
;; primary-expression => "(" expression ")"
(lambda ($3 $2 $1 . $rest) $2)
;; postfix-expression => primary-expression
(lambda ($1 . $rest) $1)
;; postfix-expression => postfix-expression "[" expression "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-ref ,$3 ,$1))
;; postfix-expression => postfix-expression "(" argument-expression-list...
(lambda ($4 $3 $2 $1 . $rest)
`(fctn-call ,$1 ,(tl->list $3)))
;; postfix-expression => postfix-expression "(" ")"
(lambda ($3 $2 $1 . $rest)
`(fctn-call ,$1 (expr-list)))
;; postfix-expression => postfix-expression "." identifier
(lambda ($3 $2 $1 . $rest) `(d-sel ,$3 ,$1))
;; postfix-expression => postfix-expression "->" identifier
(lambda ($3 $2 $1 . $rest) `(i-sel ,$3 ,$1))
;; postfix-expression => postfix-expression "++"
(lambda ($2 $1 . $rest) `(post-inc ,$1))
;; postfix-expression => postfix-expression "--"
(lambda ($2 $1 . $rest) `(post-dec ,$1))
;; postfix-expression => "(" type-name ")" "{" initializer-list "}"
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(comp-lit ,$2 ,(tl->list $5)))
;; postfix-expression => "(" type-name ")" "{" initializer-list "," "}"
(lambda ($7 $6 $5 $4 $3 $2 $1 . $rest)
`(comp-lit ,$2 ,(tl->list $5)))
;; argument-expression-list => assignment-expression
(lambda ($1 . $rest) (make-tl 'expr-list $1))
;; argument-expression-list => argument-expression-list "," assignment-e...
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; argument-expression-list => arg-expr-hack
(lambda ($1 . $rest) (make-tl 'expr-list $1))
;; argument-expression-list => argument-expression-list "," arg-expr-hack
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; arg-expr-hack => declaration-specifiers abstract-declarator
(lambda ($2 $1 . $rest)
`(param-decl ,(tl->list $1) $2))
;; arg-expr-hack => declaration-specifiers
(lambda ($1 . $rest)
`(param-decl ,(tl->list $1)))
;; unary-expression => postfix-expression
(lambda ($1 . $rest) $1)
;; unary-expression => "++" unary-expression
(lambda ($2 $1 . $rest) `(pre-inc ,$2))
;; unary-expression => "--" unary-expression
(lambda ($2 $1 . $rest) `(pre-dec ,$2))
;; unary-expression => unary-operator cast-expression
(lambda ($2 $1 . $rest) (list $1 $2))
;; unary-expression => "sizeof" unary-expression
(lambda ($2 $1 . $rest) `(sizeof-expr ,$2))
;; unary-expression => "sizeof" "(" type-name ")"
(lambda ($4 $3 $2 $1 . $rest) `(sizeof-type ,$3))
;; unary-operator => "&"
(lambda ($1 . $rest) 'ref-to)
;; unary-operator => "*"
(lambda ($1 . $rest) 'de-ref)
;; unary-operator => "+"
(lambda ($1 . $rest) 'pos)
;; unary-operator => "-"
(lambda ($1 . $rest) 'neg)
;; unary-operator => "~"
(lambda ($1 . $rest) 'bitwise-not)
;; unary-operator => "!"
(lambda ($1 . $rest) 'not)
;; cast-expression => unary-expression
(lambda ($1 . $rest) $1)
;; cast-expression => "(" type-name ")" cast-expression
(lambda ($4 $3 $2 $1 . $rest) `(cast ,$2 ,$4))
;; multiplicative-expression => cast-expression
(lambda ($1 . $rest) $1)
;; multiplicative-expression => multiplicative-expression "*" cast-expre...
(lambda ($3 $2 $1 . $rest) `(mul ,$1 ,$3))
;; multiplicative-expression => multiplicative-expression "/" cast-expre...
(lambda ($3 $2 $1 . $rest) `(div ,$1 ,$3))
;; multiplicative-expression => multiplicative-expression "%" cast-expre...
(lambda ($3 $2 $1 . $rest) `(mod ,$1 ,$3))
;; additive-expression => multiplicative-expression
(lambda ($1 . $rest) $1)
;; additive-expression => additive-expression "+" multiplicative-expression
(lambda ($3 $2 $1 . $rest) `(add ,$1 ,$3))
;; additive-expression => additive-expression "-" multiplicative-expression
(lambda ($3 $2 $1 . $rest) `(sub ,$1 ,$3))
;; shift-expression => additive-expression
(lambda ($1 . $rest) $1)
;; shift-expression => shift-expression "<<" additive-expression
(lambda ($3 $2 $1 . $rest) `(lshift ,$1 ,$3))
;; shift-expression => shift-expression ">>" additive-expression
(lambda ($3 $2 $1 . $rest) `(rshift ,$1 ,$3))
;; relational-expression => shift-expression
(lambda ($1 . $rest) $1)
;; relational-expression => relational-expression "<" shift-expression
(lambda ($3 $2 $1 . $rest) `(lt ,$1 ,$3))
;; relational-expression => relational-expression ">" shift-expression
(lambda ($3 $2 $1 . $rest) `(gt ,$1 ,$3))
;; relational-expression => relational-expression "<=" shift-expression
(lambda ($3 $2 $1 . $rest) `(le ,$1 ,$3))
;; relational-expression => relational-expression ">=" shift-expression
(lambda ($3 $2 $1 . $rest) `(ge ,$1 ,$3))
;; equality-expression => relational-expression
(lambda ($1 . $rest) $1)
;; equality-expression => equality-expression "==" relational-expression
(lambda ($3 $2 $1 . $rest) `(eq ,$1 ,$3))
;; equality-expression => equality-expression "!=" relational-expression
(lambda ($3 $2 $1 . $rest) `(ne ,$1 ,$3))
;; bitwise-and-expression => equality-expression
(lambda ($1 . $rest) $1)
;; bitwise-and-expression => bitwise-and-expression "&" equality-expression
(lambda ($3 $2 $1 . $rest)
`(bitwise-and ,$1 ,$3))
;; bitwise-xor-expression => bitwise-and-expression
(lambda ($1 . $rest) $1)
;; bitwise-xor-expression => bitwise-xor-expression "^" bitwise-and-expr...
(lambda ($3 $2 $1 . $rest)
`(bitwise-xor ,$1 ,$3))
;; bitwise-or-expression => bitwise-xor-expression
(lambda ($1 . $rest) $1)
;; bitwise-or-expression => bitwise-or-expression "|" bitwise-xor-expres...
(lambda ($3 $2 $1 . $rest) `(bitwise-or ,$1 ,$3))
;; logical-and-expression => bitwise-or-expression
(lambda ($1 . $rest) $1)
;; logical-and-expression => logical-and-expression "&&" bitwise-or-expr...
(lambda ($3 $2 $1 . $rest) `(and ,$1 ,$3))
;; logical-or-expression => logical-and-expression
(lambda ($1 . $rest) $1)
;; logical-or-expression => logical-or-expression "||" logical-and-expre...
(lambda ($3 $2 $1 . $rest) `(or ,$1 ,$3))
;; conditional-expression => logical-or-expression
(lambda ($1 . $rest) $1)
;; conditional-expression => logical-or-expression "?" expression ":" co...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(cond-expr ,$1 ,$2 ,$3))
;; assignment-expression => conditional-expression
(lambda ($1 . $rest) $1)
;; assignment-expression => unary-expression assignment-operator assignm...
(lambda ($3 $2 $1 . $rest)
`(assn-expr ,$1 (op ,$2) ,$3))
;; assignment-operator => "="
(lambda ($1 . $rest) $1)
;; assignment-operator => "+="
(lambda ($1 . $rest) $1)
;; assignment-operator => "-="
(lambda ($1 . $rest) $1)
;; assignment-operator => "*="
(lambda ($1 . $rest) $1)
;; assignment-operator => "/="
(lambda ($1 . $rest) $1)
;; assignment-operator => "%="
(lambda ($1 . $rest) $1)
;; assignment-operator => "<<="
(lambda ($1 . $rest) $1)
;; assignment-operator => ">>="
(lambda ($1 . $rest) $1)
;; assignment-operator => "&="
(lambda ($1 . $rest) $1)
;; assignment-operator => "^="
(lambda ($1 . $rest) $1)
;; assignment-operator => "|="
(lambda ($1 . $rest) $1)
;; expression => assignment-expression
(lambda ($1 . $rest) $1)
;; expression => expression "," assignment-expression
(lambda ($3 $2 $1 . $rest)
(if (eqv? 'comma-expr (sx-tag $1))
(append $1 (list $3))
`(comma-expr ,$1 ,$3)))
;; constant-expression => conditional-expression
(lambda ($1 . $rest) $1)
;; declaration => declaration-specifiers init-declarator-list $P1 ";" op...
(lambda ($5 $4 $3 $2 $1 . $rest)
(if (pair? $5) (append $3 (list $5)) $3))
;; declaration => declaration-specifiers ";" opt-code-comment
(lambda ($3 $2 $1 . $rest)
(if (pair? $3)
`(decl ,(tl->list $1) ,(list $3))
`(decl ,(tl->list $1))))
;; $P1 =>
(lambda ($2 $1 . $rest)
(save-typenames
`(decl ,(tl->list $1) ,(tl->list $2))))
;; declaration-specifiers => storage-class-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => storage-class-specifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; declaration-specifiers => type-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => type-specifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; declaration-specifiers => type-qualifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => type-qualifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; declaration-specifiers => function-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; declaration-specifiers => function-specifier declaration-specifiers
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; init-declarator-list => init-declarator
(lambda ($1 . $rest)
(make-tl 'init-declr-list $1))
;; init-declarator-list => init-declarator-list "," init-declarator
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; init-declarator => declarator
(lambda ($1 . $rest) `(init-declr ,$1))
;; init-declarator => declarator "=" initializer
(lambda ($3 $2 $1 . $rest) `(init-declr ,$1 ,$3))
;; storage-class-specifier => "auto"
(lambda ($1 . $rest) '(stor-spec (auto)))
;; storage-class-specifier => "extern"
(lambda ($1 . $rest) '(stor-spec (extern)))
;; storage-class-specifier => "register"
(lambda ($1 . $rest) '(stor-spec (register)))
;; storage-class-specifier => "static"
(lambda ($1 . $rest) '(stor-spec (static)))
;; storage-class-specifier => "typedef"
(lambda ($1 . $rest) '(stor-spec (typedef)))
;; type-specifier => "void"
(lambda ($1 . $rest) '(type-spec (void)))
;; type-specifier => fixed-type-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => float-type-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => "_Bool"
(lambda ($1 . $rest)
'(type-spec (fixed-type "_Bool")))
;; type-specifier => complex-type-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => struct-or-union-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => enum-specifier
(lambda ($1 . $rest) `(type-spec ,$1))
;; type-specifier => typedef-name
(lambda ($1 . $rest) `(type-spec ,$1))
;; fixed-type-specifier => "short"
(lambda ($1 . $rest) '(fixed-type "short"))
;; fixed-type-specifier => "short" "int"
(lambda ($2 $1 . $rest)
'(fixed-type "short int"))
;; fixed-type-specifier => "signed" "short"
(lambda ($2 $1 . $rest)
'(fixed-type "signed short"))
;; fixed-type-specifier => "signed" "short" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "signed short int"))
;; fixed-type-specifier => "int"
(lambda ($1 . $rest) '(fixed-type "int"))
;; fixed-type-specifier => "signed"
(lambda ($1 . $rest) '(fixed-type "signed"))
;; fixed-type-specifier => "signed" "int"
(lambda ($2 $1 . $rest)
'(fixed-type "signed int"))
;; fixed-type-specifier => "long"
(lambda ($1 . $rest) '(fixed-type "long"))
;; fixed-type-specifier => "long" "int"
(lambda ($2 $1 . $rest) '(fixed-type "long int"))
;; fixed-type-specifier => "signed" "long"
(lambda ($2 $1 . $rest)
'(fixed-type "signed long"))
;; fixed-type-specifier => "signed" "long" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "signed long int"))
;; fixed-type-specifier => "long" "long"
(lambda ($2 $1 . $rest)
'(fixed-type "long long"))
;; fixed-type-specifier => "long" "long" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "long long int"))
;; fixed-type-specifier => "signed" "long" "long"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "signed long long"))
;; fixed-type-specifier => "signed" "long" "long" "int"
(lambda ($4 $3 $2 $1 . $rest)
'(fixed-type "signed long long int"))
;; fixed-type-specifier => "unsigned" "short" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "unsigned short int"))
;; fixed-type-specifier => "unsigned" "short"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned short"))
;; fixed-type-specifier => "unsigned" "int"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned int"))
;; fixed-type-specifier => "unsigned"
(lambda ($1 . $rest) '(fixed-type "unsigned"))
;; fixed-type-specifier => "unsigned" "long" "int"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "unsigned long"))
;; fixed-type-specifier => "unsigned" "long"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned long"))
;; fixed-type-specifier => "unsigned" "long" "long" "int"
(lambda ($4 $3 $2 $1 . $rest)
'(fixed-type "unsigned long long int"))
;; fixed-type-specifier => "unsigned" "long" "long"
(lambda ($3 $2 $1 . $rest)
'(fixed-type "unsigned long long"))
;; fixed-type-specifier => "char"
(lambda ($1 . $rest) '(fixed-type "char"))
;; fixed-type-specifier => "signed" "char"
(lambda ($2 $1 . $rest)
'(fixed-type "signed char"))
;; fixed-type-specifier => "unsigned" "char"
(lambda ($2 $1 . $rest)
'(fixed-type "unsigned char"))
;; float-type-specifier => "float"
(lambda ($1 . $rest) '(float-type "float"))
;; float-type-specifier => "double"
(lambda ($1 . $rest) '(float-type "double"))
;; float-type-specifier => "long" "double"
(lambda ($2 $1 . $rest)
'(float-type "long double"))
;; complex-type-specifier => "_Complex"
(lambda ($1 . $rest) '(complex-type "_Complex"))
;; complex-type-specifier => "float" "_Complex"
(lambda ($2 $1 . $rest)
'(complex-type "float _Complex"))
;; complex-type-specifier => "double" "_Complex"
(lambda ($2 $1 . $rest)
'(complex-type "double _Complex"))
;; complex-type-specifier => "long" "double" "_Complex"
(lambda ($3 $2 $1 . $rest)
'(complex-type "long double _Complex"))
;; struct-or-union-specifier => "struct" ident-like "{" struct-declarati...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(struct-def ,$2 ,(tl->list $4)))
;; struct-or-union-specifier => "struct" "{" struct-declaration-list "}"
(lambda ($4 $3 $2 $1 . $rest)
`(struct-def ,(tl->list $3)))
;; struct-or-union-specifier => "struct" ident-like
(lambda ($2 $1 . $rest) `(struct-ref ,$2))
;; struct-or-union-specifier => "union" ident-like "{" struct-declaratio...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(union-def ,$2 ,(tl->list $4)))
;; struct-or-union-specifier => "union" "{" struct-declaration-list "}"
(lambda ($4 $3 $2 $1 . $rest)
`(union-def ,(tl->list $3)))
;; struct-or-union-specifier => "union" ident-like
(lambda ($2 $1 . $rest) `(union-ref ,$2))
;; ident-like => identifier
(lambda ($1 . $rest) $1)
;; ident-like => typedef-name
(lambda ($1 . $rest) `(ident ,(cdr $1)))
;; struct-declaration-list => struct-declaration
(lambda ($1 . $rest) (make-tl 'field-list $1))
;; struct-declaration-list => lone-comment
(lambda ($1 . $rest) (make-tl 'field-list $1))
;; struct-declaration-list => struct-declaration-list struct-declaration
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; struct-declaration-list => struct-declaration-list lone-comment
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; struct-declaration => specifier-qualifier-list struct-declarator-list...
(lambda ($4 $3 $2 $1 . $rest)
(if (pair? $4)
`(comp-decl ,(tl->list $1) ,(tl->list $2) ,$4)
`(comp-decl ,(tl->list $1) ,(tl->list $2))))
;; specifier-qualifier-list => type-specifier specifier-qualifier-list
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; specifier-qualifier-list => type-specifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; specifier-qualifier-list => type-qualifier specifier-qualifier-list
(lambda ($2 $1 . $rest) (tl-insert $2 $1))
;; specifier-qualifier-list => type-qualifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; struct-declarator-list => struct-declarator
(lambda ($1 . $rest)
(make-tl 'comp-declr-list $1))
;; struct-declarator-list => struct-declarator-list "," struct-declarator
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; struct-declarator => declarator
(lambda ($1 . $rest) `(comp-declr ,$1))
;; struct-declarator => declarator ":" constant-expression
(lambda ($3 $2 $1 . $rest)
`(comp-declr (bit-field ,$1 ,$3)))
;; struct-declarator => ":" constant-expression
(lambda ($2 $1 . $rest)
`(comp-declr (bit-field ,$2)))
;; enum-specifier => "enum" identifier "{" enumerator-list "}"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(enum-def ,$2 ,(tl->list $4)))
;; enum-specifier => "enum" identifier "{" enumerator-list "," "}"
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(enum-def ,$2 ,(tl->list $4)))
;; enum-specifier => "enum" "{" enumerator-list "}"
(lambda ($4 $3 $2 $1 . $rest)
`(enum-def ,(tl->list $3)))
;; enum-specifier => "enum" "{" enumerator-list "," "}"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(enum-def ,(tl->list $3)))
;; enum-specifier => "enum" identifier
(lambda ($2 $1 . $rest) `(enum-ref ,$2))
;; enumerator-list => enumerator
(lambda ($1 . $rest) (make-tl 'enum-def-list $1))
;; enumerator-list => enumerator-list "," enumerator
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; enumerator => identifier
(lambda ($1 . $rest) `(enum-defn ,$1))
;; enumerator => identifier "=" constant-expression
(lambda ($3 $2 $1 . $rest) `(enum-defn ,$1 ,$3))
;; type-qualifier => "const"
(lambda ($1 . $rest) `(type-qual ,$1))
;; type-qualifier => "volatile"
(lambda ($1 . $rest) `(type-qual ,$1))
;; type-qualifier => "restrict"
(lambda ($1 . $rest) `(type-qual ,$1))
;; function-specifier => "inline"
(lambda ($1 . $rest) `(fctn-spec ,$1))
;; declarator => pointer direct-declarator
(lambda ($2 $1 . $rest) `(ptr-declr ,$1 ,$2))
;; declarator => direct-declarator
(lambda ($1 . $rest) $1)
;; direct-declarator => identifier
(lambda ($1 . $rest) $1)
;; direct-declarator => "(" declarator ")"
(lambda ($3 $2 $1 . $rest) `(scope ,$2))
;; direct-declarator => direct-declarator "[" type-qualifier-list assign...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3 ,$4))
;; direct-declarator => direct-declarator "[" type-qualifier-list "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3))
;; direct-declarator => direct-declarator "[" assignment-expression "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3))
;; direct-declarator => direct-declarator "[" "]"
(lambda ($3 $2 $1 . $rest) `(array-of ,$1))
;; direct-declarator => direct-declarator "[" "static" type-qualifier-li...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(array-of
,$1
,(tl->list (tl-insert '(stor-spec "static") $4))
,$5))
;; direct-declarator => direct-declarator "[" type-qualifier-list "stati...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(array-of
,$1
,(tl->list (tl-insert '(stor-spec "static") $3))
,$5))
;; direct-declarator => direct-declarator "[" type-qualifier-list "*" "]"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(array-of ,$1 ,$3 (var-len)))
;; direct-declarator => direct-declarator "[" "*" "]"
(lambda ($4 $3 $2 $1 . $rest)
`(array-of ,$1 (var-len)))
;; direct-declarator => direct-declarator "(" parameter-type-list ")"
(lambda ($4 $3 $2 $1 . $rest)
`(ftn-declr ,$1 ,(tl->list $3)))
;; direct-declarator => direct-declarator "(" identifier-list ")"
(lambda ($4 $3 $2 $1 . $rest)
`(ftn-declr ,$1 ,(tl->list $3)))
;; direct-declarator => direct-declarator "(" ")"
(lambda ($3 $2 $1 . $rest)
`(ftn-declr ,$1 (param-list)))
;; pointer => "*" type-qualifier-list
(lambda ($2 $1 . $rest)
`(pointer ,(tl->list $2)))
;; pointer => "*"
(lambda ($1 . $rest) '(pointer))
;; pointer => "*" type-qualifier-list pointer
(lambda ($3 $2 $1 . $rest)
`(pointer ,(tl->list $2) ,$3))
;; pointer => "*" pointer
(lambda ($2 $1 . $rest) `(pointer ,$2))
;; type-qualifier-list => type-qualifier
(lambda ($1 . $rest)
(make-tl 'decl-spec-list $1))
;; type-qualifier-list => type-qualifier-list type-qualifier
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; parameter-type-list => parameter-list
(lambda ($1 . $rest) $1)
;; parameter-type-list => parameter-list "," "..."
(lambda ($3 $2 $1 . $rest)
(tl-append $1 '(ellipis)))
;; parameter-list => parameter-declaration
(lambda ($1 . $rest) (make-tl 'param-list $1))
;; parameter-list => parameter-list "," parameter-declaration
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; parameter-declaration => declaration-specifiers declarator
(lambda ($2 $1 . $rest)
`(param-decl ,(tl->list $1) (param-declr ,$2)))
;; parameter-declaration => declaration-specifiers abstract-declarator
(lambda ($2 $1 . $rest)
`(param-decl ,(tl->list $1) (param-declr ,$2)))
;; parameter-declaration => declaration-specifiers
(lambda ($1 . $rest)
`(param-decl ,(tl->list $1)))
;; identifier-list => identifier
(lambda ($1 . $rest) (make-tl 'ident-list $1))
;; identifier-list => identifier-list "," identifier
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; type-name => specifier-qualifier-list abstract-declarator
(lambda ($2 $1 . $rest)
`(type-name ,(tl->list $1) ,$2))
;; type-name => declaration-specifiers
(lambda ($1 . $rest) `(type-name ,(tl->list $1)))
;; abstract-declarator => pointer
(lambda ($1 . $rest) `(abs-declr ,$1))
;; abstract-declarator => pointer direct-abstract-declarator
(lambda ($2 $1 . $rest) `(abs-declr ,$1 ,$2))
;; abstract-declarator => direct-abstract-declarator
(lambda ($1 . $rest) `(abs-declr ,$1))
;; direct-abstract-declarator => "(" abstract-declarator ")"
(lambda ($3 $2 $1 . $rest) `(declr-scope ,$2))
;; direct-abstract-declarator => direct-abstract-declarator "[" type-qua...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-array ,$3 ,$4))
;; direct-abstract-declarator => direct-abstract-declarator "[" type-qua...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-array ,$1 ,$3))
;; direct-abstract-declarator => direct-abstract-declarator "[" assignme...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-array ,$1 ,$3))
;; direct-abstract-declarator => direct-abstract-declarator "[" "]"
(lambda ($3 $2 $1 . $rest) `(declr-array ,$1))
;; direct-abstract-declarator => direct-abstract-declarator "[" "static"...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(declr-array
,$1
,(tl->list (tl-insert '(stor-spec "static") $4))
,$5))
;; direct-abstract-declarator => direct-abstract-declarator "[" "static"...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-array
,$1
,(tl->list (tl-insert '(stor-spec "static") $4))))
;; direct-abstract-declarator => direct-abstract-declarator "[" type-qua...
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(declr-array
,$1
,(tl->list (tl-insert '(stor-spec "static") $3))
,$5))
;; direct-abstract-declarator => "[" type-qualifier-list assignment-expr...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-anon-array ,$2 ,$3))
;; direct-abstract-declarator => "[" type-qualifier-list "]"
(lambda ($3 $2 $1 . $rest)
`(declr-anon-array ,$2))
;; direct-abstract-declarator => "[" assignment-expression "]"
(lambda ($3 $2 $1 . $rest)
`(declr-anon-array ,$2))
;; direct-abstract-declarator => "[" "]"
(lambda ($2 $1 . $rest) `(declr-anon-array))
;; direct-abstract-declarator => "[" "static" type-qualifier-list assign...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $3))
,$4))
;; direct-abstract-declarator => "[" "static" type-qualifier-list "]"
(lambda ($4 $3 $2 $1 . $rest)
`(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $3))))
;; direct-abstract-declarator => "[" type-qualifier-list "static" assign...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $2))
,$4))
;; direct-abstract-declarator => direct-abstract-declarator "[" "*" "]"
(lambda ($4 $3 $2 $1 . $rest) `(declr-STAR ,$1))
;; direct-abstract-declarator => "[" "*" "]"
(lambda ($3 $2 $1 . $rest) '(declr-STAR))
;; direct-abstract-declarator => direct-abstract-declarator "(" paramete...
(lambda ($4 $3 $2 $1 . $rest)
`(declr-fctn ,$1 ,(tl->list $3)))
;; direct-abstract-declarator => direct-abstract-declarator "(" ")"
(lambda ($3 $2 $1 . $rest) `(declr-fctn ,$1))
;; direct-abstract-declarator => "(" parameter-type-list ")"
(lambda ($3 $2 $1 . $rest)
`(declr-anon-fctn ,(tl->list $2)))
;; direct-abstract-declarator => "(" ")"
(lambda ($2 $1 . $rest) '(declr-anon-fctn))
;; typedef-name => 'typename
(lambda ($1 . $rest) `(typename ,$1))
;; initializer => assignment-expression
(lambda ($1 . $rest) `(initzer ,$1))
;; initializer => "{" initializer-list "}"
(lambda ($3 $2 $1 . $rest)
`(initzer ,(tl->list $2)))
;; initializer => "{" initializer-list "," "}"
(lambda ($4 $3 $2 $1 . $rest)
`(initzer ,(tl->list $2)))
;; initializer-list => designation initializer
(lambda ($2 $1 . $rest)
(make-tl 'initzer-list $1 $2))
;; initializer-list => initializer
(lambda ($1 . $rest) (make-tl 'initzer-list $1))
;; initializer-list => initializer-list "," designation initializer
(lambda ($4 $3 $2 $1 . $rest)
(tl-append $1 $3 $4))
;; initializer-list => initializer-list "," initializer
(lambda ($3 $2 $1 . $rest) (tl-append $1 $3))
;; designation => designator-list "="
(lambda ($2 $1 . $rest) `(desig ,$1))
;; designator-list => designator
(lambda ($1 . $rest) (make-tl 'desgr-list $1))
;; designator-list => designator-list designator
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; designator => "[" constant-expression "]"
(lambda ($3 $2 $1 . $rest) (list 'array-dsgr $2))
;; designator => "." identifier
(lambda ($2 $1 . $rest) (list 'sel-dsgr $2))
;; statement => labeled-statement
(lambda ($1 . $rest) $1)
;; statement => compound-statement
(lambda ($1 . $rest) $1)
;; statement => expression-statement
(lambda ($1 . $rest) $1)
;; statement => selection-statement
(lambda ($1 . $rest) $1)
;; statement => iteration-statement
(lambda ($1 . $rest) $1)
;; statement => jump-statement
(lambda ($1 . $rest) $1)
;; statement => cpp-statement
(lambda ($1 . $rest) $1)
;; labeled-statement => identifier ":" statement
(lambda ($3 $2 $1 . $rest)
`(labeled-stmt ,$1 ,$3))
;; labeled-statement => "case" constant-expression ":" statement
(lambda ($4 $3 $2 $1 . $rest) `(case ,$2 ,$4))
;; labeled-statement => "default" ":" statement
(lambda ($3 $2 $1 . $rest) `(default ,$3))
;; compound-statement => "{" block-item-list "}"
(lambda ($3 $2 $1 . $rest)
`(compd-stmt ,(tl->list $2)))
;; compound-statement => "{" "}"
(lambda ($2 $1 . $rest)
`(compd-stmt (block-item-list)))
;; block-item-list => block-item
(lambda ($1 . $rest)
(make-tl 'block-item-list $1))
;; block-item-list => block-item-list block-item
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; block-item => declaration
(lambda ($1 . $rest) $1)
;; block-item => statement
(lambda ($1 . $rest) $1)
;; expression-statement => expression ";"
(lambda ($2 $1 . $rest) `(expr-stmt ,$1))
;; expression-statement => ";"
(lambda ($1 . $rest) '(expr-stmt))
;; selection-statement => "if" "(" expression ")" statement
(lambda ($5 $4 $3 $2 $1 . $rest) `(if ,$3 ,$5))
;; selection-statement => "if" "(" expression ")" statement "else" state...
(lambda ($7 $6 $5 $4 $3 $2 $1 . $rest)
`(if ,$3 ,$5 ,$7))
;; selection-statement => "switch" "(" expression ")" statement
(lambda ($5 $4 $3 $2 $1 . $rest)
`(switch ,$3 ,$5))
;; iteration-statement => "while" "(" expression ")" statement
(lambda ($5 $4 $3 $2 $1 . $rest)
`(while ,$3 ,$5))
;; iteration-statement => "do" statement "while" "(" expression ")" ";"
(lambda ($7 $6 $5 $4 $3 $2 $1 . $rest)
`(do-while ,$2 ,$5))
;; iteration-statement => "for" "(" initial-clause opt-expression ";" op...
(lambda ($8 $7 $6 $5 $4 $3 $2 $1 . $rest)
`(for ,$3 ,$4 ,$6 ,$8))
;; initial-clause => expression ";"
(lambda ($2 $1 . $rest) $1)
;; initial-clause => ";"
(lambda ($1 . $rest) '(expr))
;; initial-clause => declaration
(lambda ($1 . $rest) $1)
;; opt-expression =>
(lambda $rest '(expr))
;; opt-expression => expression
(lambda ($1 . $rest) $1)
;; jump-statement => "goto" identifier ";"
(lambda ($3 $2 $1 . $rest) `(goto $2))
;; jump-statement => "continue" ";"
(lambda ($2 $1 . $rest) '(continue))
;; jump-statement => "break" ";"
(lambda ($2 $1 . $rest) '(break))
;; jump-statement => "return" expression ";"
(lambda ($3 $2 $1 . $rest) `(return ,$2))
;; jump-statement => "return" ";"
(lambda ($2 $1 . $rest) `(return (expr)))
;; translation-unit => external-declaration
(lambda ($1 . $rest) (make-tl 'trans-unit $1))
;; translation-unit => translation-unit external-declaration
(lambda ($2 $1 . $rest)
(cond ((eqv? 'trans-unit (car $2))
(let* ((t1 (tl-append $1 '(extern-C-begin)))
(t2 (tl-extend t1 (cdr $2)))
(t3 (tl-append t2 '(extern-C-end))))
t3))
(else (tl-append $1 $2))))
;; external-declaration => function-definition
(lambda ($1 . $rest) $1)
;; external-declaration => declaration
(lambda ($1 . $rest) $1)
;; external-declaration => lone-comment
(lambda ($1 . $rest) $1)
;; external-declaration => cpp-statement
(lambda ($1 . $rest) $1)
;; external-declaration => "extern" '$string "{" translation-unit "}"
(lambda ($5 $4 $3 $2 $1 . $rest) (tl->list $4))
;; function-definition => declaration-specifiers declarator declaration-...
(lambda ($4 $3 $2 $1 . $rest)
`(knr-fctn-defn
,(tl->list $1)
,$2
,(tl->list $3)
,$4))
;; function-definition => declaration-specifiers declarator compound-sta...
(lambda ($3 $2 $1 . $rest)
`(fctn-defn ,(tl->list $1) ,$2 ,$3))
;; declaration-list => declaration
(lambda ($1 . $rest) (make-tl $1))
;; declaration-list => declaration-list declaration
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; opt-code-comment =>
(lambda $rest (list))
;; opt-code-comment => code-comment
(lambda ($1 . $rest) $1)
;; identifier => '$ident
(lambda ($1 . $rest) `(ident ,$1))
;; identifier => 'cpp-ident
(lambda ($1 . $rest) `(ident ,$1))
;; constant => '$fixed
(lambda ($1 . $rest) `(fixed ,$1))
;; constant => '$float
(lambda ($1 . $rest) `(float ,$1))
;; constant => '$chlit
(lambda ($1 . $rest) `(char ,$1))
;; string-literal => '$string
(lambda ($1 . $rest) (make-tl 'string $1))
;; string-literal => string-literal '$string
(lambda ($2 $1 . $rest) (tl-append $1 $2))
;; code-comment => '$code-comm
(lambda ($1 . $rest) `(comment ,$1))
;; lone-comment => '$lone-comm
(lambda ($1 . $rest) `(comment ,$1))
;; cpp-statement => 'cpp-stmt
(lambda ($1 . $rest) `(cpp-stmt ,$1))
))
;;; end tables

View file

@ -0,0 +1,559 @@
;; ./mach.d/c99xtab.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;;
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;; or any later version published by the Free Software Foundation. See the
;; file COPYING included with the this distribution.
(define len-v
#(1 1 1 1 1 3 1 4 4 3 3 3 2 2 6 7 1 3 1 3 2 1 1 2 2 2 2 4 1 1 1 1 1 1 1 4
1 3 3 3 1 3 3 1 3 3 1 3 3 3 3 1 3 3 1 3 1 3 1 3 1 3 1 3 1 5 1 3 1 1 1 1 1
1 1 1 1 1 1 1 3 1 5 3 0 1 2 1 2 1 2 1 2 1 3 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2 2 3 1 1 2 1 2 2 3 2 3 3 4 3 2 2 1 3 2 4 3 1 2 2 1 1 2 1 2 2 3 5 4 2 5
4 2 1 1 1 1 2 2 4 2 1 2 1 1 3 1 3 2 5 6 4 5 2 1 3 1 3 1 1 1 1 2 1 1 3 5 4
4 3 6 6 5 4 4 4 3 2 1 3 2 1 2 1 3 1 3 2 2 1 1 3 2 1 1 2 1 3 5 4 4 3 6 5 6
4 3 3 2 5 4 5 4 3 4 3 3 2 1 1 3 4 2 1 4 3 2 1 2 3 2 1 1 1 1 1 1 1 3 4 3 3
2 1 2 1 1 2 1 5 7 5 5 7 8 2 1 1 0 1 3 2 2 3 2 1 2 1 1 1 1 5 4 3 1 2 0 1 1
1 1 1 1 1 2 1 1 1))
(define pat-v
#(((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (
7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (
176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (
78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (
164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (169 . 36)
(175 . 37)) ((-1 . -36)) ((79 . 119) (74 . 120) (73 . 121) (-1 . -40)) ((
78 . 117) (77 . 118) (-1 . -43)) ((72 . 115) (71 . 116) (-1 . -46)) ((70
. 111) (69 . 112) (68 . 113) (67 . 114) (-1 . -51)) ((66 . 109) (65 . 110)
(-1 . -54)) ((80 . 108) (-1 . -56)) ((-1 . -299)) ((-1 . -298)) ((-1 .
-297)) ((-1 . -296)) ((-1 . -295)) ((-1 . -294)) ((64 . 107) (-1 . -58)) (
(63 . 106) (-1 . -60)) ((7 . 105) (-1 . -4)) ((-1 . -3)) ((-1 . -2)) ((62
. 104) (-1 . -62)) ((-1 . -33)) ((-1 . -32)) ((-1 . -31)) ((-1 . -30)) ((
-1 . -29)) ((-1 . -28)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5)
(158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (
156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20)
(76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (
153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (
152 . 35) (169 . 36) (175 . 66) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (
30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36
. 78) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 .
85) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 .
92) (43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 . 98) (146 .
99) (147 . 100) (167 . 101) (130 . 102) (171 . 103)) ((-1 . -6)) ((60 . 64
) (61 . 65) (-1 . -64)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 .
13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 .
23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32
) (173 . 33) (165 . 62) (92 . 63)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5
. 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 .
22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31
) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 61)) ((7 . 8) (2 . 9) (
3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 .
20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 57) (174 . 27)
(81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 59)) ((7 . 8)
(2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 .
18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 57)
(174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 58))
((90 . 51) (92 . 52) (88 . 53) (87 . 54) (86 . 55) (85 . 56) (-1 . -22))
((48 . 39) (49 . 40) (50 . 41) (51 . 42) (52 . 43) (53 . 44) (54 . 45) (55
. 46) (56 . 47) (57 . 48) (58 . 49) (151 . 50) (-1 . -34)) ((-1 . -66)) (
(-1 . -79)) ((82 . 38) (96 . 0)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4)
(159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (
6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19)
(75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174
. 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165
. 34) (152 . 35) (169 . 190)) ((-1 . -78)) ((-1 . -77)) ((-1 . -76)) ((-1
. -75)) ((-1 . -74)) ((-1 . -73)) ((-1 . -72)) ((-1 . -71)) ((-1 . -70))
((-1 . -69)) ((-1 . -68)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 .
5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13)
(156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 .
20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27)
(153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34)
(152 . 35) (169 . 189)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5
) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13)
(156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20
) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (
153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (
152 . 35) (169 . 36) (175 . 188)) ((91 . 183) (163 . 1) (162 . 2) (161 . 3
) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11
) (5 . 12) (6 . 13) (156 . 14) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (30
. 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 .
78) (39 . 79) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (23 . 80) (24 .
81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 .
88) (139 . 89) (140 . 90) (41 . 91) (42 . 92) (43 . 93) (44 . 94) (45 . 95
) (46 . 96) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (
80 . 25) (92 . 26) (174 . 27) (144 . 97) (145 . 146) (146 . 147) (147 .
100) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165
. 34) (152 . 35) (167 . 184) (168 . 185) (169 . 186) (172 . 187)) ((5 . 12
) (6 . 13) (178 . 182)) ((5 . 12) (6 . 13) (178 . 181)) ((-1 . -12)) ((-1
. -13)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32
. 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (23 . 80
) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87
) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92) (43 . 93) (44 . 94)
(45 . 95) (46 . 96) (144 . 97) (145 . 98) (146 . 99) (147 . 100) (167 .
101) (130 . 102) (171 . 180) (163 . 1) (162 . 2) (161 . 3) (160 . 4) (159
. 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 .
13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75
. 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 .
27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 .
34) (152 . 35) (169 . 36) (175 . 66)) ((-1 . -23)) ((-1 . -24)) ((-1 . -34
)) ((-1 . -25)) ((-1 . -26)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30
. 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78
) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85)
(137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92)
(43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 . 98) (146 . 99) (
147 . 100) (167 . 101) (130 . 102) (171 . 179) (163 . 1) (162 . 2) (161 .
3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 .
11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 .
18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25)
(92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32)
(173 . 33) (165 . 34) (152 . 35) (169 . 36) (175 . 66)) ((163 . 1) (162 .
2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 .
10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17)
(178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (
80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (
86 . 32) (173 . 33) (165 . 34) (152 . 35) (169 . 36) (175 . 178)) ((7 . 8)
(2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 .
18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27)
(81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60)
(163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (156
. 14) (155 . 15) (154 . 177)) ((91 . 176) (82 . 38)) ((-1 . -234)) ((84
. 174) (5 . 12) (6 . 13) (178 . 175)) ((84 . 172) (5 . 12) (6 . 13) (21 .
67) (135 . 169) (178 . 170) (134 . 173)) ((84 . 168) (5 . 12) (6 . 13) (21
. 67) (135 . 169) (178 . 170) (134 . 171)) ((-1 . -139)) ((30 . 167) (-1
. -137)) ((30 . 166) (-1 . -136)) ((-1 . -133)) ((39 . 162) (37 . 163) (35
. 164) (33 . 165) (-1 . -128)) ((37 . 159) (35 . 160) (31 . 161) (-1 .
-117)) ((-1 . -114)) ((39 . 155) (37 . 156) (35 . 157) (33 . 158) (-1 .
-115)) ((37 . 154) (-1 . -110)) ((-1 . -177)) ((-1 . -176)) ((-1 . -175))
((-1 . -174)) ((-1 . -109)) ((-1 . -108)) ((-1 . -107)) ((-1 . -106)) ((-1
. -105)) ((-1 . -104)) ((-1 . -103)) ((-1 . -102)) ((-1 . -101)) ((-1 .
-100)) ((-1 . -99)) ((-1 . -98)) ((-1 . -97)) ((21 . 67) (27 . 68) (28 .
69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76)
(37 . 77) (36 . 78) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135
. 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (
41 . 91) (42 . 92) (43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145
. 146) (146 . 147) (147 . 100) (167 . 153) (-1 . -91)) ((23 . 80) (42 .
92) (43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (147 . 100) (167 .
151) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73)
(33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (24 . 81) (25
. 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (
139 . 89) (140 . 90) (41 . 91) (145 . 98) (146 . 99) (130 . 152) (91 . -89
) (79 . -159) (90 . -159) (92 . -159)) ((23 . 80) (42 . 92) (43 . 93) (44
. 94) (45 . 95) (46 . 96) (144 . 97) (147 . 100) (167 . 149) (21 . 67) (27
. 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 .
75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83)
(135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90
) (41 . 91) (145 . 98) (146 . 99) (130 . 150) (91 . -87) (79 . -157) (90
. -157) (92 . -157)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (
31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39
. 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137
. 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92) (43
. 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 . 146) (146 . 147) (
147 . 100) (167 . 148) (-1 . -85)) ((91 . -209)) ((90 . 140) (92 . 141) (
79 . 142) (117 . 143) (124 . 144) (166 . 145)) ((91 . 139)) ((7 . 8) (2 .
9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (
75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81
. 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163
. 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (156 . 14
) (155 . 138)) ((-1 . -300)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (
6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78
. 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86
. 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (161 . 3) (160
. 4) (159 . 5) (158 . 6) (157 . 7) (156 . 137)) ((7 . 8) (2 . 9) (3 . 10)
(4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76
. 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 .
30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2
) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 136)) ((7 . 8) (2 . 9) (3
. 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 .
20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29)
(164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1)
(162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 135)) ((7 . 8) (2 . 9) (3
. 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20
) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (
164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (
162 . 2) (161 . 3) (160 . 4) (159 . 134)) ((7 . 8) (2 . 9) (3 . 10) (4 .
11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21)
(77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (
85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (
161 . 3) (160 . 4) (159 . 133)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12
) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22)
(78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (
86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (161 . 3) (
160 . 132)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16
) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24)
(80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (
92 . 26) (165 . 60) (163 . 1) (162 . 2) (161 . 3) (160 . 131)) ((7 . 8) (2
. 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18)
(75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (
81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (
163 . 1) (162 . 2) (161 . 3) (160 . 130)) ((7 . 8) (2 . 9) (3 . 10) (4 .
11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21)
(77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (
85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (
161 . 3) (160 . 129)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13)
(176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23)
(79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (
173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (161 . 128)) ((7 . 8) (
2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18
) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (
81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (
163 . 1) (162 . 2) (161 . 127)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12
) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22)
(78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (
86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 126)) ((7 . 8) (
2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18
) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (
81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (
163 . 1) (162 . 125)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13)
(176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23)
(79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (
173 . 33) (92 . 26) (165 . 60) (163 . 124)) ((7 . 8) (2 . 9) (3 . 10) (4
. 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 .
21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30
) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 123)) ((7 . 8
) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178
. 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 .
27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 .
60) (163 . 122)) ((-1 . -39)) ((-1 . -38)) ((-1 . -37)) ((79 . 119) (74 .
120) (73 . 121) (-1 . -42)) ((79 . 119) (74 . 120) (73 . 121) (-1 . -41))
((78 . 117) (77 . 118) (-1 . -45)) ((78 . 117) (77 . 118) (-1 . -44)) ((72
. 115) (71 . 116) (-1 . -50)) ((72 . 115) (71 . 116) (-1 . -49)) ((72 .
115) (71 . 116) (-1 . -48)) ((72 . 115) (71 . 116) (-1 . -47)) ((70 . 111)
(69 . 112) (68 . 113) (67 . 114) (-1 . -53)) ((70 . 111) (69 . 112) (68
. 113) (67 . 114) (-1 . -52)) ((66 . 109) (65 . 110) (-1 . -55)) ((80 .
108) (-1 . -57)) ((64 . 107) (-1 . -59)) ((63 . 106) (-1 . -61)) ((84 .
237) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177
. 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 .
25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 .
26) (165 . 60) (163 . 238)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159
. 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 .
13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75
. 20) (76 . 21) (77 . 22) (78 . 23) (80 . 25) (92 . 26) (174 . 27) (153 .
28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 .
35) (169 . 232) (89 . 233) (43 . 234) (24 . 81) (25 . 82) (26 . 83) (145
. 223) (122 . 235) (79 . 236)) ((90 . 140) (92 . 141) (79 . 142) (117 .
143) (124 . 144) (166 . 226) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (30
. 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78
) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85)
(137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92)
(43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 . 146) (146 . 147)
(147 . 100) (167 . 227) (118 . 228) (119 . 229) (121 . 230) (91 . 231)) (
(24 . 81) (25 . 82) (26 . 83) (145 . 223) (122 . 224) (79 . 142) (124 .
225) (-1 . -194)) ((90 . 221) (92 . 222) (91 . -212) (82 . -212)) ((90 .
140) (92 . 141) (117 . 220) (91 . -210) (82 . -210)) ((91 . -208)) ((21 .
67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (33 . 74)
(34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (23 . 80) (24 . 81) (25
. 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (139
. 89) (140 . 90) (41 . 91) (42 . 92) (43 . 93) (44 . 94) (45 . 95) (46 .
96) (144 . 97) (145 . 146) (146 . 147) (147 . 100) (167 . 151) (-1 . -89))
((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (
33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (23 . 80) (24
. 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40
. 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92) (43 . 93) (44 . 94) (45 .
95) (46 . 96) (144 . 97) (145 . 146) (146 . 147) (147 . 100) (167 . 149) (
-1 . -87)) ((-1 . -86)) ((-1 . -88)) ((-1 . -156)) ((-1 . -90)) ((-1 .
-158)) ((-1 . -92)) ((-1 . -111)) ((37 . 219) (-1 . -112)) ((-1 . -116)) (
(35 . 217) (37 . 218) (-1 . -119)) ((-1 . -134)) ((-1 . -118)) ((37 . 216)
(-1 . -121)) ((30 . 215) (-1 . -138)) ((37 . 214) (-1 . -126)) ((-1 .
-127)) ((35 . 212) (37 . 213) (-1 . -130)) ((-1 . -135)) ((-1 . -140)) ((
-1 . -141)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (
32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (24
. 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40
. 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (146 . 204) (94 . 205) (
130 . 206) (131 . 207) (132 . 208) (133 . 211)) ((-1 . -150)) ((-1 . -149)
) ((84 . 210) (-1 . -145)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 .
71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78)
(39 . 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (
138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (146 . 204
) (94 . 205) (130 . 206) (131 . 207) (132 . 208) (133 . 209)) ((84 . 202)
(-1 . -148)) ((5 . 12) (6 . 13) (178 . 199) (125 . 200) (126 . 201)) ((84
. 198) (-1 . -169)) ((-1 . -5)) ((62 . 104) (-1 . -63)) ((59 . 197) (82 .
38)) ((91 . 196)) ((91 . 195)) ((-1 . -11)) ((-1 . -10)) ((-1 . -9)) ((90
. 140) (92 . 141) (79 . 142) (117 . 143) (124 . 144) (166 . 194) (91 . -21
) (82 . -21)) ((91 . -18) (82 . -18)) ((91 . -16) (82 . -16)) ((91 . 192)
(82 . 193)) ((89 . 191) (82 . 38)) ((-1 . -67)) ((-1 . -80)) ((-1 . -7)) (
(-1 . -8)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (
32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (23
. 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138
. 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92) (43 . 93) (44 .
94) (45 . 95) (46 . 96) (144 . 97) (145 . 146) (146 . 147) (147 . 100) (
167 . 184) (168 . 291) (163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (
158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (
156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20)
(76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (
153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (
152 . 35) (169 . 292)) ((91 . -20) (82 . -20)) ((84 . 237)) ((84 . 237) (
-1 . -27)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16)
(177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (
80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (
92 . 26) (165 . 60) (163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158
. 6) (157 . 7) (156 . 14) (155 . 15) (154 . 19) (153 . 28) (152 . 290)) (
(5 . 12) (6 . 13) (178 . 199) (125 . 200) (126 . 289)) ((58 . 288) (83 .
-172) (82 . -172)) ((83 . -170) (82 . -170)) ((83 . 286) (82 . 287)) ((21
. 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (33 . 74
) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (24 . 81) (25 . 82) (
26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (139 . 89)
(140 . 90) (41 . 91) (145 . 203) (146 . 204) (94 . 205) (130 . 206) (131
. 207) (132 . 208) (133 . 285)) ((21 . 67) (27 . 68) (28 . 69) (29 . 70) (
30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36
. 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137
. 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (
146 . 204) (130 . 152) (-1 . -159)) ((21 . 67) (27 . 68) (28 . 69) (29 .
70) (30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77)
(36 . 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (
137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203)
(146 . 204) (130 . 150) (-1 . -157)) ((94 . -302) (-1 . -302)) ((5 . 12)
(6 . 13) (79 . 142) (92 . 279) (178 . 257) (123 . 258) (124 . 280) (59 .
281) (142 . 282) (128 . 283) (129 . 284)) ((94 . -152) (-1 . -152)) ((94
. -151) (-1 . -151)) ((83 . 278) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (
30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36
. 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137
. 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (
146 . 204) (130 . 206) (132 . 275) (94 . 205) (131 . 276)) ((21 . 67) (27
. 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75
) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83) (
135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90)
(41 . 91) (145 . 203) (146 . 204) (94 . 205) (130 . 206) (131 . 207) (132
. 208) (133 . 277)) ((83 . 274) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (
30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36
. 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137
. 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (
146 . 204) (130 . 206) (132 . 275) (94 . 205) (131 . 276)) ((37 . 273) (-1
. -132)) ((-1 . -129)) ((-1 . -125)) ((-1 . -142)) ((-1 . -122)) ((37 .
272) (-1 . -123)) ((-1 . -120)) ((-1 . -113)) ((90 . 221) (92 . 222) (91
. -211) (82 . -211)) ((43 . 267) (89 . 268) (163 . 1) (162 . 2) (161 . 3)
(160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11)
(5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (
154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 269) (80 . 25) (92
. 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173
. 33) (165 . 34) (152 . 35) (169 . 270) (24 . 81) (25 . 82) (26 . 83) (
145 . 223) (122 . 271)) ((91 . 265) (21 . 67) (27 . 68) (28 . 69) (29 . 70
) (30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (
36 . 78) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136
. 85) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42
. 92) (43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 . 146) (146
. 147) (147 . 100) (167 . 227) (118 . 228) (119 . 229) (121 . 266)) ((-1
. -197)) ((79 . 142) (124 . 264) (24 . 81) (25 . 82) (26 . 83) (145 . 250)
(-1 . -193)) ((-1 . -196)) ((91 . 263)) ((5 . 12) (6 . 13) (178 . 257) (
123 . 258) (142 . 259) (90 . 140) (92 . 260) (79 . 142) (117 . 143) (124
. 261) (166 . 262) (91 . -205) (82 . -205)) ((82 . -201) (91 . -201)) ((82
. 256) (91 . -199)) ((91 . 255)) ((-1 . -233)) ((89 . 254)) ((-1 . -224))
((24 . 81) (25 . 82) (26 . 83) (145 . 223) (122 . 253)) ((43 . 249) (24
. 81) (25 . 82) (26 . 83) (145 . 250) (89 . 251) (163 . 1) (162 . 2) (161
. 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4
. 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178
. 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 .
25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 .
32) (173 . 33) (165 . 34) (152 . 35) (169 . 252)) ((89 . 248) (-1 . -29))
((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7
. 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (
176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (
78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (88 . 239) (90 . 240) (
153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (114 . 241)
(165 . 34) (152 . 35) (115 . 242) (84 . 243) (169 . 244) (141 . 245) (116
. 246) (170 . 247)) ((-1 . -35)) ((5 . 12) (6 . 13) (178 . 329)) ((7 . 8)
(2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 .
18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27)
(81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60)
(163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (156
. 14) (155 . 15) (154 . 19) (153 . 28) (152 . 295) (127 . 328)) ((58 .
-243) (88 . -243) (90 . -243)) ((58 . 326) (88 . 239) (90 . 240) (114 .
327)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 .
7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 .
15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 .
22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (88 . 239) (90 .
240) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (114
. 241) (165 . 34) (152 . 35) (115 . 242) (84 . 243) (169 . 244) (141 . 245
) (116 . 246) (170 . 325)) ((83 . -235) (82 . -235)) ((83 . -239) (82 .
-239)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157
. 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155
. 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77
. 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 .
29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (84 .
243) (169 . 244) (141 . 324)) ((83 . 322) (82 . 323)) ((-1 . -229)) ((163
. 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (
2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16
) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23)
(79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30)
(85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (169 . 321)) ((-1 .
-198)) ((-1 . -222)) ((89 . 320)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4)
(159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12)
(6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19)
(75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (
174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (
165 . 34) (152 . 35) (169 . 318) (24 . 81) (25 . 82) (26 . 83) (145 . 250)
(89 . 319)) ((-1 . -223)) ((-1 . -232)) ((21 . 67) (27 . 68) (28 . 69) (
29 . 70) (30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37
. 77) (36 . 78) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 .
84) (136 . 85) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41
. 91) (42 . 92) (43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 .
146) (146 . 147) (147 . 100) (167 . 227) (118 . 316) (22 . 317)) ((-1 .
-180)) ((90 . 314) (92 . 315) (-1 . -179)) ((91 . -203) (82 . -203)) ((90
. 140) (117 . 143) (166 . 226) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (30
. 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 .
78) (39 . 79) (23 . 80) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85
) (137 . 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (42 . 92
) (43 . 93) (44 . 94) (45 . 95) (46 . 96) (144 . 97) (145 . 146) (146 .
147) (147 . 100) (167 . 227) (118 . 228) (119 . 229) (121 . 230) (91 . 231
) (5 . 12) (6 . 13) (79 . 142) (92 . 260) (178 . 257) (123 . 258) (124 .
261) (142 . 305)) ((90 . 140) (117 . 220) (5 . 12) (6 . 13) (92 . 260) (
178 . 257) (123 . 304) (91 . -210) (82 . -210)) ((91 . -204) (82 . -204))
((-1 . -213)) ((-1 . -195)) ((-1 . -231)) ((91 . 313)) ((24 . 81) (25 . 82
) (26 . 83) (145 . 223) (122 . 312)) ((-1 . -217)) ((89 . 311) (-1 . -29))
((89 . 310)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6)
(157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14)
(155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21)
(77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (
81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (
169 . 307) (24 . 81) (25 . 82) (26 . 83) (145 . 250) (89 . 308) (43 . 309)
) ((-1 . -124)) ((-1 . -131)) ((-1 . -144)) ((94 . -153) (-1 . -153)) ((94
. -154) (-1 . -154)) ((83 . 306) (21 . 67) (27 . 68) (28 . 69) (29 . 70)
(30 . 71) (31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36
. 78) (39 . 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137
. 86) (138 . 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (
146 . 204) (130 . 206) (132 . 275) (94 . 205) (131 . 276)) ((-1 . -147)) (
(5 . 12) (6 . 13) (79 . 142) (92 . 279) (178 . 257) (123 . 258) (124 . 280
) (142 . 305)) ((5 . 12) (6 . 13) (92 . 279) (178 . 257) (123 . 304)) ((7
. 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (
178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (174
. 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (92 . 26) (165
. 60) (163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7
) (156 . 14) (155 . 15) (154 . 19) (153 . 28) (152 . 295) (127 . 303)) ((
59 . 302) (47 . -162) (82 . -162)) ((47 . -160) (82 . -160)) ((47 . 300) (
82 . 301)) ((83 . 299) (21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (
31 . 72) (32 . 73) (33 . 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39
. 79) (24 . 81) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138
. 87) (40 . 88) (139 . 89) (140 . 90) (41 . 91) (145 . 203) (146 . 204) (
130 . 206) (132 . 275) (94 . 205) (131 . 276)) ((-1 . -167)) ((83 . 297) (
5 . 12) (6 . 13) (178 . 199) (125 . 298)) ((7 . 8) (2 . 9) (3 . 10) (4 .
11) (5 . 12) (6 . 13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21)
(77 . 22) (78 . 23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (
85 . 31) (86 . 32) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (
161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (156 . 14) (155 . 15) (
154 . 19) (153 . 28) (152 . 295) (127 . 296)) ((82 . 293) (83 . 294)) ((-1
. -65)) ((91 . -19) (82 . -19)) ((91 . -17) (82 . -17)) ((5 . 12) (6 . 13
) (178 . 199) (125 . 298) (83 . 357)) ((-1 . -165)) ((-1 . -81)) ((83 .
-173) (82 . -173)) ((-1 . -168)) ((83 . -171) (82 . -171)) ((-1 . -146)) (
(93 . 354) (97 . 355) (148 . 356) (94 . -292) (-1 . -292)) ((5 . 12) (6 .
13) (79 . 142) (92 . 279) (178 . 257) (123 . 258) (124 . 280) (59 . 281) (
142 . 282) (128 . 353)) ((7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 .
13) (176 . 16) (177 . 17) (178 . 18) (75 . 20) (76 . 21) (77 . 22) (78 .
23) (79 . 24) (80 . 25) (174 . 27) (81 . 29) (164 . 30) (85 . 31) (86 . 32
) (173 . 33) (92 . 26) (165 . 60) (163 . 1) (162 . 2) (161 . 3) (160 . 4)
(159 . 5) (158 . 6) (157 . 7) (156 . 14) (155 . 15) (154 . 19) (153 . 28)
(152 . 295) (127 . 352)) ((47 . -164) (82 . -164)) ((90 . 314) (92 . 315)
(-1 . -178)) ((91 . 351)) ((-1 . -143)) ((89 . 350)) ((-1 . -215)) ((163
. 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (
2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16
) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23)
(79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30)
(85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (169 . 349)) ((-1 .
-216)) ((-1 . -228)) ((89 . 347) (24 . 81) (25 . 82) (26 . 83) (145 . 250)
(163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7
. 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (
176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (
78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (
164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (169 . 348)
) ((-1 . -230)) ((43 . 342) (89 . 343) (163 . 1) (162 . 2) (161 . 3) (160
. 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 .
12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154
. 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 344) (80 . 25) (92 .
26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 .
33) (165 . 34) (152 . 35) (169 . 345) (24 . 81) (25 . 82) (26 . 83) (145
. 223) (122 . 346)) ((91 . 338) (5 . 12) (6 . 13) (178 . 339) (120 . 340)
(21 . 67) (27 . 68) (28 . 69) (29 . 70) (30 . 71) (31 . 72) (32 . 73) (33
. 74) (34 . 75) (35 . 76) (37 . 77) (36 . 78) (39 . 79) (23 . 80) (24 . 81
) (25 . 82) (26 . 83) (135 . 84) (136 . 85) (137 . 86) (138 . 87) (40 . 88
) (139 . 89) (140 . 90) (41 . 91) (42 . 92) (43 . 93) (44 . 94) (45 . 95)
(46 . 96) (144 . 97) (145 . 146) (146 . 147) (147 . 100) (167 . 227) (118
. 228) (119 . 229) (121 . 341)) ((82 . -202) (91 . -202)) ((91 . -200)) ((
89 . 337)) ((-1 . -226)) ((-1 . -221)) ((89 . 336)) ((-1 . -14)) ((83 .
333) (163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7)
(7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15)
(176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22)
(78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (
164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (84 . 243)
(169 . 244) (141 . 334) (88 . 239) (90 . 240) (114 . 241) (115 . 242) (116
. 335)) ((83 . -238) (82 . -238)) ((82 . 331) (83 . 332)) ((-1 . -242)) (
(58 . -244) (88 . -244) (90 . -244)) ((89 . 330)) ((58 . -246) (90 . -246)
(88 . -246)) ((58 . -245) (90 . -245) (88 . -245)) ((163 . 1) (162 . 2) (
161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10)
(4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (
178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80
. 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86
. 32) (173 . 33) (165 . 34) (152 . 35) (84 . 243) (169 . 244) (141 . 334)
(88 . 239) (90 . 240) (114 . 241) (115 . 242) (116 . 335) (83 . 371)) ((83
. -236) (82 . -236)) ((-1 . -15)) ((83 . -241) (82 . -241)) ((163 . 1) (
162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9)
(3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177
. 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79
. 24) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85
. 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (84 . 243) (169 . 244) (
141 . 370)) ((-1 . -227)) ((-1 . -225)) ((-1 . -192)) ((91 . -206) (82 .
-206)) ((91 . 368) (82 . 369)) ((91 . 367)) ((24 . 81) (25 . 82) (26 . 83)
(145 . 223) (122 . 366)) ((-1 . -185)) ((89 . 365) (-1 . -29)) ((89 . 364
)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (158 . 6) (157 . 7)
(7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (156 . 14) (155 . 15)
(176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20) (76 . 21) (77 . 22)
(78 . 23) (80 . 25) (92 . 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (
85 . 31) (86 . 32) (173 . 33) (165 . 34) (152 . 35) (169 . 360) (24 . 81)
(25 . 82) (26 . 83) (145 . 250) (89 . 361) (43 . 362) (79 . 363)) ((-1 .
-219)) ((89 . 359)) ((89 . 358)) ((-1 . -214)) ((-1 . -181)) ((47 . -163)
(82 . -163)) ((47 . -161) (82 . -161)) ((94 . -301) (-1 . -301)) ((94 .
-293) (-1 . -293)) ((94 . -155) (-1 . -155)) ((-1 . -166)) ((-1 . -220)) (
(-1 . -218)) ((89 . 376)) ((-1 . -183)) ((163 . 1) (162 . 2) (161 . 3) (
160 . 4) (159 . 5) (158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (
5 . 12) (6 . 13) (156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (
154 . 19) (75 . 20) (76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92
. 26) (174 . 27) (153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173
. 33) (165 . 34) (152 . 35) (169 . 375)) ((89 . 374) (-1 . -29)) ((-1 .
-184)) ((-1 . -189)) ((163 . 1) (162 . 2) (161 . 3) (160 . 4) (159 . 5) (
158 . 6) (157 . 7) (7 . 8) (2 . 9) (3 . 10) (4 . 11) (5 . 12) (6 . 13) (
156 . 14) (155 . 15) (176 . 16) (177 . 17) (178 . 18) (154 . 19) (75 . 20)
(76 . 21) (77 . 22) (78 . 23) (79 . 24) (80 . 25) (92 . 26) (174 . 27) (
153 . 28) (81 . 29) (164 . 30) (85 . 31) (86 . 32) (173 . 33) (165 . 34) (
152 . 35) (169 . 373) (24 . 81) (25 . 82) (26 . 83) (145 . 250)) ((-1 .
-190)) ((-1 . -191)) ((5 . 12) (6 . 13) (178 . 372)) ((83 . -240) (82 .
-240)) ((83 . -237) (82 . -237)) ((91 . -207) (82 . -207)) ((89 . 378)) ((
-1 . -188)) ((89 . 377)) ((-1 . -182)) ((-1 . -187)) ((-1 . -186))))
(define rto-v
#(#f 180 174 174 174 174 173 173 173 173 173 173 173 173 173 173 172 172
172 172 168 168 165 165 165 165 165 165 164 164 164 164 164 164 163 163
162 162 162 162 161 161 161 160 160 160 159 159 159 159 159 158 158 158
157 157 156 156 155 155 154 154 153 153 152 152 169 169 151 151 151 151
151 151 151 151 151 151 151 175 175 127 103 103 149 167 167 167 167 167
167 167 167 150 150 143 143 147 147 147 147 147 146 146 146 146 146 146
146 146 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140
140 140 140 140 140 140 140 140 140 140 139 139 139 138 138 138 138 137
137 137 137 137 137 134 134 133 133 133 133 132 130 130 130 130 129 129
128 128 128 136 136 136 136 136 126 126 125 125 145 145 145 144 142 142
123 123 123 123 123 123 123 123 123 123 123 123 123 124 124 124 124 122
122 121 121 119 119 118 118 118 120 120 171 171 166 166 166 117 117 117
117 117 117 117 117 117 117 117 117 117 117 117 117 117 117 117 117 117
135 141 141 141 170 170 170 170 116 115 115 114 114 106 106 106 106 106
106 106 113 113 113 112 112 105 105 104 104 111 111 110 110 110 109 109
109 102 102 102 101 101 108 108 108 108 108 179 179 100 100 100 100 100 99
99 98 98 148 148 178 178 177 177 177 176 176 97 131 107))
(define mtab
'((cpp-stmt . 1) ($chlit . 2) ($float . 3) ($fixed . 4) (cpp-ident . 5) (
$ident . 6) ($string . 7) ("return" . 8) ("break" . 9) ("continue" . 10) (
"goto" . 11) ("for" . 12) ("do" . 13) ("while" . 14) ("switch" . 15) (
"else" . 16) (then . 17) ("if" . 18) ("default" . 19) ("case" . 20) (
typename . 21) ("..." . 22) ("inline" . 23) ("restrict" . 24) ("volatile"
. 25) ("const" . 26) ("enum" . 27) ("union" . 28) ("struct" . 29) (
"_Complex" . 30) ("double" . 31) ("float" . 32) ("char" . 33) ("unsigned"
. 34) ("long" . 35) ("signed" . 36) ("int" . 37) (imp . 38) ("short" . 39)
("_Bool" . 40) ("void" . 41) ("typedef" . 42) ("static" . 43) ("register"
. 44) ("extern" . 45) ("auto" . 46) (";" . 47) ("|=" . 48) ("^=" . 49) (
"&=" . 50) (">>=" . 51) ("<<=" . 52) ("%=" . 53) ("/=" . 54) ("*=" . 55) (
"-=" . 56) ("+=" . 57) ("=" . 58) (":" . 59) ("?" . 60) ("||" . 61) ("&&"
. 62) ("|" . 63) ("^" . 64) ("!=" . 65) ("==" . 66) (">=" . 67) ("<=" . 68
) (">" . 69) ("<" . 70) (">>" . 71) ("<<" . 72) ("%" . 73) ("/" . 74) ("!"
. 75) ("~" . 76) ("-" . 77) ("+" . 78) ("*" . 79) ("&" . 80) ("sizeof" .
81) ("," . 82) ("}" . 83) ("{" . 84) ("--" . 85) ("++" . 86) ("->" . 87) (
"." . 88) ("]" . 89) ("[" . 90) (")" . 91) ("(" . 92) ($code-comm . 93) (
$lone-comm . 94) ($error . 95) ($end . 96)))
;;; end tables

View file

@ -0,0 +1,110 @@
;; ./mach.d/cppact.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;;
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;; or any later version published by the Free Software Foundation. See the
;; file COPYING included with the this distribution.
(define act-v
(vector
;; $start => conditional-expression
(lambda ($1 . $rest) $1)
;; conditional-expression => logical-or-expression
(lambda ($1 . $rest) $1)
;; conditional-expression => logical-or-expression "?" logical-or-expres...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(cond-expr ,$1 ,$3 ,$5))
;; logical-or-expression => logical-and-expression
(lambda ($1 . $rest) $1)
;; logical-or-expression => logical-or-expression "||" logical-and-expre...
(lambda ($3 $2 $1 . $rest) `(or ,$1 ,$3))
;; logical-and-expression => bitwise-or-expression
(lambda ($1 . $rest) $1)
;; logical-and-expression => logical-and-expression "&&" bitwise-or-expr...
(lambda ($3 $2 $1 . $rest) `(and ,$1 ,$3))
;; bitwise-or-expression => bitwise-xor-expression
(lambda ($1 . $rest) $1)
;; bitwise-or-expression => bitwise-or-expression "|" bitwise-xor-expres...
(lambda ($3 $2 $1 . $rest) `(bitwise-or ,$1 ,$3))
;; bitwise-xor-expression => bitwise-and-expression
(lambda ($1 . $rest) $1)
;; bitwise-xor-expression => bitwise-xor-expression "^" bitwise-and-expr...
(lambda ($3 $2 $1 . $rest)
`(bitwise-xor ,$1 ,$3))
;; bitwise-and-expression => equality-expression
(lambda ($1 . $rest) $1)
;; bitwise-and-expression => bitwise-and-expression "&" equality-expression
(lambda ($3 $2 $1 . $rest)
`(bitwise-and ,$1 ,$3))
;; equality-expression => relational-expression
(lambda ($1 . $rest) $1)
;; equality-expression => equality-expression "==" relational-expression
(lambda ($3 $2 $1 . $rest) `(equal ,$1 ,$3))
;; equality-expression => equality-expression "!=" relational-expression
(lambda ($3 $2 $1 . $rest) `(noteq ,$1 ,$3))
;; relational-expression => shift-expression
(lambda ($1 . $rest) $1)
;; relational-expression => relational-expression "<" shift-expression
(lambda ($3 $2 $1 . $rest) `(lt ,$1 ,$3))
;; relational-expression => relational-expression "<=" shift-expression
(lambda ($3 $2 $1 . $rest) `(le ,$1 ,$3))
;; relational-expression => relational-expression ">" shift-expression
(lambda ($3 $2 $1 . $rest) `(gt ,$1 ,$3))
;; relational-expression => relational-expression ">=" shift-expression
(lambda ($3 $2 $1 . $rest) `(ge ,$1 ,$3))
;; shift-expression => additive-expression
(lambda ($1 . $rest) $1)
;; shift-expression => shift-expression "<<" additive-expression
(lambda ($3 $2 $1 . $rest) `(lshift ,$1 ,$3))
;; shift-expression => shift-expression ">>" additive-expression
(lambda ($3 $2 $1 . $rest) `(rshift ,$1 ,$3))
;; additive-expression => multiplicative-expression
(lambda ($1 . $rest) $1)
;; additive-expression => additive-expression "+" multiplicative-expression
(lambda ($3 $2 $1 . $rest) `(add ,$1 ,$3))
;; additive-expression => additive-expression "-" multiplicative-expression
(lambda ($3 $2 $1 . $rest) `(sub ,$1 ,$3))
;; multiplicative-expression => unary-expression
(lambda ($1 . $rest) $1)
;; multiplicative-expression => multiplicative-expression "*" unary-expr...
(lambda ($3 $2 $1 . $rest) `(mul ,$1 ,$3))
;; multiplicative-expression => multiplicative-expression "/" unary-expr...
(lambda ($3 $2 $1 . $rest) `(div ,$1 ,$3))
;; multiplicative-expression => multiplicative-expression "%" unary-expr...
(lambda ($3 $2 $1 . $rest) `(mod ,$1 ,$3))
;; unary-expression => postfix-expression
(lambda ($1 . $rest) $1)
;; unary-expression => "-" unary-expression
(lambda ($2 $1 . $rest) `(neg ,$2))
;; unary-expression => "+" unary-expression
(lambda ($2 $1 . $rest) `(pos ,$2))
;; unary-expression => "!" unary-expression
(lambda ($2 $1 . $rest) `(not ,$2))
;; unary-expression => "~" unary-expression
(lambda ($2 $1 . $rest) `(bitwise-not ,$2))
;; unary-expression => "++" unary-expression
(lambda ($2 $1 . $rest) `(pre-inc ,$2))
;; unary-expression => "--" unary-expression
(lambda ($2 $1 . $rest) `(pre-dec ,$2))
;; postfix-expression => primary-expression
(lambda ($1 . $rest) $1)
;; postfix-expression => postfix-expression "++"
(lambda ($2 $1 . $rest) `(post-inc ,$1))
;; postfix-expression => postfix-expression "--"
(lambda ($2 $1 . $rest) `(post-dec ,$1))
;; primary-expression => '$fixed
(lambda ($1 . $rest) `(fixed ,$1))
;; primary-expression => '$chlit
(lambda ($1 . $rest) `(char ,$1))
;; primary-expression => "defined" "(" '$ident ")"
(lambda ($4 $3 $2 $1 . $rest) `(defined ,$3))
;; primary-expression => "(" expression-list ")"
(lambda ($3 $2 $1 . $rest) $2)
;; expression-list => conditional-expression
(lambda ($1 . $rest) $1)
;; expression-list => expression-list "," conditional-expression
(lambda ($3 $2 $1 . $rest) $3)
))
;;; end tables

View file

@ -0,0 +1,106 @@
;; ./mach.d/cpptab.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;;
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;; or any later version published by the Free Software Foundation. See the
;; file COPYING included with the this distribution.
(define len-v
#(1 1 5 1 3 1 3 1 3 1 3 1 3 1 3 3 1 3 3 3 3 1 3 3 1 3 3 1 3 3 3 1 2 2 2 2
2 2 1 2 2 1 1 4 3 1 3))
(define pat-v
#(((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11
. 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16)
(43 . 17) (44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23) (50
. 24)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8)
(11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42
. 16) (43 . 17) (44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23
) (50 . 53) (36 . 54)) ((4 . 52)) ((-1 . -42)) ((-1 . -41)) ((-1 . -38)) (
(4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9)
(16 . 10) (15 . 11) (38 . 12) (39 . 51)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4)
(37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12)
(39 . 50)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10
. 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 49)) ((4 . 1) (5 . 2) (6
. 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 .
11) (38 . 12) (39 . 48)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6)
(9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 47)) ((4 .
1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16
. 10) (15 . 11) (38 . 12) (39 . 46)) ((9 . 44) (8 . 45) (-1 . -31)) ((-1
. -27)) ((14 . 41) (13 . 42) (12 . 43) (-1 . -24)) ((16 . 39) (15 . 40) (
-1 . -21)) ((18 . 37) (17 . 38) (-1 . -16)) ((22 . 33) (21 . 34) (20 . 35)
(19 . 36) (-1 . -13)) ((24 . 31) (23 . 32) (-1 . -11)) ((25 . 30) (-1 .
-9)) ((26 . 29) (-1 . -7)) ((27 . 28) (-1 . -5)) ((28 . 27) (-1 . -3)) ((
31 . 25) (29 . 26) (2 . -1) (1 . -1) (35 . -1)) ((35 . 0)) ((4 . 1) (5 . 2
) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15
. 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 .
18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 76)) ((4 . 1) (5 . 2) (6
. 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 .
11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 . 18)
(45 . 19) (46 . 20) (47 . 21) (48 . 75)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4)
(37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (
39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 . 18) (45 . 19) (46
. 20) (47 . 74)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7)
(10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41
. 15) (42 . 16) (43 . 17) (44 . 18) (45 . 19) (46 . 73)) ((4 . 1) (5 . 2)
(6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15
. 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 . 18
) (45 . 72)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10
. 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15)
(42 . 16) (43 . 17) (44 . 71)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5)
(8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13)
(40 . 14) (41 . 15) (42 . 16) (43 . 70)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4)
(37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (
39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 69)) ((4 . 1) (5 . 2) (6 . 3)
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 68)) ((4 . 1) (5 . 2) (6 . 3)
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 67)) ((4 . 1) (5 . 2) (6 . 3)
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 66)) ((4 . 1) (5 . 2) (6 . 3)
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 65)) ((4 . 1) (5 . 2) (6 . 3)
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
38 . 12) (39 . 13) (40 . 14) (41 . 64)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (
37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (
39 . 13) (40 . 14) (41 . 63)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8
. 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (
40 . 62)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 .
8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 61)) ((4 . 1) (5
. 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10)
(15 . 11) (38 . 12) (39 . 60)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5)
(8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 59))
((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 .
9) (16 . 10) (15 . 11) (38 . 12) (39 . 58)) ((-1 . -39)) ((-1 . -40)) ((-1
. -32)) ((-1 . -33)) ((-1 . -34)) ((-1 . -35)) ((-1 . -36)) ((-1 . -37))
((3 . 57)) ((2 . -45) (1 . -45)) ((2 . 55) (1 . 56)) ((-1 . -44)) ((4 . 1)
(5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 .
10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17)
(44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23) (50 . 79)) ((2
. 78)) ((-1 . -30)) ((-1 . -29)) ((-1 . -28)) ((14 . 41) (13 . 42) (12 .
43) (-1 . -26)) ((14 . 41) (13 . 42) (12 . 43) (-1 . -25)) ((16 . 39) (15
. 40) (-1 . -23)) ((16 . 39) (15 . 40) (-1 . -22)) ((18 . 37) (17 . 38) (
-1 . -20)) ((18 . 37) (17 . 38) (-1 . -19)) ((18 . 37) (17 . 38) (-1 . -18
)) ((18 . 37) (17 . 38) (-1 . -17)) ((22 . 33) (21 . 34) (20 . 35) (19 .
36) (-1 . -15)) ((22 . 33) (21 . 34) (20 . 35) (19 . 36) (-1 . -14)) ((24
. 31) (23 . 32) (-1 . -12)) ((25 . 30) (-1 . -10)) ((26 . 29) (-1 . -8)) (
(27 . 28) (-1 . -6)) ((28 . 27) (-1 . -4)) ((30 . 77) (29 . 26)) ((4 . 1)
(5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 .
10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17)
(44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23) (50 . 80)) ((
-1 . -43)) ((2 . -46) (1 . -46)) ((2 . -2) (1 . -2) (35 . -2))))
(define rto-v
#(#f 50 50 49 49 48 48 47 47 46 46 45 45 44 44 44 43 43 43 43 43 42 42 42
41 41 41 40 40 40 40 39 39 39 39 39 39 39 38 38 38 37 37 37 37 36 36))
(define mtab
'(("," . 1) (")" . 2) ($ident . 3) ("(" . 4) ("defined" . 5) ($chlit . 6)
($fixed . 7) ("--" . 8) ("++" . 9) ("~" . 10) ("!" . 11) ("%" . 12) ("/"
. 13) ("*" . 14) ("-" . 15) ("+" . 16) (">>" . 17) ("<<" . 18) (">=" . 19)
(">" . 20) ("<=" . 21) ("<" . 22) ("!=" . 23) ("==" . 24) ("&" . 25) ("^"
. 26) ("|" . 27) ("&&" . 28) ("||" . 29) (":" . 30) ("?" . 31) (
$code-comm . 32) ($lone-comm . 33) ($error . 34) ($end . 35)))
;;; end tables

View file

@ -0,0 +1,763 @@
;;; lang/c99/mach.scm
;;;
;;; Copyright (C) 2015,2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C parser generator: based on ISO-C99; with comments and CPP statements
(define-module (nyacc lang c99 mach)
#:export (c99-spec c99-mach dev-parse-c dev-parse-c99
gen-c99-files gen-c99x-files)
#:use-module (nyacc lang c99 cpp)
#:use-module (nyacc lang util)
#:use-module (nyacc lalr)
#:use-module (nyacc parse)
#:use-module (nyacc lex)
#:use-module (nyacc util)
#:use-module ((srfi srfi-9) #:select (define-record-type))
#:use-module ((srfi srfi-43) #:select (vector-map))
#:use-module ((sxml xpath) #:select (sxpath))
)
;; @item c99-spec
;; This variable is the specification a-list for the hacked ISO C99 language.
;; Run this through @code{make-lalr-machine} to get an a-list for the
;; automaton. The grammar is modified to parse CPP statements and comments.
;; The output of the end parser will be a SXML tree (w/o the @code{*TOP*} node.
(define c99-spec
(lalr-spec
(notice lang-crn-lic)
(prec< 'then "else") ; "then/else" SR-conflict resolution
(prec< 'imp ; "implied type" SR-conflict resolution
"char" "short" "int" "long"
"float" "double" "_Complex")
(start translation-unit-proxy)
(grammar
(translation-unit-proxy (translation-unit ($$ (tl->list $1))))
;; expressions
(primary-expression ; S 6.5.1
(identifier ($$ `(p-expr ,$1)))
(constant ($$ `(p-expr ,$1)))
(string-literal ($$ `(p-expr ,(tl->list $1))))
("(" expression ")" ($$ $2))
)
(postfix-expression ; S 6.5.2
(primary-expression)
(postfix-expression "[" expression "]" ($$ `(array-ref ,$3 ,$1)))
(postfix-expression "(" argument-expression-list ")"
($$ `(fctn-call ,$1 ,(tl->list $3))))
(postfix-expression "(" ")" ($$ `(fctn-call ,$1 (expr-list))))
(postfix-expression "." identifier ($$ `(d-sel ,$3 ,$1)))
(postfix-expression "->" identifier ($$ `(i-sel ,$3 ,$1)))
(postfix-expression "++" ($$ `(post-inc ,$1)))
(postfix-expression "--" ($$ `(post-dec ,$1)))
("(" type-name ")" "{" initializer-list "}"
($$ `(comp-lit ,$2 ,(tl->list $5))))
("(" type-name ")" "{" initializer-list "," "}"
($$ `(comp-lit ,$2 ,(tl->list $5))))
)
(argument-expression-list
(assignment-expression ($$ (make-tl 'expr-list $1)))
(argument-expression-list "," assignment-expression ($$ (tl-append $1 $3)))
;; The following is a modification to deal with using abstract declarations
;; as arguments to CPP macros (e.g., see offsetof in <stddef.h>).
(arg-expr-hack ($$ (make-tl 'expr-list $1)))
(argument-expression-list "," arg-expr-hack ($$ (tl-append $1 $3)))
)
(arg-expr-hack
(declaration-specifiers
abstract-declarator ($$ `(param-decl ,(tl->list $1) $2)))
(declaration-specifiers ($$ `(param-decl ,(tl->list $1)))))
(unary-expression
(postfix-expression) ; S 6.5.3
("++" unary-expression ($$ `(pre-inc ,$2)))
("--" unary-expression ($$ `(pre-dec ,$2)))
(unary-operator cast-expression ($$ (list $1 $2)))
("sizeof" unary-expression ($$ `(sizeof-expr ,$2)))
("sizeof" "(" type-name ")" ($$ `(sizeof-type ,$3)))
)
(unary-operator ("&" ($$ 'ref-to)) ("*" ($$ 'de-ref))
("+" ($$ 'pos)) ("-" ($$ 'neg))
("~" ($$ 'bitwise-not)) ("!" ($$ 'not)))
(cast-expression ; S 6.5.4
(unary-expression)
("(" type-name ")" cast-expression ($$ `(cast ,$2 ,$4)))
)
(multiplicative-expression ; S 6.5.5
(cast-expression)
(multiplicative-expression "*" cast-expression ($$ `(mul ,$1 ,$3)))
(multiplicative-expression "/" cast-expression ($$ `(div ,$1 ,$3)))
(multiplicative-expression "%" cast-expression ($$ `(mod ,$1 ,$3)))
)
(additive-expression ; S 6.5.6
(multiplicative-expression)
(additive-expression "+" multiplicative-expression ($$ `(add ,$1 ,$3)))
(additive-expression "-" multiplicative-expression ($$ `(sub ,$1 ,$3)))
)
(shift-expression ; S 6.5.7
(additive-expression)
(shift-expression "<<" additive-expression ($$ `(lshift ,$1 ,$3)))
(shift-expression ">>" additive-expression ($$ `(rshift ,$1 ,$3)))
)
(relational-expression ; S 6.5.8
(shift-expression)
(relational-expression "<" shift-expression ($$ `(lt ,$1 ,$3)))
(relational-expression ">" shift-expression ($$ `(gt ,$1 ,$3)))
(relational-expression "<=" shift-expression ($$ `(le ,$1 ,$3)))
(relational-expression ">=" shift-expression ($$ `(ge ,$1 ,$3)))
)
(equality-expression ; S 6.5.9
(relational-expression)
(equality-expression "==" relational-expression ($$ `(eq ,$1 ,$3)))
(equality-expression "!=" relational-expression ($$ `(ne ,$1 ,$3)))
)
;; called AND-expression
(bitwise-and-expression ; S 6.5.10
(equality-expression)
(bitwise-and-expression "&" equality-expression
($$ `(bitwise-and ,$1 ,$3)))
)
;; called exclusive-OR-expression
(bitwise-xor-expression ; S 6.5.11
(bitwise-and-expression)
(bitwise-xor-expression "^" bitwise-and-expression
($$ `(bitwise-xor ,$1 ,$3)))
)
;; called inclusive-OR-expression
(bitwise-or-expression ; S 6.5.12
(bitwise-xor-expression)
(bitwise-or-expression "|" bitwise-xor-expression
($$ `(bitwise-or ,$1 ,$3)))
)
(logical-and-expression ; S 6.5.13
(bitwise-or-expression)
(logical-and-expression "&&" bitwise-or-expression
($$ `(and ,$1 ,$3)))
)
(logical-or-expression ; 6.5.14
(logical-and-expression)
(logical-or-expression "||" logical-and-expression
($$ `(or ,$1 ,$3)))
)
(conditional-expression
(logical-or-expression)
(logical-or-expression "?" expression ":" conditional-expression
($$ `(cond-expr ,$1 ,$2 ,$3)))
)
(assignment-expression ; S 6.5.16
(conditional-expression)
(unary-expression assignment-operator assignment-expression
($$ `(assn-expr ,$1 (op ,$2) ,$3)))
)
(assignment-operator
("=") ("+=") ("-=") ("*=") ("/=") ("%=")
("<<=") (">>=") ("&=") ("^=") ("|="))
(expression ; S 6.5.17
(assignment-expression)
(expression "," assignment-expression
($$ (if (eqv? 'comma-expr (sx-tag $1))
(append $1 (list $3))
`(comma-expr ,$1 ,$3))))
)
(constant-expression ; S 6.6
(conditional-expression)
)
;; declarations
(declaration
(declaration-specifiers
init-declarator-list
($$ (save-typenames `(decl ,(tl->list $1) ,(tl->list $2))))
";" opt-code-comment
($$ (if (pair? $5) (append $3 (list $5)) $3)))
(declaration-specifiers
";" opt-code-comment
($$ (if (pair? $3)
`(decl ,(tl->list $1) ,(list $3))
`(decl ,(tl->list $1)))))
)
(declaration-specifiers ; S 6.7
;; storage-class-specifier declaration-specifiers_opt
(storage-class-specifier ($$ (make-tl 'decl-spec-list $1)))
(storage-class-specifier declaration-specifiers ($$ (tl-insert $2 $1)))
;; type-specifier declaration-specifiers_opt
(type-specifier ($$ (make-tl 'decl-spec-list $1)))
(type-specifier declaration-specifiers ($$ (tl-insert $2 $1)))
;; type-qualifier declaration-specifiers_opt
(type-qualifier ($$ (make-tl 'decl-spec-list $1)))
(type-qualifier declaration-specifiers ($$ (tl-insert $2 $1)))
;; function-specifier declaration-specifiers_opt
(function-specifier ($$ (make-tl 'decl-spec-list $1)))
(function-specifier declaration-specifiers ($$ (tl-insert $2 $1)))
)
(init-declarator-list ; S 6.7
(init-declarator ($$ (make-tl 'init-declr-list $1)))
(init-declarator-list "," init-declarator ($$ (tl-append $1 $3)))
)
(init-declarator ; S 6.7
(declarator ($$ `(init-declr ,$1)))
(declarator "=" initializer ($$ `(init-declr ,$1 ,$3)))
)
(storage-class-specifier ; S 6.7.1
("auto" ($$ '(stor-spec (auto))))
("extern" ($$ '(stor-spec (extern))))
("register" ($$ '(stor-spec (register))))
("static" ($$ '(stor-spec (static))))
("typedef" ($$ '(stor-spec (typedef))))
)
(type-specifier ; S 6.7.2
("void" ($$ '(type-spec (void))))
(fixed-type-specifier ($$ `(type-spec ,$1))) ; I made this up
(float-type-specifier ($$ `(type-spec ,$1))) ; I made this up
("_Bool" ($$/ref 's5.1.5-01 '(type-spec (fixed-type "_Bool"))))
(complex-type-specifier ($$ `(type-spec ,$1))) ; I made this up
(struct-or-union-specifier ($$ `(type-spec ,$1)))
(enum-specifier ($$ `(type-spec ,$1)))
(typedef-name ($$ `(type-spec ,$1)))
)
(fixed-type-specifier
("short" ($prec 'imp) ($$ '(fixed-type "short")))
("short" "int" ($$ '(fixed-type "short int")))
("signed" "short" ($prec 'imp) ($$ '(fixed-type "signed short")))
("signed" "short" "int" ($$ '(fixed-type "signed short int")))
("int" ($$ '(fixed-type "int")))
("signed" ($prec 'imp) ($$ '(fixed-type "signed")))
("signed" "int" ($$ '(fixed-type "signed int")))
("long" ($prec 'imp) ($$ '(fixed-type "long")))
("long" "int" ($$ '(fixed-type "long int")))
("signed" "long" ($prec 'imp) ($$ '(fixed-type "signed long")))
("signed" "long" "int" ($$ '(fixed-type "signed long int")))
("long" "long" ($prec 'imp) ($$ '(fixed-type "long long")))
("long" "long" "int" ($$ '(fixed-type "long long int")))
("signed" "long" "long" ($prec 'imp)
($$ '(fixed-type "signed long long")))
("signed" "long" "long" "int" ($$ '(fixed-type "signed long long int")))
("unsigned" "short" "int" ($$ '(fixed-type "unsigned short int")))
("unsigned" "short" ($prec 'imp) ($$ '(fixed-type "unsigned short")))
("unsigned" "int" ($$ '(fixed-type "unsigned int")))
("unsigned" ($prec 'imp) ($$ '(fixed-type "unsigned")))
("unsigned" "long" "int" ($$ '(fixed-type "unsigned long")))
("unsigned" "long" ($prec 'imp) ($$ '(fixed-type "unsigned long")))
("unsigned" "long" "long" "int"
($$ '(fixed-type "unsigned long long int")))
("unsigned" "long" "long" ($prec 'imp)
($$ '(fixed-type "unsigned long long")))
("char" ($$ '(fixed-type "char")))
("signed" "char" ($$ '(fixed-type "signed char")))
("unsigned" "char" ($$ '(fixed-type "unsigned char"))))
(float-type-specifier
("float" ($prec 'imp) ($$ '(float-type "float")))
("double" ($prec 'imp) ($$ '(float-type "double")))
("long" "double" ($$ '(float-type "long double"))))
(complex-type-specifier
("_Complex" ($$ '(complex-type "_Complex")))
("float" "_Complex" ($$ '(complex-type "float _Complex")))
("double" "_Complex" ($$ '(complex-type "double _Complex")))
("long" "double" "_Complex" ($$ '(complex-type "long double _Complex")))
)
;; This one modified: split out struct-or-union = "struct"|"union"
(struct-or-union-specifier ; S 6.7.2.1
("struct" ident-like "{" struct-declaration-list "}"
($$ `(struct-def ,$2 ,(tl->list $4))))
("struct" "{" struct-declaration-list "}"
($$ `(struct-def ,(tl->list $3))))
("struct" ident-like ($$ `(struct-ref ,$2)))
("union" ident-like "{" struct-declaration-list "}"
($$ `(union-def ,$2 ,(tl->list $4))))
("union" "{" struct-declaration-list "}"
($$ `(union-def ,(tl->list $3))))
("union" ident-like ($$ `(union-ref ,$2)))
)
;; because name following struct/union can be indentifier or typeref
(ident-like (identifier) (typedef-name ($$ `(ident ,(cdr $1)))))
;; Calling this field-list in the parse tree.
(struct-declaration-list ; S 6.7.2.1
(struct-declaration ($$ (make-tl 'field-list $1)))
(lone-comment ($$ (make-tl 'field-list $1)))
(struct-declaration-list struct-declaration ($$ (tl-append $1 $2)))
(struct-declaration-list lone-comment ($$ (tl-append $1 $2)))
)
(struct-declaration ; S 6.7.2.1
(specifier-qualifier-list
struct-declarator-list ";" opt-code-comment
($$ (if (pair? $4)
`(comp-decl ,(tl->list $1) ,(tl->list $2) ,$4)
`(comp-decl ,(tl->list $1) ,(tl->list $2)))))
)
(specifier-qualifier-list ; S 6.7.2.1
(type-specifier specifier-qualifier-list ($$ (tl-insert $2 $1)))
(type-specifier ($$ (make-tl 'decl-spec-list $1)))
(type-qualifier specifier-qualifier-list ($$ (tl-insert $2 $1)))
(type-qualifier ($$ (make-tl 'decl-spec-list $1)))
)
(struct-declarator-list ; S 6.7.2.1
(struct-declarator ($$ (make-tl 'comp-declr-list $1)))
(struct-declarator-list "," struct-declarator ($$ (tl-append $1 $3)))
)
(struct-declarator ; S 6.7.2.1
(declarator ($$ `(comp-declr ,$1)))
(declarator ":" constant-expression ($$ `(comp-declr (bit-field ,$1 ,$3))))
(":" constant-expression ($$ `(comp-declr (bit-field ,$2))))
)
(enum-specifier ; S 6.7.2.2
("enum" identifier "{" enumerator-list "}"
($$ `(enum-def ,$2 ,(tl->list $4))))
("enum" identifier "{" enumerator-list "," "}"
($$ `(enum-def ,$2 ,(tl->list $4))))
("enum" "{" enumerator-list "}" ($$ `(enum-def ,(tl->list $3))))
("enum" "{" enumerator-list "," "}" ($$ `(enum-def ,(tl->list $3))))
("enum" identifier ($$ `(enum-ref ,$2)))
)
;; keeping old enum-def-list in parse tree
(enumerator-list ; S 6.7.2.2
(enumerator ($$ (make-tl 'enum-def-list $1)))
(enumerator-list "," enumerator ($$ (tl-append $1 $3)))
)
;; Had to change enumeration-constant => identifier
(enumerator ; S 6.7.2.2
(identifier ($$ `(enum-defn ,$1)))
(identifier "=" constant-expression ($$ `(enum-defn ,$1 ,$3)))
)
(type-qualifier
("const" ($$ `(type-qual ,$1)))
("volatile" ($$ `(type-qual ,$1)))
("restrict" ($$ `(type-qual ,$1)))
)
(function-specifier ("inline" ($$ `(fctn-spec ,$1))))
(declarator
(pointer direct-declarator ($$ `(ptr-declr ,$1 ,$2)))
(direct-declarator)
)
(direct-declarator
(identifier ($$ $1))
("(" declarator ")" ($$ `(scope ,$2)))
(direct-declarator
"[" type-qualifier-list assignment-expression "]"
($$ `(array-of ,$1 ,$3 ,$4)))
(direct-declarator "[" type-qualifier-list "]" ($$ `(array-of ,$1 ,$3)))
(direct-declarator "[" assignment-expression "]" ($$ `(array-of ,$1 ,$3)))
(direct-declarator "[" "]" ($$ `(array-of ,$1)))
(direct-declarator
"[" "static" type-qualifier-list assignment-expression "]"
($$ `(array-of ,$1 ,(tl->list (tl-insert '(stor-spec "static") $4)) ,$5)))
(direct-declarator
"[" type-qualifier-list "static" assignment-expression "]"
($$ `(array-of ,$1 ,(tl->list (tl-insert '(stor-spec "static") $3)) ,$5)))
(direct-declarator
"[" type-qualifier-list "*" "]" ; variable length array
($$ `(array-of ,$1 ,$3 (var-len))))
(direct-declarator
"[" "*" "]" ; variable length array
($$ `(array-of ,$1 (var-len))))
(direct-declarator "(" parameter-type-list ")"
($$ `(ftn-declr ,$1 ,(tl->list $3))))
(direct-declarator "(" identifier-list ")"
($$ `(ftn-declr ,$1 ,(tl->list $3))))
(direct-declarator "(" ")" ($$ `(ftn-declr ,$1 (param-list))))
)
(pointer
("*" type-qualifier-list ($$ `(pointer ,(tl->list $2))))
("*" ($$ '(pointer)))
("*" type-qualifier-list pointer ($$ `(pointer ,(tl->list $2) ,$3)))
("*" pointer ($$ `(pointer ,$2)))
)
;; But put in tree as decl-spec-list
(type-qualifier-list
(type-qualifier ($$ (make-tl 'decl-spec-list $1)))
(type-qualifier-list type-qualifier ($$ (tl-append $1 $2)))
)
(parameter-type-list
(parameter-list ($$ $1))
(parameter-list "," "..." ($$ (tl-append $1 '(ellipis))))
)
(parameter-list
(parameter-declaration ($$ (make-tl 'param-list $1)))
(parameter-list "," parameter-declaration ($$ (tl-append $1 $3)))
)
(parameter-declaration
(declaration-specifiers declarator
($$ `(param-decl ,(tl->list $1)
(param-declr ,$2))))
(declaration-specifiers abstract-declarator
($$ `(param-decl ,(tl->list $1)
(param-declr ,$2))))
(declaration-specifiers ($$ `(param-decl ,(tl->list $1))))
)
(identifier-list
(identifier ($$ (make-tl 'ident-list $1)))
(identifier-list "," identifier ($$ (tl-append $1 $3)))
)
(type-name ; S 6.7.6
;; e.g., (foo_t *)
(specifier-qualifier-list abstract-declarator
($$ `(type-name ,(tl->list $1) ,$2)))
;; e.g., (int)
(declaration-specifiers ($$ `(type-name ,(tl->list $1))))
)
(abstract-declarator ; S 6.7.6
(pointer ($$ `(abs-declr ,$1)))
(pointer direct-abstract-declarator ($$ `(abs-declr ,$1 ,$2)))
(direct-abstract-declarator ($$ `(abs-declr ,$1)))
)
(direct-abstract-declarator
("(" abstract-declarator ")" ($$ `(declr-scope ,$2)))
(direct-abstract-declarator
"[" type-qualifier-list assignment-expression "]"
($$ `(declr-array ,$3 ,$4)))
(direct-abstract-declarator
"[" type-qualifier-list "]"
($$ `(declr-array ,$1 ,$3)))
(direct-abstract-declarator
"[" assignment-expression "]"
($$ `(declr-array ,$1 ,$3)))
(direct-abstract-declarator
"[" "]" ($$ `(declr-array ,$1)))
(direct-abstract-declarator
"[" "static" type-qualifier-list assignment-expression "]"
($$ `(declr-array
,$1 ,(tl->list (tl-insert '(stor-spec "static") $4)) ,$5)))
(direct-abstract-declarator
"[" "static" type-qualifier-list "]"
($$ `(declr-array ,$1 ,(tl->list (tl-insert '(stor-spec "static") $4)))))
(direct-abstract-declarator
"[" type-qualifier-list "static" assignment-expression "]"
($$ `(declr-array
,$1 ,(tl->list (tl-insert '(stor-spec "static") $3)) ,$5)))
;;
("[" type-qualifier-list assignment-expression "]"
($$ `(declr-anon-array ,$2 ,$3)))
("[" type-qualifier-list "]" ($$ `(declr-anon-array ,$2)))
("[" assignment-expression "]" ($$ `(declr-anon-array ,$2)))
("[" "]" ($$ `(declr-anon-array)))
("[" "static" type-qualifier-list assignment-expression "]"
($$ `(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $3)) ,$4)))
("[" "static" type-qualifier-list "]"
($$ `(declr-anon-array ,(tl->list (tl-insert '(stor-spec "static") $3)))))
("[" type-qualifier-list "static" assignment-expression "]"
($$ `(declr-anon-array
,(tl->list (tl-insert '(stor-spec "static") $2)) ,$4)))
(direct-abstract-declarator "[" "*" "]" ($$ `(declr-STAR ,$1)))
("[" "*" "]" ($$ '(declr-STAR)))
(direct-abstract-declarator "(" parameter-type-list ")"
($$ `(declr-fctn ,$1 ,(tl->list $3))))
(direct-abstract-declarator "(" ")" ($$ `(declr-fctn ,$1)))
("(" parameter-type-list ")" ($$ `(declr-anon-fctn ,(tl->list $2))))
("(" ")" ($$ '(declr-anon-fctn)))
)
;;typedef-name must be hacked w/ the lexical analyzer
(typedef-name ('typename ($$ `(typename ,$1))))
(initializer ; S 6.7.8
(assignment-expression ($$ `(initzer ,$1)))
("{" initializer-list "}" ($$ `(initzer ,(tl->list $2))))
("{" initializer-list "," "}" ($$ `(initzer ,(tl->list $2))))
)
;; The designation productions are from C99.
(initializer-list
(designation initializer ($$ (make-tl 'initzer-list $1 $2)))
(initializer ($$ (make-tl 'initzer-list $1)))
(initializer-list "," designation initializer ($$ (tl-append $1 $3 $4)))
(initializer-list "," initializer ($$ (tl-append $1 $3)))
)
(designation ; S 6.7.8
(designator-list "=" ($$ `(desig ,$1)))
)
(designator-list
(designator ($$ (make-tl 'desgr-list $1)))
(designator-list designator ($$ (tl-append $1 $2)))
)
(designator
("[" constant-expression "]" ($$ (list 'array-dsgr $2)))
("." identifier ($$ (list 'sel-dsgr $2)))
)
;; statements
(statement
(labeled-statement)
(compound-statement)
(expression-statement)
(selection-statement)
(iteration-statement)
(jump-statement)
(cpp-statement)
)
(labeled-statement
(identifier ":" statement ($$ `(labeled-stmt ,$1 ,$3)))
("case" constant-expression ":" statement ($$ `(case ,$2 ,$4)))
("default" ":" statement ($$ `(default ,$3)))
)
(compound-statement
("{" block-item-list "}"
($$ `(compd-stmt ,(tl->list $2))))
("{" "}"
($$ `(compd-stmt (block-item-list))))
)
(block-item-list
(block-item ($$ (make-tl 'block-item-list $1)))
(block-item-list block-item ($$ (tl-append $1 $2)))
)
(block-item
(declaration)
(statement)
)
(expression-statement
(expression ";" ($$ `(expr-stmt ,$1)))
(";" ($$ '(expr-stmt)))
)
(selection-statement
("if" "(" expression ")" statement ($prec 'then)
($$ `(if ,$3 ,$5)))
("if" "(" expression ")" statement "else" statement
($$ `(if ,$3 ,$5 ,$7)))
("switch" "(" expression ")" statement ($$ `(switch ,$3 ,$5)))
)
(iteration-statement
("while" "(" expression ")" statement ($$ `(while ,$3 ,$5)))
("do" statement "while" "(" expression ")" ";" ($$ `(do-while ,$2 ,$5)))
("for" "(" initial-clause opt-expression ";" opt-expression ")" statement
($$ `(for ,$3 ,$4 ,$6 ,$8)))
)
(initial-clause ; <= added for convenience
(expression ";")
(";" ($$ '(expr)))
(declaration))
(opt-expression ; <= added for convenience
($empty ($$ '(expr)))
(expression))
(jump-statement ; S 6.8.6
("goto" identifier ";" ($$ `(goto $2)))
("continue" ";" ($$ '(continue)))
("break" ";" ($$ '(break)))
("return" expression ";" ($$ `(return ,$2)))
("return" ";" ($$ `(return (expr))))
)
;; external definitions
(translation-unit
(external-declaration ($$ (make-tl 'trans-unit $1)))
(translation-unit
external-declaration
($$ (cond ((eqv? 'trans-unit (car $2))
(let* ((t1 (tl-append $1 '(extern-C-begin)))
(t2 (tl-extend t1 (cdr $2)))
(t3 (tl-append t2 '(extern-C-end))))
t3))
(else (tl-append $1 $2)))))
)
(external-declaration
(function-definition)
(declaration)
(lone-comment)
(cpp-statement)
;; The following is a kludge to deal with @code{extern "C" @{}.
("extern" $string "{" translation-unit "}" ($$ (tl->list $4)))
)
(function-definition
(declaration-specifiers
declarator declaration-list compound-statement
($$ `(knr-fctn-defn ,(tl->list $1) ,$2 ,(tl->list $3) ,$4)))
(declaration-specifiers
declarator compound-statement
($$ `(fctn-defn ,(tl->list $1) ,$2 ,$3)))
)
(declaration-list
(declaration ($$ (make-tl $1)))
(declaration-list declaration ($$ (tl-append $1 $2)))
)
(opt-code-comment () (code-comment))
;;(opt-lone-comment () (lone-comment))
;;(opt-comment () (code-comment) (lone-comment))
;; non-terminal leaves
(identifier
($ident ($$ `(ident ,$1)))
('cpp-ident ($$ `(ident ,$1))))
(constant
($fixed ($$ `(fixed ,$1))) ; integer-constant
($float ($$ `(float ,$1))) ; floating-constant
($chlit ($$ `(char ,$1)))) ; char-constant
(string-literal
($string ($$ (make-tl 'string $1))) ; string-constant
(string-literal $string ($$ (tl-append $1 $2))))
(code-comment ($code-comm ($$ `(comment ,$1))))
(lone-comment ($lone-comm ($$ `(comment ,$1))))
(cpp-statement ('cpp-stmt ($$ `(cpp-stmt ,$1))))
)))
(define c99-mach
(compact-machine
(hashify-machine
(make-lalr-machine c99-spec))))
;;; =====================================
;; The following are needed by the code in pbody.scm.
(define len-v (assq-ref c99-mach 'len-v))
(define pat-v (assq-ref c99-mach 'pat-v))
(define rto-v (assq-ref c99-mach 'rto-v))
(define mtab (assq-ref c99-mach 'mtab))
(define act-v (vector-map
(lambda (ix f) (eval f (current-module)))
(vector-map (lambda (ix actn) (wrap-action actn))
(assq-ref c99-mach 'act-v))))
(include-from-path "nyacc/lang/c99/body.scm")
(define raw-parser (make-lalr-parser c99-mach))
(define (run-parse)
(let ((info (fluid-ref *info*)))
(raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
(define* (dev-parse-c99 #:key
(cpp-defs '()) ; CPP defines
(inc-dirs '()) ; include directories
(td-dict '()) ; typedef dictionary
(mode 'file) ; mode: 'file or 'code
(xdef? #f) ; expand def function: proc name mode
(debug #f)) ; debug
(catch
'parse-error
(lambda ()
(let ((info (make-cpi debug cpp-defs (cons "." inc-dirs) td-dict)))
(with-fluid* *info* info
(lambda ()
(raw-parser (gen-c-lexer #:mode mode #:xdef? xdef?)
#:debug debug)))))
(lambda (key fmt . rest)
(apply simple-format (current-error-port) (string-append fmt "\n") rest)
#f)))
(define dev-parse-c dev-parse-c99)
;;; =====================================
;; @item gen-c99-files [dir] => #t
;; Update or generate the files @quot{c99act.scm} and @quot{c99tab.scm}.
;; These are the tables and actions for the C99 parser.
;; If there are no changes to existing files, no update occurs.
(define (gen-c99-files . rest)
(define (lang-dir path)
(if (pair? rest) (string-append (car rest) "/" path) path))
(define (xtra-dir path)
(lang-dir (string-append "mach.d/" path)))
(write-lalr-actions c99-mach (xtra-dir "c99act.scm.new"))
(write-lalr-tables c99-mach (xtra-dir "c99tab.scm.new"))
(let ((a (move-if-changed (xtra-dir "c99act.scm.new")
(xtra-dir "c99act.scm")))
(b (move-if-changed (xtra-dir "c99tab.scm.new")
(xtra-dir "c99tab.scm"))))
(when (or a b)
(system (string-append "touch " (lang-dir "parser.scm")))
#;(compile-file (lang-dir "parser.scm"))
)))
;; @item gen-c99x-files [dir] => #t
;; Update or generate the files @quot{c99xact.scm} and @quot{c99xtab.scm}.
;; These are the tables and actions for the C99 expression parser.
;; If there are no changes to existing files, no update occurs.
(define (gen-c99x-files . rest)
(define (lang-dir path)
(if (pair? rest) (string-append (car rest) "/" path) path))
(define (xtra-dir path)
(lang-dir (string-append "mach.d/" path)))
(let* ((cexpr-spec (restart-spec c99-mach 'expression))
(cexpr-mach (compact-machine
(hashify-machine
(make-lalr-machine cexpr-spec)))))
(write-lalr-actions cexpr-mach (xtra-dir "c99xact.scm.new"))
(write-lalr-tables cexpr-mach (xtra-dir "c99xtab.scm.new")))
(let ((a (move-if-changed (xtra-dir "c99xact.scm.new")
(xtra-dir "c99xact.scm")))
(b (move-if-changed (xtra-dir "c99xtab.scm.new")
(xtra-dir "c99xtab.scm"))))
(when (or a b)
(system (string-append "touch " (lang-dir "parser.scm")))
#;(compile-file (lang-dir "xparser.scm"))
)))
;; --- last line ---

View file

@ -0,0 +1,74 @@
;;; nyacc/lang/c99/parser.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C parser
(define-module (nyacc lang c99 parser)
#:export (parse-c parse-c99 def-xdef? std-dict)
#:use-module (nyacc lex)
#:use-module (nyacc parse)
#:use-module (nyacc lang util)
#:use-module (nyacc lang c99 cpp)
#:use-module ((srfi srfi-9) #:select (define-record-type))
#:use-module ((sxml xpath) #:select (sxpath))
)
(include-from-path "nyacc/lang/c99/mach.d/c99tab.scm")
(include-from-path "nyacc/lang/c99/body.scm")
(include-from-path "nyacc/lang/c99/mach.d/c99act.scm")
;; Parse given a token generator. Uses fluid @code{*info*}.
(define raw-parser
(make-lalr-parser
(list
(cons 'len-v len-v)
(cons 'pat-v pat-v)
(cons 'rto-v rto-v)
(cons 'mtab mtab)
(cons 'act-v act-v))))
(define (run-parse)
(let ((info (fluid-ref *info*)))
(raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
;; @item parse-c [#:cpp-defs def-a-list] [#:inc-dirs dir-list] [#:debug bool] \
;; [#:mode ('code|'file)]
;; This needs to be explained in some detail.
;; tdd = typedef dict: (("<time>" time_t) ... ("<unistd.h>" ...))
(define* (parse-c99 #:key
(cpp-defs '()) ; CPP defines
(inc-dirs '()) ; include dirs
(td-dict '()) ; typedef dictionary
(mode 'file) ; mdoe: 'file or 'code
(xdef? #f) ; pred to determine expand
(debug #f)) ; debug
(catch
'parse-error
(lambda ()
(let ((info (make-cpi debug cpp-defs (cons "." inc-dirs) td-dict)))
(with-fluid*
*info* info
(lambda ()
(raw-parser (gen-c-lexer #:mode mode #:xdef? xdef?)
#:debug debug)))))
(lambda (key fmt . rest)
(apply simple-format (current-error-port) (string-append fmt "\n") rest)
#f)))
(define parse-c parse-c99)
;; --- last line ---

View file

@ -0,0 +1,512 @@
;;; nyacc/lang/c99/pprint.scm
;;;
;;; Copyright (C) 2015,2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (nyacc lang c99 pprint)
#:export (pretty-print-c99)
#:use-module ((srfi srfi-1) #:select (pair-for-each))
#:use-module (nyacc lang util)
#:use-module (sxml match)
#:use-module (ice-9 pretty-print)
)
(define op-sym
(let ((ot '(("=" . eq) ("+=" . pl-eq) ("-=" . mi-eq) ("*=" . ti-eq)
("/=" . di-eq) ("%=" . mo-eq) ("<<=" . ls-eq) (">>=" . rs-eq)
("&=" . ba-eq) ("^=" . bx-eq) ("|=" bo-eq))))
(lambda (name)
(assoc-ref ot name))))
(define op-prec
;; in order of decreasing precedence
'((p-expr ident fixed float string)
(comp-lit post-inc post-dec i-sel d-sel fctn-call array-ref)
(de-ref ref-to neg pos not bitwise-not sizeof pre-inc pre-dec)
(cast)
(mul div mod)
(add sub)
(lshift rshift)
(lt gt le ge)
(eq ne)
(bitwise-and)
(bitwise-xor)
(bitwise-or)
(and)
(or)
(cond-expr)
(assn-expr)
(comma)))
(define op-assc
'((left array-ref d-sel i-sel post-inc post-dec comp-lit mul div mod add sub
lshift rshift lt gt le ge bitwise-and bitwise-xor bitwise-or and or)
(right pre-inc pre-dec sizeof bitwise-not not pos neg ref-to de-ref cast
cond assn-expr)
(nonassoc)))
(define protect-expr? (make-protect-expr op-prec op-assc))
;; @deffn pretty-print-c99 tree [#:indent-level 2]
;; Convert and print a C99 sxml tree to the current output port.
;; The optional keyword argument @code{#:indent-level} provides the
;; indent level, with default of 2.
(define* (pretty-print-c99 tree #:key (indent-level 2) (ugly #f))
;;(define fmtr (make-pp-formatter))
(define fmtr (if ugly (make-pp-formatter/ugly) (make-pp-formatter)))
(define (push-il)(fmtr 'push))
(define (pop-il) (fmtr 'pop))
(define (sf . args) (apply fmtr args))
(define (cpp-ppx tree)
(fmtr 'nlin)
(sxml-match tree
((define (name ,name) (args . ,args) (repl ,repl))
(sf "#define ~A(" name)
(pair-for-each
(lambda (pair) (sf "~A" (car pair)) (if (pair? (cdr pair)) (sf ",")))
args)
(sf ") ~A\n" repl))
((define (name ,name) (repl ,repl))
(sf "#define ~A ~A\n" name repl))
((if ,text) (sf "#if ~A\n" text))
((elif ,text) (sf "#elif ~A\n" text))
((else ,text) (sf "#else ~A\n" text))
((else) (sf "#else\n"))
((endif ,text) (sf "#endif ~A\n" text))
((endif) (sf "#endif\n"))
((include . ,rest) (sf "#include ~A\n" (sx-ref tree 1)))
((error ,text) (sf "#error ~A\n" text))
((pragma ,text) (sf "#pragma ~A\n" text))
(,otherwise
(simple-format #t "\n*** pprint/cpp-ppx: NO MATCH: ~S\n" tree))
))
(define (unary/l op rep rval)
(sf rep)
(if (protect-expr? 'rt op rval)
(ppx/p rval)
(ppx rval)))
(define (unary/r op rep lval)
(sf rep)
(if (protect-expr? 'lt op lval)
(ppx/p lval)
(ppx lval)))
(define (binary op rep lval rval)
(if (protect-expr? 'lt op lval)
(ppx/p lval)
(ppx lval))
(sf rep)
(if (protect-expr? 'rt op rval)
(ppx/p rval)
(ppx rval)))
(define (comp declr initr)
(let ((iexpr (and initr (sx-ref initr 1))))
(ppx declr)
(when initr
(sf " = ")
(case (sx-tag iexpr)
((initzer-list)
(sf "{")
(sf "initzer-list") ; TODO
(sf " }"))
(else
(ppx iexpr))))))
(define (struct-union-def struct-or-union name fields)
(if name
(sf "~A ~A {\n" struct-or-union name)
(sf "~A {\n" struct-or-union))
(push-il)
(for-each ppx fields)
(pop-il)
(sf "}"))
(define (ppx/p tree) (sf "(") (ppx tree) (sf ")"))
;; TODO: comp-lit
(define (ppx-1 tree)
(sxml-match tree
((p-expr ,expr) (ppx expr))
((ident ,name) (sf "~A" name))
((char ,value) (sf "'~A'" (sx-ref tree 1)))
((fixed ,value) (sf "~A" value))
((float ,value) (sf "~A" value))
((string . ,value-l)
(pair-for-each
(lambda (pair)
(sf "~S" (car pair))
(if (pair? (cdr pair)) (sf " ")))
value-l))
((comment ,text) (sf "/*~A */\n" text))
((scope ,expr) (sf "(") (ppx expr) (sf ")"))
((array-ref ,dim ,expr)
(ppx expr) (sf "[") (ppx dim) (sf "]"))
((d-sel ,id ,ex) (binary 'd-del "." ex id))
((i-sel ,id ,ex) (binary 'i-del "->" ex id))
((pre-inc ,expr) (unary/l 'pre-inc "++" expr))
((pre-dec ,expr) (unary/l 'pre-dec "--" expr))
((ref-to ,expr) (unary/l 'ref-to "&" expr))
((de-ref ,expr) (unary/l 'de-ref "*" expr))
((pos ,expr) (unary/l 'pos "+" expr))
((neg ,expr) (unary/l 'neg "-" expr))
((bitwise-not ,expr) (unary/l 'bitwise-not "~" expr))
((not ,expr) (unary/l 'not "!" expr))
((sizeof-expr ,expr) (sf "sizeof(") (ppx expr) (sf ")"))
((sizeof-type ,type) (sf "sizeof(") (ppx type) (sf ")"))
((cast ,tn ,ex)
(sf "(") (ppx tn) (sf ")")
(if (protect-expr? 'rt 'cast ex)
(ppx/p ex)
(ppx ex)))
((add ,lval ,rval) (binary 'add " + " lval rval))
((sub ,lval ,rval) (binary 'sub " - " lval rval))
((mul ,lval ,rval) (binary 'mul "*" lval rval))
((div ,lval ,rval) (binary 'div "/" lval rval))
((mod ,lval ,rval) (binary 'mod "%" lval rval))
((lt ,lval ,rval) (binary 'lt " < " lval rval))
((gt ,lval ,rval) (binary 'gt " > " lval rval))
((le ,lval ,rval) (binary 'le " <= " lval rval))
((ge ,lval ,rval) (binary 'ge " >= " lval rval))
((eq ,lval ,rval) (binary 'eq " == " lval rval))
((ne ,lval ,rval) (binary 'ne " != " lval rval))
((bitwise-and ,lval ,rval) (binary 'bitwise-and " & " lval rval))
((bitwise-or ,lval ,rval) (binary 'bitwise-and " | " lval rval))
((bitwise-xor ,lval ,rval) (binary 'bitwise-xor " ^ " lval rval))
((post-inc ,expr) (unary/r 'post-inc "++" expr))
((post-dec ,expr) (unary/r 'post-dec "--" expr))
;; TODO: check protection
((fctn-call ,expr ,arg-list)
(if (protect-expr? 'rt 'fctn-call expr)
(ppx/p expr)
(ppx expr))
(sf "(")
(ppx arg-list)
(sf ")"))
((expr-list . ,expr-l)
(pair-for-each
(lambda (pair)
(ppx (car pair))
(if (pair? (cdr pair)) (sf ", ")))
expr-l))
((assn-expr ,lval ,op ,rval)
(binary (car op) (simple-format #f " ~A " (cadr op)) lval rval))
;; TODO: check protection
((comma-expr . ,expr-list)
(pair-for-each
(lambda (pair)
(cond
((pair? (cdr pair))
(if (protect-expr? 'rt 'comma-expr (car pair))
(ppx/p (car pair))
(ppx (car pair)))
(sf ", "))
(else (ppx (car pair)))))
expr-list))
;; #|
;; gotta break up ppx because sxml-match seems to eat stack space:
;; everthing together results in SIGABRT from vm_error_stack_overflow()
(,otherwise
(ppx-2 tree))))
(define (ppx-2 tree)
(sxml-match tree
;; sxml-match continues here to avoid stack overflow
;; |#
((decl ,decl-spec-list)
(ppx decl-spec-list) (sf ";\n"))
((decl ,decl-spec-list ,init-declr-list)
(ppx decl-spec-list) (ppx init-declr-list) (sf ";\n"))
((decl ,decl-spec-list ,init-declr-list ,comment)
(ppx decl-spec-list) (ppx init-declr-list) (sf "; ") (ppx comment))
((decl-no-newline ,decl-spec-list ,init-declr-list) ; for (int i = 0;
(ppx decl-spec-list) (ppx init-declr-list) (sf ";"))
((comp-decl ,spec-qual-list ,declr-list)
(ppx spec-qual-list) (ppx declr-list) (sf ";\n"))
((comp-decl ,spec-qual-list ,declr-list ,comment)
(ppx spec-qual-list) (ppx declr-list) (sf "; ") (ppx comment))
((decl-spec-list . ,dsl)
(let iter ((dsl dsl))
(when (pair? dsl)
(case (sx-tag (car dsl))
((stor-spec) (sf "~A" (car (sx-ref (car dsl) 1))))
((type-qual) (sf "qual=~A" (sx-ref (car dsl) 1)))
((type-spec) (ppx (car dsl)))
(else (sf "[?:~S] " (car dsl))))
(if (pair? (cdr dsl)) (sf " "))
(iter (cdr dsl)))))
((init-declr-list . ,rest)
(pair-for-each
(lambda (pair)
(sf " ")
(ppx (car pair))
(if (pair? (cdr pair)) (sf ",")))
rest))
((comp-declr-list . ,rest)
(pair-for-each
(lambda (pair)
(sf " ")
(ppx (car pair))
(if (pair? (cdr pair)) (sf ",")))
rest))
((init-declr ,declr ,initr) (comp declr initr))
((init-declr ,declr) (comp declr #f))
((comp-declr ,declr) (comp declr #f))
((param-declr ,declr) (comp declr #f))
((type-spec ,arg)
(case (sx-tag arg)
((fixed-type) (sf "~A" (sx-ref arg 1)))
((float-type) (sf "~A" (sx-ref arg 1)))
((struct-ref) (ppx arg))
((struct-def) (ppx arg))
((union-ref) (ppx arg))
((union-def) (ppx arg))
((enum-def) (ppx arg))
((typename) (sf "~A" (sx-ref arg 1)))
((void) (sf "void"))
(else (error "missing " arg))))
((struct-ref (ident ,name)) (sf "struct ~A" name))
((union-ref (ident ,name)) (sf "union ~A" name))
((struct-def (ident ,name) (field-list . ,fields))
(struct-union-def 'struct name fields))
((struct-def (field-list . ,fields))
(struct-union-def 'struct #f fields))
((union-def (ident ,name) (field-list . ,fields))
(struct-union-def 'union name fields))
((union-def (field-list . ,fields))
(struct-union-def 'union #f fields))
((enum-def (ident ,name) (enum-def-list . ,edl))
(sf "enum ~A " name) (ppx `(enum-def-list . ,edl)))
((enum-def-list . ,defns)
(sf "{\n") (push-il)
(for-each ppx defns)
(pop-il) (sf "}"))
((enum-defn (ident ,name) (p-expr (fixed ,value)))
(sf "~A = ~A,\n" name value))
((enum-defn (ident ,name))
(sf "~A,\n" name))
((fctn-spec "inline")
(sf "inline "))
((ptr-declr ,ptr ,dir-declr)
(ppx ptr) (ppx dir-declr))
((pointer) (sf "*"))
((pointer ,one) (sf "*") (ppx one))
((pointer ,one ,two) (sf "*") (ppx one) (ppx two))
((array-of ,dir-declr ,arg)
(ppx dir-declr) (sf "[") (ppx arg) (sf "]"))
((array-of ,dir-declr)
(ppx dir-declr) (sf "[]"))
;; MORE TO GO
((ftn-declr ,dir-declr ,param-list)
(ppx dir-declr) (sf "(") (ppx param-list) (sf ")"))
((type-name ,spec-qual-list ,abs-declr)
(ppx spec-qual-list) (ppx abs-declr))
((type-name ,decl-spec-list)
(ppx decl-spec-list))
((abs-declr ,pointer ,dir-abs-declr) (ppx pointer) (ppx dir-abs-declr))
((abs-declr ,one-of-above) (ppx one-of-above))
((compd-stmt (block-item-list . ,items))
(sf "{\n") (push-il) (for-each ppx items) (pop-il) (sf "}\n"))
((compd-stmt-no-newline (block-item-list . ,items))
(sf "{\n") (push-il) (for-each ppx items) (pop-il) (sf "} "))
;; #|
;; gotta break up ppx because sxml-match seems to eat stack space:
;; everthing together results in SIGABRT from vm_error_stack_overflow()
(,otherwise
(ppx-3 tree))))
(define (ppx-3 tree)
(sxml-match tree
;; sxml-match continues here to avoid stack overflow
;; |#
;; expression-statement
((expr-stmt ,expr) (ppx expr) (sf ";\n"))
((expr-stmt ,expr ,comm) (ppx expr) (sf "; ") (ppx comm))
((expr) (sf "")) ; for lone expr-stmt and return-stmt
;; selection-statement
((if . ,rest)
(let ((cond-part (sx-ref tree 1))
(then-part (sx-ref tree 2)))
(sf "if (") (ppx cond-part) (sf ") ")
(ppx then-part)
(let iter ((else-l (sx-tail tree 3)))
(cond
((null? else-l) #t)
((eqv? 'else-if (caar else-l))
(sf "else if (") (ppx (sx-ref (car else-l) 1)) (sf ") ")
(ppx (sx-ref (car else-l) 2))
(iter (cdr else-l)))
(else
(sf "else ")
(ppx (car else-l)))))))
((switch ,expr (compd-stmt (block-item-list . ,items)))
(sf "switch (") (ppx expr) (sf ") {\n")
(for-each
(lambda (item)
(unless (memq (car item) '(case default)) (push-il))
(ppx item)
(unless (memq (car item) '(case default)) (pop-il)))
items)
(sf "}\n"))
;; labeled-statement
((case ,expr ,stmt)
(sf "case ") (ppx expr) (sf ":\n")
(push-il) (ppx stmt) (pop-il))
((default ,stmt)
(sf "default:\n")
(push-il) (ppx stmt) (pop-il))
;; This does not meet the convention of "} while" on same line.
((do-while ,stmt ,expr)
(sf "do ")
(if (eqv? 'compd-stmt (sx-tag stmt))
(ppx `(compd-stmt-no-newline ,(sx-ref stmt 1)))
(ppx stmt))
(sf "while (") (ppx expr) (sf ");\n"))
;; for
((for (decl . ,rest) ,test ,iter ,stmt)
(sf "for (") (ppx `(decl-no-newline . ,rest))
(sf " ") (ppx test) (sf "; ") (ppx iter) (sf ") ")
(ppx stmt))
((for (decl . ,rest) ,expr2 ,expr3 ,stmt)
(sf "for (")
(ppx `(decl . ,rest)) (sf " ") (ppx expr2) (sf "; ") (ppx expr3)
(sf ") ") (ppx stmt))
((for ,expr1 ,expr2 ,expr3 ,stmt)
(sf "for (")
(ppx expr1) (sf "; ") (ppx expr2) (sf "; ") (ppx expr3)
(sf ") ") (ppx stmt))
;; jump-statement
((goto ,where)
(pop-il) ; unindent
(sf "goto ~A;" (sx-ref where 1))
;; comment?
(sf "\n")
(push-il)) ; re-indent
((continue) (sf "continue;\n"))
((break) (sf "break;\n"))
((return ,expr) (sf "return ") (ppx expr) (sf ";\n"))
((return) (sf "return;\n"))
((trans-unit . ,items)
(pair-for-each
(lambda (pair)
(let ((this (car pair))
(next (and (pair? (cdr pair)) (cadr pair))))
(ppx this)
(cond ;; add blank line if next is different or fctn defn
((not next))
((not (eqv? (sx-tag this) (sx-tag next))) (sf "\n"))
((eqv? (sx-tag next) 'fctn-defn) (sf "\n")))))
items))
((fctn-defn . ,rest) ;; but not yet (knr-fctn-defn)
(let* ((decl-spec-list (sx-ref tree 1))
(declr (sx-ref tree 2))
(compd-stmt (sx-ref tree 3)))
(ppx decl-spec-list)
(sf " ")
(ppx declr)
(sf " ")
(ppx compd-stmt)))
((ptr-declr . ,rest)
(ppx (sx-ref tree 1)) (ppx (sx-ref tree 2)))
((ftn-declr . ,rest)
(ppx (sx-ref tree 1)) ; direct-declarator
(sf "(") (ppx (sx-ref tree 2)) (sf ")"))
((param-list . ,params)
(pair-for-each
(lambda (pair) (ppx (car pair)) (if (pair? (cdr pair)) (sf ", ")))
params))
((param-decl ,decl-spec-list ,param-declr)
(ppx decl-spec-list) (sf " ") (ppx param-declr))
((param-decl ,decl-spec-list)
(ppx decl-spec-list))
((cpp-stmt . ,rest)
(cpp-ppx (sx-ref tree 1)))
((extern-C-begin) (sf "extern \"C\" {\n"))
((extern-C-end) (sf "}\n"))
(,otherwise
(simple-format #t "\n*** pprint/ppx: NO MATCH: ~S\n" (car tree)))
))
(define ppx ppx-1)
(ppx tree)
(if ugly (newline)))
;; --- last line ---

View file

@ -0,0 +1,135 @@
;;; lang/c/util1.scm
;;;
;;; Copyright (C) 2015,2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C parser utilities
(define-module (nyacc lang c99 util1)
#:export (remove-inc-trees merge-inc-trees! elifify)
#:use-module (nyacc lang util)
#:use-module ((srfi srfi-1) #:select (append-reverse))
#:use-module (srfi srfi-2) ;; and-let*
#:use-module (sxml fold)
#:use-module (sxml match)
)
;; @item remove-inc-trees tree
;; Remove the trees included with cpp-include statements.
;; @example
;; '(... (cpp-stmt (include "<foo.h>" (trans-unit ...))) ...)
;; => '(... (cpp-stmt (include "<foo.h>")) ...)
;; @end example
(define (remove-inc-trees tree)
(if (not (eqv? 'trans-unit (car tree))) (error "expecting c-tree"))
(let iter ((rslt (make-tl 'trans-unit))
;;(head '(trans-unit)) (tail (cdr tree))
(tree (cdr tree)))
(cond
((null? tree) (tl->list rslt))
((and (eqv? 'cpp-stmt (car (car tree)))
(eqv? 'include (caadr (car tree))))
(iter (tl-append rslt `(cpp-stmt (include ,(cadadr (car tree)))))
(cdr tree)))
(else (iter (tl-append rslt (car tree)) (cdr tree))))))
;; @item merge-inc-trees tree
;; Remove the trees included with cpp-include statements.
;; @example
;; '(... (cpp-stmt (include "<foo.h>" (trans-unit (stmt ...))) ...)
;; => '(... (stmt...) ...)
;; @end example
#;(define (Xmerge-inc-trees tree)
(if (not (eqv? 'trans-unit (car tree))) (error "expecting c-tree"))
(let iter ((rslt (make-tl 'trans-unit))
(tree (cdr tree)))
(cond
((null? tree) (tl->list rslt))
((and (eqv? 'cpp-stmt (caar tree)) (eqv? 'include (cadar tree)))
(iter (tl-extend rslt (cdr (merge-inc-trees (cdddar tree)))) (cdr tree)))
(else (iter (tl-append rslt (car tree)) (cdr tree))))))
;; @item merge-inc-trees! tree => tree
;; This will (recursively) merge code from cpp-includes into the tree.
;; @example
;; (trans-unit
;; (decl (a))
;; (cpp-stmt (include "<hello.h>" (trans-unit (decl (b)))))
;; (decl (c)))
;; =>
;; (trans-unit (decl (a)) (decl (b)) (decl (c)))
;; @end example
(define (merge-inc-trees! tree)
;; @item find-span (trans-unit a b c) => ((a . +->) . (c . '())
(define (find-span tree)
(cond
((not (pair? tree)) '()) ; maybe parse failed
((not (eqv? 'trans-unit (car tree))) (error "expecting c-tree"))
((null? (cdr tree)) (error "null c99-tree"))
(else
(let ((fp tree)) ; first pair
(let iter ((lp tree) ; last pair
(np (cdr tree))) ; next pair
(cond
((null? np) (cons (cdr fp) lp))
;; The following is an ugly hack to find cpp-include
;; with trans-unit attached.
((and-let* ((expr (car np))
((eqv? 'cpp-stmt (car expr)))
((eqv? 'include (caadr expr)))
(rest (cddadr expr))
((pair? rest))
(span (find-span (car rest))))
(set-cdr! lp (car span))
(iter (cdr span) (cdr np))))
(else
(set-cdr! lp np)
(iter np (cdr np)))))))))
;; Use cons to generate a new reference:
;; (cons (car tree) (car (find-span tree)))
;; or not:
(find-span tree)
tree)
;; @deffn elifify tree => tree
;; This procedure will find patterns of
;; @example
;; (if cond-1 then-part-1
;; (if cond-2 then-part-2
;; else-part-2
;; @end example
;; @noindent
;; and convert to
;; @example
;; (if cond-1 then-part-1
;; (elif cond-2 then-part-2)
;; else-part-2
;; @end example
(define (elifify tree)
(define (fU tree)
(sxml-match tree
((if ,x1 ,t1 (if ,x2 ,t2 (else-if ,x3 ,t3) . ,rest))
`(if ,x1 ,t1 (else-if ,x2 ,t2) (else-if ,x3 ,t3) . ,rest))
((if ,x1 ,t1 (if ,x2 ,t2 . ,rest))
`(if ,x1 ,t1 (else-if ,x2 ,t2) . ,rest))
(,otherwise
tree)))
(foldt fU identity tree))
;; --- last line ---

View file

@ -0,0 +1,605 @@
;;; nyacc/lang/c99/util2.scm - C processing code
;;;
;;; Copyright (C) 2015,2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; utilities for processing output trees
;; The idea is to convert declarations into something like
;; @example
;; const char *args[21]; /* command arguments */
;; @end example
;; @noindent
;; into
;; @example
;; ("args" (comment " command arguments ")
;; (array-of 21) (pointer-to) (fixed "char"))
;; @end example
;; @noindent
;; or without the comment. It is a question whether we need the fixed part.
;; In addition, we want to reduce to a set of canonical types. So something
;; like @code{foo_t} should be expanded.
;; KEEPING STRUCTS ENUMS etc
;; if have typename and want to keep it, then change
;; (typename "foo_t")
;; to
;; (typename (@ (base "struct")) "foo_t")
;; ALSO
;; (make-proxy comp-udecl) => udecl
;; (revert-proxy udecl) => comp-udecl
(define-module (nyacc lang c99 util2)
#:export (tree->udict
stripdown stripdown-2
udecl->mspec
udecl->mspec/comm
unwrap-decl
canize-enum-def-list
fix-fields
fixed-width-int-names
match-decl match-comp-decl
declr->ident
expand-decl-typerefs
)
#:use-module (nyacc lang c99 pprint)
#:use-module (ice-9 pretty-print)
#:use-module (srfi srfi-1)
#:use-module ((sxml fold) #:select (foldts foldts*))
#:use-module (sxml match)
#:use-module (nyacc lang util)
#:use-module (nyacc lang c99 pprint)
)
;; Use the term @dfn{udecl}, or unit-declaration, for a declaration which has
;; only one decl-item. That is where,
;; @example
;; @end example
;; (decl (decl-spec-list ...) (init-declr-list (init-declr ...) ...))
;; @noindent
;; has been replaced by
;; (decl (decl-spec-list ...) (init-declr ...))
;; ...
;; @example
;; @end example
;; mspec is
;; ("foo" (pointer-to) (array-of 3) (fixed-type "unsigned int"))
;; which can be converted to
;; ("(*foo) (array-of 3) (fixed-type "unsigned int"))
;; which can be converted to
;; (("((*foo)[0])" (fixed-type "unsigned int"))
;; ("((*foo)[1])" (fixed-type "unsigned int"))
;; ("((*foo)[2])" (fixed-type "unsigned int"))
;; may need to replace (typename "int32_t") with (fixed-type "int32_t")
;; @deffn declr->ident declr => (ident "name")
;; just match the declarator
;; (init-declr <declr> [<initzer>])
;; See also: declr->id-name in body.scm.
(define (declr->ident declr)
(sxml-match declr
((init-declr ,declr . ,rest) (declr->ident declr))
((comp-declr ,declr) (declr->ident declr))
((param-declr ,declr) (declr->ident declr))
((ident ,name) declr)
((array-of ,dir-declr ,array-spec) (declr->ident dir-declr))
((array-of ,dir-declr) (declr->ident dir-declr))
((ptr-declr ,pointer ,dir-declr) (declr->ident dir-declr))
((ftn-declr ,dir-declr ,rest ...) (declr->ident dir-declr))
((scope ,declr) (declr->ident declr))
(,otherwise (throw 'util-error "c99/util2: unknown declarator: " declr))))
;; @deffn unwrap-decl decl seed => seed
;; This is a fold to break up multiple declarators.
;; @example
;; (decl (decl-spec-list ...) (init-declr-list (init-declr ...) ...))
;; =>
;; ((decl (decl-spec-list ...) (init-declr ...))
;; (decl (decl-spec-list ...) (init-declr ...))
;; ...)
;; @end example
(define (unwrap-decl decl seed)
(cond
((not (eqv? 'decl (car decl))) seed)
((< (length decl) 3) seed) ; this should catch struct-ref etc.
(else
(let* ((tag (sx-ref decl 0))
(attr (sx-attr decl))
(spec (sx-ref decl 1)) ; (decl-spec-list ...)
(id-l (sx-ref decl 2)) ; (init-declr-list ...)
(tail (sx-tail decl 3))) ; comment
(let iter ((res seed) (idl (cdr id-l)))
(if (null? idl) res
(let* ((declr (sx-ref (car idl) 1))
(ident (declr->ident declr))
(name (cadr ident)))
(iter (cons (if attr
(cons* tag attr spec (car idl) tail)
(cons* tag spec (car idl) tail))
res)
(cdr idl)))))))))
;; @deffn tree->udict tree => udict
;; Turn a C parse tree into a assoc-list of names and definitions.
;; This will unwrap @code{init-declr-list} into list of decls w/
;; @code{init-declr}.
;; BUG: need to add struct and union defn's: struct foo { int x; };
;; how to deal with this
;; lookup '(struct . "foo"), "struct foo", ???
;; wanted "struct" -> dict but that is not great
;; solution: match-decl => '(struct . "foo") then filter to generate
;; ("struct" ("foo" . decl) ..)
;; ("union" ("bar" . decl) ..)
(define (tree->udict tree)
(if (pair? tree)
;;(reverse (fold match-decl '() (cdr tree)))
(fold match-decl '() (cdr tree))
'()))
;; @deffn match-decl decl seed
;; This procedure is intended to be used with @code{fold}. It breaks up
;; up the init-declr-list into individual init-declr items and associates
;; with the identifier being declared. So this is a fold iterator to
;; provide a dictionary of declared names.
;; @example
;; (decl (decl-spec-list ...) (init-declr-list (init-declr ...) ...))
;; @end example
;; @noindent
;; has been replaced by
;; @example
;; (decl (decl-spec-list ...) (init-declr ...))
;; (decl (decl-spec-list ...) ...)
;; @end example
;; Here we generate a dictionary of all declared items:
;; @example
;; (let* ((sx0 (with-input-from-file src-file parse-c))
;; (sx1 (merge-inc-trees! sx0))
;; (name-dict (fold match-decl-1 '() (cdr sx1))))
;; @end example
(define (match-decl decl seed)
(let* ((tag (sx-ref decl 0)) (attr (sx-attr decl)))
(case tag
((decl)
(let* ((spec (sx-ref decl 1)) ; (decl-spec-list ...)
(tbd (sx-ref decl 2))) ; (init-declr-list ...) OR ...
(cond
((or (not tbd) (eqv? 'comment (sx-tag tbd)))
(display "ISSUE: some decls have no init-declr-list\n")
;; no init-declr-list => struct or union def
;;(display "spec:\n") (pretty-print spec)
(sxml-match spec
((decl-spec-list
(type-spec
(struct-def (ident ,name) . ,rest2) . ,rest1))
(acons `(struct . ,name) decl seed))
((decl-spec-list
(type-spec
(union-def (ident ,name) . ,rest2) . ,rest1))
(acons `(union . ,name) decl seed))
(,otherwise
(display "otherwise:\n") (pretty-print (cdr spec))
seed)))
(else ;; decl with init-declr-list
(let* ((id-l tbd) (tail (sx-tail decl 3)))
(let iter ((res seed) (idl (cdr id-l)))
(if (null? idl) res
(let* ((declr (sx-ref (car idl) 1))
(ident (declr->ident declr))
(name (cadr ident)))
(iter
(acons name
(if attr
(cons* tag attr spec (car idl) tail)
(cons* tag spec (car idl) tail))
res)
(cdr idl))))))))))
(else seed))))
;; @deffn match-comp-decl decl seed
;; This will turn
;; @example
;; (comp-decl (decl-spec-list (type-spec "int"))
;; (comp-decl-list (comp-decl (ident "a")) (comp-decl (ident "b"))))
;; @end example
;; @noindent
;; into
;; @example
;; ("a" . (comp-decl (decl-spec-list ...) (comp-decl (ident "a"))))
;; ("b" . (comp-decl (decl-spec-list ...) (comp-decl (ident "b"))))
;; @end example
;; @noindent
;; This is coded to be used with fold-right in order to preserve order
;; in @code{struct} and @code{union} field lists.
(define (match-comp-decl decl seed)
(if (not (eqv? 'comp-decl (car decl))) seed
(let* ((tag (sx-ref decl 0))
(attr (sx-attr decl))
(spec (sx-ref decl 1)) ; (type-spec ...)
(id-l (sx-ref decl 2)) ; (init-declr-list ...)
(tail (sx-tail decl 3))) ; opt comment, different here
;;(simple-format #t "1: ~S\n" id-l)
(let iter ((res seed) (idl (cdr id-l)))
(if (null? idl) res
(let* ((declr (sx-ref (car idl) 1))
(ident (declr->ident declr))
(name (cadr ident)))
;;(pretty-print `(comp-decl ,spec ,(car idl) . ,tail))
(acons name
(if attr
(cons* tag attr spec (car idl) tail)
(cons* tag spec (car idl) tail))
(iter res (cdr idl)))))))))
;; @deffn find-special udecl-alist seed => ..
;; NOT DONE
;; @example
;; '((struct . ("foo" ...) ...)
;; (union . ("bar" ...) ...)
;; (enum . ("bar" ...) ...)
;; seed)
;; @end example
(define (find-special udecl-alist seed)
(let iter ((struct '()) (union '()) (enum '()) (udal udecl-alist))
(if (null? udal) (cons* (cons 'struct struct)
(cons 'union union)
(cons 'enum enum)
seed)
'())))
(define tmap-fmt
'(("char" "%hhd")
("unsigned char" "%hhu")
("short int" "%hd")
("unsigned short int" "%hu")
("int" "%d")
("unsigned int" "%u")
("long int" "%ld")
("unsigned long int" "%lu")
("long long int" "%lld")
("unsigned long long int" "%llu")))
(define fixed-width-int-names
'("int8_t" "uint8_t" "int16_t" "uint16_t"
"int32_t" "uint32_t" "int64_t" "uint64_t"))
;; @deffn typedef-decl? decl)
(define (typedef-decl? decl)
(sxml-match decl
((decl (decl-spec-list (stor-spec (typedef)) . ,r1) . ,r2) #t)
(,otherwise #f)))
;; @deffn splice-declarators orig-declr tdef-declr =>
;; Splice the original declarator into the typedef declarator.
;; This is a helper for @code{expand-*-typename-ref} procecures.
(define (splice-declarators orig-declr tdef-declr)
(define (fD seed tree) ; => (values seed tree)
(sxml-match tree
((param-list . ,rest) (values tree '())) ; don't process
((ident ,name) (values (reverse (cadr orig-declr)) '())) ; replace
(,otherwise (values '() tree))))
(define (fU seed kseed tree)
(let ((ktree (case (car kseed)
((param-list ident) kseed)
(else (reverse kseed)))))
(if (null? seed) ktree (cons ktree seed))))
(define (fH seed tree)
(cons tree seed))
;; This cons transfers the tag from orig-declr to the result.
(cons
(car orig-declr) ; init-declr or comp-declr
(cdr (foldts* fD fU fH '() tdef-declr)))) ; always init-declr
;; @deffn repl-typespec decl-spec-list replacement
;; This is a helper for expand-decl-typerefs
(define (repl-typespec decl-spec-list replacement)
(fold-right
(lambda (item seed)
(cond ((symbol? item) (cons item seed))
((eqv? 'type-spec (car item))
(if (pair? (car replacement))
(append replacement seed)
(cons replacement seed)))
(else (cons item seed))))
'() decl-spec-list))
;; @deffn expand-decl-typerefs udecl udecl-dict => udecl
;; Given a declaration or component-declaration, expand all typename,
;; struct, union and enum refs.
;; @example
;; typedef const int (*foo_t)(int a, double b);
;; extern foo_t fctns[2];
;; @noindent
;; This routine should create an init-declarator associated with
;; @end example
;; extern {const int} (*{fctns[2]})(int a, double b);
;; @end example
;; @noindent
;; Cool. Eh? (but is it done?)
(define* (expand-decl-typerefs udecl udecl-dict #:key (keep '()))
(display "FIXME: some decls have no init-declr-list\n")
;; between adding (init-declr-list) to those or having predicate
;; (has-init-declr? decl)
(let* ((tag (sx-tag udecl)) ; decl or comp-decl
(attr (sx-attr udecl)) ; (@ ...)
(specl (sx-ref udecl 1)) ; decl-spec-list
(declr (or (sx-find 'init-declr udecl)
(sx-find 'comp-declr udecl)))
(tail (if declr (sx-tail udecl 3) (sx-tail udecl 2))) ; opt comment
(tspec (cadr (sx-find 'type-spec specl))))
;;(simple-format #t "=D> ~S\n" decl-spec-list)
;;(simple-format #t "init-declr: ~S\n" init-declr)
(case (car tspec)
((typename)
(cond
((member (cadr tspec) keep)
udecl)
#;((member (cadr tspec) fixed-width-int-names)
;; Convert it to @code{fixed-type}.
(let* ((name (cadr tspec))
(fixd-tspec `(type-spec (fixed-type ,name)))
(fixd-specl (repl-typespec specl fixd-tspec))
;; TODO add attr
(fixed-udecl (cons* tag fixd-specl declr tail)))
;;(expand-decl-typerefs fixed-udecl udecl-dict))) ; not needed ?
fixed-udecl))
(else
;; splice in the typedef
(let* ((name (sx-ref tspec 1))
(decl (assoc-ref udecl-dict name)) ; decl for typename
(tdef-specl (sx-ref decl 1)) ; decl-spec-list for typename
(tdef-declr (sx-ref decl 2)) ; init-declr for typename
;; splice the typedef specifiers into target:
(fixd-specl (repl-typespec specl (sx-tail tdef-specl 2)))
(fixd-declr (splice-declarators declr tdef-declr))
(fixed-udecl (cons* tag fixd-specl fixd-declr tail)))
(expand-decl-typerefs fixed-udecl udecl-dict #:keep keep)))))
((struct-ref union-ref)
(simple-format (current-error-port)
"+++ c99/util2: struct/union-ref: more to do?\n")
;;(simple-format #t "\nstruct-ref:\n") (pretty-print udecl)
udecl)
((struct-def union-def)
(let* ((ident (sx-find 'ident tspec))
(field-list (sx-find 'field-list tspec))
(orig-flds (cdr field-list))
(unit-flds (map cdr (fold-right match-comp-decl '() orig-flds)))
(fixd-flds (map
(lambda (fld)
(expand-decl-typerefs fld udecl-dict #:keep keep))
unit-flds))
(fixd-tspec
(if #f ;;ident
`(type-spec (struct-def ,ident (field-list ,@fixd-flds)))
`(type-spec (struct-def (field-list ,@fixd-flds)))))
(fixd-specl (repl-typespec specl fixd-tspec)))
(if declr (cons* tag fixd-specl declr tail)
(cons* tag fixd-specl tail))))
((enum-def)
(let* ((enum-def-list (sx-find 'enum-def-list tspec))
(fixd-def-list (canize-enum-def-list enum-def-list))
(fixd-tspec `(type-spec (enum-def ,fixd-def-list)))
(fixd-specl (repl-typespec specl fixd-tspec))
(fixed-decl (cons* tag fixd-specl declr tail))) ;; !!!
fixed-decl))
((enum-ref)
(simple-format (current-error-port) "chack: enum-ref NOT DONE\n")
udecl)
(else udecl))))
;; @deffn canize-enum-def-list
;; Fill in constants for all entries of an enum list.
(define (canize-enum-def-list enum-def-list)
(define (get-used edl)
(let iter ((uzd '()) (edl edl))
(cond
((null? edl) uzd)
((assq-ref (cdar edl) 'p-expr) =>
(lambda (x)
(iter (cons (string->number (cadar x)) uzd) (cdr edl))))
(else
(iter uzd (cdr edl))))))
(let ((used (get-used (cdr enum-def-list))))
(let iter ((rez '()) (ix 0) (edl (cdr enum-def-list)))
(cond
((null? edl) (cons (car enum-def-list) (reverse rez)))
((assq-ref (cdar edl) 'p-expr)
(iter (cons (car edl) rez) ix (cdr edl)))
(else
(let* ((ix1 (let iter ((ix (1+ ix)))
(if (memq ix used) (iter (1+ ix)) ix)))
(is1 (number->string ix1)))
(iter (cons (append (car edl) `((p-expr (fixed ,is1)))) rez)
ix1 (cdr edl))))))))
;; @deffn stripdown udecl decl-dict => decl
;; 1) remove stor-spec
;; 2) expand typenames
;; @example
;; typedef int *x_t;
;; x_t a[10];
;; (spec (typename x_t)) (init-declr (array-of 10 (ident a)))
;; (spec (typedef) (fixed-type "int")) (init-declr (pointer) (ident "x_t"))
;; =>
;; [TO BE DOCUMENTED]
;; @end example
(define* (stripdown udecl decl-dict #:key (keep '()))
;;(define strip-list '(stor-spec type-qual comment))
(define strip-list '(stor-spec type-qual))
(define (fsD seed tree)
'())
(define (fsU seed kseed tree)
(if (memq (car tree) strip-list)
seed
(if (null? seed)
(reverse kseed)
(cons (reverse kseed) seed))))
(define (fsH seed tree)
(cons tree seed))
(let* ((xdecl (expand-decl-typerefs udecl decl-dict #:keep keep))
(tag (sx-tag xdecl))
(attr (sx-attr xdecl))
(specl (sx-ref xdecl 1))
(declr (sx-ref xdecl 2))
(specl1 (foldts fsD fsU fsH '() specl)))
(list tag specl1 declr)))
;; This one experimental for guile ffi.
(define* (stripdown-2 udecl decl-dict #:key (keep '()))
;;(define strip-list '(stor-spec type-qual comment))
(define strip-list '(stor-spec type-qual))
(define (fsD seed tree)
'())
(define (fsU seed kseed tree)
(if (memq (car tree) strip-list)
seed
(if (null? seed)
(reverse kseed)
(cons (reverse kseed) seed))))
(define (fsH seed tree)
(cons tree seed))
(let* ((speclt (sx-tail udecl 1))) ; decl-spec-list tail
;; don't expand typedefs, structure specs etc,
(cond
((and (eqv? 'stor-spec (caar speclt))
(eqv? 'typedef (cadar speclt)))
udecl)
;; lone struct ref
(else
(let* ((xdecl (expand-decl-typerefs udecl decl-dict #:keep keep))
(tag (sx-tag xdecl))
(attr (sx-attr xdecl))
(specl (sx-ref xdecl 1))
(declr (sx-ref xdecl 2))
(specl1 (foldts fsD fsU fsH '() specl)))
(list tag specl1 declr))))
))
;; @deffn udecl->mspec sudecl
;; Turn a stripped-down unit-declaration into an m-spec.
;; This assumes decls have been run through @code{stripdown}.
(define (udecl->mspec decl . rest)
(define (cnvt-array-size size-spec)
(simple-format #t "cnvt-array-size\n")
(with-output-to-string (lambda () (pretty-print-c99 size-spec))))
(define (unwrap-specl specl)
(let ((tspec (cadadr specl)))
;;(simple-format #t "tspec:\n") (pretty-print tspec)
(sxml-match tspec
((xxx-struct-def (field-list . ,rest))
`(struct-def ,@rest))
(,otherwise
tspec))))
(define (unwrap-declr declr)
(sxml-match declr
((ident ,name)
(list name))
((init-declr ,item)
(unwrap-declr item))
((comp-declr ,item)
(unwrap-declr item))
((ptr-declr (pointer . ,r) ,dir-declr)
(cons '(pointer-to) (unwrap-declr dir-declr)))
((array-of ,dir-declr ,size)
(cons `(array-of ,(cnvt-array-size size)) (unwrap-declr dir-declr)))
((ftn-declr ,dir-declr ,params)
(cons '(function-returning) (unwrap-declr dir-declr)))
((scope ,expr)
(unwrap-declr expr))
(,otherwise
(simple-format #t "unwrap-declr: OTHERWISE\n") (pretty-print otherwise)
;; failed got: (array-of (ident "foo")) FROM const char foo[];
#f)))
(define (find-type-spec decl-spec-list)
(let iter ((tsl (cdr decl-spec-list)))
(if (eqv? 'type-spec (caar tsl)) (car tsl)
(iter (cdr tsl)))))
(let* ((decl-dict (if (pair? rest) (car rest) '()))
(specl (sx-ref decl 1))
(declr (sx-ref decl 2))
(comm (sx-ref decl 3))
(m-specl (unwrap-specl specl))
(m-declr (unwrap-declr declr))
(m-decl (reverse (cons m-specl m-declr))))
m-decl))
(define* (udecl->mspec/comm decl #:optional (dict '()) #:key (def-comm ""))
(let* ((comm (sx-ref decl 3))
(spec (udecl->mspec decl dict)))
(cons* (car spec) (or comm `(comment ,def-comm)) (cdr spec))))
;; @deffn fix-fields flds => flds
;; This will take a list of fields from a struct and remove lone comments.
;; If a field following a lone comment has no code-comment, the lone comment
;; will be used. For example,
;; @example
;; /* foo */
;; int x;
;; @end example
;; @noindent
;; will be treated as if it was denereed
;; @example
;; int x; /* foo */
;; @end example
;; @noindent
(define (fix-fields flds)
(let iter ((rz '()) (cl '()) (fl flds))
;;(pretty-print fl)
(cond
((null? fl) (reverse rz))
((eqv? 'comment (caar fl))
(iter rz (cons (cadar fl) cl) (cdr fl)))
((eqv? 'comp-decl (caar fl))
(if (eq? 4 (length (car fl)))
(iter (cons (car fl) rz) '() (cdr fl)) ; has comment
(let* ((cs (apply string-append (reverse cl))) ; add comment
(fd (append (car fl) (list (list 'comment cs)))))
(iter (cons fd rz) '() (cdr fl)))))
(else
(error "bad field")))))
;; --- last line ---

View file

@ -0,0 +1,70 @@
;;; nyacc/lang/c99/xparser.scm - copied from parser.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; C parser
(define-module (nyacc lang c99 xparser)
#:export (parse-cx parse-c99x)
#:use-module (nyacc lex)
#:use-module (nyacc parse)
#:use-module (nyacc lang util)
#:use-module (nyacc lang c99 cpp)
#:use-module ((srfi srfi-9) #:select (define-record-type))
#:use-module ((sxml xpath) #:select (sxpath))
)
(include-from-path "nyacc/lang/c99/mach.d/c99xtab.scm")
(include-from-path "nyacc/lang/c99/body.scm")
(include-from-path "nyacc/lang/c99/mach.d/c99xact.scm")
;; Parse given a token generator. Uses fluid @code{*info*}.
(define raw-parser
(make-lalr-parser
(list
(cons 'len-v len-v)
(cons 'pat-v pat-v)
(cons 'rto-v rto-v)
(cons 'mtab mtab)
(cons 'act-v act-v))))
(define (run-parse)
(let ((info (fluid-ref *info*)))
(raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
;; @item parse-cx [#:cpp-defs def-a-list] [#:debug bool]
;; This needs to be explained in some detail.
;; [#:tyns '("foo_t")]
(define* (parse-c99x xstr
#:key (cpp-defs '()) (tn-dict '()) (debug #f) (tyns '()))
(catch
'parse-error
(lambda ()
(let ((info (make-cpi debug cpp-defs '(".") tn-dict)))
(set-cpi-ptl! info (cons tyns (cpi-ptl info)))
(with-fluid*
*info* info
(lambda ()
(with-input-from-string xstr
(lambda ()
(raw-parser (gen-c-lexer #:mode 'code) #:debug debug)))))))
(lambda (key fmt . rest)
(apply simple-format (current-error-port) (string-append fmt "\n") rest)
#f)))
(define parse-cx parse-c99x)
;; --- last line ---

View file

@ -0,0 +1,66 @@
;;; nyacc/lang/calc/parser
;;;
;;; Copyright (C) 2015,2016 Matthew R. Wette
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (nyacc lang calc parser)
#:export (calc-parse calc-spec calc-mach)
#:use-module (nyacc lalr)
#:use-module (nyacc lex)
#:use-module (nyacc parse)
)
(define calc-spec
(lalr-spec
(prec< (left "+" "-") (left "*" "/"))
(start stmt-list-proxy)
(grammar
(stmt-list-proxy
(stmt-list "\n" ($$ `(stmt-list ,@(reverse $1)))))
(stmt-list
(stmt ($$ (list $1)))
(stmt-list ";" stmt ($$ (cons $3 $1))))
(stmt
(ident "=" expr ($$ `(assn-stmt ,$1 ,$3)))
(expr ($$ `(expr-stmt ,$1)))
( ($$ '(empty-stmt))))
(expr
(expr "+" expr ($$ `(add ,$1 ,$3)))
(expr "-" expr ($$ `(sub ,$1 ,$3)))
(expr "*" expr ($$ `(mul ,$1 ,$3)))
(expr "/" expr ($$ `(div ,$1 ,$3)))
($fixed ($$ `(fixed ,$1)))
($float ($$ `(float ,$1)))
("(" expr ")" ($$ $2)))
(ident ($ident ($$ `(ident ,$1))))
)))
(define calc-mach
(compact-machine
(hashify-machine
(make-lalr-machine calc-spec))))
(define calc-parse
(let ((gen-lexer (make-lexer-generator (assq-ref calc-mach 'mtab)
#:space-chars " \t"))
(parser (make-lalr-ia-parser calc-mach)))
(lambda* (#:key (debug #f)) (parser (gen-lexer) #:debug debug))))
;; --- last line ---

398
module/nyacc/lang/util.scm Normal file
View file

@ -0,0 +1,398 @@
;;; module/nyacc/util.scm
;;;
;;; Copyright (C) 2015 Matthew R. Wette
;;;
;;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
;;; or any later version published by the Free Software Foundation. See the
;;; file COPYING included with the nyacc distribution.
;; runtime utilities for the parsers -- needs work
(define-module (nyacc lang util)
#:export (lang-crn-lic
push-input pop-input reset-input-stack
make-tl tl->list ;; rename?? to tl->sx for sxml-expr
tl-append tl-insert tl-extend tl+attr
sx-tag
sx-attr sx-attr-ref sx-has-attr? sx-set-attr! sx-set-attr*
sx-ref sx-tail sx-find
;; for pretty-printing
make-protect-expr make-pp-formatter make-pp-formatter/ugly
;; for ???
move-if-changed
fmterr)
#:use-module ((srfi srfi-1) #:select(find))
)
;; This is a generic copyright/licence that will be printed in the output
;; of the examples/nyacc/lang/*/ actions.scm and tables.scm files.
(define lang-crn-lic "Copyright (C) 2015,2016 Matthew R. Wette
This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
or any later version published by the Free Software Foundation. See the
file COPYING included with the this distribution.")
(define (fmterr fmt . args)
(apply simple-format (current-error-port) fmt args))
;; === input stack =====================
(define *input-stack* (make-fluid '()))
(define (reset-input-stack)
(fluid-set! *input-stack* '()))
(define (push-input port)
(let ((curr (current-input-port))
(ipstk (fluid-ref *input-stack*)))
(fluid-set! *input-stack* (cons curr ipstk))
(set-current-input-port port)))
;; Return #f if empty
(define (pop-input)
(let ((ipstk (fluid-ref *input-stack*)))
(if (null? ipstk) #f
(begin
(set-current-input-port (car ipstk))
(fluid-set! *input-stack* (cdr ipstk))))))
;; It may be possible to reimplement with closures, using soft-ports.
;; (push-string-input ...
#|
(define (push-string-input str)
(let* ((prev (current-input-port))
(port (make-soft-port ...))
)
#f))
|#
;; === tl ==============================
;; @section Tagged Lists
;; Tagged lists are
;; They are implemented as a cons cell with the car and the cdr a list.
;; The cdr is used to accumulate appended items and the car is used to
;; keep the tag, attributes and inserted items.
;; @example
;; tl => '(H . T), H => (c a b 'tag); T =>
;; @end example
;; @table code
;; @deffn make-tl tag [item item ...]
;; Create a tagged-list structure.
(define (make-tl tag . rest)
(let iter ((tail tag) (l rest))
(if (null? l) (cons '() tail)
(iter (cons (car l) tail) (cdr l)))))
;; @deffn tl->list tl
;; Convert a tagged list structure to a list. This collects added attributes
;; and puts them right after the (leading) tag, resulting in something like
;; @example
;; (<tag> (@ <attr>) <rest>)
;; @end example
(define (tl->list tl)
(let ((heda (car tl))
(head (let iter ((head '()) (attr '()) (tl-head (car tl)))
(if (null? tl-head)
(if (pair? attr)
(cons (cons '@ attr) (reverse head))
(reverse head))
(if (and (pair? (car tl-head)) (eq? '@ (caar tl-head)))
(iter head (cons (cdar tl-head) attr) (cdr tl-head))
(iter (cons (car tl-head) head) attr (cdr tl-head)))))))
(let iter ((tail '()) (tl-tail (cdr tl)))
(if (pair? tl-tail)
(iter (cons (car tl-tail) tail) (cdr tl-tail))
(cons tl-tail (append head tail))))))
;; @deffn tl-insert tl item
;; Insert item at front of tagged list (but after tag).
(define (tl-insert tl item)
(cons (cons item (car tl)) (cdr tl)))
;; @deffn tl-append tl item ...
;; Append item at end of tagged list.
(define (tl-append tl . rest)
(cons (car tl)
(let iter ((tail (cdr tl)) (items rest))
(if (null? items) tail
(iter (cons (car items) tail) (cdr items))))))
;; @deffn tl-extend tl item-l
;; Extend with a list of items.
(define (tl-extend tl item-l)
(apply tl-append tl item-l))
;; @deffn tl+attr tl key val)
;; Add an attribute to a tagged list. Return the tl.
;; @example
;; (tl+attr tl 'type "int")
;; @end example
(define (tl+attr tl key val)
(tl-insert tl (cons '@ (list key val))))
;; @deffn tl-merge tl tl1
;; Merge guts of phony-tl @code{tl1} into @code{tl}.
(define (tl-merge tl tl1)
(error "not implemented (yet)")
)
;; === sx ==============================
;; @section SXML Utility Procedures
;; @deffn sx-ref sx ix => item
;; Reference the @code{ix}-th element of the list, not counting the optional
;; attributes item. If the list is shorter than the index, return @code{#f}.
;; @example
;; (sx-ref '(abc "def") 1) => "def"
;; (sx-ref '(abc (@ (foo "1")) "def") 1) => "def"
;; @end example
(define (sx-ref sx ix)
(define (list-xref l x) (if (> (length l) x) (list-ref l x) #f))
(cond
((zero? ix) (car sx))
((and (pair? (cadr sx)) (eqv? '@ (caadr sx)))
(list-xref sx (1+ ix)))
(else
(list-xref sx ix))))
;; @deffn sx-tag sx => tag
;; Return the tag for a tree
(define (sx-tag sx)
(if (pair? sx) (car sx) #f))
;; @deffn sx-tail sx ix => (list)
;; Return the tail starting at the ix-th cdr, starting from 0.
;; For example, if sx has 3 items then (sx-tail sx 2) returns '().
;; BUG: not working for (sx '(foo) 1)
(define (sx-tail sx ix)
(if (zero? ix) (error "zero index not supported"))
(let ((sx (cdr sx)) (ix (1- ix)))
(cond
((and (null? sx) (zero? ix)) sx)
((and (pair? (car sx)) (eqv? '@ (caar sx))) (list-tail sx (1+ ix)))
(else (list-tail sx ix)))))
;; @deffn sx-has-attr? sx
;; p to determine if @arg{sx} has attributes.
(define (sx-has-attr? sx)
(and (pair? (cdr sx)) (pair? (cadr sx)) (eqv? '@ (caadr sx))))
;; @deffn sx-attr sx => '(@ ...)|#f
;; @example
;; (sx-attr '(abc (@ (foo "1")) def) 1) => '(@ (foo "1"))
;; @end example
(define (sx-attr sx)
(if (and (pair? (cdr sx)) (pair? (cadr sx)))
(if (eqv? '@ (caadr sx))
(cadr sx)
#f)
#f))
;; @deffn sx-attr-ref sx key => val
;; Return an attribute value given the key, or @code{#f}.
(define (sx-attr-ref sx key)
(and=> (sx-attr sx)
(lambda (attr)
(and=> (assq-ref (cdr attr) key) car))))
;; @deffn sx-set-attr! sx key val
;; Set attribute for sx. If no attributes exist, if key does not exist,
;; add it, if it does exist, replace it.
(define (sx-set-attr! sx key val . rest)
(if (sx-has-attr? sx)
(let ((attr (cadr sx)))
(set-cdr! attr (assoc-set! (cdr attr) key (list val))))
(set-cdr! sx (cons `(@ (,key ,val)) (cdr sx))))
sx)
;; @deffn sx-set-attr* sx key val [key val [key ... ]]
;; Set attribute for sx. If no attributes exist, if key does not exist,
;; add it, if it does exist, replace it.
(define (sx-set-attr* sx . rest)
(let iter ((attr (or (and=> (sx-attr sx) cdr) '())) (kvl rest))
(cond
((null? kvl) (cons* (sx-tag sx) (cons '@ (reverse attr)) (sx-tail sx 1)))
(else (iter (cons (list (car kvl) (cadr kvl)) attr) (cddr kvl))))))
;; @deffn sx-find tag sx => ((tag ...) (tag ...))
;; Find the first matching element (in the first level).
(define (sx-find tag sx)
(find (lambda (node)
(and (pair? node) (eqv? tag (car node))))
sx))
;;; === pp ==========================
;; @section Pretty-Print and Other Utility Procedures
;; @deffn make-protect-expr op-prec op-assc => side op expr => #t|#f
;; Generate procedure @code{protect-expr} for pretty-printers, which takes
;; the form @code{(protect-expr? side op expr)} and where @code{side}
;; is @code{'lval} or @code{'rval}, @code{op} is the operator and @code{expr}
;; is the expression. The argument @arg{op-prec} is a list of equivalent
;; operators in order of decreasing precedence and @arg{op-assc} is an
;; a-list of precedence with keys @code{'left}, @code{'right} and
;; @code{nonassoc}.
;; @example
;; (protect-expr? 'lval '+ '(mul ...)) => TBD
;; @end example
(define (make-protect-expr op-prec op-assc)
(define (assc-lt? op)
(memq op (assq-ref op-assc 'left)))
(define (assc-rt? op)
(memq op (assq-ref op-assc 'right)))
;; @deffn prec a b => '>|'<|'=|#f
;; Returns the prececence relation of @code{a}, @code{b} as
;; @code{<}, @code{>}, @code{=} or @code{#f} (no relation).
(define (prec a b)
(let iter ((ag #f) (bg #f) (opg op-prec)) ;; a-group, b-group
(cond
((null? opg) #f) ; indeterminate
((memq a (car opg))
(if bg '<
(if (memq b (car opg)) '=
(iter #t bg (cdr opg)))))
((memq b (car opg))
(if ag '>
(if (memq a (car opg)) '=
(iter ag #t (cdr opg)))))
(else
(iter ag bg (cdr opg))))))
(lambda (side op expr)
(let ((assc? (case side
((lt left) assc-rt?)
((rt right) assc-lt?)))
(vtag (car expr)))
(case (prec op vtag)
((>) #t)
((<) #f)
((=) (assc? op))
(else #f)))))
;; @deffn make-pp-formatter => fmtr
;; @example
;; (fmtr 'push) ;; push indent level
;; (fmtr 'pop) ;; pop indent level
;; (fmtr "fmt" arg1 arg2 ...)
;; @end example
(define* (make-pp-formatter)
(letrec
((maxcol 78)
(maxind 36)
(column 0)
(ind-lev 0)
(ind-len 0)
(blanks " ")
(ind-str (lambda () (substring blanks 0 ind-len)))
(cnt-str (lambda () (substring blanks 0 (+ 4 ind-len))))
;;(sf-nl (lambda () (newline) (set! column 0)))
(push-il
(lambda ()
(set! ind-lev (min maxind (1+ ind-lev)))
(set! ind-len (* 2 ind-lev))))
(pop-il
(lambda ()
(set! ind-lev (max 0 (1- ind-lev)))
(set! ind-len (* 2 ind-lev))))
(sf
(lambda (fmt . args)
(let* ((str (apply simple-format #f fmt args))
(len (string-length str)))
(when (zero? column)
(display (ind-str))
(set! column (+ column ind-len)))
(when (> (+ column len) maxcol)
(newline)
(display (cnt-str))
(set! column (+ column ind-len 4)))
(display str)
(when (and (positive? len)
(eqv? #\newline (string-ref str (1- len))))
(set! column 0))))))
(lambda (arg0 . rest)
(cond
((string? arg0) (apply sf arg0 rest))
((eqv? 'push arg0) (push-il))
((eqv? 'pop arg0) (pop-il))
((eqv? 'nlin arg0) ;; newline if needed
(cond ((positive? column) (newline) (set! column 0))))
(else (error "pp-formatter: bad args"))
))))
;; @deffn make-pp-formatter/ugly => fmtr
;; Makes a @code{fmtr} like @code{make-pp-formatter} but no indentation
;; and just adds strings on ...
(define* (make-pp-formatter/ugly)
(let*
((maxcol 78)
(column 0)
(sf (lambda (fmt . args)
(let* ((str (apply simple-format #f fmt args))
(len (string-length str)))
(cond
((char=? #\# (string-ref str 0))
(display str))
(else
(when (> (+ column len) maxcol)
(newline)
(set! column 0))
(if (char=? #\newline (string-ref str (1- len)))
(string-set! str (1- len) #\space))
(display str)
(set! column (+ column len))))))))
(lambda (arg0 . rest)
(cond
((string? arg0) (apply sf arg0 rest))
((eqv? 'nlin arg0) ;; newline if needed
(cond ((positive? column) (newline) (set! column 0))))
((eqv? 'push arg0) #f)
((eqv? 'pop arg0) #f)
(else (error "pp-formatter/ugly: bad args"))))))
;; @deffn move-if-changed src-file dst-file [sav-file]
;; Return @code{#t} if changed.
(define (move-if-changed src-file dst-file . rest)
(define (doit)
(let ((sav-file (if (pair? rest) (car rest) #f)))
(if (and sav-file (access? sav-file W_OK))
(system (simple-format #f "mv ~A ~A" dst-file sav-file)))
(system (simple-format #f "mv ~A ~A" src-file dst-file))
#t))
(cond
;; src-file does not exist
((not (access? src-file R_OK)) #f)
;; dst-file does not exist, update anyhow
((not (access? dst-file F_OK))
(system (simple-format #f "mv ~A ~A" src-file dst-file)) #t)
;; both exist, but no changes
((zero? (system
(simple-format #f "cmp ~A ~A >/dev/null" src-file dst-file)))
(system (simple-format #f "rm ~A" src-file)) #f)
;; both exist, update
((access? dst-file W_OK)
(doit))
(else
(simple-format (current-error-port) "move-if-changed: no write access\n")
#f)))
;; @end table
;;; --- last line ---

523
module/nyacc/lex.scm Normal file
View file

@ -0,0 +1,523 @@
;;; nyacc/lex.scm
;;;
;;; Copyright (C) 2015,2016 - Matthew R.Wette
;;;
;;; This library is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU Lesser General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public License
;;; along with this library; if not, see <http://www.gnu.org/licenses/>
;; A module providing procedures for constructing lexical analyzers.
;; '$fixed '$float '$string '$chlit '$ident
;; todo: change lexer to return @code{cons-source} instead of @code{cons}
;; todo: to be fully compliant, C readers need to deal with \ at end of line
;; todo: figure out what readers return atoms and which pairs
;; tokens: read-c-ident
;; pairs: num-reader read-c-num read-c-string
;; issue: if returning pairs we need this for hashed parsers:
;; (define (assc-$ pair) (cons (assq-ref symbols (car pair)) (cdr pair)))
;; read-comm changed to (read-comm ch bol) where bol is begin-of-line cond
;;
;; read-c-ident
(define-module (nyacc lex)
#:export (make-lexer-generator
make-ident-reader
make-comm-reader
make-string-reader
make-chseq-reader
make-num-reader
eval-reader
make-like-ident-p
read-c-ident
read-c-comm
read-c-string
read-c-chlit
read-c-num
read-oct read-hex
like-c-ident?
filter-mt remove-mt map-mt make-ident-like-p
c:ws c:if c:ir)
#:use-module ((srfi srfi-1) #:select (remove append-reverse))
#:use-module (ice-9 pretty-print)
)
;; @section Constructing Lexical Analyzers
;; The @code{lex} module provides a set of procedures to build lexical
;; analyzers. The approach is to first build a set of @defn{readers} for
;; MORE TO COME
;;
;; Readers are procecures that take one character (presumably from the
;; current-input-port) and determine try to make a match. If a match is
;; made something is returned, with any lookaheads pushed back into the
;; input port. If no match is made @code{#f} is returned and the input
;; argument is still the character to work on.
;;
;; Here are the procedures used:
;; @table @code
(define digit "0123456789")
(define ucase "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(define lcase "abcdefghijklmnopqrstuvwxyz")
;; C lexemes are popular so include those.
;;(define c:ws (list->char-set '(#\space #\tab #\newline #\return )))
(define c:ws char-set:whitespace)
(define c:if (let ((cs (char-set #\_))) ; ident, first char
(string->char-set! ucase cs)
(string->char-set! lcase cs)))
(define c:ir (string->char-set digit c:if)) ; ident, rest chars
(define c:nx (string->char-set "eEdD")) ; number exponent
(define c:hx (string->char-set "abcdefABCDEF"))
;; @deffn eval-reader reader string => result
;; For test and debug, this procedure will evaluate a reader on a string.
;; A reader is a procedure that accepts a single character argument intended
;; to match a specific character sequence. A reader will read more characters
;; by evaluating @code{read-char} until it matches or fails. If it fails, it
;; will pushback all characters read via @code{read-char} and return @code{#f}.
;; If it succeeds the input pointer will be at the position following the
;; last matched character.
(define (eval-reader reader string)
(with-input-from-string string
(lambda () (reader (read-char)))))
;; @deffn make-space-skipper chset => proc
;; This routine will generate a reader to skip whitespace.
(define (make-space-skipper chset)
(lambda (ch)
(if (char-set-contains? chset ch)
(let iter ((ch (read-char)))
(cond
((char-set-contains? chset ch)
(iter (read-char)))
(else
(unread-char ch)
#t)))
#f)))
;; @deffn skip-c-space ch => #f|#t
;; If @code{ch} is space, skip all spaces, then return @code{#t}, else
;; return @code{#f}.
(define skip-c-space (make-space-skipper c:ws))
;; @deffn make-ident-reader cs-first cs-rest => ch -> #f|string
;; For identifiers, given the char-set for first character and the char-set
;; for following characters, return a return a reader for identifiers.
;; The reader takes a character as input and returns @code{#f} or @code{string}.
(define (make-ident-reader cs-first cs-rest)
(lambda (ch)
(if (char-set-contains? cs-first ch)
(let iter ((chl (list ch)) (ch (read-char)))
(cond
((eof-object? ch)
(if (null? chl) #f
(list->string (reverse chl))))
((char-set-contains? cs-rest ch)
(iter (cons ch chl) (read-char)))
(else (unread-char ch)
(list->string (reverse chl)))))
#f)))
;; @deffn read-c-ident ch => #f|string
;; If ident pointer at following char, else (if #f) ch still last-read.
(define read-c-ident (make-ident-reader c:if c:ir))
;; @deffn make-ident-like-p ident-reader
;; Generate a predicate, from a reader, that determines if a string qualifies
;; as an identifier.
(define (make-like-ident-p reader)
(lambda (s) (and (string? s) (eval-reader reader s))))
(define make-ident-like-p make-like-ident-p)
(define like-c-ident? (make-like-ident-p read-c-ident))
;; @deffn make-string-reader delim
;; Generate a reader that uses @code{delim} as delimiter for strings.
;; TODO: need to handle matlab-type strings.
;; TODO: need to handle multiple delim's (like python)
(define (make-string-reader delim) ;; #:xxx
(lambda (ch)
(if (eq? ch delim)
(let iter ((cl '()) (ch (read-char)))
(cond ((eq? ch #\\)
(let ((c1 (read-char)))
(if (eq? c1 #\newline)
(iter cl (read-char))
(iter (cons* c1 cl) (read-char)))))
((eq? ch delim) (cons '$string (list->string (reverse cl))))
(else (iter (cons ch cl) (read-char)))))
#f)))
;; @deffn read-oct ch => "0123"|#f
;; Read octal number.
(define read-oct
(let ((cs:oct (string->char-set "01234567")))
(lambda (ch)
(let iter ((cv 0) (ch ch) (n 1))
(cond
((eof-object? ch) cv)
((> n 3) (unread-char ch) cv)
((char-set-contains? cs:oct ch)
(iter (+ (* 8 cv) (- (char->integer ch) 48)) (read-char) (1+ n)))
(else
(unread-char ch)
cv))))))
;; @deffn read-hex ch => "0x7f"|#f
;; Read octal number.
(define read-hex
(let ((cs:dig (string->char-set "0123456789"))
(cs:uhx (string->char-set "ABCDEF"))
(cs:lhx (string->char-set "abcdef")))
(lambda (ch) ;; ch == #\x always
(let iter ((cv 0) (ch (read-char)) (n 0))
(simple-format #t "ch=~S\n" ch)
(cond
((eof-object? ch) cv)
((> n 2) (unread-char ch) cv)
((char-set-contains? cs:dig ch)
(iter (+ (* 16 cv) (- (char->integer ch) 48)) (read-char) (1+ n)))
((char-set-contains? cs:uhx ch)
(iter (+ (* 16 cv) (- (char->integer ch) 55)) (read-char) (1+ n)))
((char-set-contains? cs:lhx ch)
(iter (+ (* 16 cv) (- (char->integer ch) 87)) (read-char) (1+ n)))
(else (unread-char ch) cv))))))
;; @deffn read-c-string ch => ($string . "foo")
;; Read a C-code string. Output to code is @code{write} not @code{display}.
;; Return #f if @var{ch} is not @code{"}.
(define (read-c-string ch)
(if (not (eq? ch #\")) #f
(let iter ((cl '()) (ch (read-char)))
(cond ((eq? ch #\\)
(let ((c1 (read-char)))
(iter
(case c1
((#\newline) cl)
((#\\) (cons #\\ cl))
((#\") (cons #\" cl))
((#\') (cons #\' cl))
((#\n) (cons #\newline cl))
((#\r) (cons #\return cl))
((#\b) (cons #\backspace cl))
((#\t) (cons #\tab cl))
((#\f) (cons #\page cl))
((#\a) (cons #\alarm cl))
((#\v) (cons #\vtab cl))
((#\x) (cons (integer->char (read-hex ch)) cl))
(else
(if (char-numeric? ch)
(cons (integer->char (read-oct ch)) cl)
(cons c1 cl))))
(read-char))))
((eq? ch #\") (cons '$string (list->string (reverse cl))))
(else (iter (cons ch cl) (read-char)))))))
;; @deffn make-chlit-reader
;; Generate a reader for character literals. NOT DONE.
;; For C, this reads @code{'c'} or @code{'\n'}.
(define (make-chlit-reader . rest) (error "NOT IMPLEMENTED"))
;; @deffn read-c-chlit ch
;; @example
;; ... 'c' ... => (read-c-chlit #\') => '($ch-lit . #\c)
;; @end example
(define (read-c-chlit ch)
(if (not (eqv? ch #\')) #f
(let ((c1 (read-char)) (c2 (read-char)))
(if (eqv? c1 #\\)
(let ((c3 (read-char)))
(cons '$chlit
(case c2
((#\0) "\0;") ; nul U+0000 (#\U+...)
((#\a) "\a") ; alert U+0007
((#\b) "\b") ; backspace U+0008
((#\t) "\t") ; horizontal tab U+0009
((#\n) "\n") ; newline U+000A
((#\v) "\v") ; verticle tab U+000B
((#\f) "\f") ; formfeed U+000C
((#\\) "\\") ; backslash
((#\' #\" #\?) (string c2))
(else (error "bad escape sequence")))))
(cons '$chlit (string c1))))))
;; @deffn make-num-reader => (proc ch) => #f|($fixed . "1")|($float . "1.0")
;; This routine will clean by adding "0" before or after dot.
;; TODO: add arg to specify alternate syntaxes (e.g. "0x123")
;; may want to replace "eEdD" w/ "e"
;; integer decimal(#t/#f) fraction exponent looking-at
;; i, f and e are lists of characters
(define (make-num-reader)
;; 0: start; 1: p-i; 2: p-f; 3: p-e-sign; 4: p-e-d; 5: packup
;; Removed support for leading '.' to be a number.
(let ((fix-dot (lambda (l) (if (char=? #\. (car l)) (cons #\0 l) l))))
(lambda (ch1)
;; chl: char list; ty: '$fixed or '$float; st: state; ch: input char
(let iter ((chl '()) (ty #f) (st 0) (ch ch1))
(case st
((0)
(cond
((eof-object? ch) (iter chl ty 5 ch))
((char=? #\0 ch) (iter (cons ch chl) '$fixed 10 (read-char)))
((char-numeric? ch) (iter chl '$fixed 1 ch))
(else #f)))
((10) ;; allow x after 0
(cond
((eof-object? ch) (iter chl ty 5 ch))
((char=? #\x ch) (iter (cons ch chl) ty 1 (read-char)))
(else (iter chl ty 1 ch))))
((1)
(cond
((eof-object? ch) (iter chl ty 5 ch))
((char-numeric? ch) (iter (cons ch chl) ty 1 (read-char)))
((char=? #\. ch) (iter (cons #\. chl) '$float 2 (read-char)))
((char-set-contains? c:hx ch)
(iter (cons ch chl) ty 1 (read-char)))
((char-set-contains? c:if ch) (error "reading number st=1"))
(else (iter chl '$fixed 5 ch))))
((2)
(cond
((eof-object? ch) (iter chl ty 5 ch))
((char-numeric? ch) (iter (cons ch chl) ty 2 (read-char)))
((char-set-contains? c:nx ch)
(iter (cons ch (fix-dot chl)) ty 3 (read-char)))
((char-set-contains? c:if ch) (error "reading number st=2"))
(else (iter (fix-dot chl) ty 5 ch))))
((3)
(cond
((eof-object? ch) (iter chl ty 5 ch))
((or (char=? #\+ ch) (char=? #\- ch))
(iter (cons ch chl) ty 4 (read-char)))
((char-numeric? ch) (iter chl ty 4 ch))
(else (error "syntax3"))))
((4)
(cond
((eof-object? ch) (iter chl ty 5 ch))
((char-numeric? ch) (iter (cons ch chl) ty 4 (read-char)))
((char-set-contains? c:if ch) (error "reading number st=4"))
(else (iter chl ty 5 ch))))
((5)
(unless (eof-object? ch) (unread-char ch))
(cons ty (list->string (reverse chl)))))))))
;; @deffn read-c-num ch => #f|string
;; Reader for unsigned numbers as used in C (or close to it).
(define read-c-num (make-num-reader))
;;.@deffn si-map string-list ix => a-list
;; Convert list of strings to alist of char at ix and strings.
;; This is a helper for make-tree.
(define (si-map string-list ix)
(let iter ((sal '()) (sl string-list))
(cond
((null? sl) sal)
((= ix (string-length (car sl)))
(iter (reverse (acons 'else (car sl) sal)) (cdr sl)))
((assq (string-ref (car sl) ix) sal) =>
(lambda (pair)
(set-cdr! pair (cons (car sl) (cdr pair)))
(iter sal (cdr sl))))
(else ;; Add (#\? . string) to alist.
(iter (cons (cons (string-ref (car sl) ix) (list (car sl))) sal)
(cdr sl))))))
;;.@deffn make-tree strtab -> tree
;; This routine takes an alist of strings and symbols and makes a tree
;; that parses one char at a time and provide @code{'else} entry for
;; signaling sequence found. That is, if @code{("ab" . 1)} is an entry
;; then a chseq-reader (see below) would stop at @code{"ab"} and
;; return @code{1}.
(define (make-tree strtab)
(define (si-cnvt string-list ix)
(map (lambda (pair)
(if (pair? (cdr pair))
(cons (car pair) (si-cnvt (cdr pair) (1+ ix)))
(cons (car pair) (assq-ref strtab (cdr pair)))))
(si-map string-list ix)))
(si-cnvt (map car strtab) 0))
;; @deffn make-chseq-reader strtab
;; Given alist of pairs (string, token) return a function that eats chars
;; until (token . string) is returned or @code{#f} if no match is found.
(define (make-chseq-reader strtab)
;; This code works on the assumption that the else-part is always last
;; in the list of transitions.
(let ((tree (make-tree strtab)))
(lambda (ch)
(let iter ((cl (list ch)) (node tree))
(cond
((assq-ref node (car cl)) => ;; accept or shift next character
(lambda (n)
(if (eq? (caar n) 'else) ; if only else, accept, else read on
(cons (cdar n) (list->string (reverse cl)))
(iter (cons (read-char) cl) n))))
((assq-ref node 'else) => ; else exists, accept
(lambda (tok)
(unread-char (car cl))
(cons tok (list->string (reverse (cdr cl))))))
(else ;; reject
(let pushback ((cl cl))
(unless (null? (cdr cl))
(unread-char (car cl))
(pushback (cdr cl))))
#f))))))
;; @deffn make-comm-reader comm-table [#:eat-newline #t] => \
;; ch bol -> ('$code-comm "..")|('$lone-comm "..")|#f
;; comm-table is list of cons for (start . end) comment.
;; e.g. ("--" "\n") ("/*" "*/")
;; test with "/* hello **/"
;; If @code{eat-newline} is specified as true then for read comments
;; ending with a newline a newline swallowed with the comment.
;; Note: assumes backslash is never part of the end
(define* (make-comm-reader comm-table #:key (eat-newline #f))
(define (mc-read-char)
(let ((ch (read-char)))
(if (eqv? ch #\\)
(let ((ch (read-char)))
(if (eqv? ch #\newline)
(read-char)
(begin (unread-char ch) #\\)))
ch)))
(let ((tree (make-tree comm-table)))
(lambda (ch bol)
(letrec
((tval (if bol '$lone-comm '$code-comm))
(match-beg ;; match start of comment, return end-string
(lambda (cl node)
(cond
((assq-ref node (car cl)) => ;; shift next character
(lambda (n) (match-beg (cons (mc-read-char) cl) n)))
((assq-ref node 'else) =>
(lambda (res) (unread-char (car cl)) res)) ; yuck?
(else
(let pushback ((cl cl))
(unless (null? (cdr cl))
(unread-char (car cl))
(pushback (cdr cl))))
#f))))
(find-end ;; find end of comment, return comment
;; cl: comm char list; sl: shift list; il: input list;
;; ps: pattern string; px: pattern index
(lambda (cl sl il ps px)
(cond
((eq? px (string-length ps))
(if (and (not eat-newline) (eq? #\newline (car sl)))
(unread-char #\newline))
(if (and (pair? cl) (eqv? (car cl) #\cr)) ;; rem trailing \r
(cons tval (list->string (reverse (cdr cl))))
(cons tval (list->string (reverse cl)))))
((null? il) (find-end cl sl (cons (mc-read-char) il) ps px))
((eof-object? (car il)) (error "open comment"))
((eqv? (car il) (string-ref ps px))
(find-end cl (cons (car il) sl) (cdr il) ps (1+ px)))
(else
(let ((il1 (append-reverse sl il)))
(find-end (cons (car il1) cl) '() (cdr il1) ps 0)))))))
(let ((ep (match-beg (list ch) tree)))
(if ep (find-end '() '() (list (mc-read-char)) ep 0) #f))))))
(define read-c-comm (make-comm-reader '(("/*" . "*/") ("//" . "\n"))))
;; @deffn filter-mt p? al => al
;; Filter match-table based on cars of al.
(define (filter-mt p? al) (filter (lambda (x) (p? (car x))) al))
;; @deffn remove-mt p? al => al
;; Remove match-table based on cars of al.
(define (remove-mt p? al) (remove (lambda (x) (p? (car x))) al))
;; @deffn map-mt f al => al
;; Map cars of al.
(define (map-mt f al) (map (lambda (x) (cons (f (car x)) (cdr x))) al))
;; @deffn make-lexer-generator match-table => lexer-generator
;; @example
;; (define gen-lexer (make-lexer-generator #:ident-reader my-id-rdr))
;; (with-input-from-file "foo" (parse (gen-lexer)))
;; @end example
;;
;; Return a thunk that returns tokens.
;; Change this to have user pass the following routines (optionally?)
;; read-num, read-ident, read-comm
;; reztab = reserved ($ident, $fixed, $float ...
;; chrtab = characters
;; comm-reader : if parser does not deal with comments must return #f
;; but problem with character ..
;; match-table:
;; @enumerate
;; symbol -> (string . symbol)
;; reserved -> (symbol . symbol)
;; char -> (char . char)
;; @end enumerate
;; todo: add bol status
(define* (make-lexer-generator match-table
#:key ident-reader num-reader
string-reader chlit-reader
comm-reader comm-skipper
space-chars)
(let* ((read-ident (or ident-reader (make-ident-reader c:if c:ir)))
(read-num (or num-reader (make-num-reader)))
(read-string (or string-reader (make-string-reader #\")))
(read-chlit (or chlit-reader (lambda (ch) #f)))
(read-comm (or comm-reader (lambda (ch bol) #f)))
(skip-comm (or comm-skipper (lambda (ch) #f)))
(spaces (or space-chars " \t\r\n"))
(space-cs (cond ((string? spaces) (string->char-set spaces))
((list? spaces) (list->char-set spaces))
((char-set? spaces) spaces)
(else (error "expecting string list or char-set"))))
;;
(ident-like? (make-ident-like-p read-ident))
;;
(strtab (filter-mt string? match-table)) ; strings in grammar
(kwstab (filter-mt ident-like? strtab)) ; keyword strings =>
(keytab (map-mt string->symbol kwstab)) ; keywords in grammar
(chrseq (remove-mt ident-like? strtab)) ; character sequences
(symtab (filter-mt symbol? match-table)) ; symbols in grammar
(chrtab (filter-mt char? match-table)) ; characters in grammar
;;
(read-chseq (make-chseq-reader chrseq))
(assc-$ (lambda (pair) (cons (assq-ref symtab (car pair)) (cdr pair))))
)
(lambda ()
(let ((bol #f))
(lambda ()
(let iter ((ch (read-char)))
(cond
((eof-object? ch) (assc-$ (cons '$end ch)))
;;((eq? ch #\newline) (set! bol #t) (iter (read-char)))
((char-set-contains? space-cs ch) (iter (read-char)))
((and (eqv? ch #\newline) (set! bol #t) #f))
((read-comm ch bol) =>
(lambda (p) (set! bol #f) (assc-$ p)))
((skip-comm ch) (iter (read-char)))
((read-ident ch) =>
(lambda (s) (or (and=> (assq-ref keytab (string->symbol s))
(lambda (tval) (cons tval s)))
(assc-$ (cons '$ident s)))))
((read-num ch) => assc-$) ; => $fixed or $float
((read-string ch) => assc-$) ; => $string
((read-chlit ch) => assc-$) ; => $chlit
((read-chseq ch) => identity)
((assq-ref chrtab ch) => (lambda (t) (cons t (string ch))))
(else (cons ch ch))))))))) ; should be error
;; @end table
;; --- last line ---

225
module/nyacc/parse.scm Normal file
View file

@ -0,0 +1,225 @@
;;; nyacc/parse.scm
;;;
;;; Copyright (C) 2014-2016 Matthew R. Wette
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 3 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;; make parser that provide list of la-toks to lexer:
;; e.g., if comment not in latok, just throw away
(define-module (nyacc parse)
#:export (make-lalr-parser
make-lalr-ia-parser
)
#:use-module (nyacc util)
#:use-module ((srfi srfi-43) #:select (vector-map vector-for-each))
)
;; @item (machine-hashed? mach) => #t|#f
;; Indicate if the machine has been hashed.
(define (machine-hashed? mach)
(number? (caar (vector-ref (assq-ref mach 'pat-v) 0))))
;; @item make-lalr-parser mach => parser
;; This generates a procedure that takes one argument, a lexical analyzer:
;; @example
;; (parser lexical-analyzer [#:debug #t])
;; @end example
;; and is used as
;; @example
;; (define xyz-parse (make-lalr-parser xyz-mach))
;; (with-input-from-file "sourcefile.xyz" (lambda () (xyz-parse (gen-lexer))))
;; @end example
;; The generated parser is reentrant.
(define* (make-lalr-parser mach)
(let* ((len-v (assq-ref mach 'len-v))
(rto-v (assq-ref mach 'rto-v)) ; reduce to
(pat-v (assq-ref mach 'pat-v))
(actn-v (assq-ref mach 'act-v)) ; unknown action vector
(mtab (assq-ref mach 'mtab))
(xact-v (if (procedure? (vector-ref actn-v 0)) actn-v
(vector-map
;; Turn symbolic action into executable procedures:
(lambda (ix f) (eval f (current-module)))
(vector-map
(lambda (ix actn) (wrap-action actn))
actn-v))))
;;
(dmsg (lambda (s t a) (fmtout "state ~S, token ~S\t=> ~S\n" s t a)))
(hashed (number? (caar (vector-ref pat-v 0)))) ; been hashified?
;;(def (assq-ref mtab '$default))
(def (if hashed -1 '$default))
(end (assq-ref mtab '$end))
(err (assq-ref mtab '$error))
(comm (list (assq-ref mtab '$lone-comm) (assq-ref mtab '$code-comm)))
;; predicate to test for shift action:
(shift? (if hashed
(lambda (a) (positive? a))
(lambda (a) (eq? 'shift (car a)))))
;; On shift, transition to this state:
(shift-to (if hashed (lambda (x) x) (lambda (x) (cdr x))))
;; Predicate to test for reduce action:
(reduce? (if hashed
(lambda (a) (negative? a))
(lambda (a) (eq? 'reduce (car a)))))
;; On reduce, reduce this production-rule:
(reduce-pr (if hashed abs cdr))
;; If error, make the right packet.
(other (if hashed 0 '(other . 0)))
)
(lambda* (lexr #:key debug)
(let iter ((state (list 0)) ; state stack
(stack (list '$@)) ; sval stack
(nval #f) ; prev reduce to non-term val
(lval (lexr))) ; lexical value (from lex'er)
(let* ((tval (car (if nval nval lval))) ; token (syntax value)
(sval (cdr (if nval nval lval))) ; semantic value
(stxl (vector-ref pat-v (car state))) ; state transition xtra
(oact #f) ;; if not shift/reduce, then accept, error or skip
(stx (cond ;; state transition
((assq-ref stxl tval)) ; shift/reduce in table
((memq tval comm) (set! oact 'skip) other)
((assq-ref stxl err)) ; error recovery
((assq-ref stxl def)) ; default action
(else (set! oact 'error) other))))
(if debug (dmsg (car state) (if nval tval sval) stx))
(cond
((shift? stx)
;; We could check here to determine if next transition only has a
;; default reduction and, if so, go ahead and process the reduction
;; without reading another input token. Needed for interactive.
(iter (cons (shift-to stx) state) (cons sval stack)
#f (if nval lval (lexr))))
((reduce? stx)
(let* ((gx (reduce-pr stx)) (gl (vector-ref len-v gx))
($$ (apply (vector-ref xact-v gx) stack)))
(iter (list-tail state gl)
(list-tail stack gl)
(cons (vector-ref rto-v gx) $$)
lval)))
(else ;; other action: skip, error, or accept
(case oact
((skip) (iter state stack nval (lexr)))
((error)
(let ((fn (or (port-filename (current-input-port)) "(unknown)"))
(ln (1+ (port-line (current-input-port)))))
(fmterr "~A:~A: parse failed at state ~A, on input ~S\n"
fn ln (car state) sval)
#f))
(else ;; accept
(car stack))))))))))
;; @item make-lalr-ia-parser mach
;; Make an interactive parser. This will automatically process default
;; redunctions if that is the only choice, and does not wait for '$end to
;; return. This needs algorithm verification. Makes some assumptions that
;; need to be verified.
(define* (make-lalr-ia-parser mach)
(let* ((len-v (assq-ref mach 'len-v))
(rto-v (assq-ref mach 'rto-v)) ; reduce to
(pat-v (assq-ref mach 'pat-v))
(actn-v (assq-ref mach 'act-v)) ; unknown action vector
(mtab (assq-ref mach 'mtab))
(xact-v (if (procedure? (vector-ref actn-v 0)) actn-v
(vector-map
;; Turn symbolic action into executable procedures:
(lambda (ix f) (eval f (current-module)))
(vector-map
(lambda (ix actn) (wrap-action actn))
actn-v))))
;;
(dmsg (lambda (s t a) (fmtout "state ~S, token ~S\t=> ~S\n" s t a)))
(hashed (number? (caar (vector-ref pat-v 0)))) ; been hashified?
;;(def (assq-ref (assq-ref mach 'mtab) '$default))
(def (if hashed -1 '$default))
(end (assq-ref mtab '$end))
;; predicate to test for shift action:
(shift? (if hashed
(lambda (a) (positive? a))
(lambda (a) (eq? 'shift (car a)))))
;; On shift, transition to this state:
(shift-to (if hashed (lambda (x) x) (lambda (x) (cdr x))))
;; predicate to test for reduce action:
(reduce? (if hashed
(lambda (a) (negative? a))
(lambda (a) (eq? 'reduce (car a)))))
;; On reduce, reduce this production-rule:
;;(reduce-pr (if hashed (lambda (a) (abs a)) (lambda (a) (cdr a))))
(reduce-pr (if hashed abs cdr))
;; If no action found in transition list, then this:
(parse-error (if hashed #f (cons 'error 0)))
;; predicate to test for error
(error? (if hashed
(lambda (a) (eq? #f a))
(lambda (a) (eq? 'error (car a)))))
)
(lambda* (lexr #:key debug)
(let iter ((state (list 0)) ; state stack
(stack (list '$@)) ; sval stack
(nval #f) ; prev reduce to non-term val
(lval #f)) ; lexical value (from lex'er)
(let ((stxl (vector-ref pat-v (car state))))
(cond
((eqv? def (caar stxl))
(let* ((stx (cdar stxl))
(gx (reduce-pr stx))
(gl (vector-ref len-v gx))
($$ (apply (vector-ref xact-v gx) stack)))
(if debug (fmtout "state ~S, default => reduce ~S, goto ~S\n"
(car state) gx (list-ref state gl)))
(iter (list-tail state gl) (list-tail stack gl)
(cons (vector-ref rto-v gx) $$) lval)))
((eqv? end (caar stxl)) ; only '$end remains, return for i/a
(if debug (fmtout "in state ~S, looking at '$end => accept\n"
(car state)))
(if (reduce? (cdar stxl))
;; Assuming this is the final reduction ...
(apply (vector-ref xact-v (reduce-pr (cdar stxl))) stack)
;; Or already done ...
(car stack)))
(else
(let* ((laval (or nval (or lval (lexr))))
(tval (car laval)) (sval (cdr laval))
(stx (or (assq-ref stxl tval)
(assq-ref stxl def)
parse-error)))
#;(if debug (fmtout " lval=~S laval=~S\n" lval laval))
(if debug (dmsg (car state) (if nval tval sval) stx))
(cond
((error? stx)
(let ((fn (or (port-filename (current-input-port)) "(???)"))
(ln (1+ (port-line (current-input-port)))))
(fmterr "~A:~A: parse failed at state ~A, on input ~S\n"
fn ln (car state) sval))
#f)
((shift? stx)
(iter (cons (shift-to stx) state) (cons sval stack)
#f (if nval lval #f)))
((reduce? stx)
(let* ((gx (reduce-pr stx)) (gl (vector-ref len-v gx))
($$ (apply (vector-ref xact-v gx) stack)))
(iter (list-tail state gl)
(list-tail stack gl)
(cons (vector-ref rto-v gx) $$)
(if nval lval laval)
)))
(else ;; accept
(car stack)))))))))))
;; @end itemize
;;; --- last line ---

304
module/nyacc/util.scm Normal file
View file

@ -0,0 +1,304 @@
;;; nyacc/util.scm
;;;
;;; Copyright (C) 2014-2016 Matthew R. Wette
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 3 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(define-module (nyacc util)
#:export (
fmtstr fmtout fmterr fmt
wrap-action
obj->str
fixed-point prune-assoc
map-attr->vector
x-flip x-comb
write-vec
ugly-print
tzort
)
#:use-module ((srfi srfi-43) #:select (vector-fold))
)
(define (fmtstr fmt . args)
(apply simple-format #f fmt args))
(define (fmtout fmt . args)
(apply simple-format (current-output-port) fmt args))
(define (fmterr fmt . args)
(apply simple-format (current-error-port) fmt args))
(define fmt simple-format)
;; @item make-arg-list N => '($N $Nm1 $Nm2 ... $1 . $rest)
;; This is a helper for @code{mkact}.
(define (make-arg-list n)
(let ((mkarg
(lambda (i) (string->symbol (string-append "$" (number->string i))))))
(let iter ((r '(. $rest)) (i 1))
(if (> i n) r (iter (cons (mkarg i) r) (1+ i))))))
;; @item wrap-action (n . guts) => `(lambda ($n ... $2 $1 . $rest) ,@guts)
;; Wrap user-specified action (body, as list) of n arguments in a lambda.
;; The rationale for the arglist format is that we can @code{apply} this
;; lambda to the the semantic stack.
(define (wrap-action actn)
(cons* 'lambda (make-arg-list (car actn)) (cdr actn)))
;; @deffn obj->str object => string
;; Convert terminal (symbol, string, character) to string.
;; This is like @code{write} but will prefix symbols with @code{'}.
(define (obj->str obj)
(cond ((string? obj) (simple-format #f "~S" obj))
((symbol? obj) (string-append "'" (symbol->string obj)))
((char? obj) (simple-format #f "~S" obj))))
;; @deffn prune-assoc al
;; Prune obsolete entries from an a-list. This is order n^2.
(define (prune-assoc al)
(let iter ((al1 '()) (al0 al))
(if (null? al0) al1
(iter (if (assoc (caar al0) al1) al1 (cons (car al0) al1)) (cdr al0)))))
;; @deffn fixed-point proc seed
;; .item fixed-point-by-elt proc seed
;; @example
;; proc: element list -> list
;; @end example
;; proc will take an element and insert updates at the front of list
;; and return the list
;; seed is a list
;; fixed-point processes a list
;; The procedure @code{proc} takes as arguments an element from the list
;; and the entire list. Updates should be cons'd onto the front of the
;; list.
;; It works by setting prev to the empty list and next, curr and item to
;; the seed. The item reference is propagated through the current list
;; until it reaches prev. The calls to proc will update @code{next}.
;; @example
;; next-> +---+
;; | |
;; curr-> +---+
;; | |
;; item-> | |
;; | |
;; prev-> +---+
;; | |
;; +---+
;; @end example
(define (fixed-point proc seed)
;; (let ((seed (if (null? seed) (fixed-point proc (proc seed '())))))
(let iter ((prev '()) (item seed) (curr seed) (next seed))
(cond
((not (eqv? item prev))
(iter prev (cdr item) curr (proc (car item) next)))
((not (eqv? next curr))
(iter curr next next next))
(else
curr))))
;; @deffn vector-fixed-point proc vec => vec
;; (proc vec) => chg (boolean)
;; Not used yet (in step3).
(define (vector-fixed-point proc vec)
(let iter ((chg #t))
(if chg (proc vec) vec)))
;; @deffn map-attr->vector list-of-alists key => vector
;; map list of attribute lists to vector of attr
;; @example
;; (map-attr->vector '(((a . 1) ...) ((a . 2) ...) ...) => #(1 2 ...)
;; @end example
(define (map-attr->vector al-l key)
(list->vector (map (lambda (al) (assq-ref al key)) al-l)))
;; @deffn flip al => a-list
;; change (a 1 2 3) to ((1 . a) (2 . a) (3 . a))
(define (x-flip al)
(let iter ((result '()) (tail (cdr al)))
(if (null? tail) result
(iter (acons (car tail) (car al) result) (cdr tail)))))
;; @deffn x-comb (a1 a2 a3) (b1 b2 b3) => (a1 b1) (a1 b2) ...
;; The implementation needs work.
(define (x-comb a b)
(let iter ((res '()) (al a) (bl b))
(cond
((null? al) res)
((pair? bl) (iter (acons (car al) (car bl) res) al (cdr bl)))
((pair? al) (iter res (cdr al) b)))))
(define (write-vec port vec)
(let* ((nv (vector-length vec)))
(fmt port " #(")
(let iter ((col 4) (ix 0))
(if (eq? ix nv) #f
(let* ((item (vector-ref vec ix))
(stng (fmt #f "~S " item))
(leng (string-length stng)))
(cond
((> (+ col leng) 78)
(fmt port "\n ~A" stng)
(iter (+ 4 leng) (1+ ix)))
(else
(fmt port "~A" stng)
(iter (+ col leng) (1+ ix)))))))
(fmt port ")")))
;; @deffn ugly-print sexp [#:indent 4] [#:extent 78] [#:port port]
;; This will print in compact form which shows no structure.
(define* (ugly-print sexp #:optional port #:key (indent 4) (extent 78))
(define (obj->str obj)
(simple-format #f "~S" obj))
;; @deffn make-strout indent extent port
;; This will generate a procedure of signature @code{(proc col str)} which
;; takes a column and string, prints the string and returns updated column.
(define (make-strout ind ext port)
(let ((leader (make-string ind #\space)))
(lambda (col str)
(let* ((len (string-length str)))
(cond
((> (+ col len) ext)
(newline port)
(display leader port)
(unless (string-every #\space str) (display str port))
(+ ind len))
(else
(display str port)
(+ col len)))))))
(letrec ((out-p (or port (current-output-port)))
(leader (make-string 2 #\space))
(strout (make-strout indent extent out-p))
(iter1
(lambda (col sx)
(cond
((pair? sx) (strout (iter2 (strout col "(") sx) ")"))
((vector? sx)
(strout
(vector-fold
(lambda (ix col elt)
(iter1 (if (zero? ix) col (strout col " ")) elt))
(strout col "#(") sx) ")"))
(else (strout col (obj->str sx))))))
(iter2
(lambda (col sx)
(cond
((pair? sx)
(if (null? (cdr sx))
(iter2 (iter1 col (car sx)) (cdr sx))
(iter2 (strout (iter1 col (car sx)) " ") (cdr sx))))
((null? sx) col)
(else (strout (strout col ". ") (obj->str sx))))))
)
;;(simple-format out-p leader)
(iter1 (if (pair? sexp) (strout indent "'") indent) sexp)
;;(iter1 indent sexp)
;;(newline out-p)
))
;; stuff
;; @deffn depth-first-search graph => (values ht gv tv xl)
;; The argument @var{gfraph} is a list of verticies and adjacency nodes:
;; @example
;; graph => ((1 2 3 4) (2 6 7) ...)
;; @end example
;; @noindent
;; @table @var
;; @item ht
;; hash of vertex to index
;; @item gv
;; vector of index to vertex
;; @item tv
;; vector of (d . f)
;; @end table
;; ref: Algorithms, p 478
(define (depth-first-search graph)
(let* ((n (length graph))
(ht (make-hash-table n)) ; vertex -> index
(gv (make-vector n)) ; index -> vertex
(tv (make-vector n #f)) ; index -> times
(pv (make-vector n #f)) ; index -> predecessor :unused
(xl '()))
(letrec
((next-t (let ((t 0)) (lambda () (set! t (+ 1 t)) t)))
(visit (lambda (k)
(vector-set! tv k (cons (next-t) #f))
(let iter ((l (cdr (vector-ref gv k))))
(if (not (null? l))
(let ((ix (hashq-ref ht (car l))))
(unless (vector-ref tv ix)
(pp 0 "set-pv! ~a ~a" ix k)
(vector-set! pv ix k)
(visit ix))
(iter (cdr l)))))
(set! xl (cons k xl))
(set-cdr! (vector-ref tv k) (next-t))
))
)
;; Set up hash of vertex to index.
(do ((i 0 (+ i 1)) (l graph (cdr l))) ((= i n))
(vector-set! gv i (car l)) ; (vector-ref gv i) = (list-ref graph i)
(hashq-set! ht (caar l) i)) ; (hash-ref ht (list-ref graph i)) = i
;; Run through vertices.
(do ((i 0 (+ 1 i))) ((= i n))
(unless (vector-ref tv i) (visit i)))
(values ht gv tv xl))))
;; @deffn tzort dag
;; Given DAG return order of nodes. The DAG is provided as list of:
;; (<node> <priors>)
;; ref: D.E.Knuth - The Art of C.P., Vol I, Sec 2.2.3
(define (tzort dag)
(let* ((n (length dag))
(ht (make-hash-table n)) ; node -> ix
(nv (make-vector n #f)) ; ix -> (node . adj-list)
(cv (make-vector n 0)) ; ix -> count
(incr (lambda (ix) (vector-set! cv ix (+ (vector-ref cv ix) 1))))
(decr (lambda (ix) (vector-set! cv ix (- (vector-ref cv ix) 1)))))
;; Set up ht and nv.
(do ((i 0 (+ i 1)) (l dag (cdr l))) ((= n i))
(vector-set! nv i (car l))
(hashq-set! ht (caar l) i))
;; set up cv
(do ((i 0 (+ i 1))) ((= n i))
(for-each (lambda (n) (incr (hashq-ref ht n)))
(cdr (vector-ref nv i))))
;; Iterate through nodes until cv all zero.
(let iter1 ((ol '()) (uh '()) ; ordered list, unordered head
(ut (let r ((l '()) (x 0)) ; unordered tail
(if (= x n) l (r (cons x l) (+ x 1))))))
(cond
((null? ut)
(if (null? uh)
(reverse (map (lambda (e) (car (vector-ref nv e))) ol))
(iter1 ol '() uh)))
(else
(let* ((ix (car ut)))
(if (zero? (vector-ref cv ix))
(iter1
(let iter2 ((l (cdr (vector-ref nv ix))))
(if (null? l) (cons ix ol)
(begin
(decr (hashq-ref ht (car l)))
(iter2 (cdr l)))))
uh
(cdr ut))
(iter1 ol (cons ix uh) (cdr ut)))))))))
;;; --- last line ---