aboutsummaryrefslogtreecommitdiff
path: root/module/c/lex.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/c/lex.scm')
-rw-r--r--module/c/lex.scm34
1 files changed, 21 insertions, 13 deletions
diff --git a/module/c/lex.scm b/module/c/lex.scm
index 2b024f1c..b6523a87 100644
--- a/module/c/lex.scm
+++ b/module/c/lex.scm
@@ -43,22 +43,23 @@
(define-peg-pattern integer all
(and (or base-8 base-16 base-10) (? integer-suffix)))
-;; (define-peg-pattern float-suffix all
-;; (* (or "f" "F" "l" "L")))
+(define-peg-pattern float-suffix all
+ (* (or "f" "F" "l" "L")))
-;; (define-peg-pattern exponent all
-;; (and (ignore (or "e" "E")) (? (or "+" "-")) base-10))
+(define-peg-pattern exponent all
+ (and (ignore (or "e" "E")) (? (or "+" "-")) base-10))
-;; (define-peg-pattern float all
-;; (or
-;; (and base-10 exponent (? float-suffix))
-;; (and base-10 (ignore ".") (? exponent) (? float-suffix))
-;; (and (? base-10) (ignore ".") base-10 (? exponent) (? float-suffix))))
+;; Helper patterns for creating named groups in float
+(define-peg-pattern float-integer all base-10)
+(define-peg-pattern float-decimal all base-10)
+
+(define-peg-pattern float all
+ (or (and float-integer exponent (? float-suffix))
+ (and (? float-integer) (ignore ".") float-decimal (? exponent) (? float-suffix))
+ (and float-integer (ignore ".") (? exponent) (? float-suffix))))
(define-peg-pattern number body
- (or ; float
- integer
- ))
+ (or float integer))
(define-peg-pattern group all
(and (ignore "(") expr (ignore ")")))
@@ -145,7 +146,14 @@
;;; main parser
(define-peg-pattern expr body
- (+ (and sp (or infix postfix prefix funcall group literal variable)
+ (+ (and sp (or
+ ;; float must be BEFORE infix, otherwise 3.2 is parsed as (infix 3 (operator ".") 2)
+ ;; that however breaks the infix logic, meaning that floating point numbers can't be
+ ;; used in basic arithmetic.
+ ;; TODO remove all implicit order of operations handling in the lexer, and move it to
+ ;; the parser. This should also fix the case of typecasts being applied incorrectly.
+ float
+ infix postfix prefix funcall group literal variable)
sp)))