GP-TRICKS Logo

Scalar's GP-TRICKS Homepage

Site MapTricks SectionA Cross-Referencing Tool for Borland Pascal


A Cross-Referencing Tool for Borland Pascal 7.0


A cross-referencing program is a helpful tool when it is getting hard to keep track of all the identifiers used in a project. For C/C++, I have found a whole bunch of nice packages that all do a bit more than just plain, old cross-referencing: They, for example, tell you where a variable was declared, when it is incremented or decremented, when it is accessed or when a new value is assigned to it.

I didn't find anything like this for Pascal, though. If you know me and my programming history, you know that this had to be reason enough for me to try and write one. Fortunately, I ran across a discussion of hashing algorithms, either in the DDJ or the CUJ, I don't remember anymore, which presented an excellent hashing method developed by Bob Jenkins.

I do not want to discuss my cross-referencer ("CAXREF" for Chaotic Arts Cross Referencer) in depth, because I neither have the time to do it nor the patience to go through my code right now. I will go over the basic structure, though.

First of all, the program initializes and checks command line parameters. Then it starts reading the input file. It reads line by line, keeping track of how many are already read. This information, of course, is needed to pinpoint identifiers in the cross-reference to be generated. It splits the lines into individual words, checking for beginnings and endings of either strings (enclosed by apostrophes) or comments (enclosed either by curly braces or by (* *) pairs). If it is in one of these sections, all words found are ignored, just like the Pascal compiler would. The program also ignores Pascal's reserved words; I decided to do so because the main interest in a cross-reference is on variables and types, not on all those "BEGIN"s and "END"s.

If, however, a non-reserved word is found that is not inside a string or a comment, the program tries to find it in the hash table. If it is found, the new occurance is added, and the line number and type of usage (declaration, incrementation, assignment, etc.) is stored. If it is not found, a new entry is initialized.

Sooner or later, the end of the source file is reached and it is closed. The program then walks through the hash table and writes all the pieces of information that were gathered into the output file.

I have included the full source code. Note that the program has to be compiled in DPMI mode, because the memory requirements are huge. You can use the program CAXREF in whatever way you want. I do not assume responsibility for any damage it may cause.

Download CAXREF Source Code


Back to Top of Page


This article is © 1998-2008 by M. G. Ricken and was exclusively written for GP-Tricks.
Copyright © 1998-2008 by M.G.Ricken        E-Mail: Scalar@psynet.net     |     mgricken@gptricks.de