From 41a386b1a35441f198e8a17fd042937c8eb5018c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 25 May 2021 20:30:53 -0400 Subject: Support pre-existing variables in the compiler --- src/c.bqn | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/c.bqn b/src/c.bqn index af1d5dfd..742a05af 100644 --- a/src/c.bqn +++ b/src/c.bqn @@ -36,7 +36,7 @@ T←⌈`× ⋄ IT←↕∘≠⊸T ⋄ I1T←(1+↕∘≠)⊸T # Source to ⟨tokens, roles, number of identifiers, literals⟩ # Identifiers then literal tokens are numbered starting at vi -Tokenize←{ +Tokenize←{System‿vars←𝕨 # Resolve comments and strings c←𝕩='#'⋄s←/0‿0⊸«⊸∧sm←𝕩='''⋄d←/dm←𝕩='"' g←⍋q←∾⟨ s⋄¯1↓d⋄/c⟩ ⋄q↩g⊏q # Open indices @@ -70,14 +70,14 @@ Tokenize←{ ir←(us/˜«⊸us)×+`w>n # Identifier groups {⟨is⊏˜𝕩/𝕨,"Numbers can't start with underscores"⟩!0}⍟(∨´⊢)⟜(ws<(⊑bA)>⊏⟜t)/(¯1»⌈`)⊸¯1»⌈`)⊸/¨˜↩j←⊐¨k # IDs j into uniques k - k↩𝕎⌾(1⊸⊑)k # System value lookup + k↩System⌾(1⊸⊑)k # System value lookup wf←¬l∨t M bW⋄ie/˜↩wf∨>⟜«l # Index management for... - t↩(w∨wf)Fs(∾j++`vd»kk←≠¨k)⌾(ki⊸⊏)t # Add IDs; remove words/whitespace + t↩(w∨wf)Fs(vars≠⊸↓∾j++`vd»kk←≠¨k)⌾(ki⊸⊏)t # Add IDs; remove words/whitespace t-↩t(M×-⟜⊑)bS # Separators are equivalent p←≠`1¨sb←¯1↓1↓/1(∾≠∾˜)t=sep # Separator group boundaries (excludes leading and trailing) sk←sb/˜p>∨⟜«(p+(sb-p)⊏t)∊3‿5+⊑bB # Keep the first of each group that's not just inside a bracket @@ -111,7 +111,7 @@ ReadNums←{ } -Parse ← {r‿vn‿i‿e←𝕨⋄nv←≠vn +Parse ← {r‿vn‿i‿e‿def←𝕨⋄nv←≠vn ErrMismatchedBrackets←{ Lcs ← ∧○(0<≠)◶⟨0, ¯1 ⊑ 0¨∘⊢ {𝕩⌈⌈`𝕨+»𝕩}˝ =⌜⟜⌽⟩ _mis_ ← {"Missing "∾𝕗∾" "∾charSet⊏˜𝕘+⊢/˜≠∘⊣=⊒} @@ -200,21 +200,25 @@ Parse ← {r‿vn‿i‿e←𝕨⋄nv←≠vn id←/(gi⊏«aa∧a)blk, oi, tx⟩ } -- cgit v1.2.3