diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/c.bqn | 39 |
1 files changed, 18 insertions, 21 deletions
@@ -32,10 +32,6 @@ vi←⊑bD # Start of identifier numbering charRole←∾⥊¨˜⟜(≠↑cgl˙)⟨1,2,3,¯1,¯3,¯1‿0,¯2,0,5/⌽↕2⟩ # For first vi chars T←⌈`× ⋄ IT←↕∘≠⊸T ⋄ I1T←(1+↕∘≠)⊸T -# Error reporting for mask indicating error positions -# 𝔽 is the message and 𝔾 returns indices corresponding to the mask -_err_←{(0!˜∧∘/⟜𝔾≍○<𝔽)⍟(∨´⍟=)} - # Source to ⟨tokens, roles, number of identifiers, literals⟩ # Identifiers then literal tokens are numbered starting at vi Tokenize←{ @@ -83,6 +79,7 @@ Tokenize←{ # 𝕩 is a list of tokens that contains the numeric literals, each # preceded by 0. Return the numbers. ReadNums←{ + _err_←{(0!˜/⟜𝔾≍○<𝔽)⍟(∨´)} EChars←⟨"Letter"⊸Pl," """,⊏⟜charSet,""" not allowed in numbers"⟩_tmpl e‿p‿i‿n‿d←=⟜𝕩¨((⊑bA)+-´"ea")∾+⟜↕´bN # Masks for eπ∞¯. EChars∘(/⟜𝕩)_err_𝕨 ¬e∨𝕩<⊑bA @@ -109,28 +106,28 @@ Parse ← {r‿vn‿i‿e←𝕨⋄nv←≠vn Msg ← >○≠◶⟨"opening"_mis_ 0, "closing"_mis_ 1˜⟩ 0 !˜ 𝕨 (Lcs<⌊○≠)◶⟨Msg,"Malformed bracket nesting"⟩ 𝕩 } - GI←{𝕤⋄g⊏i} + _err_←{(0!˜(∧∘⍉(i≍e)⊏⎉1˜/⟜𝔾)≍○<𝔽)⍟(∨´⍟=)} g←⍋pd←+`p←(¯1-2×r)×𝕩 M bB⋄gb←g⊏r=¯1⋄gx←g⊏𝕩 (g⊏p)(>⟜0⊸/ErrMismatchedBrackets⍟≢1-˜<⟜0⊸/)gx "Swapped open and closed brackets" ! 0≤(⊑g)⊑pd - "Parentheses can't contain separators"_err_(gb/GI) ((⊑bB)⊸=»⊸∧sep⊸=)gb/gx - {"Empty statement or expression"_err_(𝕩/0∾GI) (4+⊑bB)≠𝕩/0∾gx}1⊸«⊸∧1∾gb + "Parentheses can't contain separators"_err_(gb/G) ((⊑bB)⊸=»⊸∧sep⊸=)gb/gx + {"Empty statement or expression"_err_(𝕩/0∾G) (4+⊑bB)≠𝕩/0∾gx}1⊸«⊸∧1∾gb r-↩(𝕩=⊑bG)>ec←«0≤r+p - "Invalid assignment or stranding use"_err_(I) ((¯4⊸<∧≤⟜¯2)r)>ec∧»0≤r + "Invalid assignment or stranding use"_err_(↕∘≠) ((¯4⊸<∧≤⟜¯2)r)>ec∧»0≤r sr←»⌾(g⊸⊏)sl←«⊸∨r=¯2⋄cp←𝕩=1+⊑bB g⊏˜↩⍋g⊏sl rev←⍋+`¯1↓(¯1∾g)(⊣⍋⊸⊏⊏˜⟜⍋¬⊏˜)⍋+`⊸+1∾g⊏sl∨r=¯1 gf←⍋fd←+`rev⊏br←p×𝕩M⟨2+⊑bB,2⟩ rev⊏˜↩gf⋄fd⊏˜↩gf - 𝕩⊏˜↩rev⋄i⊏˜↩rev⋄bv←rev⊏br⋄b←/bv<0⋄fi←+`c←bv>0 + 𝕩⊏˜↩rev⋄i⊏˜↩rev⋄e⊏˜↩rev⋄bv←rev⊏br⋄b←/bv<0⋄fi←+`c←bv>0 H←¬1(∾/∾˜)c(∨/⊣)= sn←(0‿3‿4‿5+5+⊑bI)⍋𝕩⋄fx←1 H sn⋄fr←(fx∨0⊸<)⊸+ft←(2⊸H⌈2×3⊸H)sn - "Special name outside of any block"_err_({(0=fi)∧𝕩 M bI}∘𝕩/I) 0<⊑fr + "Special name outside of any block"_err_(/{(0=fi)∧𝕩 M bI}∘𝕩) 0<⊑fr nf←(⊑bG)H𝕩 - "Can't export from a non-immediate block"_err_({(fi⊏0≠fr)∧𝕩=⊑bG}∘𝕩/I) ∨´nf>fr=0 + "Can't export from a non-immediate block"_err_(/{(fi⊏0≠fr)∧𝕩=⊑bG}∘𝕩) ∨´nf>fr=0 fsc←(ft⊏0‿2‿3)+3×fx pt←cp∧ns←¬sl∨sr r↩sl-˜ns×(1↓fr)⌾((b⊏rev)⊸⊏)r @@ -145,23 +142,23 @@ Parse ← {r‿vn‿i‿e←𝕨⋄nv←≠vn g⊏˜↩gs←⍋gr⊏sl⋄gr↩g⊏rev⋄ginv←⍋g 𝕩⊏˜↩g⋄r⊏˜↩gr⋄ir⊏˜↩gr⋄l↩(l⊏⍋gs)∾/gr⊏sr>sl ni←1+(1↓nf)/bk←b⊏ginv - "Modules must be immediately assigned"_err_(ni⊏GI)∘(∨˝¯3‿0‿¯1≠r∾⟜¯1‿1⊸(⊏˜)(↕3)+⌜⊢)⍟(0<≠)ni - "Modules must be destructured"_err_(ni⊏GI) (⊏⟜idm>⊏⟜rev⊏sr˙)(ni+1)⊏g + "Modules must be immediately assigned"_err_(ni⊏G)∘(∨˝¯3‿0‿¯1≠r∾⟜¯1‿1⊸(⊏˜)(↕3)+⌜⊢)⍟(0<≠)ni + "Modules must be destructured"_err_(ni⊏G) (⊏⟜idm>⊏⟜rev⊏sr˙)(ni+1)⊏g a←r≤¯3⋄ps←a<r<0⋄tr←1≤er←ir⊏˜IT»ps oa←⌽/op←(er<2)∧r≥2⋄ro←op∨«op∧m2←r=3 - "Missing operand"_err_(GI) op>(«∧m2≤»)m2<ro∨r∊↕2 - "Double subjects (missing ‿?)"_err_(GI) ∧⟜«ro»⊸∨⊸<r=0 + "Missing operand"_err_(G) op>(«∧m2≤»)m2<ro∨r∊↕2 + "Double subjects (missing ‿?)"_err_(G) ∧⟜«ro»⊸∨⊸<r=0 ma←tr<(𝕩=2+⊑bG)∧«ir≥1 os←↕∘≠⊸(⊣-T)⌾⌽¬ro∨ma⋄at←1+⊏⟜os⊸+ai←/a⋄af←¯4≠ai⊏r - "Role of the two sides in assignment must match"_err_(at⊏GI) (at⊏er)≠ar←at⊏r + "Role of the two sides in assignment must match"_err_(at⊏G) (at⊏er)≠ar←at⊏r aid←(¯10⊸≤∧<⟜nv)𝕩-vi - "Function or modifier assignment to a non-name"_err_(at⊏GI) ¬(ar=0)∨at⊏aid + "Function or modifier assignment to a non-name"_err_(at⊏G) ¬(ar=0)∨at⊏aid aa←×g⊏ac←»+`ginv⊏«⊸-(1+af+(ai∊ni)+2×(⊑bG)-˜ai⊏𝕩)⌾(at⊸⊏)0¨𝕩 - "Assignment target must be a name or list of targets"_err_(GI) (aid∨ps∨𝕩∊bB⊑⊸+1‿5)<aa∧0=er - "Can't use result of function/modifier assignment without parentheses"_err_(GI) (0<er)∧(0≤r)∧»⊸>aa + "Assignment target must be a name or list of targets"_err_(G) (aid∨ps∨𝕩∊bB⊑⊸+1‿5)<aa∧0=er + "Can't use result of function/modifier assignment without parentheses"_err_(G) (0<er)∧(0≤r)∧»⊸>aa ip←id⊏ac⋄d←ip M 2‿4 - zic←0¨ic←id/˜icf←2(<∧|)ip⋄II←∾⟜(icf⊸/)id⊏I + zic←0¨ic←id/˜icf←2(<∧|)ip⋄II←∾⟜(icf⊸/)∘id il←ic⊏+`bv<0⋄ex←il⊏(/∾≠)c ixf←(((1=ip)+⊏⟜(¯1∾c/gf))∾(il∾d⊸/)⊏((≠𝕩)∾b⊏gf)˜)id⊏fi d∾↩zic⋄idx∾↩icf/idx @@ -181,7 +178,7 @@ Parse ← {r‿vn‿i‿e←𝕨⋄nv←≠vn ta←tr∧2(>∨|)ps(⊢-T)+`¬ro fa←/(fe←ta∨ro∨«⊸∨ps<aa)<ff←(r=1)∨»op - "Second-level parts of a train must be functions"_err_(GI) tr>fe∨ff + "Second-level parts of a train must be functions"_err_(G) tr>fe∨ff dy←fa⊏«(𝕩=⊑bO)<(tr∧r≥0)∨ro<r=0 ob←pr⊏/¯1(⊢-»)u←⍷∧pr←𝕩⊏˜pi←/𝕩<sep cn←pi∾lt←/𝕩≥ci←vi+nv⋄ob∾↩(ci-˜≠u)+lt⊏𝕩 |
