parsing a line into stem



IBM's Command List programming language & Restructured Extended Executor

parsing a line into stem

Postby senthil » Sat Aug 01, 2009 6:17 pm

hi all,
i have a line say "if cust_id = ' ' then". i am passing this line to a sub routine.
    myline = 'if cust_id = xyz then'
       call mod_line    myline
 



mod_line:
parse arg var1 var2 var3 var4 var5

now instead of parsing into var1 var2 and so on...
is it possible to have it in a stem and access it whenever i wanted?
if so please provide me with a solution...
Thanks
Senthil Kumar
senthil
 
Posts: 12
Joined: Mon Jun 01, 2009 3:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: parsing a line into stem

Postby expat » Sat Aug 01, 2009 7:46 pm

Have you tried
mod_line:
aa = aa +1
parse arg var1.aa var2.aa var3.aa var4.aa var5.aa
expat
 
Posts: 459
Joined: Sat Jun 09, 2007 3:21 pm
Has thanked: 0 time
Been thanked: 8 times

Re: parsing a line into stem

Postby senthil » Sun Aug 02, 2009 5:21 pm

hi expat,
That was a good one, but if i am not sure that how many words i am going to have in the line that is aa was used 5 times since we knew the number of words in the line,if we dont know the number of words then ?
i want something like
mod_line:
parse arg var.

so that no matter how many words in that line should be parsed into var.
do i = 1 to var.0
    say var.i
end

var.1 should have the first word and so on,
the above mentioned code is the task.but how am i gonna PARSE , its left with you all.
Thanks
Senthil Kumar
senthil
 
Posts: 12
Joined: Mon Jun 01, 2009 3:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: parsing a line into stem

Postby expat » Mon Aug 03, 2009 3:05 pm

Why not try to parse a line with a variable number of inputs yourself and see what happens

It's easy enough and far quicker than waiting for someone else to do it for you
expat
 
Posts: 459
Joined: Sat Jun 09, 2007 3:21 pm
Has thanked: 0 time
Been thanked: 8 times

Re: parsing a line into stem

Postby RazVorox » Mon Feb 13, 2023 6:45 pm

wonder if it was ever solved.. coz. I'm having the same issue. as a beginner.
string, words, no idea how to push them to stem. ~shrug~
RazVorox
 
Posts: 16
Joined: Wed Oct 19, 2022 11:52 am
Has thanked: 7 times
Been thanked: 1 time

Re: parsing a line into stem

Postby enrico-sorichetti » Mon Feb 13, 2023 7:12 pm

quick and dirty ....

the snippet :

words = "word1 word2 word3 word4 word5 word6"

do i = 1 while ( words \= "" )
  parse var words word words
  stem.i = word
  stem.0 = i
end

do i = 1 to stem.0
  say i stem.i
end
 


result :

1 word1
2 word2
3 word3
4 word4
5 word5
6 word6
 
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
RazVorox (Mon Feb 13, 2023 7:30 pm)
enrico-sorichetti
Global moderator
 
Posts: 3002
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: parsing a line into stem

Postby RazVorox » Mon Feb 13, 2023 7:37 pm

The part I was missing (And didn't know existed) was WORD
The hardest part in being a newbie, is not knowing what tools exists,
when you try to translate thought patterns from other langs.

So - Thank you.
and -code- in case anyone else stumbles upon here.

Used this to parse the "SUPERC.LIST" output to words

/* Rexx -1----+----2----+----3----+----4----+----5----+----6----+----7*/
SAY "---- LINE TO STEM ----"

/* Set file vars */
DD_NAME = "Prefix.SUPERC.LIST"

/* Alloc file */
Address tso
"ALLOC F(INDD) DA("DD_NAME") SHR REUSE"
SAY " - Alloc RC = ["rc"]"

/* Read file to stem*/
"EXECIO * DISKR INDD (STEM REC. FINIS"
Say " - Read RC = ["rc"]"

/* Release file */
"FREE F(INDD)"
Say " - Free RC = ["rc"]"

/* Parse stem */
DO i=1 to REC.0  /* REC.0 holds arr len */
  PARSE VAR REC.i STR

  wordCount = WORDS(STR)
  SAY "Line ["i","wordCount"] = "STR

  DO j=0 to wordCount
    loc = j+1 /* word count starts at 1 */
    SAY "Line ["i","j"] = " WORD(STR,loc)
  END
                                       
END
                                                                   
/* End prog */                                            
Say " - Gen RC = ["rc"]"
SAY "---- EXIT ----"
EXIT
RazVorox
 
Posts: 16
Joined: Wed Oct 19, 2022 11:52 am
Has thanked: 7 times
Been thanked: 1 time

Re: parsing a line into stem

Postby sergeyken » Wed Feb 15, 2023 2:01 am

The loop
DO j=0 to wordCount
will retrieve one extra word from the input line

The statement
PARSE VAR REC.i STR
is equivalent to
STR = REC.i
and neither of them is required: REC.i can be used instead of STR everywhere.

The statement
DD_NAME = "Prefix.SUPERC.LIST"
is misleading: the value of DSNAME is assigned to variable named DD_NAME

Dataset read can be organized without any stem at all:
"EXECIO * DISKR INDD (FINIS"

DO i = 1 to Queued()  /* stack size */
  PARSE PULL STR    /* use PARSE before PULL to prevent conversion to uppercase */
  wordCount = WORDS(STR)
  DO j = 1 to wordCount
    SAY "Line ["i", "j"] = " WORD( STR, j )
  END j                                    
END i


Potential interview would be failed...
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 430
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: parsing a line into stem

Postby willy jensen » Wed Feb 15, 2023 2:16 pm

DO i = 1 to Queued() can be shortened to DO Queued() if you dont need the counter.
willy jensen
 
Posts: 465
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 70 times

Re: parsing a line into stem

Postby sergeyken » Wed Feb 15, 2023 5:50 pm

willy jensen wrote:DO i = 1 to Queued() can be shortened to DO Queued() if you dont need the counter.

Not in this particular example:
SAY "Line ["i", "j"] = " WORD( STR, j )


But there was another problem in my code; needs to be fixed:
stack_size = Queued()  
DO i = 1 to stack_size


or:
DO While Queued() > 0
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 430
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Next

Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post