I am currently puzzled on how to use yacc together with XCode/Objective-C. Searching the web left me empty-handed, and trying it myself by trial and error is giving me at-least 142492 error-messages.
I describe a successful approach I used, without making any claims for its elegance or efficiency.
First, I had files Foo.y, Foo.l, Bar.y, Bar.l. I created two object file targets, one for each pair, and added the appropriate source files to the targets. I also added to each target an empty file with a ".c" extension so that the build system thinks it has something to do.
Once the files are assigned to their targets, then look at the build options for each target. They now expose options for lex and yacc. I added a "-P" value to Other Lex Flags to define the prefix for the lex files, e.g. "-PFoo". In the yacc section, I set Generated File Stem to "Input File Stem", and Other Yacc Flags to "-pFoo -bFoo -y".
When the targets are built, the appropriate derived sources and object files are created, as you can see by digging into the build directory. Most importantly, this results in the creation of entry points FooParse and BarParse.
How do you link these object files into your main program? In my case, I created a framework target, added the object files and a framework header file to the target, and built it.
If you want to include Objective-C code in the yacc and lex sources, then in the build option for each object file target you can set Compile Sources As (one of the GCC Language Options) to "Objective C". This makes gcc choose the Obj-C compiler for the derived sources with .c extensions.
Finally, some time has passed since I did this. There may have been some other steps which I have forgotten. I hope they are minor.
-- Timothy Larkin Abstract Tools Caroline, NY
|