• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[ANN] DDMathParser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ANN] DDMathParser


  • Subject: [ANN] DDMathParser
  • From: Dave DeLong <email@hidden>
  • Date: Mon, 22 Nov 2010 20:41:20 -0800

Hi everyone,

I thought it'd be fun to write a mathematical expression evaluator, a la Graham Cox's GCMathParser, but one that was extensible.  So I dusted off my parsing skills and wrote DDMathParser: https://github.com/davedelong/DDMathParser

It's an NSString => NSNumber expression evaluator, and its major feature is that you can define custom mathematical functions.  So if you really need to have a multiplyBy42() function, then you can quickly write one, register it, and use it.

You can use it very simply:

	NSLog(@"%@", [@"1 + 2" numberByEvaluatingString]); //logs "3"

Or very complexly:

	DDMathParser * parser = [DDMathParser mathParserWithString:@"2 ** 3 ** 2"];
	[parser setPowerAssociativity:DDMathParserAssociativityRight];
	DDExpression * e = [parser parsedExpression];
	NSLog(@"%@", [e evaluateWithSubstitutions:nil evaluator:nil]); //logs "512"

It supports pretty much all of the functions defined by NSExpression, plus many more (primarily trig functions: sin(), cos(), atanh(), etc).  And like I mentioned above, you can create new functions as well.

It supports variables of the same format used by NSPredicate/NSExpression ("$variable") for substituting in values during evaluation.

It has rudimentary support for simplifying expressions, and I'm currently working on support for translating an arbitrary "DDExpression" into an NSExpression and still having it work properly (even with custom functions).

The source code is available on my github page, and I'd appreciate any comments or feedback you might have.

https://github.com/davedelong/DDMathParser

Cheers,

Dave DeLong
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [ANN] DDMathParser
      • From: Carter Allen <email@hidden>
    • Re: [ANN] DDMathParser
      • From: Graham Cox <email@hidden>
  • Prev by Date: Radio dial buttons [iOS]
  • Next by Date: Re: Obtaining all points on a line segment
  • Previous by thread: Re: Radio dial buttons [iOS] -sheesh
  • Next by thread: Re: [ANN] DDMathParser
  • Index(es):
    • Date
    • Thread