cancel
Showing results for 
Search instead for 
Did you mean: 

Software compilers.. Chicken or the Egg?

Community Veteran
Posts: 13,923
Thanks: 515
Fixes: 7
Registered: 01-08-2007

Software compilers.. Chicken or the Egg?

I do a bit of hobbyist programming with object pascal.. Delphi, Lazarus.. call it what you like lol.
Anyway i was reading something the other day that said the guy who came up with pascal wrote it in pascal and then created the compiler in pascal.
So.. how do you compile the first compiler in a language that doesn't yet have a compiler? - and more to the point, how do you write it in a language that doesn't technically even exist because it has no compiler?
Mook?
I need a new signature... i'm bored of the old one!
7 REPLIES
Community Veteran
Posts: 6,586
Thanks: 206
Fixes: 14
Registered: 16-02-2009

Re: Software compilers.. Chicken or the Egg?

Write a compiler in assembly to compile your statements, then write the statements and run them through the compiler to generate machine code.
So something like I want to use fred to display something, so I write a bit of assembly code to translate fred into something that will display what was passed.
So now I can write:
fred"Hello World!"
pass it through the compiler and it will display :
Hello World!
when run.
Community Veteran
Posts: 5,322
Thanks: 467
Fixes: 1
Registered: 21-03-2011

Re: Software compilers.. Chicken or the Egg?

or design the computer operating system and implement a virtual machine on an existing computer. Create a compiler, using assembly language on the virtual machine. When the physical machine has been manufactured start developing software using the compiler you developed on a virtual machine.
Now Zen, but a +Net residue.
Community Veteran
Posts: 4,772
Thanks: 1,053
Fixes: 27
Registered: 16-10-2014

Re: Software compilers.. Chicken or the Egg?

The creation of a compiler is complicated and something I’ve never given much thought to, but in basic terms when you set out to write such an item you know what its intentions are. Most compilers are multi phase and or multi pass. Meaning that the process to generate the object code is done as part of multiple steps, such as reading input, lexical analysis, syntax analysis, parse tree and basic translation to object code.
As a (very bad) example when you want to write to stdout you want to use a key word “print”. So in your code you have what is a look up table that equates to :
mov ax, data
mov ds, ax
mov dx, offset DataSegmentToPrint
mov ah, 09h
int 21h

Of course the above is missing the code that loads the string in to the registers, and iterating to actually output the character to the screen as only one at a time is done, but you get the idea. So every time you encounter the word print in your input (source) it would be output as above.
You then do the same for every aspect of your language construct, if, for, while next, switch, case, blah, blah, blah. These would then be optimised by a good compiler and then written to disk. But of course .o or .obj files are useless without a linker to link them and add the boot strapping code needed to execute them.
Hope this makes some sense.
Community Veteran
Posts: 3,364
Thanks: 15
Registered: 06-04-2007

Re: Software compilers.. Chicken or the Egg?

look up tools known as yacc and bison
but at some point the compiler (and the linker) need to generate instructions in assembler or RTL.
--
3Mb FTTC
https://portal.plus.net/my.html?action=data_transfer_speed
Community Veteran
Posts: 6,735
Thanks: 12
Registered: 02-02-2008

Re: Software compilers.. Chicken or the Egg?

There is so much technology/IT support and tools available that many are not aware of where it all bootstraps from, many years ago and layers down.
Think thermionic valves, wires and physical switches..........................
The first computer I worked on used sound travelling through a column of mercury (with piezoelectric transducers at each end) to store data as the "memory".
The first program I wrote I loaded into it by flicking toggle switches.
Moderator
Moderator
Posts: 25,784
Thanks: 1,132
Fixes: 47
Registered: 14-04-2007

Re: Software compilers.. Chicken or the Egg?

And I thought I was having a hard time with Machine Code on a Sinclair ZX81 Sad
Customer and Forum Moderator.
Product of the Tyrell Corporation
Community Veteran
Posts: 5,322
Thanks: 467
Fixes: 1
Registered: 21-03-2011

Re: Software compilers.. Chicken or the Egg?

Quote from: HPsauce

a column of mercury

Mercury, eh that's posh. Mine was paper tape with a toggle switch bootstrap.
Now Zen, but a +Net residue.