antlr logoYears 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. Comming 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 is made for Delphi), so I started looking what other parser generator source 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. That's also the reason I never published it so far. The package below 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 upcoming 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

The Java source code
Version: n/a Last change: 18. Nov 2012
Download count: 12861 Size: 312 KB
Author: Mike Lischke Website:
Platform: Any platform / OS Type of download: Java Source Code