| 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 |
;;; ;;; |
| 3 |
;;; Language Technologies Institute ;;; |
| 4 |
;;; Carnegie Mellon University ;;; |
| 5 |
;;; Copyright (c) 2002 ;;; |
| 6 |
;;; All Rights Reserved. ;;; |
| 7 |
;;; ;;; |
| 8 |
;;; Permission is hereby granted, free of charge, to use and distribute ;;; |
| 9 |
;;; this software and its documentation without restriction, including ;;; |
| 10 |
;;; without limitation the rights to use, copy, modify, merge, publish, ;;; |
| 11 |
;;; distribute, sublicense, and/or sell copies of this work, and to ;;; |
| 12 |
;;; permit persons to whom this work is furnished to do so, subject to ;;; |
| 13 |
;;; the following conditions: ;;; |
| 14 |
;;; 1. The code must retain the above copyright notice, this list of ;;; |
| 15 |
;;; conditions and the following disclaimer. ;;; |
| 16 |
;;; 2. Any modifications must be clearly marked as such. ;;; |
| 17 |
;;; 3. Original authors' names are not deleted. ;;; |
| 18 |
;;; 4. The authors' names are not used to endorse or promote products ;;; |
| 19 |
;;; derived from this software without specific prior written ;;; |
| 20 |
;;; permission. ;;; |
| 21 |
;;; ;;; |
| 22 |
;;; CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ;;; |
| 23 |
;;; DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ;;; |
| 24 |
;;; ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ;;; |
| 25 |
;;; SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ;;; |
| 26 |
;;; FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;;; |
| 27 |
;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ;;; |
| 28 |
;;; AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ;;; |
| 29 |
;;; ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ;;; |
| 30 |
;;; THIS SOFTWARE. ;;; |
| 31 |
;;; ;;; |
| 32 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 33 |
;;; Author: Alan W Black ([email protected]) ;;; |
| 34 |
;;; Date: August 2002 ;;; |
| 35 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 36 |
;;; ;;; |
| 37 |
;;; Generate a C compilable lts rewrite rules. ;;; |
| 38 |
;;; ;;; |
| 39 |
;;; From CMU Flite ;;; |
| 40 |
;;; ;;; |
| 41 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 42 |
|
| 43 |
(define (lts_norm_rule rule) |
| 44 |
(let (q w) |
| 45 |
|
| 46 |
(mapcar |
| 47 |
(lambda (l) |
| 48 |
(cond |
| 49 |
((string-equal l "[") |
| 50 |
(set! q (list w)) |
| 51 |
(set! w nil)) |
| 52 |
((string-equal l "]") |
| 53 |
(set! q (cons (reverse w) q)) |
| 54 |
(set! w nil)) |
| 55 |
((string-equal l "=") |
| 56 |
(set! q (cons (reverse w) q)) |
| 57 |
(set! w nil)) |
| 58 |
(t |
| 59 |
(set! w (cons l w))))) |
| 60 |
rule) |
| 61 |
|
| 62 |
(set! xxx (list |
| 63 |
(car (cddr q)) ;; reversed left hand side of rules |
| 64 |
(car (cdr q)) ;; middle condition |
| 65 |
(flip_stars (car q)) ;; RHS with * reverse |
| 66 |
(reverse w))) ;; re-write output |
| 67 |
(format t "%l %l\n" rule xxx) |
| 68 |
xxx)) |
| 69 |
|
| 70 |
(define (flip_stars q) |
| 71 |
;; We want klene star to appear before the object |
| 72 |
(cond |
| 73 |
((null q) q) |
| 74 |
((and (cdr q) |
| 75 |
(string-equal (cadr q) "*")) |
| 76 |
(cons (cadr q) |
| 77 |
(cons (car q) |
| 78 |
(flip_stars (cddr q))))) |
| 79 |
(t |
| 80 |
(cons (car q) (flip_stars (cdr q)))))) |
| 81 |
|
| 82 |
(define (ltsrewritestoC name fname odir) |
| 83 |
"(ltsrewritestoC name idir odir)" |
| 84 |
|
| 85 |
(let |
| 86 |
((ofde (fopen (path-append odir (string-append name ".c")) "w")) |
| 87 |
(ofdh (fopen (path-append odir (string-append name ".h")) "w")) |
| 88 |
(rules (car (load fname t))) |
| 89 |
(ifd)) |
| 90 |
(format ofde "/*******************************************************/\n") |
| 91 |
(format ofde "/** Autogenerated lts rewrite rules for %s */\n" name) |
| 92 |
(format ofde "/** from %s */\n" name) |
| 93 |
(format ofde "/*******************************************************/\n") |
| 94 |
(format ofde "\n") |
| 95 |
(format ofde "#include \"cst_string.h\"\n") |
| 96 |
(format ofde "#include \"cst_val.h\"\n") |
| 97 |
(format ofde "#include \"cst_lts_rewrites.h\"\n") |
| 98 |
(format ofdh "extern const cst_lts_rewrites %s;\n\n" name) |
| 99 |
|
| 100 |
(cellstovals |
| 101 |
(format nil "%s_lts_sets" name) |
| 102 |
(car (cdr (cdr rules))) |
| 103 |
ofde) |
| 104 |
(set! eoc_sets cells_count) |
| 105 |
(cellstovals |
| 106 |
(format nil "%s_lts_rules" name) |
| 107 |
(mapcar |
| 108 |
lts_norm_rule |
| 109 |
(car (cdr (cdr (cdr rules))))) |
| 110 |
ofde) |
| 111 |
|
| 112 |
(if (equal? eoc_sets 0) |
| 113 |
(format ofde "#define %s_lts_sets 0\n" name) |
| 114 |
(format ofde "#define %s_lts_sets &%s_lts_sets_%04d\n" |
| 115 |
name name eoc_sets)) |
| 116 |
(format ofde "#define %s_lts_rules &%s_lts_rules_%04d\n" |
| 117 |
name name cells_count) |
| 118 |
|
| 119 |
(format ofde "\n") |
| 120 |
(format ofde "const cst_lts_rewrites %s = {\n" name) |
| 121 |
(format ofde " \"%s\",\n" name) |
| 122 |
(format ofde " %s_lts_sets,\n" name) |
| 123 |
(format ofde " %s_lts_rules,\n" name) |
| 124 |
(format ofde "};\n") |
| 125 |
(format ofde "\n") |
| 126 |
|
| 127 |
(fclose ofde) |
| 128 |
(fclose ofdh) |
| 129 |
)) |
| 130 |
|
| 131 |
(provide 'make_lts_rewrite) |