Develop a program in C++ which takes input a file of C Language and process all #define
(i.e. #define MAX 100, than replace every occurrence of MAX with 100).
(Macro value 100 can be an expression also.)

9 Years
Discussion Span
Last Post by Salem

That doesn't seem very urgent. One already exists, it's called the C preprocessor.

I am a newbie poster , I dont sure that I have something to share with you . But ,
it looks like you are asking how to preprocessor is working ?

so the simple answer is using a secnario like this :
[1] : first using a symbol table you stroe your preprocessor information.like this
id | value
MAX 100
MED 50
simply this is a array of a datastructure like
lpsz id ;
int value ;
}symbol_data_structure ;

and your symbol table is simply a array like this .
struct symbol_data_structure symbol_table[SYMBOL_TABLE_SIZE ];

in your code fill up your symbol table with appropriate user inputs.

hmm , so then thereafter , you are just going to tokernize that input C file and then process and replace this with the value in the symbol table if there is a id is found .

for the tokernize it , there are free libraries on the internet that you can freely download . Even there are free lexical generators and all the suff that make your work easy . for a example javacc and SABLECC are good examples . javacc is for the java language and I will be banned again if I talk about it here . But the same theory about lexical tokernizing there exists .

happy reading , there are more to read on lexical processing and torkernizing .
[please dont bug me about the C++ language syntax , I new to C++ , but the theory behind this I believe the same]


No, you're supposed to watch L-o-B to find that really funny :)
But then again, L-o-B isn't exactly your run-of-the-mill hollywood pap.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.