Page 1 of 2

parsing a line into stem

PostPosted: Sat Aug 01, 2009 6:17 pm
by senthil
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...

Re: parsing a line into stem

PostPosted: Sat Aug 01, 2009 7:46 pm
by expat
Have you tried
mod_line:
aa = aa +1
parse arg var1.aa var2.aa var3.aa var4.aa var5.aa

Re: parsing a line into stem

PostPosted: Sun Aug 02, 2009 5:21 pm
by senthil
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.

Re: parsing a line into stem

PostPosted: Mon Aug 03, 2009 3:05 pm
by expat
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

Re: parsing a line into stem

PostPosted: Mon Feb 13, 2023 6:45 pm
by RazVorox
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~

Re: parsing a line into stem

PostPosted: Mon Feb 13, 2023 7:12 pm
by enrico-sorichetti
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
 

Re: parsing a line into stem

PostPosted: Mon Feb 13, 2023 7:37 pm
by RazVorox
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

Re: parsing a line into stem

PostPosted: Wed Feb 15, 2023 2:01 am
by sergeyken
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...

Re: parsing a line into stem

PostPosted: Wed Feb 15, 2023 2:16 pm
by willy jensen
DO i = 1 to Queued() can be shortened to DO Queued() if you dont need the counter.

Re: parsing a line into stem

PostPosted: Wed Feb 15, 2023 5:50 pm
by sergeyken
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