View Full Version : Learning Python on OS X
Aug 7, 2007, 03:13 PM
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?
Aug 7, 2007, 04:54 PM
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 (http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html), 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.
Aug 7, 2007, 06:39 PM
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.
Aug 7, 2007, 07:11 PM
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.
Aug 7, 2007, 09:11 PM
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.