OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Nov 13, 2019 9:42 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 118 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Author Message
 Post subject: Re: CompilerDev?
PostPosted: Tue Jul 29, 2014 8:09 am 
Offline
Member
Member

Joined: Fri Jan 04, 2013 6:56 pm
Posts: 98
Combuster wrote:
[...]

Antti wrote:
I am quite sure that many OS developers are also interested in compilers
I actually have a sort of compiler in my OS source tree that gets built and then builds parts of my OS ;) (same with a runtime linker, of which I have two now)


Cool! Is there a specific reason why you do it this way? Smaller build time for the kernel itself?


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Tue Jul 29, 2014 2:38 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9287
Location: On the balcony, watching the Swedish Chef
Quote:
Cool! Is there a specific reason why you do it this way? Smaller build time for the kernel itself?
The "kernel" is only worth one assembler command. The tool turns data definitions into code that reads and writes the data, as well as header files for various languages and implementation styles, so that there's only one place where the OS's primitives are used directly.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Wed Jul 30, 2014 9:02 am 
Offline
Member
Member

Joined: Fri Jan 04, 2013 6:56 pm
Posts: 98
Combuster wrote:
Quote:
Cool! Is there a specific reason why you do it this way? Smaller build time for the kernel itself?
The "kernel" is only worth one assembler command. The tool turns data definitions into code that reads and writes the data, as well as header files for various languages and implementation styles, so that there's only one place where the OS's primitives are used directly.

I couldn't think of a good reason bu that makes a lot of sense. Cool approach :)


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Wed Jul 30, 2014 10:24 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:59 am
Posts: 541
Location: Shahpur, Layyah, Pakistan
You're Right there is no (Standard) Websites for Compilers Development. I think Operating system development is much easier than implement a language translator. In my opinion Compiler development is "Science" while Operating system development is "Engineering". Compiler development requires knowledge of Discrete mathematics, Automata theory, Logic etc. I am interested in writing an Assembler not high-level language compiler. Because there is no need of higher level languages (for me).


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Wed Jul 30, 2014 11:29 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2000
Location: USA (and Australia)
I have the basics of a compiler down (lexers, grammars, abstract syntax trees, linking, simple stop-the-world garbage collector, SSA) - I took a course at university and figured the rest out online. But, information online is very scarce. There are research white papers, people's blogs, slideshow notes from college courses online - but they are usually really indepth and upclose - and you wish someone could stand back and give you the overall picture of how it fits in, or they're talking high level (how do I implement this!) and you understand the theory, but you really wish someone would kind of hint (not do it for you, but point you in the right direction to get started) at how you would implement this algorithm in a low level language.

Everyone seems to be pointing to the dragon book as the go-to reference guide, so I ordered myself a copy to see what the fuss is about.

_________________
My OS is Perception. (1 2)


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Wed Jul 30, 2014 1:27 pm 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 304
Location: Germany
muazzam wrote:
Compiler development requires knowledge of Discrete mathematics, Automata theory, Logic etc.

