?
Solved

Writing a language compiler

Posted on 2005-03-13
6
Medium Priority
?
265 Views
Last Modified: 2010-05-18
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
Comment
Question by:abhinaysinha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13529046
Hi abhinaysinha,

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

Bye
---
Harish
0
 
LVL 6

Accepted Solution

by:
SCDMETA earned 750 total points
ID: 13529382
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
 
LVL 3

Expert Comment

by:djwillms
ID: 13529739
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 24

Expert Comment

by:SunBow
ID: 13538863
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
 
LVL 1

Author Comment

by:abhinaysinha
ID: 13542383
Thanks for the reply to all.

But the links pointed by SCDMETA is the most appropiate for me.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 13545544
>  conforms to the Microsoft specification
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Introduction to Processes
Starting up a Project
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question