For computer applications of Lojban, there needs to be a formal grammar of numbers. I started from xorxes' grammar below, and revised it in places and made it into a PEG grammar.
I intend to meet all the rules in chapter 18 of CLL, except the one where it contradicts Lojban for Beginners, and LfB has the more useful reading. Namely, you can have a decimal point inside a "digit" (segment) of a mixed-base number like a time.
This involves defining 14 new selma'o. SA is not handled yet (what should it do inside a number?) Also, letters mixed with numbers are not handled, but I consider this a feature and not a bug.
The "number" rule in the existing grammar is replaced, and these rules are inserted:
digits <- digit+
thousand <- digits? KIhO
whole <- thousand+ digits? / digits
approx <- whole / MAhU
after-decimal <- whole? ( RAhE whole? / JIhI approx? )?
approx-decimal <- (whole? PI)? approx
decimal2 <- whole (PI after-decimal / JIhI approx-decimal)? / PAI
decimal1 <- MAhU? decimal2 / MAhU
decimal <- decimal1 CEhI?
digitplace <- decimal PIhE?
tuple <- digitplace+
real <- decimal / tuple / indef
indef <- PI? RO / TUhO
fraction <- real? FIhU fraction? / real
complex <- fraction? KAhO fraction? / fraction
quantity <- real / fraction / DAhA quantity
range <- DAhA? SUhO quantity?
number <- indef number / range+ / complex / quantity
NO <- pre-cmavo NO-words post-cmavo
NO-words <- "no" / "pa" / "re" / "ci" / "vo" / "mu" / "xa" / "ze" / "bi" / "so" / "dau" / "fei" / "gai" / "jau" / "rei" / "vai" / "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
MAhU <- pre-cmavo MAhU-words post-cmavo
MAhU-words <- "ma'u" / "ni'u"
SUhO <- pre-cmavo SUhO-words post-cmavo
SUhO-words <- "su'e" / "su'o" / "me'i" / "za'u"
TUhO <- pre-cmavo TUhO-words post-cmavo
TUhO-words <- "tu'o" / "xo"
PAI <- pre-cmavo PAI-words post-cmavo
PAI-words <- "pai" / "te'o" / "ci'i"
CEhI <- pre-cmavo CEhI-words post-cmavo
CEhI-words <- "ce'i"
KIhO <- pre-cmavo KIhO-words post-cmavo
KIhO-words <- "ki'o"
PI <- pre-cmavo PI-words post-cmavo
PI-words <- "pi"
PIhE <- pre-cmavo PIhE-words post-cmavo
PIhE-words <- "pi'e"
RAhE <- pre-cmavo RAhE-words post-cmavo
RAhE-words <- "ra'e"
RO <- pre-cmavo RO-words post-cmavo
RO-words <- "ro" / "so'a" / "so'e" / "so'i" / "so'o" / "so'u" / "rau" / "du'e" / "mo'a" / "no'o"
JIhI <- pre-cmavo JIhI-words post-cmavo
JIhI-words <- "ji'i"
KAhO <- pre-cmavo KAhO-words post-cmavo
KAhO-words <- "ka'o"
DAhA <- pre-cmavo DAhA-words post-cmavo
DAhA-words <- "da'a"
FIhU <- pre-cmavo FIhU-words post-cmavo
FIhU-words <- "fi'u"
mi'e rab.spir
I have reformulated my grammar somewhat in light of Rob's grammar and some further thought:
quantifier = [DAhA | SUhO] ... decimal CEhI | [PI] quantity | [quantity] FIhU quantity [quantity] | quantity quantity
quantity = (DAhA | SUhO) ... & (RO | CIhI | digits)
tuple = complex & PIhE [tuple]
complex = fraction & KAhO [complex]
fraction = real & FIhU [fraction]
real = [SUhO & MAhU] (decimal | CIhI)
decimal = PAI | digits & PI (digits & RAhE digits)
digits = NO... | TUhO
New selma'o:
NO = no | pa | re | ci | vo | mu | xa | ze | bi | so | dau | fei | gai | jau | rei | vai | ki'o
RO = ro | so'a | so'e | so'i | so'o | so'u | no'o | rau | du'e | mo'a
SUhO = su'o | su'e | me'i | za'u | ji'i
DAhA = da'a
TUhO = tu'o | xo
MAhU = ma'u | ni'u
FIhU = fi'u
PI = pi
RAhE = ra'e
PAI = pai | te'o
CIhI = ci'i
KAhO = ka'o
PIhE = pi'e
CEhI = ce'i
mi'e xorxes