News:

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

Creating compiler with MASM

Started by panther, March 06, 2007, 11:05:15 AM

Previous topic - Next topic

panther

Hello every body, can all of you tell me where i can get tutorial about creating a simple compiler. Because

i need it :( . I hope who read this can help me, because i want to create a simple compiler

ramguru

It depends on what type of compiler you're after. Recently I wrote a resource compiler (partially) to incorporate it into my application. So it's basically all about translating from text format to binary format. You can read some stuff that describes this process (like "Red Dragon" book) before you try to code, or you can start right away... Everything is straightforward: you read file, you parse it line by line, you accumulate a pile of binary data in other buffer, you omit whitespace, you pay attention at separators...and you finally have a binary output, all PE32 specification you'll ever need is already available (up-to-date) and waiting for ye.

BPak

QDepartment at the Yahoo Groups has some good tutorials on compilers and interpreters.

http://tech.groups.yahoo.com/group/QDepartment

Look in the Files section.

Randall Hyde

Quote from: panther on March 06, 2007, 11:05:15 AM
Hello every body, can all of you tell me where i can get tutorial about creating a simple compiler. Because

i need it :( . I hope who read this can help me, because i want to create a simple compiler

You might want to visit this:

http://webster.cs.ucr.edu/AsmTools/RollYourOwn/index.html

Beyond describing how to write an assembler with the HLA assembler (not MASM, sorry), it also contains a copy of P.D. Terry's compiler e-text that you might find interesting.
Cheers,
Randy Hyde

SteveA

As a co-owner and moderator of the afore mentioned QDepartment, (a number of years ago) I wrote an e-book, a 16 chapter tutorial on writing compilers and scripting engines, titled:
"Blunt Axe Basic:
Let's Build a Scripting Engine-Compiler"

This tutorial series develops a QBasic'ish type of language I call Bxbasic. Simple to program in and easy to understand.
Bxbasic is presented as a programming tutorial, to develop and construct a Console Mode Scripting Engine and Byte Code Compiler. The Bxbasic dialect, included here, is a subset of the GW-Basic and QBasic programming languages.

This e-book can be found at the following locations:

http://tech.groups.yahoo.com/group/QDepartment/     
(in the files section, membership required for files access)

and:
http://sites.google.com/site/bluntaxebasic/tutor/Bxb-Tutor.doc

Additionally, there is also an Masm32 version called: BxbAsm
which uses Masm32 to output x86 binaries. This version is not written in a tutorial format, but, complete source code and executables are provided for the experienced programmer.

May also be downloaded from:
the QDepartment group site (above),

as well as at:
http://sites.google.com/site/bluntaxebasic/tutor/


jj2007


TmX

Hi jj,

beside the alleg40.dll, cgui16.dll is also required

Those 2 files can be found from these:
http://www.allegro.cc/depot/project.php?_id=717
http://home.tele2.at/raphae/cgui16.zip


jj2007

Quote from: TmX on January 02, 2010, 03:18:32 AM
Hi jj,

beside the alleg40.dll, cgui16.dll is also required

Those 2 files can be found from these:
http://www.allegro.cc/depot/project.php?_id=717
http://home.tele2.at/raphae/cgui16.zip


Thanks. I just downloaded these two but now it complains that alleg42.dll is missing. Starts looking suspicious - why does a simple BASIC need so many external dlls...??

TmX

Quote from: jj2007 on January 02, 2010, 10:02:09 AM
why does a simple BASIC need so many external dlls...??

I guess it has something to do with with emulating old school BASIC screen, or probably GUI.
Allegro is a game programming library, and CGUI16 is a GUI library (based on Allegro).

SteveA

Quote from: TmX on January 02, 2010, 05:14:33 PM
Quote from: jj2007 on January 02, 2010, 10:02:09 AM
why does a simple BASIC need so many external dlls...??

I guess it has something to do with with emulating old school BASIC screen, or probably GUI.
Allegro is a game programming library, and CGUI16 is a GUI library (based on Allegro).

Hi jj and TmX,
Actually, Bxbasic (or BxbAsm) by itself does not require Allegro or it's DLL's.
That version, (called Bxb-E), is an Allegro "port", written mainly by QDepartment member: Tom Chandler.
Tom took the basic Bxb and added the routines to support Allegro. As TmX stated, Allegro adds GUI and Game support.

jj, I'm curious, from what source did you download the version of Bxbasic you have ?
The standard version of Bxb should not be calling for the Allegro or any DLL's.

Steve


jj2007

Quote from: SteveA on January 02, 2010, 11:46:46 PM
jj, I'm curious, from what source did you download the version of Bxbasic you have ?

Steve,

One of the links you posted: http://sites.google.com/site/bluntaxebasic/tutor/

Where could I get the "good" version?

SteveA

Quote from: jj2007 on January 02, 2010, 11:51:14 PM
Quote from: SteveA on January 02, 2010, 11:46:46 PM
jj, I'm curious, from what source did you download the version of Bxbasic you have ?

Steve,

One of the links you posted: http://sites.google.com/site/bluntaxebasic/tutor/

Where could I get the "good" version?

jj,
you are absolutely correct !!
After looking at the source for that compile, I had some flags set that I forgot about, after Tom and I tested some Allegro stuff.
And since I had Allegro installed, it didn't raise any red flags.
I have since deleted the Exe's from that site.
Give me a bit and I'll try to do a recompile before too long.
I'll post a message here after testing and uploading.

Thanks,
Steve

ecube

If you're creating a compiler to produce pe, elf etc files you may want to just create a preprocessor like I did here http://www.masm32.com/board/index.php?topic=13003.0. Assemblers already do all the pain staking backend work to produce the executable, so you can just add the features you want ontop of that, and have the backend compile it for you. Since things like JWASM are open source you can integrate your "languages features" right inside that and have it process the syntax before jwasm gets to it, it's a lot faster, more intelligent approach then trying to reinvent the wheel from scratch.
JWASM is based off a open source project that already existed, so is pelle C, so it's not unheard of.

jj2007

Quote from: SteveA on January 03, 2010, 01:05:49 AM
Give me a bit and I'll try to do a recompile before too long.
I'll post a message here after testing and uploading.

Thanks, Steve. In the meantime, I'll try hard to get rid of a nasty little bug in MasmBasic. As you can see, I am an old fan of Basic, too :bg

SteveA

Quote from: jj2007 on January 03, 2010, 10:12:34 PM
Quote from: SteveA on January 03, 2010, 01:05:49 AM
Give me a bit and I'll try to do a recompile before too long.
I'll post a message here after testing and uploading.

Thanks, Steve. In the meantime, I'll try hard to get rid of a nasty little bug in MasmBasic. As you can see, I am an old fan of Basic, too :bg

Hi jj,
I've uploaded the corrected executables, that go along with the tutorial.
Sorry it too so long. It's been a busy past couple of days.
After recompiling the correct version, (that goes along with the tutorial), I noticed a couple of glitches that weren't there before, so I had to make some minor fixes. I used Lcc-Win32, to produce Bxbasic (the scripting engine) and earlier versions of Lcc had some bugs that I had to develop work arounds for. The newer version of Lcc has been fixed, so now it introduced a glitch that I had to fix. I tested it out with the samples in the .txt file and all seemed to be working.

Last night I was looking over the source-code for the (Allegro) version you previously downloaded.
I was amazed at the complexity and of the newer (undocumented) features we had added to it. I don't think we (Tom and I) ever released the source-code for that version. I may have to revisit it and see which of the newer parts I can get to run without the need for the Allegro DLL's. That set of executables has no relation to the tutorial, tho.  It was more experimental.

Thanks,
Steve