I need to write a c program which takes a algorithm as the input and gives the equivalent c source code as the output.any ideas????

Recommended Answers

All 10 Replies

The easiest way to do this is to write a program that takes a problem as the input and gives the source code of the solution... then you can use it to solve this problem.

Seriously though, what kind of algorithm? Don't say "any"!

Simple. Just have a precondition that the algorithm be specified in correct C code.


Algorithms are just general guides, they have to adjusted for every specific problem. There are programs that do this, for a very limited environment, and limited algorithms, but they are a very big project.

Not something for the beginner.

Actually its enuf if ican write a program which can convert simple c algorithms to c source code like sum of two numbers
i need some help

Of course you need help. Isn't that obvious?

But you need to give a very specific set of guidelines about exactly what you need. What "algorithms"?

Based on your almost description above, check each character input and create variables for num1 , num2 , and operation . Then test the operation and perform it on the two numbers.

sample input
1-get input in a and b
2-add a and b
3-display the result

now this program should give a c program as output which takes 2 numbers as input and returns the sum as output

You want a very high level programming domain-specific programming language. Treat the problem as such and you'll be less confused as how to proceed. However, creating a language (even a simple one) can be a surprisingly difficult undertaking if you're new to that particular field. I'd suggest making your "algorithm" language look more like assembly language for simpler parsing, then work your way up to a more prose/list-like grammar.

Also i want to say that this question is related to compiler design. So i would suggest to learn compiler design/programming in general, before advancing to concrete problem.

set K:=LB

1) First you have to take 2 variables like int a,b,s;
2) Then add a and b.
3) Then print the output.

int a,b,s;
cout<<"Enter value for a : ";
cout<<"Enter value for b : ";
//now add them
//Now print s
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.