(*Construct in C program using Visual Studio 2013*) In this assignment we will c
ID: 666421 • Letter: #
Question
(*Construct in C program using Visual Studio 2013*)
In this assignment we will construct a simple C preprocessor, pre.c, that will prepare a C program, test.c, for compilation. The preprocessor will parse the source code in test.c and create and output file, out.c, containing the preprocessed code. The contents of out.c should then be output, compiled and executed.
The preprocessor should perform the following operations:
Remove all comments from the source code.
Recognize the #include preprocessor command and insert the contents of the named file into out.c
Recognize the #define preprocessor command and substitute all symbolic names with their corresponding replacement strings.
To assist in the processing of the #define commands, we will use the following scheme:
Each defined symbol, along with its replacement string indentified in test.c, should be placed in a file, define.txt. As each token is read from the source code, test.c, it must then be checked against the contents of define.txt in order to determine whether or not the token is a predefined symbol. If it is, the appropriate replacement string must be placed into out.c. Otherwise, the token itself is placed in out.c.
To prevent our having to compare each token against the contents of define.txt, we will utilize a simple hash table with each location initialized to 0. For each #defined symbol encountered, we will get its hash, set the contents of the appropriate location in the hash table to 1, and send the symbol and its replacement string to define.txt. For every other token in test.c, we must also get its hash and check its particular location in the hash table. If a 0 is found, the token is not a predefined symbol and should be placed into out.c. If, however, the token hashes to a location that contains a 1, it is possible that token is a predefined symbol. We must then search define.txt for that token. If a match is found, the replacement string should be placed in out.c, otherwise, the token itself should be placed in out.c.
Note that your program should not rely on file redirection but should utilize the I/O functions provided by the standard C library to set up and use external disk files.
Output from your program should be sent to the terminal window (your screen) as well as the requested csis.txt output file.
test.c
header.h
Explanation / Answer
This program is right i have already run the coding and it comes out to be without an error.But for this i am again replicating the same.
header.h
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.