nyacc: more CPP fixes
This commit is contained in:
parent
50fc6f6966
commit
85cb3731cc
|
@ -1,3 +1,10 @@
|
||||||
|
2017-01-18 Matt Wette <mwette@alumni.caltech.edu>
|
||||||
|
|
||||||
|
* lang/c99/parser.scm: check for EOF in end of CPP line
|
||||||
|
|
||||||
|
* lang/c99/mach.scm (c99-spec): decl for translation unit was
|
||||||
|
updated to allow programs with no declarations or statements
|
||||||
|
|
||||||
2017-01-08 Matt Wette <mwette@alumni.caltech.edu>
|
2017-01-08 Matt Wette <mwette@alumni.caltech.edu>
|
||||||
|
|
||||||
* ../../test-suite/nyacc/lang/c99/exam.d/ex05.c: C99 does not
|
* ../../test-suite/nyacc/lang/c99/exam.d/ex05.c: C99 does not
|
||||||
|
@ -8,7 +15,7 @@
|
||||||
* lang/c99/body.scm (read-cpp-line): cpp statement should not
|
* lang/c99/body.scm (read-cpp-line): cpp statement should not
|
||||||
include newline? Changed to unread final newline.
|
include newline? Changed to unread final newline.
|
||||||
|
|
||||||
* lang/util.scm: add report-error: prints msg w/ file, line
|
* lang/util.scm: add report-error: prints msg w/ file, line
|
||||||
|
|
||||||
* parse.scm (make-lalr-parser): changed printout of parse error to
|
* parse.scm (make-lalr-parser): changed printout of parse error to
|
||||||
(throw 'parse-error . args) and expect the full parser to catch
|
(throw 'parse-error . args) and expect the full parser to catch
|
||||||
|
|
|
@ -213,6 +213,7 @@
|
||||||
(if (not (eq? ch #\#)) #f
|
(if (not (eq? ch #\#)) #f
|
||||||
(let iter ((cl '()) (ch (read-char)))
|
(let iter ((cl '()) (ch (read-char)))
|
||||||
(cond
|
(cond
|
||||||
|
((eof-object? ch) (throw 'cpp-error "CPP lines must end in newline"))
|
||||||
((eq? ch #\newline) (unread-char ch) (list->string (reverse cl)))
|
((eq? ch #\newline) (unread-char ch) (list->string (reverse cl)))
|
||||||
((eq? ch #\\)
|
((eq? ch #\\)
|
||||||
(let ((c2 (read-char)))
|
(let ((c2 (read-char)))
|
||||||
|
@ -350,6 +351,7 @@
|
||||||
(cond
|
(cond
|
||||||
((exec-cpp-stmts?)
|
((exec-cpp-stmts?)
|
||||||
(let ((val (eval-cpp-cond-text (cadr stmt))))
|
(let ((val (eval-cpp-cond-text (cadr stmt))))
|
||||||
|
;;(simple-format #t "if val=~S\n" val)
|
||||||
(cond
|
(cond
|
||||||
((not val) (p-err "unresolved: ~S" (cadr stmt)))
|
((not val) (p-err "unresolved: ~S" (cadr stmt)))
|
||||||
((zero? val) (set! ppxs (cons* 'skip1-pop 'skip-look ppxs)))
|
((zero? val) (set! ppxs (cons* 'skip1-pop 'skip-look ppxs)))
|
||||||
|
@ -397,6 +399,7 @@
|
||||||
(else (cons 'cpp-stmt stmt))))
|
(else (cons 'cpp-stmt stmt))))
|
||||||
|
|
||||||
(define (eval-cpp-line line)
|
(define (eval-cpp-line line)
|
||||||
|
;;(simple-format #t "eval-cpp-line: ~S\n" line)
|
||||||
(with-throw-handler
|
(with-throw-handler
|
||||||
'cpp-error
|
'cpp-error
|
||||||
(lambda () (eval-cpp-stmt (read-cpp-stmt line)))
|
(lambda () (eval-cpp-stmt (read-cpp-stmt line)))
|
||||||
|
@ -421,10 +424,12 @@
|
||||||
((read-comm ch bol) => assc-$)
|
((read-comm ch bol) => assc-$)
|
||||||
((read-cpp ch) =>
|
((read-cpp ch) =>
|
||||||
(lambda (res) ;; if '() stmt expanded so re-read
|
(lambda (res) ;; if '() stmt expanded so re-read
|
||||||
|
;;(simple-format #t "res=~S\n" res)
|
||||||
(if (pair? res) (assc-$ res) (iter (read-char)))))
|
(if (pair? res) (assc-$ res) (iter (read-char)))))
|
||||||
(else (set! bol #f) (iter ch))))
|
(else (set! bol #f) (iter ch))))
|
||||||
((read-ident ch) =>
|
((read-ident ch) =>
|
||||||
(lambda (name)
|
(lambda (name)
|
||||||
|
;;(simple-format #t "read-ident=>~S\n" name)
|
||||||
(let ((symb (string->symbol name)))
|
(let ((symb (string->symbol name)))
|
||||||
(cond
|
(cond
|
||||||
((and (x-def? name mode)
|
((and (x-def? name mode)
|
||||||
|
|
|
@ -163,6 +163,9 @@
|
||||||
(((key . val) . rest)
|
(((key . val) . rest)
|
||||||
(iter (cons val stl) (cdr tkl)))
|
(iter (cons val stl) (cdr tkl)))
|
||||||
|
|
||||||
|
(('space . rest)
|
||||||
|
(iter (cons " " stl) rest))
|
||||||
|
|
||||||
(((? char? ch) . rest)
|
(((? char? ch) . rest)
|
||||||
(iter (cons (string ch) stl) rest))
|
(iter (cons (string ch) stl) rest))
|
||||||
|
|
||||||
|
@ -226,9 +229,13 @@
|
||||||
(unread-char ch) (rtokl->string tkl))
|
(unread-char ch) (rtokl->string tkl))
|
||||||
|
|
||||||
((read-c-comm ch #f) =>
|
((read-c-comm ch #f) =>
|
||||||
(lambda (cp) (iter (acons `comm cp tkl) lvl (read-char))))
|
(lambda (cp) (iter (acons `comm (cdr cp) tkl) lvl (read-char))))
|
||||||
|
|
||||||
|
((char-set-contains? c:ws ch)
|
||||||
|
(if (and (pair? tkl) (char? (car tkl)))
|
||||||
|
(iter (cons 'space tkl) lvl (read-char))
|
||||||
|
(iter tkl lvl (read-char))))
|
||||||
|
|
||||||
((char-set-contains? c:ws ch) (iter tkl lvl (read-char)))
|
|
||||||
((char=? #\( ch) (iter (cons ch tkl) (1+ lvl) (read-char)))
|
((char=? #\( ch) (iter (cons ch tkl) (1+ lvl) (read-char)))
|
||||||
((char=? #\) ch) (iter (cons ch tkl) (1- lvl) (read-char)))
|
((char=? #\) ch) (iter (cons ch tkl) (1- lvl) (read-char)))
|
||||||
((char=? #\# ch)
|
((char=? #\# ch)
|
||||||
|
|
|
@ -699,8 +699,8 @@
|
||||||
(lambda ($2 $1 . $rest) `(return (expr)))
|
(lambda ($2 $1 . $rest) `(return (expr)))
|
||||||
;; translation-unit => external-declaration-list
|
;; translation-unit => external-declaration-list
|
||||||
(lambda ($1 . $rest) (tl->list $1))
|
(lambda ($1 . $rest) (tl->list $1))
|
||||||
;; external-declaration-list => external-declaration
|
;; external-declaration-list =>
|
||||||
(lambda ($1 . $rest) (make-tl 'trans-unit $1))
|
(lambda $rest (make-tl 'trans-unit))
|
||||||
;; external-declaration-list => external-declaration-list external-decla...
|
;; external-declaration-list => external-declaration-list external-decla...
|
||||||
(lambda ($2 $1 . $rest)
|
(lambda ($2 $1 . $rest)
|
||||||
(if (eqv? (sx-tag $2) 'extern-block)
|
(if (eqv? (sx-tag $2) 'extern-block)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -699,8 +699,8 @@
|
||||||
(lambda ($2 $1 . $rest) `(return (expr)))
|
(lambda ($2 $1 . $rest) `(return (expr)))
|
||||||
;; translation-unit => external-declaration-list
|
;; translation-unit => external-declaration-list
|
||||||
(lambda ($1 . $rest) (tl->list $1))
|
(lambda ($1 . $rest) (tl->list $1))
|
||||||
;; external-declaration-list => external-declaration
|
;; external-declaration-list =>
|
||||||
(lambda ($1 . $rest) (make-tl 'trans-unit $1))
|
(lambda $rest (make-tl 'trans-unit))
|
||||||
;; external-declaration-list => external-declaration-list external-decla...
|
;; external-declaration-list => external-declaration-list external-decla...
|
||||||
(lambda ($2 $1 . $rest)
|
(lambda ($2 $1 . $rest)
|
||||||
(if (eqv? (sx-tag $2) 'extern-block)
|
(if (eqv? (sx-tag $2) 'extern-block)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
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
|
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 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
|
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 1 2 1 1 1 1 1 5 1 4 3 1 2 0
|
1 2 1 1 2 1 5 7 5 5 7 8 2 1 1 0 1 3 2 2 3 2 1 0 2 1 1 1 1 1 5 1 4 3 1 2 0
|
||||||
1 1 1 1 1 1 1 2 1 1 1 1))
|
1 1 1 1 1 1 1 2 1 1 1 1))
|
||||||
|
|
||||||
(define pat-v
|
(define pat-v
|
||||||
|
|
|
@ -609,7 +609,8 @@
|
||||||
(external-declaration-list ($$ (tl->list $1)))
|
(external-declaration-list ($$ (tl->list $1)))
|
||||||
)
|
)
|
||||||
(external-declaration-list
|
(external-declaration-list
|
||||||
(external-declaration ($$ (make-tl 'trans-unit $1)))
|
;;(external-declaration ($$ (make-tl 'trans-unit $1)))
|
||||||
|
($empty ($$ (make-tl 'trans-unit)))
|
||||||
(external-declaration-list
|
(external-declaration-list
|
||||||
external-declaration
|
external-declaration
|
||||||
;; A ``kludge'' to deal with @code{extern "C" ...}:
|
;; A ``kludge'' to deal with @code{extern "C" ...}:
|
||||||
|
|
Loading…
Reference in a new issue