nyacc: lots of C99/CPP fixes. now more robust for code mode
This commit is contained in:
parent
0b46949f48
commit
9c32a41370
|
@ -315,13 +315,8 @@
|
||||||
'cpp-error
|
'cpp-error
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let* ((defs (cpi-defs info))
|
(let* ((defs (cpi-defs info))
|
||||||
;;(x (simple-format #t "eval-cpp-cond-text: ~S\n" text))
|
|
||||||
(rhs (cpp-expand-text text defs))
|
(rhs (cpp-expand-text text defs))
|
||||||
;;(x (simple-format #t " rhs=>~S\n" rhs))
|
(exp (parse-cpp-expr rhs)))
|
||||||
(exp (parse-cpp-expr rhs))
|
|
||||||
;;(x (simple-format #t " exp=>~S\n" exp))
|
|
||||||
)
|
|
||||||
(if (not exp) (throw 'c99-error "CPP parse failed"))
|
|
||||||
(eval-cpp-expr exp defs)))
|
(eval-cpp-expr exp defs)))
|
||||||
(lambda (key fmt . args)
|
(lambda (key fmt . args)
|
||||||
(report-error fmt args)
|
(report-error fmt args)
|
||||||
|
|
|
@ -143,10 +143,7 @@ todo:
|
||||||
(list (cons 'len-v len-v) (cons 'pat-v pat-v) (cons 'rto-v rto-v)
|
(list (cons 'len-v len-v) (cons 'pat-v pat-v) (cons 'rto-v rto-v)
|
||||||
(cons 'mtab mtab) (cons 'act-v act-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")
|
(include-from-path "nyacc/lang/c99/cppbody.scm")
|
||||||
|
;; cppbody.scm provides: gen-cpp-lexer parse-cpp-expr eval-cpp-expr
|
||||||
|
|
||||||
;; --- last line ---
|
;; --- last line ---
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
(lambda (ch)
|
(lambda (ch)
|
||||||
(reader ch #f))))
|
(reader ch #f))))
|
||||||
|
|
||||||
|
;; generate a lexical analyzer per string
|
||||||
(define gen-cpp-lexer
|
(define gen-cpp-lexer
|
||||||
(make-lexer-generator mtab #:comm-skipper cpp-comm-skipper))
|
(make-lexer-generator mtab #:comm-skipper cpp-comm-skipper))
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@
|
||||||
;; expanded already so no identifiers should appear in the text.
|
;; expanded already so no identifiers should appear in the text.
|
||||||
;; A @code{cpp-error} will be thrown if a parse error occurs.
|
;; A @code{cpp-error} will be thrown if a parse error occurs.
|
||||||
(define (parse-cpp-expr text)
|
(define (parse-cpp-expr text)
|
||||||
(catch
|
(with-throw-handler
|
||||||
'nyacc-error
|
'nyacc-error
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(with-input-from-string text
|
(with-input-from-string text
|
||||||
|
@ -48,7 +49,6 @@
|
||||||
;; Evaluate a tree produced from @code{parse-cpp-expr}.
|
;; Evaluate a tree produced from @code{parse-cpp-expr}.
|
||||||
;; The tree passed to this routine is
|
;; The tree passed to this routine is
|
||||||
(define (eval-cpp-expr tree dict)
|
(define (eval-cpp-expr tree dict)
|
||||||
;;(display "eval-cpp-expr:\n") (pretty-print tree)
|
|
||||||
(letrec
|
(letrec
|
||||||
((tx (lambda (tr ix) (list-ref tr ix)))
|
((tx (lambda (tr ix) (list-ref tr ix)))
|
||||||
(tx1 (lambda (tr) (tx tr 1)))
|
(tx1 (lambda (tr) (tx tr 1)))
|
||||||
|
@ -62,7 +62,6 @@
|
||||||
((fixed) (string->number (tx1 tree)))
|
((fixed) (string->number (tx1 tree)))
|
||||||
((char) (char->integer (tx1 tree)))
|
((char) (char->integer (tx1 tree)))
|
||||||
((defined) (if (assoc-ref dict (tx1 tree)) 1 0))
|
((defined) (if (assoc-ref dict (tx1 tree)) 1 0))
|
||||||
;;
|
|
||||||
((pre-inc post-inc) (1+ (ev1 tree)))
|
((pre-inc post-inc) (1+ (ev1 tree)))
|
||||||
((pre-dec post-dec) (1- (ev1 tree)))
|
((pre-dec post-dec) (1- (ev1 tree)))
|
||||||
((pos) (ev1 tree))
|
((pos) (ev1 tree))
|
||||||
|
@ -88,12 +87,9 @@
|
||||||
((or) (if (and (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
|
((or) (if (and (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
|
||||||
((and) (if (or (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)))
|
((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"))))))
|
(else (error "incomplete implementation"))))))
|
||||||
(catch 'cpp-error
|
(eval-expr tree)))
|
||||||
(lambda () (eval-expr tree))
|
|
||||||
(lambda () #f))))
|
|
||||||
|
|
||||||
|
|
||||||
;; @deffn scan-cpp-input argd used dict for-argl => string
|
;; @deffn scan-cpp-input argd used dict for-argl => string
|
||||||
;; Process the replacement text and generate a (reversed) token-list.
|
;; Process the replacement text and generate a (reversed) token-list.
|
||||||
|
|
|
@ -95,9 +95,9 @@
|
||||||
(postfix-expression "++" ($$ `(post-inc ,$1)))
|
(postfix-expression "++" ($$ `(post-inc ,$1)))
|
||||||
(postfix-expression "--" ($$ `(post-dec ,$1))))
|
(postfix-expression "--" ($$ `(post-dec ,$1))))
|
||||||
(primary-expression
|
(primary-expression
|
||||||
;;($ident ($$ `(ident ,$1)))
|
($ident ($$ `(ident ,$1)))
|
||||||
($fixed ($$ `(fixed ,$1))) ; integer-constant
|
($fixed ($$ `(fixed ,$1))) ; integer-constant
|
||||||
($chlit ($$ `(char ,$1))) ; char-constant
|
($chlit ($$ `(char ,$1))) ; char-constant
|
||||||
("defined" "(" $ident ")" ($$ `(defined ,$3)))
|
("defined" "(" $ident ")" ($$ `(defined ,$3)))
|
||||||
("(" expression-list ")" ($$ $2)))
|
("(" expression-list ")" ($$ $2)))
|
||||||
(expression-list
|
(expression-list
|
||||||
|
|
|
@ -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,
|
;; This software is covered by the GNU GENERAL PUBLIC LICENCE, Version 3,
|
||||||
;; or any later version published by the Free Software Foundation. See the
|
;; or any later version published by the Free Software Foundation. See
|
||||||
;; file COPYING included with the this distribution.
|
;; the file COPYING included with the this distribution.
|
||||||
|
|
||||||
(define act-v
|
(define act-v
|
||||||
(vector
|
(vector
|
||||||
;; $start => expression
|
;; $start => expression
|
||||||
(lambda ($1 . $rest) $1)
|
(lambda ($1 . $rest) $1)
|
||||||
;; translation-unit-proxy => translation-unit
|
|
||||||
(lambda ($1 . $rest) (tl->list $1))
|
|
||||||
;; primary-expression => identifier
|
;; primary-expression => identifier
|
||||||
(lambda ($1 . $rest) `(p-expr ,$1))
|
(lambda ($1 . $rest) `(p-expr ,$1))
|
||||||
;; primary-expression => constant
|
;; primary-expression => constant
|
||||||
|
@ -399,10 +397,10 @@
|
||||||
;; struct-declarator => ":" constant-expression
|
;; struct-declarator => ":" constant-expression
|
||||||
(lambda ($2 $1 . $rest)
|
(lambda ($2 $1 . $rest)
|
||||||
`(comp-declr (bit-field ,$2)))
|
`(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)
|
(lambda ($5 $4 $3 $2 $1 . $rest)
|
||||||
`(enum-def ,$2 ,(tl->list $4)))
|
`(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)
|
(lambda ($6 $5 $4 $3 $2 $1 . $rest)
|
||||||
`(enum-def ,$2 ,(tl->list $4)))
|
`(enum-def ,$2 ,(tl->list $4)))
|
||||||
;; enum-specifier => "enum" "{" enumerator-list "}"
|
;; enum-specifier => "enum" "{" enumerator-list "}"
|
||||||
|
@ -411,7 +409,7 @@
|
||||||
;; enum-specifier => "enum" "{" enumerator-list "," "}"
|
;; enum-specifier => "enum" "{" enumerator-list "," "}"
|
||||||
(lambda ($5 $4 $3 $2 $1 . $rest)
|
(lambda ($5 $4 $3 $2 $1 . $rest)
|
||||||
`(enum-def ,(tl->list $3)))
|
`(enum-def ,(tl->list $3)))
|
||||||
;; enum-specifier => "enum" identifier
|
;; enum-specifier => "enum" ident-like
|
||||||
(lambda ($2 $1 . $rest) `(enum-ref ,$2))
|
(lambda ($2 $1 . $rest) `(enum-ref ,$2))
|
||||||
;; enumerator-list => enumerator
|
;; enumerator-list => enumerator
|
||||||
(lambda ($1 . $rest) (make-tl 'enum-def-list $1))
|
(lambda ($1 . $rest) (make-tl 'enum-def-list $1))
|
||||||
|
@ -690,7 +688,7 @@
|
||||||
;; opt-expression => expression
|
;; opt-expression => expression
|
||||||
(lambda ($1 . $rest) $1)
|
(lambda ($1 . $rest) $1)
|
||||||
;; jump-statement => "goto" identifier ";"
|
;; jump-statement => "goto" identifier ";"
|
||||||
(lambda ($3 $2 $1 . $rest) `(goto $2))
|
(lambda ($3 $2 $1 . $rest) `(goto ,$2))
|
||||||
;; jump-statement => "continue" ";"
|
;; jump-statement => "continue" ";"
|
||||||
(lambda ($2 $1 . $rest) '(continue))
|
(lambda ($2 $1 . $rest) '(continue))
|
||||||
;; jump-statement => "break" ";"
|
;; jump-statement => "break" ";"
|
||||||
|
@ -699,16 +697,15 @@
|
||||||
(lambda ($3 $2 $1 . $rest) `(return ,$2))
|
(lambda ($3 $2 $1 . $rest) `(return ,$2))
|
||||||
;; jump-statement => "return" ";"
|
;; jump-statement => "return" ";"
|
||||||
(lambda ($2 $1 . $rest) `(return (expr)))
|
(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))
|
(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)
|
(lambda ($2 $1 . $rest)
|
||||||
(cond ((eqv? 'trans-unit (car $2))
|
(if (eqv? (sx-tag $2) 'extern-block)
|
||||||
(let* ((t1 (tl-append $1 '(extern-C-begin)))
|
(tl-extend $1 (sx-tail $2 2))
|
||||||
(t2 (tl-extend t1 (cdr $2)))
|
(tl-append $1 $2)))
|
||||||
(t3 (tl-append t2 '(extern-C-end))))
|
|
||||||
t3))
|
|
||||||
(else (tl-append $1 $2))))
|
|
||||||
;; external-declaration => function-definition
|
;; external-declaration => function-definition
|
||||||
(lambda ($1 . $rest) $1)
|
(lambda ($1 . $rest) $1)
|
||||||
;; external-declaration => declaration
|
;; external-declaration => declaration
|
||||||
|
@ -717,8 +714,13 @@
|
||||||
(lambda ($1 . $rest) $1)
|
(lambda ($1 . $rest) $1)
|
||||||
;; external-declaration => cpp-statement
|
;; external-declaration => cpp-statement
|
||||||
(lambda ($1 . $rest) $1)
|
(lambda ($1 . $rest) $1)
|
||||||
;; external-declaration => "extern" '$string "{" translation-unit "}"
|
;; external-declaration => "extern" '$string "{" external-declaration-li...
|
||||||
(lambda ($5 $4 $3 $2 $1 . $rest) (tl->list $4))
|
(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-...
|
;; function-definition => declaration-specifiers declarator declaration-...
|
||||||
(lambda ($4 $3 $2 $1 . $rest)
|
(lambda ($4 $3 $2 $1 . $rest)
|
||||||
`(knr-fctn-defn
|
`(knr-fctn-defn
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -93,6 +93,8 @@
|
||||||
(lambda ($2 $1 . $rest) `(post-inc ,$1))
|
(lambda ($2 $1 . $rest) `(post-inc ,$1))
|
||||||
;; postfix-expression => postfix-expression "--"
|
;; postfix-expression => postfix-expression "--"
|
||||||
(lambda ($2 $1 . $rest) `(post-dec ,$1))
|
(lambda ($2 $1 . $rest) `(post-dec ,$1))
|
||||||
|
;; primary-expression => '$ident
|
||||||
|
(lambda ($1 . $rest) `(ident ,$1))
|
||||||
;; primary-expression => '$fixed
|
;; primary-expression => '$fixed
|
||||||
(lambda ($1 . $rest) `(fixed ,$1))
|
(lambda ($1 . $rest) `(fixed ,$1))
|
||||||
;; primary-expression => '$chlit
|
;; primary-expression => '$chlit
|
||||||
|
|
|
@ -8,96 +8,100 @@
|
||||||
|
|
||||||
(define len-v
|
(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
|
#(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
|
(define pat-v
|
||||||
#(((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11
|
#(((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 .
|
||||||
. 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16)
|
9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (
|
||||||
(43 . 17) (44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23) (50
|
42 . 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22) (48 . 23) (49
|
||||||
. 24)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8)
|
. 24) (50 . 25)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7)
|
||||||
(11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42
|
(9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 .
|
||||||
. 16) (43 . 17) (44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23
|
15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22)
|
||||||
) (50 . 53) (36 . 54)) ((4 . 52)) ((-1 . -42)) ((-1 . -41)) ((-1 . -38)) (
|
(48 . 23) (49 . 24) (50 . 54) (36 . 55)) ((3 . 53)) ((-1 . -43)) ((-1 .
|
||||||
(4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9)
|
-42)) ((-1 . -41)) ((-1 . -38)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (
|
||||||
(16 . 10) (15 . 11) (38 . 12) (39 . 51)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4)
|
37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (
|
||||||
(37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12)
|
39 . 52)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8
|
||||||
(39 . 50)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10
|
) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 51)) ((3 . 1) (4
|
||||||
. 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 49)) ((4 . 1) (5 . 2) (6
|
. 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (
|
||||||
. 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 .
|
16 . 11) (15 . 12) (38 . 13) (39 . 50)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (
|
||||||
11) (38 . 12) (39 . 48)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6)
|
7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38
|
||||||
(9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 47)) ((4 .
|
. 13) (39 . 49)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7
|
||||||
1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16
|
) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 48)) ((3
|
||||||
. 10) (15 . 11) (38 . 12) (39 . 46)) ((9 . 44) (8 . 45) (-1 . -31)) ((-1
|
. 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11
|
||||||
. -27)) ((14 . 41) (13 . 42) (12 . 43) (-1 . -24)) ((16 . 39) (15 . 40) (
|
. 10) (16 . 11) (15 . 12) (38 . 13) (39 . 47)) ((9 . 45) (8 . 46) (-1 .
|
||||||
-1 . -21)) ((18 . 37) (17 . 38) (-1 . -16)) ((22 . 33) (21 . 34) (20 . 35)
|
-31)) ((-1 . -27)) ((14 . 42) (13 . 43) (12 . 44) (-1 . -24)) ((16 . 40) (
|
||||||
(19 . 36) (-1 . -13)) ((24 . 31) (23 . 32) (-1 . -11)) ((25 . 30) (-1 .
|
15 . 41) (-1 . -21)) ((18 . 38) (17 . 39) (-1 . -16)) ((22 . 34) (21 . 35)
|
||||||
-9)) ((26 . 29) (-1 . -7)) ((27 . 28) (-1 . -5)) ((28 . 27) (-1 . -3)) ((
|
(20 . 36) (19 . 37) (-1 . -13)) ((24 . 32) (23 . 33) (-1 . -11)) ((25 .
|
||||||
31 . 25) (29 . 26) (2 . -1) (1 . -1) (35 . -1)) ((35 . 0)) ((4 . 1) (5 . 2
|
31) (-1 . -9)) ((26 . 30) (-1 . -7)) ((27 . 29) (-1 . -5)) ((28 . 28) (-1
|
||||||
) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15
|
. -3)) ((31 . 26) (29 . 27) (2 . -1) (1 . -1) (35 . -1)) ((35 . 0)) ((3 .
|
||||||
. 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 .
|
1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11
|
||||||
18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 76)) ((4 . 1) (5 . 2) (6
|
. 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17
|
||||||
. 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 .
|
) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22) (48 . 23) (49 . 77)) (
|
||||||
11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 . 18)
|
(3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9)
|
||||||
(45 . 19) (46 . 20) (47 . 21) (48 . 75)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4)
|
(11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42
|
||||||
(37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (
|
. 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 22) (48 . 76)) ((3 . 1
|
||||||
39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 . 18) (45 . 19) (46
|
) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 .
|
||||||
. 20) (47 . 74)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7)
|
10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17)
|
||||||
(10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41
|
(43 . 18) (44 . 19) (45 . 20) (46 . 21) (47 . 75)) ((3 . 1) (4 . 2) (5 . 3
|
||||||
. 15) (42 . 16) (43 . 17) (44 . 18) (45 . 19) (46 . 73)) ((4 . 1) (5 . 2)
|
) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (
|
||||||
(6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15
|
15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44
|
||||||
. 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17) (44 . 18
|
. 19) (45 . 20) (46 . 74)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 .
|
||||||
) (45 . 72)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10
|
6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 .
|
||||||
. 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15)
|
14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 73)) ((3 . 1)
|
||||||
(42 . 16) (43 . 17) (44 . 71)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5)
|
(4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10
|
||||||
(8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13)
|
) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (
|
||||||
(40 . 14) (41 . 15) (42 . 16) (43 . 70)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4)
|
43 . 18) (44 . 72)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8
|
||||||
(37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (
|
. 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (
|
||||||
39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 69)) ((4 . 1) (5 . 2) (6 . 3)
|
40 . 15) (41 . 16) (42 . 17) (43 . 71)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (
|
||||||
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
|
7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38
|
||||||
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 68)) ((4 . 1) (5 . 2) (6 . 3)
|
. 13) (39 . 14) (40 . 15) (41 . 16) (42 . 17) (43 . 70)) ((3 . 1) (4 . 2)
|
||||||
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
|
(5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16
|
||||||
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 67)) ((4 . 1) (5 . 2) (6 . 3)
|
. 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 69)) ((3 . 1
|
||||||
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
|
) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 .
|
||||||
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 66)) ((4 . 1) (5 . 2) (6 . 3)
|
10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (42 . 68))
|
||||||
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
|
((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9
|
||||||
38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 65)) ((4 . 1) (5 . 2) (6 . 3)
|
) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41 . 16) (
|
||||||
(7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (
|
42 . 67)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8
|
||||||
38 . 12) (39 . 13) (40 . 14) (41 . 64)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (
|
) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 15) (41
|
||||||
37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (
|
. 16) (42 . 66)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7
|
||||||
39 . 13) (40 . 14) (41 . 63)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8
|
) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40
|
||||||
. 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (
|
. 15) (41 . 65)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7)
|
||||||
40 . 62)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 .
|
(9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 .
|
||||||
8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 13) (40 . 61)) ((4 . 1) (5
|
15) (41 . 64)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (
|
||||||
. 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10)
|
9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 63
|
||||||
(15 . 11) (38 . 12) (39 . 60)) ((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5)
|
)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10
|
||||||
(8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 . 10) (15 . 11) (38 . 12) (39 . 59))
|
. 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 14) (40 . 62)) ((3 . 1)
|
||||||
((4 . 1) (5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 .
|
(4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 .
|
||||||
9) (16 . 10) (15 . 11) (38 . 12) (39 . 58)) ((-1 . -39)) ((-1 . -40)) ((-1
|
10) (16 . 11) (15 . 12) (38 . 13) (39 . 61)) ((3 . 1) (4 . 2) (5 . 3) (6
|
||||||
. -32)) ((-1 . -33)) ((-1 . -34)) ((-1 . -35)) ((-1 . -36)) ((-1 . -37))
|
. 4) (7 . 5) (37 . 6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 .
|
||||||
((3 . 57)) ((2 . -45) (1 . -45)) ((2 . 55) (1 . 56)) ((-1 . -44)) ((4 . 1)
|
12) (38 . 13) (39 . 60)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 . 6)
|
||||||
(5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 .
|
(8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 . 59
|
||||||
10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17)
|
)) ((-1 . -39)) ((-1 . -40)) ((-1 . -32)) ((-1 . -33)) ((-1 . -34)) ((-1
|
||||||
(44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23) (50 . 79)) ((2
|
. -35)) ((-1 . -36)) ((-1 . -37)) ((7 . 58)) ((2 . -46) (1 . -46)) ((2 .
|
||||||
. 78)) ((-1 . -30)) ((-1 . -29)) ((-1 . -28)) ((14 . 41) (13 . 42) (12 .
|
56) (1 . 57)) ((-1 . -45)) ((3 . 1) (4 . 2) (5 . 3) (6 . 4) (7 . 5) (37 .
|
||||||
43) (-1 . -26)) ((14 . 41) (13 . 42) (12 . 43) (-1 . -25)) ((16 . 39) (15
|
6) (8 . 7) (9 . 8) (10 . 9) (11 . 10) (16 . 11) (15 . 12) (38 . 13) (39 .
|
||||||
. 40) (-1 . -23)) ((16 . 39) (15 . 40) (-1 . -22)) ((18 . 37) (17 . 38) (
|
14) (40 . 15) (41 . 16) (42 . 17) (43 . 18) (44 . 19) (45 . 20) (46 . 21)
|
||||||
-1 . -20)) ((18 . 37) (17 . 38) (-1 . -19)) ((18 . 37) (17 . 38) (-1 . -18
|
(47 . 22) (48 . 23) (49 . 24) (50 . 80)) ((2 . 79)) ((-1 . -30)) ((-1 .
|
||||||
)) ((18 . 37) (17 . 38) (-1 . -17)) ((22 . 33) (21 . 34) (20 . 35) (19 .
|
-29)) ((-1 . -28)) ((14 . 42) (13 . 43) (12 . 44) (-1 . -26)) ((14 . 42) (
|
||||||
36) (-1 . -15)) ((22 . 33) (21 . 34) (20 . 35) (19 . 36) (-1 . -14)) ((24
|
13 . 43) (12 . 44) (-1 . -25)) ((16 . 40) (15 . 41) (-1 . -23)) ((16 . 40)
|
||||||
. 31) (23 . 32) (-1 . -12)) ((25 . 30) (-1 . -10)) ((26 . 29) (-1 . -8)) (
|
(15 . 41) (-1 . -22)) ((18 . 38) (17 . 39) (-1 . -20)) ((18 . 38) (17 .
|
||||||
(27 . 28) (-1 . -6)) ((28 . 27) (-1 . -4)) ((30 . 77) (29 . 26)) ((4 . 1)
|
39) (-1 . -19)) ((18 . 38) (17 . 39) (-1 . -18)) ((18 . 38) (17 . 39) (-1
|
||||||
(5 . 2) (6 . 3) (7 . 4) (37 . 5) (8 . 6) (9 . 7) (10 . 8) (11 . 9) (16 .
|
. -17)) ((22 . 34) (21 . 35) (20 . 36) (19 . 37) (-1 . -15)) ((22 . 34) (
|
||||||
10) (15 . 11) (38 . 12) (39 . 13) (40 . 14) (41 . 15) (42 . 16) (43 . 17)
|
21 . 35) (20 . 36) (19 . 37) (-1 . -14)) ((24 . 32) (23 . 33) (-1 . -12))
|
||||||
(44 . 18) (45 . 19) (46 . 20) (47 . 21) (48 . 22) (49 . 23) (50 . 80)) ((
|
((25 . 31) (-1 . -10)) ((26 . 30) (-1 . -8)) ((27 . 29) (-1 . -6)) ((28 .
|
||||||
-1 . -43)) ((2 . -46) (1 . -46)) ((2 . -2) (1 . -2) (35 . -2))))
|
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
|
(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
|
#(#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
|
(define mtab
|
||||||
'(("," . 1) (")" . 2) ($ident . 3) ("(" . 4) ("defined" . 5) ($chlit . 6)
|
'(("," . 1) (")" . 2) ("(" . 3) ("defined" . 4) ($chlit . 5) ($fixed . 6)
|
||||||
($fixed . 7) ("--" . 8) ("++" . 9) ("~" . 10) ("!" . 11) ("%" . 12) ("/"
|
($ident . 7) ("--" . 8) ("++" . 9) ("~" . 10) ("!" . 11) ("%" . 12) ("/"
|
||||||
. 13) ("*" . 14) ("-" . 15) ("+" . 16) (">>" . 17) ("<<" . 18) (">=" . 19)
|
. 13) ("*" . 14) ("-" . 15) ("+" . 16) (">>" . 17) ("<<" . 18) (">=" . 19)
|
||||||
(">" . 20) ("<=" . 21) ("<" . 22) ("!=" . 23) ("==" . 24) ("&" . 25) ("^"
|
(">" . 20) ("<=" . 21) ("<" . 22) ("!=" . 23) ("==" . 24) ("&" . 25) ("^"
|
||||||
. 26) ("|" . 27) ("&&" . 28) ("||" . 29) (":" . 30) ("?" . 31) (
|
. 26) ("|" . 27) ("&&" . 28) ("||" . 29) (":" . 30) ("?" . 31) (
|
||||||
|
|
|
@ -48,10 +48,12 @@
|
||||||
(cons 'rto-v rto-v) (cons 'mtab mtab)
|
(cons 'rto-v rto-v) (cons 'mtab mtab)
|
||||||
(cons 'act-v act-v)))))
|
(cons 'act-v act-v)))))
|
||||||
(lambda* (lexer #:key (debug #f))
|
(lambda* (lexer #:key (debug #f))
|
||||||
|
|
||||||
(with-throw-handler
|
(with-throw-handler
|
||||||
'nyacc-error
|
'nyacc-error
|
||||||
(lambda () (c99-parser lexer #:debug debug))
|
(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.
|
;; This is used to parse included files at top level.
|
||||||
(define (run-parse)
|
(define (run-parse)
|
||||||
|
|
|
@ -45,30 +45,31 @@
|
||||||
(let ((info (fluid-ref *info*)))
|
(let ((info (fluid-ref *info*)))
|
||||||
(raw-parser (gen-c-lexer) #:debug (cpi-debug 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.
|
;; This needs to be explained in some detail.
|
||||||
;; [#:tyns '("foo_t")]
|
;; [#:tyns '("foo_t")]
|
||||||
(define* (parse-c99x xstr
|
(define* (parse-c99x expr-string
|
||||||
#:key
|
#:key
|
||||||
(cpp-defs '()) ; CPP defines
|
(cpp-defs '()) ; CPP defines
|
||||||
(tn-dict '()) ; typedef dictionary
|
(tn-dict '()) ; typedef dictionary
|
||||||
(xdef? #f) ; pred to determine expand
|
(xdef? #f) ; pred to determine expand
|
||||||
(debug #f) ; debug?
|
(debug #f) ; debug?
|
||||||
(tyns '())) ; defined typenames
|
(tyns '())) ; defined typenames
|
||||||
(with-input-from-string xstr
|
(with-input-from-string expr-string
|
||||||
(catch
|
(lambda ()
|
||||||
#t
|
(catch
|
||||||
(lambda ()
|
'c99-error
|
||||||
(let ((info (make-cpi debug cpp-defs '(".") tn-dict)))
|
(lambda ()
|
||||||
(set-cpi-ptl! info (cons tyns (cpi-ptl info)))
|
(let ((info (make-cpi debug cpp-defs '(".") tn-dict)))
|
||||||
(with-fluid*
|
(set-cpi-ptl! info (cons tyns (cpi-ptl info)))
|
||||||
*info* info
|
(with-fluid*
|
||||||
(lambda ()
|
*info* info
|
||||||
(raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
|
(lambda ()
|
||||||
#:debug debug))))))
|
(raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
|
||||||
(lambda (key fmt . rest)
|
#:debug debug)))))
|
||||||
(report-error fmt rest)
|
(lambda (key fmt . rest)
|
||||||
#f)))
|
(report-error fmt rest)
|
||||||
|
#f)))))
|
||||||
|
|
||||||
(define parse-cx parse-c99x)
|
(define parse-cx parse-c99x)
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ the file COPYING included with the this distribution.")
|
||||||
(let ((fn (or (port-filename (current-input-port)) "(unknown)"))
|
(let ((fn (or (port-filename (current-input-port)) "(unknown)"))
|
||||||
(ln (1+ (port-line (current-input-port)))))
|
(ln (1+ (port-line (current-input-port)))))
|
||||||
(apply simple-format (current-error-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 =====================
|
;; === input stack =====================
|
||||||
|
|
||||||
|
|
|
@ -473,6 +473,7 @@
|
||||||
;; char -> (char . char)
|
;; char -> (char . char)
|
||||||
;; @end enumerate
|
;; @end enumerate
|
||||||
;; todo: add bol status
|
;; todo: add bol status
|
||||||
|
;; todo: maybe separate reading of keywords from identifiers: (keywd ch) =>
|
||||||
(define* (make-lexer-generator match-table
|
(define* (make-lexer-generator match-table
|
||||||
#:key ident-reader num-reader
|
#:key ident-reader num-reader
|
||||||
string-reader chlit-reader
|
string-reader chlit-reader
|
||||||
|
|
Loading…
Reference in New Issue