Re: reverse scanner

2013-08-13 Thread Boyd Collier
Well, after more testing, I found that my first version (labelled frontal 
attack) doesn't always work.  Just in case anyone other than me cares, here's 
a new version that seems to work properly.  Sorry for the noise.
Boyd


// frontal attack
//  testString = @0756013;
testString = @4756013;
//  testString = @0756;
//  testString = @0;

// alleles and digitsPerAllele are passed as arguments; the values shown 
here are just for testing
int alleles = 3;
NSUInteger digitsPerAllele = 3;

NSString *subString;
NSRange range;
int theInt;
int i;
int sLength = [testString length];
range.location = 0;
int remainder = [testString length] % digitsPerAllele;
if (remainder  0) {
range.length = remainder;
subString = [testString substringWithRange:range];
theInt = [subString intValue];
--alleles;
range.location = remainder;
sLength = sLength - remainder;
}
if (sLength  0) {
range.length = digitsPerAllele;
for (i = 0; i  alleles; i++ ) {
subString = [testString substringWithRange:range];
theInt = [subString intValue];
range.location += digitsPerAllele;
}
}


Begin forwarded message:

 From: Boyd Collier bcolli...@cox.net
 Subject: Re: reverse scanner
 Date: August 12, 2013 1:00:56 PM PDT
 To: Cocoa Dev List cocoa-dev@lists.apple.com
 
 I've come up with a couple of reasonably straight-forward solutions to my 
 problem, but first, thanks to everyone who offered suggestions. Even though I 
 didn't choose to use them, your willingness to make them is definitely 
 appreciated.
 
 Here are my solutions (note that there are 2, one labelled attack from the 
 rear, the other labelled frontal attack).  I won't claim that they have 
 been really thoroughly tested, but I have tried a variety of values for 
 testString, d, digitsPerAllele and alleles and both methods appear to work.  
 If anyone sees a problem or an improvements, please let me know.  Right now, 
 I favor the frontal attack, which occurred to me in the middle of the night 
 -- I seldom have reason to use the % operator and so didn't think of it right 
 away.  Of course, in actual use, I'll first take steps to separate the string 
 that's being processed into substrings, if the original string uses a ; 
 (for example) to separate allelic values, e.g. if the string being processed 
 is 04;756;013.
 
 NSString *testString = @0756013;
 NSUInteger d = 3;
 NSUInteger digitsPerAllele = d;
 NSUInteger alleles = 3;
 
 NSString *subString;
 NSRange range;
 int theInt;
 
 // attack from the rear
 int startOfRange = [testString length];
 int length = d;
 int i;
 for (i = 0; i  alleles; i++ ) {
 startOfRange = startOfRange-d;
 if (startOfRange  0) {
   length = length + startOfRange; // note that startOfRange is 
 negative here
   if (length = 0)
 break;
 startOfRange = 0;
 d = length;
   }
 range.location = startOfRange;
   range.length = d;
 subString = [testString substringWithRange:range];
 theInt = [subString intValue];
 }
 
 // frontal attack
 testString = @04756013;
 int remainder = [testString length] % digitsPerAllele;
 range.location = 0;
 range.length = remainder;
 subString = [testString substringWithRange:range];
 theInt = [subString intValue];
 --alleles;
 range.location = remainder;
 range.length = digitsPerAllele;
 for (i = 0; i  alleles; i++ ) {
   subString = [testString substringWithRange:range];
 theInt = [subString intValue];
 range.location += digitsPerAllele;
 }
 
 
 On Aug 10, 2013, at 10:07 AM, Boyd Collier bcolli...@cox.net wrote:
 
 I'm dealing with a situation in which I have to scan strings that are 
 separated by tabs, and for each string, I have to extract two numerical 
 values, with these values being separated by a non-numerical character or 
 not being separated by any character at all.  I know the maximum number of 
 characters used to represent each number, but unfortunately, the first 
 character in the group of characters used to represent the first number can, 
 quite arbitrarily, be either a 0 or missing.  For example, with the number 
 of characters used to represent each number known to be 2, the strings 607, 
 0607, 06;07 (note the semicolon between 06 and 07) should all result in 6 
 and 7 being extracted as the two numerical values. Of course, I'd like to do 
 something simple, and were it not for the arbitrary inclusion of a leading 
 0, it would be quite simple to use an instance of NSScanner.  Or, if there 
 were such a beast as NSReverseScanner, it would also be relatively straight 
 forward, but so far as I'm aware, no such beast exists. I can think of a 
 couple

