nyacc: lots of C99/CPP fixes. now more robust for code mode

This commit is contained in:
Matt Wette 2017-01-08 12:16:28 -08:00 committed by Jan Nieuwenhuizen
parent 0b46949f48
commit 9c32a41370
12 changed files with 658 additions and 658 deletions

View File

@ -315,13 +315,8 @@
'cpp-error
(lambda ()
(let* ((defs (cpi-defs info))
;;(x (simple-format #t "eval-cpp-cond-text: ~S\n" text))
(rhs (cpp-expand-text text defs))
;;(x (simple-format #t " rhs=>~S\n" rhs))
(exp (parse-cpp-expr rhs))
;;(x (simple-format #t " exp=>~S\n" exp))
)
(if (not exp) (throw 'c99-error "CPP parse failed"))
(exp (parse-cpp-expr rhs)))
(eval-cpp-expr exp defs)))
(lambda (key fmt . args)
(report-error fmt args)

View File

@ -143,10 +143,7 @@ todo:
(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")
;; cppbody.scm provides: gen-cpp-lexer parse-cpp-expr eval-cpp-expr
;; --- last line ---

View File

@ -27,6 +27,7 @@
(lambda (ch)
(reader ch #f))))
;; generate a lexical analyzer per string
(define gen-cpp-lexer
(make-lexer-generator mtab #:comm-skipper cpp-comm-skipper))
@ -36,7 +37,7 @@
;; expanded already so no identifiers should appear in the text.
;; A @code{cpp-error} will be thrown if a parse error occurs.
(define (parse-cpp-expr text)
(catch
(with-throw-handler
'nyacc-error
(lambda ()
(with-input-from-string text
@ -48,7 +49,6 @@
;; Evaluate a tree produced from @code{parse-cpp-expr}.
;; The tree passed to this routine is
(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)))
@ -62,7 +62,6 @@
((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))
@ -88,12 +87,9 @@
((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)))
((ident) (error "text should not have identifiers"))
((ident) (cpp-err "undefined identifier: ~S" (cadr tree)))
(else (error "incomplete implementation"))))))
(catch 'cpp-error
(lambda () (eval-expr tree))
(lambda () #f))))
(eval-expr tree)))
;; @deffn scan-cpp-input argd used dict for-argl => string
;; Process the replacement text and generate a (reversed) token-list.

View File

@ -95,9 +95,9 @@
(postfix-expression "++" ($$ `(post-inc ,$1)))
(postfix-expression "--" ($$ `(post-dec ,$1))))
(primary-expression
;;($ident ($$ `(ident ,$1)))
($ident ($$ `(ident ,$1)))
($fixed ($$ `(fixed ,$1))) ; integer-constant
($chlit ($$ `(char ,$1))) ; char-constant
($chlit ($$ `(char ,$1))) ; char-constant
("defined" "(" $ident ")" ($$ `(defined ,$3)))
("(" expression-list ")" ($$ $2)))
(expression-list

View File

@ -1,17 +1,15 @@
;; ../../../../module/nyacc/lang/c99/mach.d/c99xact.scm
;; ./mach.d/c99xact.scm
;; Copyright (C) 2015,2016 Matthew R. Wette
;; Copyright (C) 2016,2017 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.
;; 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
@ -399,10 +397,10 @@
;; struct-declarator => ":" constant-expression
(lambda ($2 $1 . $rest)
`(comp-declr (bit-field ,$2)))
;; enum-specifier => "enum" identifier "{" enumerator-list "}"
;; enum-specifier => "enum" ident-like "{" enumerator-list "}"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(enum-def ,$2 ,(tl->list $4)))
;; enum-specifier => "enum" identifier "{" enumerator-list "," "}"
;; enum-specifier => "enum" ident-like "{" enumerator-list "," "}"
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
`(enum-def ,$2 ,(tl->list $4)))
;; enum-specifier => "enum" "{" enumerator-list "}"
@ -411,7 +409,7 @@
;; enum-specifier => "enum" "{" enumerator-list "," "}"
(lambda ($5 $4 $3 $2 $1 . $rest)
`(enum-def ,(tl->list $3)))
;; enum-specifier => "enum" identifier
;; enum-specifier => "enum" ident-like
(lambda ($2 $1 . $rest) `(enum-ref ,$2))
;; enumerator-list => enumerator
(lambda ($1 . $rest) (make-tl 'enum-def-list $1))
@ -690,7 +688,7 @@
;; opt-expression => expression
(lambda ($1 . $rest) $1)
;; jump-statement => "goto" identifier ";"
(lambda ($3 $2 $1 . $rest) `(goto $2))
(lambda ($3 $2 $1 . $rest) `(goto ,$2))
;; jump-statement => "continue" ";"
(lambda ($2 $1 . $rest) '(continue))
;; jump-statement => "break" ";"
@ -699,16 +697,15 @@
(lambda ($3 $2 $1 . $rest) `(return ,$2))
;; jump-statement => "return" ";"
(lambda ($2 $1 . $rest) `(return (expr)))
;; translation-unit => external-declaration
;; translation-unit => external-declaration-list
(lambda ($1 . $rest) (tl->list $1))
;; external-declaration-list => external-declaration
(lambda ($1 . $rest) (make-tl 'trans-unit $1))
;; translation-unit => translation-unit external-declaration
;; external-declaration-list => external-declaration-list external-decla...
(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))))
(if (eqv? (sx-tag $2) 'extern-block)
(tl-extend $1 (sx-tail $2 2))
(tl-append $1 $2)))
;; external-declaration => function-definition
(lambda ($1 . $rest) $1)
;; external-declaration => declaration
@ -717,8 +714,13 @@
(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))
;; external-declaration => "extern" '$string "{" external-declaration-li...
(lambda ($5 $4 $3 $2 $1 . $rest)
`(extern-block
,$2
(extern-begin ,$2)
,@(sx-tail (tl->list $4) 1)
(extern-end)))
;; function-definition => declaration-specifiers declarator declaration-...
(lambda ($4 $3 $2 $1 . $rest)
`(knr-fctn-defn

File diff suppressed because it is too large Load Diff

View File

@ -93,6 +93,8 @@
(lambda ($2 $1 . $rest) `(post-inc ,$1))
;; postfix-expression => postfix-expression "--"
(lambda ($2 $1 . $rest) `(post-dec ,$1))
;; primary-expression => '$ident
(lambda ($1 . $rest) `(ident ,$1))
;; primary-expression => '$fixed
(lambda ($1 . $rest) `(fixed ,$1))
;; primary-expression => '$chlit

View File

@ -8,96 +8,100 @@
(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))
2 2 1 2 2 1 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))))
#(((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 .
9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (
42 . 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22) (48 . 23) (49
. 24) (50 . 25)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7)
(9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 .
15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22)
(48 . 23) (49 . 24) (50 . 54) (36 . 55)) ((3 . 53)) ((-1 . -43)) ((-1 .
-42)) ((-1 . -41)) ((-1 . -38)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (
37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (
39 . 52)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8
) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 51)) ((3 . 1) (4
. 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (
16 . 11) (15 . 12) (38 . 13) (39 . 50)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (
7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38
. 13) (39 . 49)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7
) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 48)) ((3
. 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11
. 10) (16 . 11) (15 . 12) (38 . 13) (39 . 47)) ((9 . 45) (8 . 46) (-1 .
-31)) ((-1 . -27)) ((14 . 42) (13 . 43) (12 . 44) (-1 . -24)) ((16 . 40) (
15 . 41) (-1 . -21)) ((18 . 38) (17 . 39) (-1 . -16)) ((22 . 34) (21 . 35)
(20 . 36) (19 . 37) (-1 . -13)) ((24 . 32) (23 . 33) (-1 . -11)) ((25 .
31) (-1 . -9)) ((26 . 30) (-1 . -7)) ((27 . 29) (-1 . -5)) ((28 . 28) (-1
. -3)) ((31 . 26) (29 . 27) (2 . -1) (1 . -1) (35 . -1)) ((35 . 0)) ((3 .
1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11
. 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17
) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22) (48 . 23) (49 . 77)) (
(3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9)
(11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42
. 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22) (48 . 76)) ((3 . 1
) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 .
10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17)
(43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 75)) ((3 . 1) (4 . 2) (5 . 3
) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (
15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44
. 19) (45 . 20) (46 . 74)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 .
6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 .
14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 73)) ((3 . 1)
(4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10
) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (
43 . 18) (44 . 72)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8
. 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (
40 . 15) (41 . 16) (42 . 17) (43 . 71)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (
7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38
. 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (43 . 70)) ((3 . 1) (4 . 2)
(5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16
. 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 69)) ((3 . 1
) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 .
10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 68))
((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9
) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (
42 . 67)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8
) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41
. 16) (42 . 66)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7
) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40
. 15) (41 . 65)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7)
(9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 .
15) (41 . 64)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (
9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 63
)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10
. 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 62)) ((3 . 1)
(4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 .
10) (16 . 11) (15 . 12) (38 . 13) (39 . 61)) ((3 . 1) (4 . 2) (5 . 3) (6
. 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 .
12) (38 . 13) (39 . 60)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6)
(8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 59
)) ((-1 . -39)) ((-1 . -40)) ((-1 . -32)) ((-1 . -33)) ((-1 . -34)) ((-1
. -35)) ((-1 . -36)) ((-1 . -37)) ((7 . 58)) ((2 . -46) (1 . -46)) ((2 .
56) (1 . 57)) ((-1 . -45)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 .
6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 .
14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21)
(47 . 22) (48 . 23) (49 . 24) (50 . 80)) ((2 . 79)) ((-1 . -30)) ((-1 .
-29)) ((-1 . -28)) ((14 . 42) (13 . 43) (12 . 44) (-1 . -26)) ((14 . 42) (
13 . 43) (12 . 44) (-1 . -25)) ((16 . 40) (15 . 41) (-1 . -23)) ((16 . 40)
(15 . 41) (-1 . -22)) ((18 . 38) (17 . 39) (-1 . -20)) ((18 . 38) (17 .
39) (-1 . -19)) ((18 . 38) (17 . 39) (-1 . -18)) ((18 . 38) (17 . 39) (-1
. -17)) ((22 . 34) (21 . 35) (20 . 36) (19 . 37) (-1 . -15)) ((22 . 34) (
21 . 35) (20 . 36) (19 . 37) (-1 . -14)) ((24 . 32) (23 . 33) (-1 . -12))
((25 . 31) (-1 . -10)) ((26 . 30) (-1 . -8)) ((27 . 29) (-1 . -6)) ((28 .
28) (-1 . -4)) ((30 . 78) (29 . 27)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7
. 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38
. 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 20
) (46 . 21) (47 . 22) (48 . 23) (49 . 24) (50 . 81)) ((-1 . -44)) ((2 .
-47) (1 . -47)) ((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))
41 41 41 40 40 40 40 39 39 39 39 39 39 39 38 38 38 37 37 37 37 37 36 36))
(define mtab
'(("," . 1) (")" . 2) ($ident . 3) ("(" . 4) ("defined" . 5) ($chlit . 6)
($fixed . 7) ("--" . 8) ("++" . 9) ("~" . 10) ("!" . 11) ("%" . 12) ("/"
'(("," . 1) (")" . 2) ("(" . 3) ("defined" . 4) ($chlit . 5) ($fixed . 6)
($ident . 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) (

View File

@ -48,10 +48,12 @@
(cons 'rto-v rto-v) (cons 'mtab mtab)
(cons 'act-v act-v)))))
(lambda* (lexer #:key (debug #f))
(with-throw-handler
'nyacc-error
(lambda () (c99-parser lexer #:debug debug))
(lambda (key fmt . args) (apply throw 'c99-error fmt args))))))
(lambda (key fmt . args) (apply throw 'c99-error fmt args)))
)))
;; This is used to parse included files at top level.
(define (run-parse)

View File

@ -45,30 +45,31 @@
(let ((info (fluid-ref *info*)))
(raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
;; @item parse-cx [#:cpp-defs def-a-list] [#:debug bool]
;; @item parse-c99x [#:cpp-defs def-a-list] [#:debug bool]
;; This needs to be explained in some detail.
;; [#:tyns '("foo_t")]
(define* (parse-c99x xstr
(define* (parse-c99x expr-string
#:key
(cpp-defs '()) ; CPP defines
(tn-dict '()) ; typedef dictionary
(xdef? #f) ; pred to determine expand
(debug #f) ; debug?
(tyns '())) ; defined typenames
(with-input-from-string xstr
(catch
#t
(lambda ()
(let ((info (make-cpi debug cpp-defs '(".") tn-dict)))
(set-cpi-ptl! info (cons tyns (cpi-ptl info)))
(with-fluid*
*info* info
(lambda ()
(raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
#:debug debug))))))
(lambda (key fmt . rest)
(report-error fmt rest)
#f)))
(with-input-from-string expr-string
(lambda ()
(catch
'c99-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 ()
(raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
#:debug debug)))))
(lambda (key fmt . rest)
(report-error fmt rest)
#f)))))
(define parse-cx parse-c99x)

View File

@ -49,7 +49,7 @@ the file COPYING included with the this distribution.")
(let ((fn (or (port-filename (current-input-port)) "(unknown)"))
(ln (1+ (port-line (current-input-port)))))
(apply simple-format (current-error-port)
(string-append "~S:~S: " fmt "\n") fn ln args)))
(string-append "~A:~A: " fmt "\n") fn ln args)))
;; === input stack =====================

View File

@ -473,6 +473,7 @@
;; char -> (char . char)
;; @end enumerate
;; todo: add bol status
;; todo: maybe separate reading of keywords from identifiers: (keywd ch) =>
(define* (make-lexer-generator match-table
#:key ident-reader num-reader
string-reader chlit-reader