From 6f9af58e183e40a3c876230e41c3221155e4dcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 30 Jun 2022 07:07:11 +0200 Subject: C parser minor cleanup. --- module/c/parse.scm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'module/c/parse.scm') 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) -- cgit v1.2.3