Re: reverse scanner

2013-08-12 Thread Boyd Collier
I've come up with a couple of reasonably straight-forward solutions to my 
problem, but first, thanks to everyone who offered suggestions. Even though I 
didn't choose to use them, your willingness to make them is definitely 
appreciated.

Here are my solutions (note that there are 2, one labelled attack from the 
rear, the other labelled frontal attack).  I won't claim that they have been 
really thoroughly tested, but I have tried a variety of values for testString, 
d, digitsPerAllele and alleles and both methods appear to work.  If anyone sees 
a problem or an improvements, please let me know.  Right now, I favor the 
frontal attack, which occurred to me in the middle of the night -- I seldom 
have reason to use the % operator and so didn't think of it right away.  Of 
course, in actual use, I'll first take steps to separate the string that's 
being processed into substrings, if the original string uses a ; (for 
example) to separate allelic values, e.g. if the string being processed is 
04;756;013.

NSString *testString = @0756013;
NSUInteger d = 3;
NSUInteger digitsPerAllele = d;
NSUInteger alleles = 3;

NSString *subString;
NSRange range;
int theInt;

// attack from the rear
int startOfRange = [testString length];
int length = d;
int i;
for (i = 0; i  alleles; i++ ) {
startOfRange = startOfRange-d;
if (startOfRange  0) {
length = length + startOfRange; // note that startOfRange is 
negative here
if (length = 0)
break;
startOfRange = 0;
d = length;
}
range.location = startOfRange;
range.length = d;
subString = [testString substringWithRange:range];
theInt = [subString intValue];
}

// frontal attack
testString = @04756013;
int remainder = [testString length] % digitsPerAllele;
range.location = 0;
range.length = remainder;
subString = [testString substringWithRange:range];
theInt = [subString intValue];
--alleles;
range.location = remainder;
range.length = digitsPerAllele;
for (i = 0; i  alleles; i++ ) {
subString = [testString substringWithRange:range];
theInt = [subString intValue];
range.location += digitsPerAllele;
}


On Aug 10, 2013, at 10:07 AM, Boyd Collier bcolli...@cox.net wrote:

 I'm dealing with a situation in which I have to scan strings that are 
 separated by tabs, and for each string, I have to extract two numerical 
 values, with these values being separated by a non-numerical character or not 
 being separated by any character at all.  I know the maximum number of 
 characters used to represent each number, but unfortunately, the first 
 character in the group of characters used to represent the first number can, 
 quite arbitrarily, be either a 0 or missing.  For example, with the number of 
 characters used to represent each number known to be 2, the strings 607, 
 0607, 06;07 (note the semicolon between 06 and 07) should all result in 6 and 
 7 being extracted as the two numerical values. Of course, I'd like to do 
 something simple, and were it not for the arbitrary inclusion of a leading 0, 
 it would be quite simple to use an instance of NSScanner.  Or, if there were 
 such a beast as NSReverseScanner, it would also be relatively straight 
 forward, but so far as I'm aware, no such beast exists. I can think of a 
 couple of ways do accomplish this task, but if someone has already come up 
 with a clean way of scanning in reverse, I'd appreciate hearing from them.
 
 Boyd

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

reverse scanner

2013-08-10 Thread Boyd Collier
I'm dealing with a situation in which I have to scan strings that are separated 
by tabs, and for each string, I have to extract two numerical values, with 
these values being separated by a non-numerical character or not being 
separated by any character at all.  I know the maximum number of characters 
used to represent each number, but unfortunately, the first character in the 
group of characters used to represent the first number can, quite arbitrarily, 
be either a 0 or missing.  For example, with the number of characters used to 
represent each number known to be 2, the strings 607, 0607, 06;07 (note the 
semicolon between 06 and 07) should all result in 6 and 7 being extracted as 
the two numerical values. Of course, I'd like to do something simple, and were 
it not for the arbitrary inclusion of a leading 0, it would be quite simple to 
use an instance of NSScanner.  Or, if there were such a beast as 
NSReverseScanner, it would also be relatively straight forward, but so far as 
I'm aware, no such beast exists. I can think of a couple of ways do accomplish 
this task, but if someone has already come up with a clean way of scanning in 
reverse, I'd appreciate hearing from them.

