XcodeLexYacc

From Clothbot

Jump to: navigation, search

Contents

Description

Trying to figure out how to write up some simple Lex/Yacc based parsers in Xcode, or anywhere for that matter, has been a challenge. Aside from the absolutely critical O'Reilly book on the subject, solid how-to documents are few and far between. I'll attempt to capture here some quick recipes for getting started.

I've developed an interest over the past few years in XML and how it can be used as an intermediate file format to make it easier to separate form from function, structure from content. Take something like a SPICE netlist, convert it into XML, then use XSLT or any of the numerous XML APIs out there to read, interact with and write out the data. It could just as easily be for parsing microcontroller code.

Since most of the inspiration and insight into this has come from reading other folks' GPL code, it's only fair I keep my examples similarly open source. That said, I'll be writing these examples completely from scratch; multiple licenses will be an option since the code is wholly my own.

Sections

Setup

  • Launch Xcode
  • Create new project
    • Scroll to Command Line Utility
    • Select C++ Tool
    • Click Next
    • Enter a Project Name
    • Click Choose... to browse to your projects directory
    • Click Finish
  • Add Lex file to your Sources
    • Add -> New File
    • Select Empty File in Project
    • Give it a name with a .l suffix.
  • Add Yacc file to your Sources
    • Add -> New File
    • Select Empty File in Project
    • Give it a name with a .y suffix.
  • On to the code...

Skeleton Code

  • place holder

Personal tools