aboutsummaryrefslogtreecommitdiff
path: root/module/c/parse.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-30 07:07:11 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:17:22 +0200
commit6f9af58e183e40a3c876230e41c3221155e4dcc2 (patch)
tree9b8395fe85fdf18dc380095a797d65ab6806624f /module/c/parse.scm
parentFix escape sequences in chars and strings. (diff)
downloadcalp-6f9af58e183e40a3c876230e41c3221155e4dcc2.tar.gz
calp-6f9af58e183e40a3c876230e41c3221155e4dcc2.tar.xz
C parser minor cleanup.
Diffstat (limited to 'module/c/parse.scm')
-rw-r--r--module/c/parse.scm24
1 files changed, 14 insertions, 10 deletions
diff --git a/module/c/parse.scm b/module/c/parse.scm
index d8cfd7cd..7d11ea17 100644
--- a/module/c/parse.scm
+++ b/module/c/parse.scm
@@ -8,8 +8,7 @@
:use-module (rnrs bytevectors)
:export (parse-lexeme-tree))
-;;; Rename this
-(define (perms set)
+(define (permutations set)
(concatenate
(map (lambda (key)
(map (lambda (o) (cons key o))
@@ -25,17 +24,17 @@
(define valid-sequences
(delete 'dummy
(lset-union eq? '(dummy)
- (map symbol-concat (perms '(() U L)))
- (map symbol-concat (perms '(() U LL))))))
+ (map symbol-concat (permutations '(() U L)))
+ (map symbol-concat (permutations '(() U LL))))))
;; => (LLU ULL LL LU UL L U)
(aif (memv (string->symbol (string-upcase str))
valid-sequences)
(case (car it)
- [(LLU ULL) '(unsigned long-long)]
+ [(LLU ULL) '(unsigned long long)]
[(LU UL) '(unsigned long)]
- [(LL) '(long-long)]
+ [(LL) '(long long)]
[(L) '(long)]
[(U) '(unsigned)])
(scm-error 'c-parse-error "parse-integer-suffix"
@@ -176,6 +175,8 @@
[('variable var) (string->symbol var)]
+ ;; normalize some binary operators to their wordy equivalent
+ ;; (which also happens to match better with scheme)
[('operator "&&") 'and]
[('operator "&=") 'and_eq]
[('operator "&") 'bitand]
@@ -185,6 +186,9 @@
[('operator "|=") 'or_eq]
[('operator "^") 'xor]
[('operator "^=") 'xor_eq]
+ ;; Change these names to something scheme can handle better
+ [('operator ".") 'object-slot]
+ [('operator "->") 'dereference-slot]
[('operator op) (string->symbol op)]
[('prefix-operator op)
@@ -211,10 +215,6 @@
[('group args ...)
(parse-lexeme-tree args)]
- ;; Atomic item. Used by flatten-infix
- [('atom body)
- (parse-lexeme-tree body)]
-
[('prefix op arg)
`(,(parse-lexeme-tree op)
,(parse-lexeme-tree arg))]
@@ -240,6 +240,8 @@
+ ;; Is it OK for literal strings to be "stored" inline?
+ ;; Or must they be a pointer?
['string #vu8(0)]
[('string str ...)
(-> (map resolve-string-fragment str)
@@ -371,6 +373,8 @@
,(resolve-order-of-operations (cons 'fixed-infix b) (cdr order))
,(resolve-order-of-operations (cons 'fixed-infix c) (cdr order)))]
[(first rest ...)
+ ;; TODO this is only valid for the associative operators (+, ...)
+ ;; but not some other (<, ...)
(if (apply eq? (map car rest))
(let ((op (caar rest)))
`((resolved-operator ,op)