Boyd
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Gary L. Wade
Is there a problem with using a character set of all digits except 0 when 
recognizing digits?
--
Gary L. Wade (Sent from my iPad)
http://www.garywade.com/

On Aug 10, 2013, at 10:07 AM, Boyd Collier bcolli...@cox.net wrote:

 I'm dealing with a situation in which I have to scan strings that are 
 separated by tabs, and for each string, I have to extract two numerical 
 values, with these values being separated by a non-numerical character or not 
 being separated by any character at all.  I know the maximum number of 
 characters used to represent each number, but unfortunately, the first 
 character in the group of characters used to represent the first number can, 
 quite arbitrarily, be either a 0 or missing.  For example, with the number of 
 characters used to represent each number known to be 2, the strings 607, 
 0607, 06;07 (note the semicolon between 06 and 07) should all result in 6 and 
 7 being extracted as the two numerical values. Of course, I'd like to do 
 something simple, and were it not for the arbitrary inclusion of a leading 0, 
 it would be quite simple to use an instance of NSScanner.  Or, if there were 
 such a beast as NSReverseScanner, it would also be relatively straight 
 forward, but so far as I'm aware, no such beast exists. I can think of a 
 couple of ways do accomplish this task, but if someone has already come up 
 with a clean way of scanning in reverse, I'd appreciate hearing from them.
 
 Boyd

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Jerry Krinock

On 2013 Aug 10, at 10:07, Boyd Collier bcolli...@cox.net wrote:

 but if someone has already come up with a clean way of scanning in reverse

In Mac OS X 10.7+, we have NSRegularExpression.  In earlier systems, call out 
to Perl.  Regexes are fun.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Tom Davie
Heh, I’d actually argue that NSScanner is a much much better API to use here 
(and in fact nearly everywhere).  Regular expressions constrain you only to 
regular grammars, which are a pretty small set.  In my experience 99% of the 
use of them is actually trying to parse something that’s not *quite* a regular 
grammar, and uses a hack on top of regular expressions to do something 
not-quite-right.

NSScanner by comparison makes the separation of what’s scanning/tokenisation, 
and what’s up to your (turing complete) program much more clear.  So basically, 
(at least in my opinion), if you want to parse something that’s regular, 
NSScanner is a great choice.  If you want to parse something that’s context 
free, look at CoreParse (Not tooting my own horn, honest).  And finally, if you 
want to parse something that’s more even than that, then you’re probably back 
to NSScanner and a turing complete program.

About the only use for regular expressions I can think of is asking NSScanner 
to scan something that it doesn’t by default know about.

Tom Davie

On 10 Aug 2013, at 19:53, Jerry Krinock je...@ieee.org wrote:

 
 On 2013 Aug 10, at 10:07, Boyd Collier bcolli...@cox.net wrote:
 
 but if someone has already come up with a clean way of scanning in reverse
 
 In Mac OS X 10.7+, we have NSRegularExpression.  In earlier systems, call out 
 to Perl.  Regexes are fun.
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/tom.davie%40gmail.com
 
 This email sent to tom.da...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Sandor Szatmari
If one number has a leading leading zero will the other number have one, if 
applicable?  For instance, is 60 followed by 7 distinguishable from 6 followed 
by 07?

Sandor Szatmari

On Aug 10, 2013, at 13:07, Boyd Collier bcolli...@cox.net wrote:

 I'm dealing with a situation in which I have to scan strings that are 
 separated by tabs, and for each string, I have to extract two numerical 
 values, with these values being separated by a non-numerical character or not 
 being separated by any character at all.  I know the maximum number of 
 characters used to represent each number, but unfortunately, the first 
 character in the group of characters used to represent the first number can, 
 quite arbitrarily, be either a 0 or missing.  For example, with the number of 
 characters used to represent each number known to be 2, the strings 607, 
 0607, 06;07 (note the semicolon between 06 and 07) should all result in 6 and 
 7 being extracted as the two numerical values. Of course, I'd like to do 
 something simple, and were it not for the arbitrary inclusion of a leading 0, 
 it would be quite simple to use an instance of NSScanner.  Or, if there were 
 such a beast as NSReverseScanner, it would also be relatively straight 
 forward, but so far as I'm aware, no such beast exists. I can think of a 
 couple of ways do accomplish this task, but if someone has already come up 
 with a clean way of scanning in reverse, I'd appreciate hearing from them.
 
 Boyd
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
 
 This email sent to admin.szatmari@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Keary Suska
