Here is my solution. I am not sure how robust it is but it passes the test cases

curPrevNext=:((|.!.0),.([ ,. 1&(|.!.0)))
findAmp =: ((<,'&') e.~ ])
translate =: (3,1,1,_1) {~ (1,2,4) i. #.
parse=: ( */\ @: translate @: curPrevNext @: findAmp </. ])  ;:

NB. parse f.
parse2=: (*/\@:(3 1 1 _1 {~ 1 2 4 i. #.)@:(|.!.0 ,. [ ,.
1&(|.!.0))@:((<,'&') e.~ ]) </. ]) ;:

parse 'str int 3 8&inrange'
parse '4&count int 3 8&inrange'


   ((0 1 2 2 2 </. ;:) -: parse) 'str int 3 8&inrange'
1

   ((1 1 1 0 2 2 2 </. ;:) -: parse) '4&count int 3 8&inrange'
1


On Sun, Jan 25, 2015 at 11:32 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> I want the following output from parsing the string on the right,
>
>   1 1 1 0 2 2 2 </. ;: '4&count int 3 
> 8&inrange'┌───────────┬─────┬───────────────┐
> │┌─┬─┬─────┐│┌───┐│┌───┬─┬───────┐│
> ││4│&│count│││int│││3 8│&│inrange││
> │└─┴─┴─────┘│└───┘│└───┴─┴───────┘│
>
> └───────────┴─────┴───────────────┘
>
> or
>
> 0 1 2 2 2 </. ;: 'str int 3 8&inrange'
> ┌─────┬─────┬───────────────┐
> │┌───┐│┌───┐│┌───┬─┬───────┐│
> ││str│││int│││3 8│&│inrange││
> │└───┘│└───┘│└───┴─┴───────┘│
> └─────┴─────┴───────────────┘
>
>
> basically, I want to group 3 words together if the middle word is a '&'
>
>
> How can I calculate either the left hand argument to </. or otherwise create 
> the groupings?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to