Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 7, 2007, 02:13 PM   #1
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Learning Python on OS X

Learning programming, I stumbled upon some problems I have.

I am fairly proficient with C++, and Objective C with Cocoa, and I have developed programs that many people use with Cocoa. But lately, I had the idea of writing my own parser in C++ (I think that for this task I should avoid Objective C).

However, I found that C++ can be very frustrating when writing a parser, even a recursive descent one. So, I decided to learn another language.

So, what I want is a language that can be used in conduction with C++. I want to be able to write parsers in it, and then use the results with C++. And I want to write it on OS X.

I was thinking of learning Python, but I thought I should ask someone first. Your ideas?
Soulstorm is offline   0 Reply With Quote
Old Aug 7, 2007, 03:54 PM   #2
iBert
macrumors regular
 
Join Date: Jul 2004
Depending on the complexity of the file you want to parse you should pick your language to use. I'll say Perl can help a lot and it's easy to understand since you know C++ and should be easy to integrate with your code. But if you wish to look at something more challenging than Perl take a look at Lex and Yacc.

This last opinion could be a more elegant way to do it, but more complex at the same time. At least what little I remember of using this a couple of years ago. Here is a link to a tutorial, first that showed up after doing a google search. (lex + yacc + c++) You'll probably able to do some wonderful thing with Lex and Yacc, but the learning curve would be higher than using Perl.

Hope someone can do a comparison of this with Python, never used Python before.
__________________
--MBP 2.4 GHz 4GB 500GB 7200 RPM Snow Leopard
iBert is offline   0 Reply With Quote
Old Aug 7, 2007, 05:39 PM   #3
toddburch
macrumors 6502a
 
Join Date: Dec 2006
Location: Katy, Texas
Send a message via AIM to toddburch Send a message via MSN to toddburch
I seem to remember YACC, and may be LEX too, being geared towards writing compilers, therefore they would be certainly be appropriate from the standpoint of writing a parser.

Todd
toddburch is offline   0 Reply With Quote
Old Aug 7, 2007, 06:11 PM   #4
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Python is a pretty good choice, as it has very good text/string handling built in, including regular expressions, and it's relatively fast for an interpreted language (most Python modules are available in native Python or written in C for increased speed). It's a great language although it takes a little while to get used to the indented syntax and lack of braces. TextWrangler makes a pretty decent editor for Python because it has syntax highlighting available for it and one of the options is to have it draw lines behind the text at tab stops. This makes it easier to identify your indenting in extended blocks. I picked up a few books on it including a Visual Quickstart one and the O'Reilly Python in a Nutshell. It's a pretty easy language to learn and actually you can learn quite a lot from the documentation. I would recommend getting the Nutshell book as a reference.

EDIT: I said compiled instead of interpreted.
__________________
Go outside, the graphics are amazing!

Last edited by HiRez; Aug 7, 2007 at 06:54 PM.
HiRez is offline   0 Reply With Quote
Old Aug 7, 2007, 08:11 PM   #5
dr_lha
macrumors 68000
 
Join Date: Oct 2003
I wrote a program to parse tcl/tk database in python. Python is great for that stuff, and really easy to understand while being powerful.

I had to laugh at the above comment about perl being "easy to understand", maybe my brain is wrong but I tried to learn perl for months before giving up because its just so odd. Python I picked up in a day and it made me a better programmer.
__________________
Me: 1Ghz 12" PB and Mac mini Intel Core Solo 1.5Ghz, The Wife: 1.86Ghz CD MacBook, Me@Work: 2.66Ghz Mac Pro and a 2.33Ghz C2D 15" Mac Book Pro
dr_lha is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Need HELP with a Python script BlueFielder Mac Programming 5 Sep 8, 2013 09:19 AM
Good Python 3.3 course vmachiel Mac Programming 2 Mar 11, 2013 03:42 AM
Python Environment Telp Mac Programming 2 Jan 12, 2013 11:37 AM
Python 3.2.3 dboxall123 Mac Programming 4 Sep 27, 2012 10:53 AM
Learning Python nashyo Mac Programming 16 Aug 3, 2012 11:12 AM

Forum Jump

All times are GMT -5. The time now is 04:06 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC