1

I'm trying to write a translator for pseudo-code to c language.which phases of compiler are necessary? I tried lexical,syntax,semantic,intermediate code is enough or machine code is necessary. I tried flex,bison for the above phases. Is it correct?

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
Tintu James
  • 113
  • 1
  • 13
  • 1
    Once you've defined "pseudo" code enough to be able to construct a compiler for it, you no longer deal with pseudo code, you deal with just another programming language. So your question is basically "how do I write a compiler" which has already been asked a hundred times. –  Jan 18 '14 at 16:54
  • not like that.my input is pseudo code (algorithm) and I want to convert it to c language and my output is c language corresponding to that pseudo code – Tintu James Jan 18 '14 at 17:06
  • @TintuJames: You didn't understand what delnan told you. Until you understand that, you won't make any real progress. And yes, you will likely need all the mechanisms you've described. See http://stackoverflow.com/questions/3455456/what-kinds-of-patterns-could-i-enforce-on-the-code-to-make-it-easier-to-translat/3460977#3460977 – Ira Baxter Jan 18 '14 at 17:19

1 Answers1

0

Yea, following the replies on your question; you want to basically design a compiler for a 'new' language.

The new language will have it's own syntax (the algorithm you mentioned) so you'll just need to design a compiler with that configuration, take in algorithim and output valid C code

AndrewSB
  • 951
  • 3
  • 11
  • 25
  • my doubt is how can i convert c language from machine language and is there any automated tool – Tintu James Jan 18 '14 at 17:17
  • There are no "automated tools" that can take in your imagined language and magically generate C. The best you can hope for is that you can *define* that language using some formal notation and hand it to an engine that can convert such a definition into a compiler. People have built research tools as PhD theses to try to do this. None of them are practical at this point. It is still necessary to build a fair amount of machinery on a per-language basis to "replace" what we don't know how to specify/implement as an automatic compiler generator. *You need to go read a good compiler book.* – Ira Baxter Jan 18 '14 at 17:23
  • @TinuJames: ...wait... you said "psuedocode" in your question, and now you say "from machine language". Machine language isn't psuedo code; it *is* a formal langauge for each machine. None of what has been otherwise said changes. But it is clear that you are not being clear about your actual problem. – Ira Baxter Jan 18 '14 at 17:29
  • I agree with Ira, what are you trying to do? – AndrewSB Jan 18 '14 at 18:35