2016-12-17 21:34:43 +00:00
|
|
|
;;; 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)
|
2017-02-05 15:52:44 +00:00
|
|
|
#:export (parse-c99x)
|
2016-12-17 21:34:43 +00:00
|
|
|
#: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*}.
|
2017-03-28 18:26:16 +00:00
|
|
|
(define c99x-raw-parser
|
2017-03-03 00:23:44 +00:00
|
|
|
(let ((parser (make-lalr-parser
|
2017-03-28 18:26:16 +00:00
|
|
|
(list (cons 'len-v c99x-len-v) (cons 'pat-v c99x-pat-v)
|
|
|
|
(cons 'rto-v c99x-rto-v) (cons 'mtab c99x-mtab)
|
|
|
|
(cons 'act-v c99x-act-v)))))
|
2017-03-03 00:23:44 +00:00
|
|
|
(lambda* (lexer #:key (debug #f))
|
|
|
|
(catch
|
|
|
|
'nyacc-error
|
|
|
|
(lambda () (parser lexer #:debug debug))
|
|
|
|
(lambda (key fmt . args)
|
|
|
|
(report-error fmt args)
|
|
|
|
(pop-input) ; not sure this is right
|
|
|
|
(throw 'c99-error "C99 parse error"))))))
|
2016-12-17 21:34:43 +00:00
|
|
|
|
2017-03-28 18:26:16 +00:00
|
|
|
(define (c99x-run-parse)
|
2016-12-17 21:34:43 +00:00
|
|
|
(let ((info (fluid-ref *info*)))
|
2017-03-28 18:26:16 +00:00
|
|
|
(c99x-raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
|
2016-12-17 21:34:43 +00:00
|
|
|
|
2017-03-02 02:11:40 +00:00
|
|
|
;; @item {Procedure} parse-c99x [#:cpp-defs defs] [#:debug bool]
|
2016-12-17 21:34:43 +00:00
|
|
|
;; This needs to be explained in some detail.
|
|
|
|
;; [#:tyns '("foo_t")]
|
2017-01-08 20:16:28 +00:00
|
|
|
(define* (parse-c99x expr-string
|
2017-01-08 00:06:09 +00:00
|
|
|
#:key
|
|
|
|
(cpp-defs '()) ; CPP defines
|
2017-02-05 15:52:44 +00:00
|
|
|
(inc-help '()) ; include helper
|
2017-01-08 00:06:09 +00:00
|
|
|
(xdef? #f) ; pred to determine expand
|
|
|
|
(debug #f) ; debug?
|
|
|
|
(tyns '())) ; defined typenames
|
2017-01-08 20:16:28 +00:00
|
|
|
(with-input-from-string expr-string
|
|
|
|
(lambda ()
|
|
|
|
(catch
|
|
|
|
'c99-error
|
|
|
|
(lambda ()
|
2017-02-05 15:52:44 +00:00
|
|
|
(let ((info (make-cpi debug cpp-defs '(".") inc-help)))
|
2017-01-08 20:16:28 +00:00
|
|
|
(set-cpi-ptl! info (cons tyns (cpi-ptl info)))
|
|
|
|
(with-fluid*
|
|
|
|
*info* info
|
|
|
|
(lambda ()
|
2017-03-28 18:26:16 +00:00
|
|
|
(c99x-raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
|
|
|
|
#:debug debug)))))
|
2017-01-08 20:16:28 +00:00
|
|
|
(lambda (key fmt . rest)
|
|
|
|
(report-error fmt rest)
|
|
|
|
#f)))))
|
2016-12-17 21:34:43 +00:00
|
|
|
|
|
|
|
;; --- last line ---
|