I'm not sure that a balanced parsing always has an odd number of boxes.

For example, 'a(b)'

Or, if we require that the first character always be a '(' then '(b)a'

If there's a requirement that the first and last characters always be
'(' and ')' then that would give the "balanced parsing always has an
odd number of boxes" constraint.

Thanks,

-- 
Raul


On Wed, Dec 7, 2016 at 3:34 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> the requirement is to cut based on outer parentheses level.  For inner 
> parentheses, if you want those also cut, then you would repeat the function 
> on odd indexes.  Yes you got this right
>
>
> "My guess is you are asking for: each time boxing changes between level 0
> and 1 you want a box fret. Box levels beyond 1 are ignored."
>
> Your solution seems beautiful
>
>
> F=: (]~:0,}:)@:(1<.])
>
> with change to depth to make it ambivalent (and so paren characters a 
> parameter)
>
> depth =: ([: +/\ =/\@(''''&~:) * 1 _1 0 {~ '()' i. ]) :  ([: +/\ 
> =/\@(''''&~:)@] * 1 _1 0 {~  i.)cutP =: ({:@] ,~ ]) <;._2~ 1 ,~ (] ~: 0 , 
> }:)@:(1 <. ])@:depth
>
> cutP '(a(bdc)g)gg(ffff)'
> ┌┬───────┬──┬────┬┐
> ││a(bdc)g│gg│ffff││
> └┴───────┴──┴────┴┘
>
> '()' cutP 'qq((a(bdc)g)gg(ffff))g'
> ┌──┬─────────────────┬─┐
> │qq│(a(bdc)g)gg(ffff)│g│
> └──┴─────────────────┴─┘
>
> I agree that you may often/always want to tunnel down into the paren group, 
> and this is accomplished by repeating the function for odd indexes.
>
>
> Assert =: 1 : '] [ [ 13!:8^:((0 e. ])`(12"_)) u@]'
> cutP2 =: 'Paren mismatch' (2 |#) Assert cutP
>
> one of the neat features of the layout is that a balanced parsing has odd 
> number of boxes.  cutP2 raises an error, though off by 2 errors are not 
> caught so not completely useful.
>
>
>
> invoke =: 4 : 'x `:0 y'"_1
> altM =: ($~ #) invoke ]
>
>
> ]`(cutP each) altM cutP 'qq((a(bdc)g)gg(ffff))g'
>
> ┌──┬───────────────────┬─┐
> │qq│┌┬───────┬──┬────┬┐│g│
> │  │││a(bdc)g│gg│ffff│││ │
> │  │└┴───────┴──┴────┴┘│ │
> └──┴───────────────────┴─┘
>
> which tunnels one level, but I am having difficulty with an elegant solution 
> to tunnel through all levels.
>
>
>
>
> ----- Original Message -----
> From: Raul Miller <[email protected]>
> To: Programming forum <[email protected]>
> Sent: Wednesday, December 7, 2016 1:31 PM
> Subject: Re: [Jprogramming] parentheses matching
>
> I am trying to make sense of your requirements.
>
> Your final example includes some parenthesis, but not others. It also
> includes at the same boxing level content from different parenthesis
> depths. How does this make sense?
>
> My guess is you are asking for: each time boxing changes between level 0
> and 1 you want a box fret. Box levels beyond 1 are ignored.
>
> With that specification, here's my F:
>
> F=: (]~:0,}:)@:(1<.])
>
> Note, of course, that this definition (and the use of <;._2) assumes that
> the first character of the argument to depth is a '('. But I think if you
> could change your specification such that it boxes level 1 content deeper
> than level 0 content that that would solve this one also.
>
> Basically, I think you need to start from what your final result looks
> like, and J's boxed type requires that everything be in boxes, so you
> should probably want a final result that looks like this:
>
>    ('a';(<'bdc');'g');'gg';(<<'ffff')
> ┌───────────┬──┬──────┐
> │┌─┬─────┬─┐│gg│┌────┐│
> ││a│┌───┐│g││  ││ffff││
> ││ ││bdc││ ││  │└────┘│
> ││ │└───┘│ ││  │      │
> │└─┴─────┴─┘│  │      │
> └───────────┴──┴──────┘
>
> In other words:
>
> *  Boxing level for characters is 1+depth.
>
> *  Box boundaries are increment boundaries.
>
> * All adjacent content at a given increment level (or higher) gets
> contained in one box.
>
> *  All parenthesis get removed.
>
> Do you agree with this specification? (Why or why not?)
>
> Thanks,
>
> --
> Raul
>
> On Wed, Dec 7, 2016 at 11:56 AM, 'Pascal Jasmin' via Programming <
> [email protected]> wrote:
>
>> There is this useful essay
>>
>> http://code.jsoftware.com/wiki/Essays/Parentheses_Matching
>>
>> but consider,
>>
>> depth =: [: +/\ =/\@(''''&~:) * 1 _1 0 {~ '()' i. ]
>>
>>     depth '(a(bdc)g)gg(ffff)'
>> 1 1 2 2 2 2 1 1 0 0 0 1 1 1 1 1 0
>>
>> my goal is to box an expression such that at the "top level", at least 3
>> boxes are generated
>>
>>
>> 'outside (' ; 'inside outer ()' ; 'outside ) and outside next top level ('
>>
>>
>> optionally followed by even number of boxes corresponding to last 2
>> conditions.
>>
>> the most straightforward path I see is to create an argument to <;._2
>> sucht that:
>>
>>  F depth '(a(bdc)g)gg(ffff)'
>> 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1
>>
>>
>> and where,
>>
>>
>> 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 1 ((<;._2) ' ' ,~ ]) '(a(bdc)g)gg(ffff)'
>> ┌┬───────┬──┬────┬┐
>> ││a(bdc)g│gg│ffff││
>> └┴───────┴──┴────┴┘
>>
>> what is F?
>> ----------------------------------------------------------------------
>> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to