Dear J enthusiasts,

I try to learn state machine parsing and try to use 4 or 5 action code in
practice.
Here is an example to be concrete.
1. So we have the file:
$ cat test1.txt
1000ddd
  2000
ab3000

11111xxx

   11
 22

2. now I want to ideally have three boxes, one containing 1000, 2000, 3000,
the second containing 11111 and the last one containing 11, 22.

3. So I create m where 1 is LF, 2 are digits, and 0 is rest
   m =. a. e. LF
   m=: m + 2* a. e. '0123456789'
   m
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4. Now I start with defining s (firstly with undesired result but still)
   s =. 1 3 2 $ 0 0  1 0  2 1
   s =. s , 3 2 $ 0 0  0 0  2 1
   s =. s , 3 2 $ 0 3  1 3  2 0

5. Running the machine gives:
d=: fread jpath './test1.txt'
   (0;s;m;0 _1 0 _1) ;: d
┌────┬────┬────┬─────┬──┬──┐
│1000│2000│3000│11111│11│22│
└────┴────┴────┴─────┴──┴──┘

which is as expected basing on s.

Now I would like to have parser that produces something like that:
┌────────────────┬───────┬───────┐
│┌────┬────┬────┐│┌─────┐│┌──┬──┐│
││1000│2000│3000│││11111│││11│22││
│└────┴────┴────┘│└─────┘│└──┴──┘│
└────────────────┴───────┴───────┘
Can I use 4/5 action code in s to achieve that in one state machine
definition? Basically the moment that separates numbers is (row) LF ->
(column) LF.

Thanks !
Pawel
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to