Refixing parsing of numbers...

This commit is contained in:
Simon Brooke 2023-03-29 14:19:49 +01:00
parent 64ff020cb4
commit 37ba03f05e
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
3 changed files with 7 additions and 5 deletions

View file

@ -78,7 +78,7 @@
"\nSprecan '" stop-word "' tó laéfan\n")) "\nSprecan '" stop-word "' tó laéfan\n"))
(binding [*options* (:options args)] (binding [*options* (:options args)]
(pprint *options*) ;; (pprint *options*)
(when (:read *options*) (when (:read *options*)
(try (SYSIN (:read *options*)) (try (SYSIN (:read *options*))
(catch Throwable any (catch Throwable any

View file

@ -186,13 +186,14 @@
(:coefficient :exponent) (generate (second p)) (:coefficient :exponent) (generate (second p))
:cond (gen-cond p) :cond (gen-cond p)
:cond-clause (gen-cond-clause p) :cond-clause (gen-cond-clause p)
(:decimal :integer) (read-string (strip-leading-zeros (second p))) :decimal (read-string (apply str (map second (rest p))))
:defn (generate-assign p) :defn (generate-assign p)
:dotted-pair (make-cons-cell :dotted-pair (make-cons-cell
(generate (nth p 1)) (generate (nth p 1))
(generate (nth p 2))) (generate (nth p 2)))
:fncall (gen-fn-call p) :fncall (gen-fn-call p)
:iexpr (gen-iexpr p) :iexpr (gen-iexpr p)
:integer (read-string (strip-leading-zeros (second p)))
:iop (case (second p) :iop (case (second p)
"/" 'DIFFERENCE "/" 'DIFFERENCE
"=" 'EQUAL "=" 'EQUAL
@ -210,6 +211,7 @@
:mconst (make-beowulf-list :mconst (make-beowulf-list
(list 'QUOTE (symbol (upper-case (second p))))) (list 'QUOTE (symbol (upper-case (second p)))))
:mvar (symbol (upper-case (second p))) :mvar (symbol (upper-case (second p)))
:number (generate (second p))
:octal (let [n (read-string (strip-leading-zeros (second p) "0")) :octal (let [n (read-string (strip-leading-zeros (second p) "0"))
scale (generate (nth p 3))] scale (generate (nth p 3))]
(* n (expt 8 scale))) (* n (expt 8 scale)))

View file

@ -24,7 +24,7 @@
;; but it's a convenience. ;; but it's a convenience.
"exprs := expr | exprs;" "exprs := expr | exprs;"
"mexpr := λexpr | fncall | defn | cond | mvar | mconst | iexpr | mexpr comment; "mexpr := λexpr | fncall | defn | cond | mvar | mconst | iexpr | number | mexpr comment;
λexpr := λ lsqb bindings semi-colon body rsqb; λexpr := λ lsqb bindings semi-colon body rsqb;
λ := '; λ := ';
bindings := lsqb args rsqb; bindings := lsqb args rsqb;
@ -76,9 +76,9 @@
;; Lisp 1.5 supported octal as well as decimal and scientific notation ;; Lisp 1.5 supported octal as well as decimal and scientific notation
"number := integer | decimal | scientific | octal; "number := integer | decimal | scientific | octal;
integer := #'-?[1-9][0-9]*'; integer := #'-?[1-9][0-9]*';
decimal := #'-?[1-9][0-9]*\\.?[0-9]*' | #'0.[0-9]*'; decimal := integer dot integer;
scientific := coefficient e exponent; scientific := coefficient e exponent;
coefficient := integer | decimal; coefficient := decimal | integer;
exponent := integer; exponent := integer;
e := 'E'; e := 'E';
octal := #'[+-]?[0-7]+{1,12}' q scale-factor; octal := #'[+-]?[0-7]+{1,12}' q scale-factor;