My final exam for the first semester is this morning. After that I intend to finish off some work I'm doing wrt compilers and interpreters. I just wanted to see if anyone was interested in a series of tutorials on compilers and interpreters from the perspective of someone who is just understanding how they work (i.e. I remember what bits were 'What?!?' so might take it in a more practical way rather than theoretical).
Note that if I do one it will probably be done either in C or C++ exclusively (I might use other languages to highlight some concepts if I have code already written, like I have a basic scanner written in python to handle the whitespace issue), it would be first of all an interpreter and then taking the parser and adding a code generator to the end of it. It would not be for any existing language (if anything it will be a very narrow subset of C) and the code output will be hopelessly inefficient. There could well be only one data type. The compiler would probably target Linux (though it would be relatively simple to port it to other archs). We would only be using C (or C++) and the standard libraries. No third party libraries for special data structures will be used so we will probably end up implementing a hash table, linked list and a stack at some point.
It's worth considering that even if you have no interest in compilers that it would be (I hope) a good exercise in C, parsers and data structures. While some assembly may be involved in the later stages it will be explained as far as needed.
Anyway, if there's any interest in it just post here. It might take me a month to get together all the stuff I'll need and write the articles.
Compiler/Interpreter tutorial - any interest?
Started by G_Morgan, Jan 22 2008 08:48 PM
11 replies to this topic
#1
Posted 22 January 2008 - 08:48 PM
|
|
|
#2
Posted 22 January 2008 - 10:58 PM
It sounds really nice to me. I was really into compilers and interpreter some years ago, and made some small ones myself. It would be really great to get it refreshed, and learn some more. I can only say; go for it! I'll definitely read them. I'm especially looking forward to the parser-process.
#3
Posted 23 January 2008 - 08:44 AM
I'm interested. I'm looking at making a general tutorial on programming concepts myself. Sort of a pseudocode tutorial.
#4
Posted 10 February 2008 - 06:30 AM
I've done the code for the first tutorial on this. Thought I'd upload it early if anyone wants a look. One change is that I've used C++ rather than C*. All the code is MIT/X11 licensed (basically do what you want but don't remove the copyright notice, see the files for more details). All it does so far is take a series of identifiers, integers and some operators and tokenises the stream. All the testing has been done on x86/Linux (Ubuntu specifically). There's no symbol table and no parsing as of yet.
The tutorial to go with this will follow at some point.
*I created a dynamic string struct and library for C but it still didn't look very nice. C++ streams are a god send.
//edit - first version had some bugs. I've fixed it and uploaded.//
The tutorial to go with this will follow at some point.
*I created a dynamic string struct and library for C but it still didn't look very nice. C++ streams are a god send.
//edit - first version had some bugs. I've fixed it and uploaded.//
Attached Files
#5
Guest_Jordan_*
Posted 29 March 2008 - 06:30 AM
Guest_Jordan_*
I'm interested in as well. This type of tutorial would benefit many people here on the forum trying to learn and understand C/C++.
#6
Posted 29 March 2008 - 07:02 AM
Jordan said:
I'm interested in as well. This type of tutorial would benefit many people here on the forum trying to learn and understand C/C++.
I should be getting to the write up for the first part pretty soon. I've stalled a bit because of piled up work at Uni.
The lecturers quite cleverly decided to avoid the masses of coursework clashes from the end of last semester by giving us every single piece early in the semester. It's not as if the coursework can clash early on instead of later is it...
Anyway should be clear by the end of the week, then I can look at writing up the framework for the lexer and getting on with making it do something useful.
#7
Posted 03 April 2008 - 01:08 AM
Sounds great to me! Would love to see something like that..
God is real... unless declared an integer
my blog :: http://techarraz.com/
#8
Posted 05 December 2008 - 11:47 PM
how do i use the compiler you have made G_Morgan? i would like to test :O
#9
Posted 06 December 2008 - 03:58 AM
I've not done it yet. Loads has come up in between but I'll probably have a look at it soon enough.
The lexer I posted merely takes in a string and recognises which type of symbol it is. It's quite simple but is the first step in building a compiler.
To build it on Windows you will need MinGW and MSYS set up. I was originally going to post a short tutorial on how to do this. For Linux you merely need the standard GCC tool chain which either ships with each distro or is easily installable ('apt-get install build-essential' on Debian based distros like Ubuntu). Then you merely open the directory in a terminal and type make.
The lexer I posted merely takes in a string and recognises which type of symbol it is. It's quite simple but is the first step in building a compiler.
To build it on Windows you will need MinGW and MSYS set up. I was originally going to post a short tutorial on how to do this. For Linux you merely need the standard GCC tool chain which either ships with each distro or is easily installable ('apt-get install build-essential' on Debian based distros like Ubuntu). Then you merely open the directory in a terminal and type make.
#10
Posted 03 March 2009 - 09:02 PM
I hope you are planning to continue the tutorial
#11
Posted 03 March 2009 - 10:04 PM
I downloaded the code and took a look at it. So you've ported Jack Crenshaw's code to C. I think you should at least have credited him for the source.
#12
Posted 04 March 2009 - 01:36 AM
I thought I mentioned I'd be getting inspiration from Crenshaws tutorial. It is where I first looked at this stuff. If not then I apologise to Crenshaw, the early code is largely the cradle from the first chapter of his tutorials.
I do intend on looking at some different things to Crenshaw. For example I will be using a different target language and will probably be contrasting recursive descent with a table driven parser. It isn't just going to be a translation of 'Lets Build a Compiler' to C++ and x86. Also my intention is to do things in order, getting lexical analysis working before trying to generate code. Whereas Crenshaw starts with a compiler that works for one character symbols.
I intended to get this done but ended up swamped under University work. Its my last year and things are currently insane. At the earliest it will be the end of April before I give it a serious look.
I do intend on looking at some different things to Crenshaw. For example I will be using a different target language and will probably be contrasting recursive descent with a table driven parser. It isn't just going to be a translation of 'Lets Build a Compiler' to C++ and x86. Also my intention is to do things in order, getting lexical analysis working before trying to generate code. Whereas Crenshaw starts with a compiler that works for one character symbols.
I intended to get this done but ended up swamped under University work. Its my last year and things are currently insane. At the earliest it will be the end of April before I give it a serious look.


Sign In
Create Account


Back to top