On Aug 10, 2013, at 12:17 PM, Tom Davie wrote:

 Heh, I’d actually argue that NSScanner is a much much better API to use here 
 (and in fact nearly everywhere).  Regular expressions constrain you only to 
 regular grammars, which are a pretty small set.  In my experience 99% of the 
 use of them is actually trying to parse something that’s not *quite* a 
 regular grammar, and uses a hack on top of regular expressions to do 
 something not-quite-right.
 
 NSScanner by comparison makes the separation of what’s scanning/tokenisation, 
 and what’s up to your (turing complete) program much more clear.  So 
 basically, (at least in my opinion), if you want to parse something that’s 
 regular, NSScanner is a great choice.  If you want to parse something that’s 
 context free, look at CoreParse (Not tooting my own horn, honest).  And 
 finally, if you want to parse something that’s more even than that, then 
 you’re probably back to NSScanner and a turing complete program.
 
 About the only use for regular expressions I can think of is asking NSScanner 
 to scan something that it doesn’t by default know about.

I would agree that NSScanner is a better API than NSRegularExpression, but I 
think that is Apple's fault because there are better regex API's, such as 
RegexKit.

I would argue, however, that it is NSScanner that only functions well with 
fixed and unvarying grammars and has no context, other than a specific, 
unvarying linear progression. Regular expressions have a huge grammar and when 
you consider conditionals and zero-width assertions you can parse information 
that would send NSScanner into dizzying fits.

Not to mention that NSScanner can't even touch the problem that the OP is 
experiencing, while regular expressions will handle it very nicely.

 On 10 Aug 2013, at 19:53, Jerry Krinock je...@ieee.org wrote:
 
 
 On 2013 Aug 10, at 10:07, Boyd Collier bcolli...@cox.net wrote:
 
 but if someone has already come up with a clean way of scanning in reverse
 
 In Mac OS X 10.7+, we have NSRegularExpression.  In earlier systems, call 
 out to Perl.  Regexes are fun.
 


Keary Suska
Esoteritech, Inc.
Demystifying technology for your home or business


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Tom Davie

On 10 Aug 2013, at 22:44, Keary Suska cocoa-...@esoteritech.com wrote:

 On Aug 10, 2013, at 12:17 PM, Tom Davie wrote:
 
 Heh, I’d actually argue that NSScanner is a much much better API to use here 
 (and in fact nearly everywhere).  Regular expressions constrain you only to 
 regular grammars, which are a pretty small set.  In my experience 99% of the 
 use of them is actually trying to parse something that’s not *quite* a 
 regular grammar, and uses a hack on top of regular expressions to do 
 something not-quite-right.
 
 NSScanner by comparison makes the separation of what’s 
 scanning/tokenisation, and what’s up to your (turing complete) program much 
 more clear.  So basically, (at least in my opinion), if you want to parse 
 something that’s regular, NSScanner is a great choice.  If you want to parse 
 something that’s context free, look at CoreParse (Not tooting my own horn, 
 honest).  And finally, if you want to parse something that’s more even than 
 that, then you’re probably back to NSScanner and a turing complete program.
 
 About the only use for regular expressions I can think of is asking 
 NSScanner to scan something that it doesn’t by default know about.
 
 I would agree that NSScanner is a better API than NSRegularExpression, but I 
 think that is Apple's fault because there are better regex API's, such as 
 RegexKit.
 
 I would argue, however, that it is NSScanner that only functions well with 
 fixed and unvarying grammars and has no context, other than a specific, 
 unvarying linear progression. Regular expressions have a huge grammar and 
 when you consider conditionals and zero-width assertions you can parse 
 information that would send NSScanner into dizzying fits.
 
 Not to mention that NSScanner can't even touch the problem that the OP is 
 experiencing, while regular expressions will handle it very nicely.

No, some hacked on extensions to regular expressions can do this.  Because 
people keep repeatedly bumping into the problem that they’re not as powerful as 
CFGs, and most parsing problems aren’t regular.

Tom Davie
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Fritz Anderson
On 10 Aug 2013, at 3:54 PM, Tom Davie tom.da...@gmail.com wrote:

 On 10 Aug 2013, at 22:44, Keary Suska cocoa-...@esoteritech.com wrote:
 
 No, some hacked on extensions to regular expressions can do this.  Because 
 people keep repeatedly bumping into the problem that they’re not as powerful 
 as CFGs, and most parsing problems aren’t regular.

