1

I hope you're doing well. I was going through the book, "Compiler Design In C", by Allen I. Holub, when I came across these header files implemented in a sample program:

#include <tools/debug.h>
#include <tools.h> /* Needed only for prototype

My compiler says that no such file or directory exists ( Dev-C++ ). I have set the compiler settings to ANSI-C, seeing as to how the author uses ANSI-C to write code, but to no avail.

The program also includes a PRIVATE keyword, which after changing from C99 to ANSI-C, is still reported by the compiler to be an unknown keyword.

Can anyone help me out with this? Apologies if this has been asked before, but I could not find a reference to this anywhere. I have also included pictures of the code down here.

First page

Second page, remaining part

If I should abstain, or I'm unable to access these files, what other options do I have? I really want to complete this project.

Thank you in advance for your time and patience in reading all this through.

Saif Ul Islam
  • 345
  • 3
  • 14
  • 4
    These headers are most likely introduced somewhere in the book. Might be on the additional CD which comes with the book (if it does), or somewhere in the appendix or introduction chapter. – Ruslan Jan 08 '19 at 08:56
  • Apparently no. I checked the appendix, but could not find the header files. If they were made the author, why would he use < > for the header files and not go for a simple " " style header file, which would seem to be the obvious choice. – Saif Ul Islam Jan 08 '19 at 09:03
  • Ruslan's answer is the correct one. Your second question about the use of ``PRIVATE`` is answered here: [https://stackoverflow.com/questions/623219/is-private-a-c-keyword](https://stackoverflow.com/questions/623219/is-private-a-c-keyword). If you have a look at the book's additional material (e.g. ``compiler.design.in.c/compiler/INCLUDE/TOOLS/DEBUG.H``, l. 11) you see exactly the ``#define`` mentioned in the accepted answer to the question in the link. – dtell Jan 08 '19 at 09:06
  • @SaifUlIslam It is a common way to include user created header files using ``<...>`` by specifying an additional include path, e.g., by using the ``-I`` flag in clang or gcc. Also see [https://learn.microsoft.com/cpp/build/reference/i-additional-include-directories?view=vs-2017](https://learn.microsoft.com/en-gb/cpp/build/reference/i-additional-include-directories?view=vs-2017). – dtell Jan 08 '19 at 09:09
  • All those icky macros are not exactly good programming practice. Besides, using something like `#define PRIVATE static` is quite questionable, that's not how you do proper private encapsulation in C. Fine for small microcontroller applications, but hardly for hosted system programming. The remark about "Microsoft's C compiler memcpy doesn't support overlapping strings" is retarded - _no compiler_ supports a memcpy with overlapping strings, this is undefined behavior by the C standard. I don't think this is a book you should be studying. – Lundin Jan 08 '19 at 09:10
  • Thank you! The book has not mentioned that the code would be available on the website, and I've been reading since the first page. :/ – Saif Ul Islam Jan 08 '19 at 09:11
  • @Lundin just look at the age of the book. It's ancient. – Ruslan Jan 08 '19 at 09:11
  • @Ruslan It was already wrong at the date of publishing back in 1990. The author clearly didn't know how memcpy was specified by ISO C90. – Lundin Jan 08 '19 at 09:12
  • @Lundin, what book do you suggest if I want to learn compiler design? I am very new to programming ( just been 4-3 months ) with some understanding of C and very little C++. The contents seem interesting to me. – Saif Ul Islam Jan 08 '19 at 10:03
  • @SaifUlIslam You should not worry about compiler design before you have 10+ years of C programming experience, if ever :) People who are interested in the topic tend to recommend ["the dragon book"](https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools) but it is also quite old and I haven't read it, so I don't know if it's any good. – Lundin Jan 08 '19 at 12:06
  • @Lundin, actually, I'm currently studying in a University, and one of the course material was "C-How To Program", The Deitel Series. It had a question about "making a compiler", so I decided to pick up a book on a compiler a C ( go all the way! ). Do you suggest any other projects like this? I'm interested in learning some advanced concepts, just for fun's sake. I think it will help me improve my concepts and logic in the long run. What do you think? Sorry, just looking for some guidance at this early stage. :) – Saif Ul Islam Jan 08 '19 at 13:44
  • @SaifUlIslam As a student you should focus on things like program design. Books about object-oriented program design are great, as are books about algorithms/data structures. A great, old-school book that I would definitely recommend is [Data structures and program design in C](https://www.amazon.com/Data-Structures-Program-Design-2nd/dp/013288366X). Goes through all fundamental algorithms and ADT design: linked lists, binary trees, search/sort algorithms etc etc. – Lundin Jan 08 '19 at 13:48
  • I sure will try to get my hands dirty in that as well. Thank you for the recommendation! – Saif Ul Islam Jan 08 '19 at 14:00

2 Answers2

6

The headers are supplementary materials. They are available for download from the author's web page: https://holub.com/compiler/ .

The book itself must have referred to this somewhere in the introductory chapters.

Ruslan
  • 18,162
  • 8
  • 67
  • 136
0

Yes, I can help. I used these tools in professional work at a contract for a ginormous data repository at Dunn and Bradstreet in Basking Ridge, NJ when the book was new. It's the only set of tools of its kind and the visible parser is especially powerful, that and the overall thing both top down and bottom up parsing with complete annotated sources make it the only thing of its kind. It's funny to see people who might not have been born with it came out trying to use it.

The quick and indeed only way to use it now without porting is to run in a DOS emulator and I have verified that that works fine but you really need a whole working build environment unless you just want to use the visible parser to verify a grammar which I'm considering doing.

To really use you would need to port it to real curses independent of the bios stuff it's dependent on now or just use in a dos container as I said above.

In the D&B contract, I used it to build parsers that read working storage sections of their COBOL legacy programs (legacy in 1991) to populate the repository.

I have in the past intended to do the port have contacted Holub and iirc he said it would be OK, he doesn't have a problem with it but he's not doing anything himself. All the copies I've seen sofar are just he same stuff from the mid 90s which work without the port except on an emulator.

仁 人 卷
  • 61
  • 1
  • 2
  • Also, no, there's nothing missing in any of the various copies that have everything from Holubs site. The written changes in the '03 note are trivial, nothing is missing in the package except ofc DOS. – 仁 人 卷 Jan 23 '19 at 10:19