;; will end up in same mode... so after
;; int x; // comment
;; the lexer will think we are not at BOL.
- (let* ((match-table mtab)
+ (let* ((match-table c99-mtab)
(read-ident read-c-ident)
(read-comm read-c-comm)
;;
(cond
((apply-helper file)) ; use helper
((not path) (p-err "not found: ~S" file)) ; file not found
- ((with-input-from-file path run-parse) => ; include tree
+ ((with-input-from-file path c99-parser-run-parse) => ; include tree
(lambda (tree) (for-each add-define (xp1 tree))))
(else (p-err "included from ~S" path)))))
((define) (add-define stmt))
(include-from-path "nyacc/lang/c99/mach.d/cpptab.scm")
(include-from-path "nyacc/lang/c99/mach.d/cppact.scm")
-(define raw-parser
+(define cpp-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))))
+ (list (cons 'len-v cpp-len-v) (cons 'pat-v cpp-pat-v) (cons 'rto-v cpp-rto-v)
+ (cons 'mtab cpp-mtab) (cons 'act-v cpp-act-v))))
(define (cpp-err fmt . args)
(apply throw 'cpp-error fmt args))
;; generate a lexical analyzer per string
(define gen-cpp-lexer
- (make-lexer-generator mtab #:comm-skipper cpp-comm-skipper))
+ (make-lexer-generator cpp-mtab #:comm-skipper cpp-comm-skipper))
;; @deffn parse-cpp-expr text => tree
;; Given a string returns a cpp parse tree. This is called by
'nyacc-error
(lambda ()
(with-input-from-string text
- (lambda () (raw-parser (gen-cpp-lexer)))))
+ (lambda () (cpp-raw-parser (gen-cpp-lexer)))))
(lambda (key fmt . args)
(apply throw 'cpp-error fmt args))))
;; or any later version published by the Free Software Foundation. See
;; the file COPYING included with the this distribution.
-(define act-v
+(define c99-act-v
(vector
;; $start => translation-unit
(lambda ($1 . $rest) $1)
;; or any later version published by the Free Software Foundation. See
;; the file COPYING included with the this distribution.
-(define len-v
+(define c99-len-v
#(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
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))
-(define pat-v
+(define c99-pat-v
#(((103 . 1) (182 . 2) (95 . -281) (-1 . -281)) ((22 . 3) (28 . 4) (29 . 5
) (30 . 6) (31 . 7) (32 . 8) (33 . 9) (34 . 10) (35 . 11) (36 . 12) (38 .
13) (37 . 14) (40 . 15) (24 . 16) (25 . 17) (26 . 18) (27 . 19) (138 . 20)
110 . 199) (111 . 200) (112 . 201) (113 . 202) (114 . 203) (115 . 204) (
116 . 205) (109 . 489)) ((-1 . -268)) ((-1 . -265)) ((-1 . -269))))
-(define rto-v
+(define c99-rto-v
#(#f 177 177 177 177 176 176 176 176 176 176 176 176 176 176 175 175 175
175 171 171 168 168 168 168 168 168 167 167 167 167 167 167 166 166 165
165 165 165 164 164 164 163 163 163 162 162 162 162 162 161 161 161 160
105 105 105 104 104 111 111 111 111 111 182 103 103 102 102 102 102 102
102 102 101 101 99 99 151 151 181 181 180 180 180 179 179 98 134 110 100))
-(define mtab
+(define c99-mtab
'((cpp-pragma . 1) (cpp-stmt . 2) ($chlit . 3) ($float . 4) ($fixed . 5) (
cpp-ident . 6) ($ident . 7) ($string . 8) ("return" . 9) ("break" . 10) (
"continue" . 11) ("goto" . 12) ("for" . 13) ("do" . 14) ("while" . 15) (
;; or any later version published by the Free Software Foundation. See
;; the file COPYING included with the this distribution.
-(define act-v
+(define c99x-act-v
(vector
;; $start => expression
(lambda ($1 . $rest) $1)
;; or any later version published by the Free Software Foundation. See
;; the file COPYING included with the this distribution.
-(define len-v
+(define c99x-len-v
#(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
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))
-(define pat-v
+(define c99x-pat-v
#(((166 . 1) (165 . 2) (164 . 3) (163 . 4) (162 . 5) (161 . 6) (160 . 7) (
8 . 8) (3 . 9) (4 . 10) (5 . 11) (6 . 12) (7 . 13) (159 . 14) (158 . 15) (
179 . 16) (180 . 17) (181 . 18) (157 . 19) (76 . 20) (77 . 21) (78 . 22) (
. -239)) ((84 . -236) (83 . -236)) ((92 . -206) (83 . -206)) ((90 . 378))
((-1 . -187)) ((90 . 377)) ((-1 . -181)) ((-1 . -186)) ((-1 . -185))))
-(define rto-v
+(define c99x-rto-v
#(#f 177 177 177 177 176 176 176 176 176 176 176 176 176 176 175 175 175
175 171 171 168 168 168 168 168 168 167 167 167 167 167 167 166 166 165
165 165 165 164 164 164 163 163 163 162 162 162 162 162 161 161 161 160
105 105 105 104 104 111 111 111 111 111 182 103 103 102 102 102 102 102
102 102 101 101 99 99 151 151 181 181 180 180 180 179 179 98 134 110 100))
-(define mtab
+(define c99x-mtab
'((cpp-pragma . 1) (cpp-stmt . 2) ($chlit . 3) ($float . 4) ($fixed . 5) (
cpp-ident . 6) ($ident . 7) ($string . 8) ("return" . 9) ("break" . 10) (
"continue" . 11) ("goto" . 12) ("for" . 13) ("do" . 14) ("while" . 15) (
;; or any later version published by the Free Software Foundation. See
;; the file COPYING included with the this distribution.
-(define act-v
+(define cpp-act-v
(vector
;; $start => conditional-expression
(lambda ($1 . $rest) $1)
;; or any later version published by the Free Software Foundation. See
;; the file COPYING included with the this distribution.
-(define len-v
+(define cpp-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 1 4 2 3 1 3))
-(define pat-v
+(define cpp-pat-v
#(((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
. 19) (45 . 20) (46 . 21) (47 . 22) (48 . 23) (49 . 24) (50 . 82)) ((-1 .
-44)) ((2 . -48) (1 . -48)) ((2 . -2) (1 . -2) (35 . -2))))
-(define rto-v
+(define cpp-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 37 37 36 36
))
-(define mtab
+(define cpp-mtab
'(("," . 1) (")" . 2) ("(" . 3) ("defined" . 4) ($chlit . 5) ($fixed . 6)
($ident . 7) ("--" . 8) ("++" . 9) ("~" . 10) ("!" . 11) ("%" . 12) ("/"
. 13) ("*" . 14) ("-" . 15) ("+" . 16) (">>" . 17) ("<<" . 18) (">=" . 19)
;;; =====================================
;; 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))))
+(define c99-mach-len-v (assq-ref c99-mach 'len-v))
+(define c99-mach-pat-v (assq-ref c99-mach 'pat-v))
+(define c99-mach-rto-v (assq-ref c99-mach 'rto-v))
+(define c99-mach-mtab (assq-ref c99-mach 'mtab))
+(define c99-mach-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 c99-mach-raw-parser (make-lalr-parser c99-mach))
-(define (run-parse)
+(define (c99-mach-run-parse)
(let ((info (fluid-ref *info*)))
- (raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
+ (c99-mach-raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
(define* (dev-parse-c99 #:key
(cpp-defs '()) ; CPP defines
(with-fluid*
*info* info
(lambda ()
- (raw-parser (gen-c-lexer #:mode mode #:xdef? xdef?)
- #:debug debug)))))
+ (c99-mach-raw-parser (gen-c-lexer #:mode mode #:xdef? xdef?)
+ #:debug debug)))))
(lambda (key fmt . rest)
(report-error fmt rest)
#f)))
;; Parse given a token generator. Uses fluid @code{*info*}.
;; A little ugly wrt re-throw but
-(define raw-parser
+(define c99-raw-parser
(let ((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)))))
+ (list (cons 'len-v c99-len-v) (cons 'pat-v c99-pat-v)
+ (cons 'rto-v c99-rto-v) (cons 'mtab c99-mtab)
+ (cons 'act-v c99-act-v)))))
(lambda* (lexer #:key (debug #f))
(catch
'nyacc-error
(throw 'c99-error "C99 parse error"))))))
;; This is used to parse included files at top level.
-(define (run-parse)
+(define (c99-parser-run-parse)
(let ((info (fluid-ref *info*)))
- (raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
+ (c99-raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
;; @deffn {Procedure} parse-c99 [#:cpp-defs def-a-list] [#:inc-dirs dir-list] \
;; [#:mode ('code|'file)] [#:debug bool]
(with-fluid*
*info* info
(lambda ()
- (raw-parser (gen-c-lexer #:mode mode #:xdef? xdef?)
- #:debug debug)))))
+ (c99-raw-parser (gen-c-lexer #:mode mode #:xdef? xdef?)
+ #:debug debug)))))
(lambda (key fmt . rest)
(report-error fmt rest)
#f)))
(include-from-path "nyacc/lang/c99/mach.d/c99xact.scm")
;; Parse given a token generator. Uses fluid @code{*info*}.
-(define raw-parser
+(define c99x-raw-parser
(let ((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)))))
+ (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)))))
(lambda* (lexer #:key (debug #f))
(catch
'nyacc-error
(pop-input) ; not sure this is right
(throw 'c99-error "C99 parse error"))))))
-(define (run-parse)
+(define (c99x-run-parse)
(let ((info (fluid-ref *info*)))
- (raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
+ (c99x-raw-parser (gen-c-lexer) #:debug (cpi-debug info))))
;; @item {Procedure} parse-c99x [#:cpp-defs defs] [#:debug bool]
;; This needs to be explained in some detail.
(with-fluid*
*info* info
(lambda ()
- (raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
- #:debug debug)))))
+ (c99x-raw-parser (gen-c-lexer #:mode 'code #:xdef? xdef?)
+ #:debug debug)))))
(lambda (key fmt . rest)
(report-error fmt rest)
#f)))))