See no true Scotsman. http://en.wikipedia.org/wiki/No_true_Scotsman

The point remains that there are quite powerful extensions to the formal 
regular-expression syntax that are reliable, in almost universal use, and 
helpful to the OP. In your heart of hearts, you will admit to knowing that.

In the '80s, I called myself a hacker, and even had a vanity license plate 
MAC HAKR. The battle over the popular meaning of hacker has been lost, and so 
it has been with regular expression.

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Philip Ershler
Are you numbers constrained to be from 1 to 9? How about 0677 (which is 
actually 6 and 7) or 0607 (which is actually 607) etc?

Phil

On Aug 10, 2013, at 2:54 PM, Tom Davie tom.da...@gmail.com wrote:

 
 On 10 Aug 2013, at 22:44, Keary Suska cocoa-...@esoteritech.com wrote:
 
 On Aug 10, 2013, at 12:17 PM, Tom Davie wrote:
 
 Heh, I’d actually argue that NSScanner is a much much better API to use 
 here (and in fact nearly everywhere).  Regular expressions constrain you 
 only to regular grammars, which are a pretty small set.  In my experience 
 99% of the use of them is actually trying to parse something that’s not 
 *quite* a regular grammar, and uses a hack on top of regular expressions to 
 do something not-quite-right.
 
 NSScanner by comparison makes the separation of what’s 
 scanning/tokenisation, and what’s up to your (turing complete) program much 
 more clear.  So basically, (at least in my opinion), if you want to parse 
 something that’s regular, NSScanner is a great choice.  If you want to 
 parse something that’s context free, look at CoreParse (Not tooting my own 
 horn, honest).  And finally, if you want to parse something that’s more 
 even than that, then you’re probably back to NSScanner and a turing 
 complete program.
 
 About the only use for regular expressions I can think of is asking 
 NSScanner to scan something that it doesn’t by default know about.
 
 I would agree that NSScanner is a better API than NSRegularExpression, but I 
 think that is Apple's fault because there are better regex API's, such as 
 RegexKit.
 
 I would argue, however, that it is NSScanner that only functions well with 
 fixed and unvarying grammars and has no context, other than a specific, 
 unvarying linear progression. Regular expressions have a huge grammar and 
 when you consider conditionals and zero-width assertions you can parse 
 information that would send NSScanner into dizzying fits.
 
 Not to mention that NSScanner can't even touch the problem that the OP is 
 experiencing, while regular expressions will handle it very nicely.
 
 No, some hacked on extensions to regular expressions can do this.  Because 
 people keep repeatedly bumping into the problem that they’re not as powerful 
 as CFGs, and most parsing problems aren’t regular.
 
 Tom Davie
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/ershler%40cvrti.utah.edu
 
 This email sent to ersh...@cvrti.utah.edu

Philip R. Ershler Ph.D.
University of Utah
Cardiovascular Research and Training Institute
95 South 2000 East
Salt Lake City, UT 84112-5000

phone: (801) 230-8771
alt ph: (801) 587-9528
fax: (801) 581-3128
e-mail: ersh...@cvrti.utah.edu


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Philip Ershler
Whoops, I meant 

Are you numbers constrained to be from 1 to 9? How about 0677 (which is 
actually 6 and 77) or 0607 (which is actually 607) etc?

Phil

