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.)

Recommended Answers

All 5 Replies

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

I can only be bothered to post this link.
Is it urgent?

> Develop a program in C++
Is that an order?

commented: hehe, the scene from monty python rules! +2

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
MIN 0
MED 50
-------------------------
simply this is a array of a datastructure like
struct
{
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]

> Develop a program in C++
Is that an order?

Are you not supposed to know Latin to find that funny?

<ot>
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.
</ot>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.