It is currently Sat May 25, 2013 10:47 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Compiler tutorial: suggest more stuff
PostPosted: Fri Sep 04, 2009 5:06 pm 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Some people wanted to know how to create a programming language in PureBasic: viewtopic.php?t=34316

So I started a tutorial: http://pbtut.blogspot.com/

Please post here if there is some particular topic you are interested in a tutorial on, or if something wasn't made clear.

Currently wanted:
(of course everything, but the following will be prioritized first)
functions (Joakim)
multiple types

Request it if you want any of this:
whole assembly file generation (so the compiler becomes usable)
anything else you can think of

Done
Expressions with variables, parentheses and 12 operators (4 precedence levels).
multiline input
if statements
loop statements
better code by using registers instead of stack
symbol table
function calls (long type)

_________________
Woa, I set up a web server.


Last edited by Trond on Sun Jan 10, 2010 3:48 pm, edited 6 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 04, 2009 6:51 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jul 22, 2003 5:02 pm
Posts: 1496
Location: Nantes, France
Looks very interesting, i will have a look.


Quote:
PS. Can anyone suggest a better publishing solution than blogspot (that is still quick to setup and use)? Blogspot keeps mutilating my code.


You might try code.google (?)

http://code.google.com/intl/fr/opensource/
http://code.google.com/p/pyfilemaker/wiki/FileMakerXMLWrappers

_________________
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 04, 2009 7:38 pm 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Google code isn't meant for sequential publishing and mixing code with text. At least it's not obvious. I always found it confusing.

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 04, 2009 10:40 pm 
Offline
Addict
Addict

Joined: Fri Apr 25, 2003 11:10 pm
Posts: 852
Trond, yes please add loop constructs and multiple types. :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 04, 2009 11:14 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jul 01, 2004 2:51 am
Posts: 905
Location: Tacoma, WA
Trond,

Wordpress? http://codex.wordpress.org/Writing_Code_in_Your_Posts

Also - very interesting tutorial. Nice work!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 05, 2009 1:02 pm 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Wordpress is even worse than blogspot. Even within code tags, double spaces are stripped, the result is that indentation is lost.

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject: Re: Compiler tutorial: suggest more stuff
PostPosted: Sat Sep 05, 2009 1:38 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Apr 25, 2005 9:28 pm
Posts: 553
Location: $300:20 58 FC 60 - Vietnam
Trond wrote:
So I started a tutorial: http://pbtut.blogspot.com/


That's a really good idea, thanks Trond :D

_________________
“Fear is a reaction. Courage is a decision.” - WC


Top
 Profile  
 
 Post subject: Re: Compiler tutorial: suggest more stuff
PostPosted: Sun Sep 06, 2009 8:07 am 
Offline
User
User

Joined: Thu Aug 27, 2009 12:13 pm
Posts: 21
Trond wrote:
Some people wanted to know how to create a programming language in PureBasic: http://www.purebasic.fr/english/viewtopic.php?t=34316

So I started a tutorial: http://pbtut.blogspot.com/

Please post here if there is some particular topic you are interested in a tutorial on, or if something wasn't made clear.

Currently wanted:
functions (Joakim)

Request it if you want any of this:
if statements
loop statements
optimizations (current code is ridiculously bad)
whole assembly file generation (so the compiler becomes usable)
multiple types
anything else you can think of

PS. Can anyone suggest a better publishing solution than blogspot (that is still quick to setup and use)? Blogspot keeps mutilating my code.


Why not just blog it here in the PureBasic forums? With the [code] tags you won't have to worry about formatting problems.

I don't know how far you plan to take this project (are you making a complete interpreter/compiler?) but if it's not too much trouble could you include if statements and also goto statements. Actually I'd like everything you're offering that includes : loop statements, optimizing, multiple types but only if you feel up to it. No pressure here, take it easy. :)


Top
 Profile  
 
 Post subject: Re: Compiler tutorial: suggest more stuff
PostPosted: Sun Sep 06, 2009 9:39 am 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Teng wrote:

I don't know how far you plan to take this project (are you making a complete interpreter/compiler?)
I will not put all the pieces together, but I will show all the pieces working independently.

The reason I haven't posted a new tutorial part yet, is that I wanted to do functions, but that requires a symbol table. Symbol tables are easy to write, but fast ones require a big amount of code. This is because they need to take into account nested scopes, which is easiest done by a linked tree of hash tables. As you may imagine, this will take a bit of pointer fiddling and a custom hash table implementation, which is really not what we want here.

