1. strtok question

For Kat or any others familiar with the lib:

Question:  Is there an easy way to keep some separators while removing 
others?  For example, if I was parsing a BASIC-like language and I 
wanted to keep comparison and math operators while stripping white 
space?

example:
if x=y then --> {"if","x","=","y","then"}

I was hoping to do a single pass because I figured I could always first 
replace "=" with " = " then parse on white space...

Thanks,
-- Brian

new topic     » topic index » view message » categorize

2. Re: strtok question

On 12 Mar 2003, at 19:31, Brian Broker wrote:

> 
> For Kat or any others familiar with the lib:
> 
> Question:  Is there an easy way to keep some separators while removing 
> others?  For example, if I was parsing a BASIC-like language and I 
> wanted to keep comparison and math operators while stripping white 
> space?
> 
> example:
> if x=y then --> {"if","x","=","y","then"}
> 
> I was hoping to do a single pass because I figured I could always first 
> replace "=" with " = " then parse on white space...

I don't understand the question. If you replace "=" with " = ", parse() will 
return as you give in your example.

Kat

new topic     » goto parent     » topic index » view message » categorize

3. Re: strtok question

On Wed, 12 Mar 2003 14:45:31 -0600, <gertie at visionsix.com> wrote:

>
> On 12 Mar 2003, at 20:22, Brian Broker wrote:
>
>>
>> But then I'm essentially making two passes to get what I want (first 
>> pass to replace, second to parse).  I was wondering if there was a way 
>> to get what I want with just one pass...
>
> Not with the currently released version of strtok, because you have no 
> delimiters around the "=" in your example, the complete token being 
> "x=y". In next release, i will be supplying an optional form to keep 
> multiple selected separators. Even then, there will be multiple passes 
> thru the list of separators supplied as the 2nd param of parse(), it will 
> just be hidden from you.
>
> Kat

I did supply an addition to strtok that broke apart a line based on 'words 
as tokens' so that the "x=y" would have been split into three tokens, just 
as "x  =  y" would have too. Kat, has not added this to the library yet.

-- 

cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

4. Re: strtok question

On 13 Mar 2003, at 9:50, Derek Parnell wrote:

> 
> On Wed, 12 Mar 2003 14:45:31 -0600, <gertie at visionsix.com> wrote:
> 
> >
> > On 12 Mar 2003, at 20:22, Brian Broker wrote:
> >
> >>
> >> But then I'm essentially making two passes to get what I want (first 
> >> pass to replace, second to parse).  I was wondering if there was a way 
> >> to get what I want with just one pass...
> >
> > Not with the currently released version of strtok, because you have no 
> > delimiters around the "=" in your example, the complete token being 
> > "x=y". In next release, i will be supplying an optional form to keep 
> > multiple selected separators. Even then, there will be multiple passes 
> > thru the list of separators supplied as the 2nd param of parse(), it will
> > just
> > be hidden from you.
> >
> > Kat
> 
> I did supply an addition to strtok that broke apart a line based on 'words as
> tokens' so that the "x=y" would have been split into three tokens, just as "x 
> =
>  y" would have too. Kat, has not added this to the library yet.

I wanted to make sure it worked with all the othe functions, and add a few 
more things too. For now, it would be easiest for him to write the lines with 
delimiters around the keywords.

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: strtok question

On Wed, 12 Mar 2003 17:27:26 -0600, <gertie at visionsix.com> wrote:

[snip]

>
> I wanted to make sure it worked with all the othe functions, and add a 
> few more things too. For now, it would be easiest for him to write the 
> lines with delimiters around the keywords.

Thanks, Kat. Of course that assumes he has control over the creation of the 
text blink

-- 
cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu