From d3abced2923c409ed27393f6ff554b5638c025e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 30 Jun 2022 00:23:06 +0200 Subject: C parser add unary minus. --- module/c/lex.scm | 10 +++++++--- module/c/parse.scm | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'module/c') diff --git a/module/c/lex.scm b/module/c/lex.scm index 30fcd3c1..2b024f1c 100644 --- a/module/c/lex.scm +++ b/module/c/lex.scm @@ -108,14 +108,18 @@ base-10-digit)))) (define-peg-pattern prefix-operator all - (or "!" "~" "*" "&" "++" "--" "+" "-")) + ;; It's important that ++ and -- are BEFORE + and - + ;; otherwise the first + is found, leaving the second +, which fails + ;; to lex since it's an invalid token + (or "*" "&" "++" "--" + "!" "~" "+" "-")) + ;;; Note that stacked pre or postfix operators without parenthesis ;;; dosen't work. So `*&C' is invalid, while `*(&C)' is valid. (define-peg-pattern prefix all - (and prefix-operator sp (or variable group funcall #; postfix - ))) + (and prefix-operator sp (or variable group funcall literal))) (define-peg-pattern postfix-operator all (or "++" "--" "*")) diff --git a/module/c/parse.scm b/module/c/parse.scm index ad716132..15240bc1 100644 --- a/module/c/parse.scm +++ b/module/c/parse.scm @@ -123,6 +123,7 @@ ((&) 'pointer) ((++) 'pre-increment) ((--) 'pre-decrement) + ((-) '-) (else (scm-error 'c-parse-error "parse-lexeme-tree" "Unknown prefix operator ~s" (list op) #f)))] @@ -150,6 +151,10 @@ `(,(parse-lexeme-tree op) ,(parse-lexeme-tree arg))] + + + + ;; resolved-operator and ternary are the return "types" ;; of resolve-order-of-operations [(('resolved-operator op) args ...) -- cgit v1.2.3