Instead I'm just going to use one hash table, implemented with PB's map. But that isn't completely working/documented yet. So I have to write a tutorial on another subject in the meantime. Because I think presenting a huge lump of code for a symbol table detracts from the subject.

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject: Re: Compiler tutorial: suggest more stuff
PostPosted: Mon Sep 07, 2009 11:08 am 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Trond wrote:
Teng wrote:

I don't know how far you plan to take this project (are you making a complete interpreter/compiler?)
I will not put all the pieces together, but I will show all the pieces working independently.
Or actually, it seems like some things don't make much sense without each other (like ifs without variables and boolean expressions), so I will make certain pieces together.

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 09, 2009 1:01 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1115
Location: North by Northwest
@Trond
great job so far.

Wondering about this:
Code:
Procedure IsDigit(C.c)
  If C >= '0' And C <= '9'
    ProcedureReturn 1
  EndIf
EndProcedure

Debug IsDigit(4)

shouldn't it output 1 :?:

Here it only works if the numbers are not using '9' but 9.

using newest beta...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 09, 2009 8:27 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 02, 2003 9:16 am
Posts: 1917
Location: Germany
fsw wrote:
@Trond
great job so far.

Wondering about this:
Code:
Procedure IsDigit(C.c)
  If C >= '0' And C <= '9'
    ProcedureReturn 1
  EndIf
EndProcedure

Debug IsDigit(4)

shouldn't it output 1 :?:

Here it only works if the numbers are not using '9' but 9.

using newest beta...


'0' = 48
'9' = '0' + 9 = 57

ASCII ;-) press Alt+A inside the PureBasic IDE for more information.

_________________
bye,
Daniel

http://www.bradan.eu/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 09, 2009 9:46 am 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
fsw wrote:
@Trond
great job so far.

Wondering about this:
Code:
Procedure IsDigit(C.c)
  If C >= '0' And C <= '9'
    ProcedureReturn 1
  EndIf
EndProcedure

Debug IsDigit(4)

shouldn't it output 1 :?:

Here it only works if the numbers are not using '9' but 9.

using newest beta...


No, the parameter is a character, not a number. If you could pass a number (like 123, 0, 8193, 573) then the procedure would always have to return 1, and thus be senseless.
The character type is a number type which holds a character in the form of its character number (ascii code or unicode character code). The procedure checks if the passed character number (which will of course always be one or more digits) specifies a character (in the ascii table) that is a digit.

If that didn't help, may blueznl's guide has something about character types?

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 09, 2009 9:52 am 
Offline
User
User

Joined: Thu Aug 27, 2009 12:13 pm
Posts: 21
Just finished reading section 11 of your tutorial on pre-optimization :) . One thing though, since your tutorial is directed at beginners, you should make passing mention that basic assembler knowledge is required but I guess that is obvious enough if you think about it :lol: . Here's a link to information on assembly for beginners :

http://maven.smith.edu/~thiebaut/ArtOfA ... ofasm.html

A program that also useful for testing basic assembler instructions without messing up your pc (e.g,. if you're trying out interrupts, otherwise just use PureBasic) :

http://www.geocities.com/emu8086/

Update :
Whoops! Sorry don't I look like the ass. :lol:
Totally missed this in the tutorial :
"I recommend that you look here: http://flatassembler.net/docs.php?article=manual to get a description of all x86 assembly instructions. You can also download the same file as a pdf file.". Sorry.


Last edited by Teng on Wed Sep 09, 2009 11:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 09, 2009 10:01 am 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
I learned assembly by writing a compiler, I don't see why anyone else shouldn't. After all, you can only learn something by doing/using it. What I should have mentioned was that if you don't know it, you'll have to make an extra effort to be sure you know what's going on at all times.

What I did was to look a lot on PB's assembly output. When I was unsure of how to translate a certain expression into assembly, I just typed the expression into PB and compiled it to asm (I have a batch file to do it from the tools menu). Very handy.

And again (I mentioned this in the tutorial, but I mention it again), read fasm.pdf on the relevant instructions. It has quite easy to understand info (at least compared to intel's manuals). The book "The art of assembly", I can't recommend, because it uses a different syntax.

_________________
Woa, I set up a web server.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye