diff options
| -rw-r--r-- | src/c.bqn | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -48,7 +48,7 @@ Tokenize←{ tw←na⌊∘÷˜(⊑bA)-˜w/c c-↩na×l∧c≥na+⊑bA li←l>in←l∧(+`w)⊏0∾tw<0 - num←ReadNum¨¬⊸(+`⊸×-⊣)∘×⊸⊔ in∨⟜»⊸/c×l + num←ReadNums in∨⟜»⊸/○(∾⟜0)c×l ti←(us/˜«⊸<li)(⊢+∧⟜(2⊸=))0⊸≤⊸/tw id←(1-˜(li>us)×+`w>in)⊔c ki←((⍋⊏⟜in)⊸⊏/w)∾(ci∾/si)⊏+`»f @@ -61,13 +61,26 @@ Tokenize←{ ⟨c,t,≠⊑k,∾1↓k⟩ } +ErrNumericChars←{ + ⟨"Letter","s"/˜1<≠𝕩," """,𝕩⊏charSet,""" not allowed in numbers"⟩∾⊸!0 +} +ReadNums←{ + e‿n‿d‿p‿i←=⟜𝕩¨((⊑bA)+-´"ea")∾+⟜↕´bN # e¯.π∞ + ErrNumericChars∘(/⟜𝕩)⍟(∨´) ¬e∨𝕩<⊑bA + st←𝕩/˜s←d∨c←e∨z←0=𝕩 + "Negative sign in the middle of a number" ! ∧´n≤1»c + "Portion of a number is empty" ! ¬∨´(1»s∨n)∧s + "Ill-formed decimal or exponent use" ! ∧´(0⊸=∨»⊸<)st + "π and ∞ must occur alone" ! ∧´(p∨i)≤1(»∧(p∧«e)∨«)z∨n + ReadNum¨(¬⊸(+`⊸×-⊣)×𝕩)⊔𝕩-⊑bD +} ReadNum←{ - n‿d‿p‿i←+⟜↕´bN # ¯.π∞ - Nat←+⟜(10⊸×)´∘⌽ -⟜(⊑bD) + n‿d‿p‿i←10+↕4 # ¯.π∞ + Nat←+⟜(10⊸×)´∘⌽ Int←(n=⊑)◶⟨Nat,-·Nat 1⊸↓⟩ Dec←⊐⟜(<d)⊸(Nat∘↑ + ·(0<≠)◶⟨0,Nat÷10⋆≠⟩+⟜1⊸↓) Pos←(⊑p‿i⊐⊏)◶⟨π,∞,Dec⟩ - e←⊑𝕩⊐(-´"ea")+⊑bA + e←⊑𝕩⊐(-´"ea")+bA-○⊑bD m←(n=⊑)◶⟨Pos,-·Pos 1⊸↓⟩e↑𝕩 𝕩×⟜(10⋆·Int(e+1)↓⊣)˜⍟(e<≠𝕩)m } |
