⍝ ⍝ Iverson's examples from 'APL IN EXPOSITION' ⍝ [0]∇ Z←C E [1] Z←E[CENTRALFN E] [2]∇ ⍝ [0]∇ Z←CENTRALFN E [1] Z←((FUNCTIONS E)∧0=DEPTH E)⍳1 [2]∇ ⍝ [0]∇ Z←DEPTH E [1] Z←+\(E='(')-0,¯1↓E=')' [2]∇ ⍝ [0]∇ Z←FUNCTIONS E [1] Z←E∊'←+-×÷<≤=≥>≠∨∧?∊⍴~↑↓⍳○*⍟⌈⌊⊥⊤|' ⍝ [0]∇ Z←L E [1] Z←(¯1+CENTRALFN E)↑E [2]∇ ⍝ [0]∇ Z←A ON B [1] A←(¯2↑1 1,⍴A)⍴A [2] B←(¯2↑1 1,⍴B)⍴B [3] Z←(((⍴A)⌈0 1×⍴B)↑A),[1]((⍴B)⌈0 1×⍴A)↑B [4]∇ ⍝ [0]∇ Z←STRIP E [1] →0×⍳1≠⌊/DEPTH Z←E [2] Z←STRIP 1↓¯1↓E [3]∇ ⍝ [0]∇ Z←PARSE E [1] →0×⍳∧/~FUNCTIONS Z←STRIP E [2] Z←(' ',' ',PARSE R Z)ON(C Z)ON' ',' ',PARSE L Z [3] ∇ ⍝ [0] Z←R E [1] Z←(CENTRALFN E)↓E [2]∇ ⍝ Exemple of an expression S3←'(A+D)-(÷A)+((B+G)×D)÷G+1○G' ⍝ ⍝ Iverson's examples from 'APL IN EXPOSITION' ⍝ ∇ Z←C E ⍝ Central operator Z←E[CENTRALFN E] ∇ ⍝ ∇ Z←CENTRALFN E ⍝ Index of operator of lexical level 0 Z←((FUNCTIONS E)∧0=DEPTH E)⍳1 ∇ ⍝ ∇ Z←DEPTH E ⍝ Lexical level of expression Z←+\(E='(')-0,¯1↓E=')' ∇ ⍝ ∇ Z←FUNCTIONS E ⍝ Mask of operators in expression Z←E∊'←+-×÷<≤=≥>≠∨∧?∊⍴~↑↓⍳○*⍟⌈⌊⊥⊤|' ∇ ⍝ ∇ Z←L E ⍝ Left operand, taken up to central op Z←(¯1+CENTRALFN E)↑E ∇ ⍝ ∇ Z←A ON B ⍝ Utility function stacking 2 strings A←(¯2↑1 1,⍴A)⍴A B←(¯2↑1 1,⍴B)⍴B Z←(((⍴A)⌈0 1×⍴B)↑A),[1]((⍴B)⌈0 1×⍴A)↑B ∇ ⍝ ∇ Z←STRIP E ⍝ Remove wrapping parentheses →0×⍳1≠⌊/DEPTH Z←E Z←STRIP 1↓¯1↓E ∇ ⍝ ∇ Z←PARSE E ⍝ Expression represented as a fallen tree ⍝ Right expression on top of central operator on top of left operator →0×⍳∧/~FUNCTIONS Z←STRIP E Z←(' ',' ',PARSE R Z)ON(C Z)ON' ',' ',PARSE L Z ∇ ⍝ ∇ Z←R E ⍝ Right operand by dropping beginning up to and including central operator Z←(CENTRALFN E)↓E ∇ ⍝ Example of a parsing S3←'(A+D)-(÷A)+((B+G)×D)÷G+1○G' ⍝ PARSE '(A+B)' ⍝