thank you Raul, Nice.
adding the steps of removing the '&'s
typeparser =: (<<,'&') -.~ each (</.~ +/\@(-.@+. _1&|.)@:=&(<,'&'))@:;:
here is a clunkier version I made
typeparser =: boxopen L:1@:(> L:1)@:([: (4 : 0)/ '&'&cut)
(}: , (}. y),~ [:< ({. y) ,~&< {:) ;: >x
)
----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Monday, January 26, 2015 12:03 AM
Subject: Re: [Jprogramming] A parsing challenge
F=: </.~ +/\@(-.@+._1&|.)@:=&(<,'&')
F ;:'4&count int 3 8&inrange'
+-----------+-----+---------------+
|+-+-+-----+|+---+|+---+-+-------+|
||4|&|count|||int|||3 8|&|inrange||
|+-+-+-----+|+---+|+---+-+-------+|
+-----------+-----+---------------+
Thanks,
--
Raul
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm