News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

making a COMPILER

Started by realtyu, May 05, 2005, 10:20:50 AM

Previous topic - Next topic

realtyu

I have seen a C++ compiler source written with delphi/pascal   :eek and I was very suprised then
I have read some articles about making a compiler yesterday .
I see that compiler exe converst script to the assembly code with text parsing...
In this case I have some quetions and prudences

* Now I think programming languages are only text notations , C or pascal or basic , We written a script then compiler
converts that to assembly. But all languages have different modelling technics ... Am I right?

* Can we say compilers are : Script parser + Assembler ?


gabor

Hi!

Generally compiling is done in 3 main steps
1. preprocessing
2. compiling
3. linking

1. I think preprocessing is the closest thing to parsing scripts. In this phase the equates and macros are substitued with their definitions. The output is a text type source file.
2. Compiling is the most difficult part. I tis recommended to compile in at least 2 cycles to resolve forward references. Optimization is another topic that must be built in a compiler. The output is a meta file containing symbolic definitions and machine codes.
3. Linking creates the executable by fixing addresses and assembling the different meta files.

I don't think that a compiler needs to know the assembly language. I guess you wanted to write machine code instead of assemlby.

An other way of building executables could be that what maybe you tried to describe:
1. Parsing and processing a high-level language and generating the equvalent asm source.
2. Compiling the asm code.
3. Linking.

You mean modelling techniques for handling the memory, addressing?

Greets, gábor

realtyu

you mean that compilers writes direct machine opcodes to the exe file ?  ::)

what is obj file and linking?
thank u


AeroASM

When people made large projects, they did not want to have all the code in one source file, so they made a system called objects. A single source file is compiled into an object, and many objects are linked to make the exe.

MOst compilers write opcodes directly, but some produce an assembly listing which you have to assemble yourself.

tenkey

Compilers are Parsers + Code Generators.

The generated code can take any form: raw binary machine code, hex file representation of raw binary machine code, assembly language, an executable file, a "linkable" file, virtual machine code (p-codes), and even...another high level language!
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

AeroASM

I used to have a system where I made Basic which was compiled into C which was compiled into assembly which was assembled into an object which was linked into an exe. It reminds me of that game where you make up a story and translate it into many differnt languages and then back to English.

cman

I now think of a compiler as a sort of translater that converts a set of symbols with a given syntax and construction rules into another set of symbols with a given syntax and formation rules. This really all a computer can do ( manipulate symbols ( shapes ) and syntax ). So I guess a compiler is really simple in concept..... :bg

Randall Hyde

Quote from: realtyu on May 05, 2005, 10:20:50 AM
I have seen a C++ compiler source written with delphi/pascal   :eek and I was very suprised then
I have read some articles about making a compiler yesterday .
I see that compiler exe converst script to the assembly code with text parsing...
In this case I have some quetions and prudences

* Now I think programming languages are only text notations , C or pascal or basic , We written a script then compiler
converts that to assembly. But all languages have different modelling technics ... Am I right?

* Can we say compilers are : Script parser + Assembler ?



There is a free on-line book on writing compilers on Webster at http://webster.cs.ucr.edu/AsmTools/RollYourOwn/index.html. I would recommend taking a look at this.
Cheers,
Randy Hyde

gabor

Hi!

Quote from: cman on May 06, 2005, 06:56:20 PM
I now think of a compiler as a sort of translater that converts a set of symbols with a given syntax and construction rules into another set of symbols with a given syntax and formation rules...
So I guess a compiler is really simple in concept..... :bg
Well, I think this was a bit quick stated. Creating translaters from one formal language into another can be really complex indeed! And do not forget the optimization need. I have some experience in creating parsers, script compilers and I can say, to create a complete and errorfree processor is not that easy. The more effective is the source language, the more complex automaton is needed to parse that language. And the parser is only to check the syntax and gather some semantic info. To get advanced semantic info and use them is another step and that is where it gets more complicated...

Well, later I'll be working on an XML lib project. When I start it, I will open a topic for it, since I surely will need help and ideas from you and - since I prefer open source and free code - I'd like to share my efforts with others.


Greets, gábor


cman

I just meant the idea was simple , the implementation never is. I just wanted to give an very simplified idea of what a compiler was. I simply turns this set of symbols:


while ( i < 10 )



into this set of symbols:


1010111001001000


how you get from high level symbols and syntax to low level symbols and syntax is VERY difficult. But I was just giving an over simplified explanation of the problem to motivate an understanding of the entire issue. I guess I'm no go at explaining things  :'(..