Sorry for contradicting, but that's not what I think. It took me about 1h of brainless coding to get a working "Hello World" compiler, without reading anything about the topic. I'm not rich enough to be able to pay 260€ for the dragon book (that's good as I want to start from scratch without being influenced by other designs).

At some point, somebody who has some knowledge about this topic should create a wiki page explaining where and how to start, as (appearently) quite a few in the OSDev forums want to start CompilerDeving too.

_________________
vineyard, a x86 OS.


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Wed Jul 30, 2014 3:23 pm 
Offline
Member
Member

Joined: Fri Jan 04, 2013 6:56 pm
Posts: 98
no92 wrote:
muazzam wrote:
Compiler development requires knowledge of Discrete mathematics, Automata theory, Logic etc.

Sorry for contradicting, but that's not what I think. It took me about 1h of brainless coding to get a working "Hello World" compiler, without reading anything about the topic. I'm not rich enough to be able to pay 260€ for the dragon book (that's good as I want to start from scratch without being influenced by other designs).

At some point, somebody who has some knowledge about this topic should create a wiki page explaining where and how to start, as (appearently) quite a few in the OSDev forums want to start CompilerDeving too.


Depends, writing a predictive recursive-descent parser is pretty simple. When you go into some more advanced topics (I think especially optimization) you're going to need some theory, I guess (I haven't really coded a compiler, but that's what I read :P ).


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Wed Jul 30, 2014 10:59 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2000
Location: USA (and Australia)
There is this wiki page.

_________________
My OS is Perception. (1 2)


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 1:09 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 304
Location: Germany
I created a tutorial on the wiki (calm down, it's a user page), waiting for reviews.

_________________
vineyard, a x86 OS.


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 3:28 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9287
Location: On the balcony, watching the Swedish Chef
Code:
$code = array(
   new Token("f", array("hello_world")),
   new Token("{", array()),
   new Token("printf", array("%s %s!\\n", "Hello", "World")),
   new Token("}", array()),
   new Token("printf", array("Test\\n")),
   new Token("hello_world", array())
);

This is really a kludgy and non-extensible way to start with things. It works for very limited cases, but there's a reason why people use abstract syntax trees, because you want to store logical blocks, rather than a mixture of random typeless symbols, which will make you put all sorts of unrelated code into blocks where they're not relevant (like the if (curly_brace) ignore(); style of code you already have).

How you actually want to write that is more like the following:
Code:
$code = array(
  new Function("hello_world", array(/*no arguments*/), array(
    new CallExpression("printf", array(
      new StringExpression("%s %s!\n"),
      new StringExpression("Hello"),
      new StringExpression("World")
    ))
  ),
  new CallExpression("printf", array(new StringExpression("Test\n"))),
  new CallExpression("hello_world", array())
)
From there, it's much easier to add additional language features. Adding integers to this structure is simple, as is 1 + 1, as well as nesting functions in arguments such as printf("%i", getch()); Try to find an obvious way to do that with your original structure :wink:

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 4:38 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 304
Location: Germany
Thanks for the reply.

I'll probably reimplement it the way you proposed it, thanks alot :D. Any other suggestions/improvements (MessiahAndrw, I'm talking to you!)? It's still a WIP, so feel free to directly edit it, if you're sure your code/explanation/etc. is better.

_________________
vineyard, a x86 OS.


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 7:02 am 
Offline
Member
Member

Joined: Fri Jan 04, 2013 6:56 pm
Posts: 98
MessiahAndrw wrote:
I have the basics of a compiler down (lexers, grammars, abstract syntax trees, linking, simple stop-the-world garbage collector, SSA) - I took a course at university and figured the rest out online. But, information online is very scarce. There are research white papers, people's blogs, slideshow notes from college courses online - but they are usually really indepth and upclose - and you wish someone could stand back and give you the overall picture of how it fits in, or they're talking high level (how do I implement this!) and you understand the theory, but you really wish someone would kind of hint (not do it for you, but point you in the right direction to get started) at how you would implement this algorithm in a low level language.

Everyone seems to be pointing to the dragon book as the go-to reference guide, so I ordered myself a copy to see what the fuss is about.


That is so true! For the dragon book, I think you can see it mainly as a reference. It is probably one of the more comprehensive works on compiler development. Don't expect too much hand-holding or implementation details. There are some sections devoted to 'the bigger picture', but the main part of the book consists of a systematic treatment of the available techniques and algorithms.

By the way, no92 and Combuster, really nice to see that people finally are creating something! :) It's probably not perfect on the first try, but actually starting to write something is sometimes the biggest problem. I'm willing to contribute, but I think I should get some more experience with building compilers first...


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 8:40 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2000
Location: USA (and Australia)
no92 wrote:
I'll probably reimplement it the way you proposed it, thanks alot :D. Any other suggestions/improvements (MessiahAndrw, I'm talking to you!)? It's still a WIP, so feel free to directly edit it, if you're sure your code/explanation/etc. is better.


It's looking good. I've thought about writing a section on language design, since I designed a compiler for my own language.

_________________
My OS is Perception. (1 2)


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 10:33 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 304
Location: Germany
kutkloon7 wrote:
By the way, no92 and Combuster, really nice to see that people finally are creating something! :) It's probably not perfect on the first try, but actually starting to write something is sometimes the biggest problem. I'm willing to contribute, but I think I should get some more experience with building compilers first...
Heh, the first time I did write a compiler was yesterday ... nothing needed except for motivation and some basic theory :D

EDIT: I updated the tutorial to include Combuster's suggestions

_________________
vineyard, a x86 OS.


Top
 Profile  
 
 Post subject: Re: CompilerDev?
PostPosted: Thu Jul 31, 2014 12:33 pm 
Offline
Member
Member

Joined: Fri Jan 04, 2013 6:56 pm
Posts: 98
no92 wrote:
kutkloon7 wrote:
By the way, no92 and Combuster, really nice to see that people finally are creating something! :) It's probably not perfect on the first try, but actually starting to write something is sometimes the biggest problem. I'm willing to contribute, but I think I should get some more experience with building compilers first...
Heh, the first time I did write a compiler was yesterday ... nothing needed except for motivation and some basic theory :D


Yeah, I did dive in the theory some time ago, but it just got me stuck with more questions.
What language am I going to parse? An existing one (or a subset or an extension based on an existing one) or a new one (what does the new language look like? Should I write a formal EBNF scheme first)? Do I want to write a recursive-descent parser or a table-driven one? What do I want to parse to? Machinecode, ASM, bytecode, intermediate code (what format? SSA, triple)...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 118 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: hadarry, YaCy [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group