Years ago I was working on a project that required XML files to specify a graphical user interface (GUI) based on SWT and Eclipse, written in Java. Coming from the Windows world and being familiar with resource files I thought it would be a cool idea to use those resource files (*.rc) to generate the GUI dialogs. This would allow reusing already designed dialogs to save some time. For this task I needed a parser that was able to recognize the content of resource files.

My Delphi Compiler Generator project wasn’t of much help here (since it was made for Delphi), so I started looking what other parser generators existed. I tried JavaCC, PCCTS and a few more until I stumbled accross ANTLR. I found it way easier to work with than any other parser generator. ANTLR is truly a great tool to build compilers, parser, lexers and similar software and I was able to quickly come up with a grammar for Windows resource files. Well, when I say quick I mean it was easy to write, however getting all the necessary information about the rc file format was really a challenge at that time. Things might have changed since 2004, though.

Unfortunately, the aforementioned project was abandoned, so I never could use my parser, even though it is to 99% complete. However I put it on Github in the case someone has any use for it.

The package contains well commented java source code and the ANTLR grammar (for version 2.7, so you need some changes if you want to use it with the current version 4), as well as a test project (using SWT) that shows how to use the parser. Since Windows resource files are in many aspects like C/C++ header files (they can contain #include and #if compiler commands etc.) the RC file parser is able to perform the full bandwidth needed to handle this. In detail:

  • Handling for unlimited nesting of include files
  • Trigraph handling and line splicing in the input reader
  • Complete macro handling, including charizing  and stringizing
  • An evaluator for #if, #ifdef and #ifndef expressions
  • Support for some specialities used by (former) Borland Compilers

Leave a Reply