On Aug 10, 2013, at 2:54 PM, Tom Davie tom.da...@gmail.com wrote:

 
 On 10 Aug 2013, at 22:44, Keary Suska cocoa-...@esoteritech.com wrote:
 
 On Aug 10, 2013, at 12:17 PM, Tom Davie wrote:
 
 Heh, I’d actually argue that NSScanner is a much much better API to use 
 here (and in fact nearly everywhere).  Regular expressions constrain you 
 only to regular grammars, which are a pretty small set.  In my experience 
 99% of the use of them is actually trying to parse something that’s not 
 *quite* a regular grammar, and uses a hack on top of regular expressions to 
 do something not-quite-right.
 
 NSScanner by comparison makes the separation of what’s 
 scanning/tokenisation, and what’s up to your (turing complete) program much 
 more clear.  So basically, (at least in my opinion), if you want to parse 
 something that’s regular, NSScanner is a great choice.  If you want to 
 parse something that’s context free, look at CoreParse (Not tooting my own 
 horn, honest).  And finally, if you want to parse something that’s more 
 even than that, then you’re probably back to NSScanner and a turing 
 complete program.
 
 About the only use for regular expressions I can think of is asking 
 NSScanner to scan something that it doesn’t by default know about.
 
 I would agree that NSScanner is a better API than NSRegularExpression, but I 
 think that is Apple's fault because there are better regex API's, such as 
 RegexKit.
 
 I would argue, however, that it is NSScanner that only functions well with 
 fixed and unvarying grammars and has no context, other than a specific, 
 unvarying linear progression. Regular expressions have a huge grammar and 
 when you consider conditionals and zero-width assertions you can parse 
 information that would send NSScanner into dizzying fits.
 
 Not to mention that NSScanner can't even touch the problem that the OP is 
 experiencing, while regular expressions will handle it very nicely.
 
 No, some hacked on extensions to regular expressions can do this.  Because 
 people keep repeatedly bumping into the problem that they’re not as powerful 
 as CFGs, and most parsing problems aren’t regular.
 
 Tom Davie
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/ershler%40cvrti.utah.edu
 
 This email sent to ersh...@cvrti.utah.edu

Philip R. Ershler Ph.D.
University of Utah
Cardiovascular Research and Training Institute
95 South 2000 East
Salt Lake City, UT 84112-5000

phone: (801) 230-8771
alt ph: (801) 587-9528
fax: (801) 581-3128
e-mail: ersh...@cvrti.utah.edu


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/ershler%40cvrti.utah.edu

This email sent to ersh...@cvrti.utah.edu

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: reverse scanner

2013-08-10 Thread Maxthon Chan
NSScanner is *not* a parser - it is a lexical analyser and you are the one that 
is responsible of writing a parser on top of it. I have a project Subtitler 
(http://github.com/xcvista/Subtitler) that included 2 parsers that is built on 
top of NSScanner, and I vaguely remember that there is an Smalltalk compiler 
written in Objective-C using NSScanner extensively as its lexer and LLVM as 
code emitter somewhere...

On Aug 11, 2013, at 4:44, Keary Suska cocoa-...@esoteritech.com wrote:

 On Aug 10, 2013, at 12:17 PM, Tom Davie wrote:
 
 Heh, I’d actually argue that NSScanner is a much much better API to use here 
 (and in fact nearly everywhere).  Regular expressions constrain you only to 
 regular grammars, which are a pretty small set.  In my experience 99% of the 
 use of them is actually trying to parse something that’s not *quite* a 
 regular grammar, and uses a hack on top of regular expressions to do 
 something not-quite-right.
 
 NSScanner by comparison makes the separation of what’s 
 scanning/tokenisation, and what’s up to your (turing complete) program much 
 more clear.  So basically, (at least in my opinion), if you want to parse 
 something that’s regular, NSScanner is a great choice.  If you want to parse 
 something that’s context free, look at CoreParse (Not tooting my own horn, 
 honest).  And finally, if you want to parse something that’s more even than 
 that, then you’re probably back to NSScanner and a turing complete program.
 
 About the only use for regular expressions I can think of is asking 
 NSScanner to scan something that it doesn’t by default know about.
 
 I would agree that NSScanner is a better API than NSRegularExpression, but I 
 think that is Apple's fault because there are better regex API's, such as 
 RegexKit.
 
 I would argue, however, that it is NSScanner that only functions well with 
 fixed and unvarying grammars and has no context, other than a specific, 
 unvarying linear progression. Regular expressions have a huge grammar and 
 when you consider conditionals and zero-width assertions you can parse 
 information that would send NSScanner into dizzying fits.
 
 Not to mention that NSScanner can't even touch the problem that the OP is 
 experiencing, while regular expressions will handle it very nicely.
 
 On 10 Aug 2013, at 19:53, Jerry Krinock je...@ieee.org wrote:
 
 
 On 2013 Aug 10, at 10:07, Boyd Collier bcolli...@cox.net wrote:
 
 but if someone has already come up with a clean way of scanning in reverse
 
 In Mac OS X 10.7+, we have NSRegularExpression.  In earlier systems, call 
 out to Perl.  Regexes are fun.
 
 
 
 Keary Suska
 Esoteritech, Inc.
 Demystifying technology for your home or business
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/xcvista%40me.com
 
 This email sent to xcvi...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com