Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Writing a language compiler

Hi,

I have a project to write a C compiler for windows with limited functionality. My problem is, that I can write parsers using bison or ANTLOR, but how can I write code to produce an executable from it. That is, I wan't to know, I I wan't to output an excutable file for windows. Is there any help available anywhere.

regards and thanks

Abhinay Sinha
0
abhinaysinha
Asked:
abhinaysinha
1 Solution
 
Harisha M GCommented:
Hi abhinaysinha,

This may be helpful (Check out free compilers with source code)
http://www.bloodshed.net/compilers/

Bye
---
Harish
0
 
SCDMETACommented:
This might be a good place to start getting an understanding of the win32 executable format.

http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx
http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/default.aspx

Your compiler should ultimately output machine code, in a file that conforms to the Microsoft specification.
0
 
djwillmsCommented:
The *easy* thing to do is to have your language compiler convert the target language into another language such as vb.net or java, or C++ and then use the corresponding compiler to generate the .EXE for you. Id recommend using the Gnu C++ compiler if you want to go down this path.

For example for your pseudo c like language, you write a converter that translates that language and writes out standard ansi c++ and then you use any standard c++ compiler against your translated source code which will generate the binary .exe for you.

On the other hand you could spend a few years writing a compiler that directly spits out x86 assembly, encapsulated in a machine specific executable format such as windows .exe but why bother when its already done for you, unless its an academic exercise. I had to write compilers in my Computer Science courses but none that had to write out a windows .exe directly. We just wrote our compiler to write out byte code, and then wrote an interpretor to execute our byte code.

In either case you might be interested in trying to make your compiler output .NET client runtime byte code, or Java byte code directly and get the .NET linker, or Jit linker to make a pass against your byte code and generate an .exe for you.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
SunBowCommented:
Treat the parsings as a stack, containing certain information that cannot be processed until a certain condition is met, such as end of line of close paren or right brace (depends on language).

You have to come up with a syntax to decode what to do with a statement based upon the formats discovered during the parsing. It must be unambiguous, so keep it real simple, defer how to do nesting, if you can, until later.

Checl out BNF

Consider making another step, of a creation of a table, where each row is a coded statement to be processed by your fixed set of rules
0
 
abhinaysinhaAuthor Commented:
Thanks for the reply to all.

But the links pointed by SCDMETA is the most appropiate for me.
0
 
SunBowCommented:
>  conforms to the Microsoft specification
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now