Writing a compiler?

Started by
25 comments, last by FearedPixel 21 years, 1 month ago
quote:Original post by Oluseyi
Not that you can''t do it in C# or that C# is a poor choice. I''m just wondering if you''re constrained by, say, the languages you know as opposed to the best tool for the job...

The only thing Perl is the best choice for is obfuscation.
.NET has a set of very good regular expression classes, offering the syntax of Perl 5 regexes without the atrocious ugliness of Perl.


"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Advertisement

Im currently following a compiler course:
http://www.it-c.dk/courses/PFOO/F2003/index.html

The teacher makes some very good slides(under Lecture plan) and has lots of example code in SML.
Btw, using a functional language(like SML(which i personally like), ,LISP or Perl etc) is a really good idea when writing a compiler. The development time will be shortened A LOT compared to using an imperative lanuage!( just thought id mention it, because you have development time as one of your reasons to use C#).
(if you doubt me take a look at some of those slides and see how small the abstract syntax datatype and the interpreter("fun eval
") is)
Wow, thanks everyone.

The way I am planning to do it now, is that my compiler will compile to assembly. I guess that initially (and possibly permanently) I will use a third party assembler to then go from assembly to machine code (.exe). To implement the various built-in language functions like printing to screen, reading input etc I will create dll files in C that contain the functions for my standard commands, so basically when such a command is encountered by my compiler, in the generated ASM, it will call the associated function from the libraries (dll''s) that I wrote in C.

Can anyone recomend an assembler I should use that would be appropriate for me? I know MASM has a lot of macros and other functions, however because the aim of this project is to learn, and it is a piece of coursework, I would ideally aim to compile to low level ASM, rather than the macro enhanced high level one.

At the moment I just need to assemble console exe''s that work under windows, and then eventually actual windows exe''s.

Again, help is much appreciated.
quote:Original post by FearedPixel
Can anyone recomend an assembler I should use that would be appropriate for me?

Take a look at nasm.
quote:
At the moment I just need to assemble console exe''s that work under windows, and then eventually actual windows exe''s.

A "console exe" IS an actual Windows executable.


"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Search for "inger"

EDIT:

make that "inger compiler" (on Google)

[edited by - Kurioes on March 7, 2003 4:47:15 PM]
quote:
A "console exe" IS an actual Windows executable.


So in terms of the exe protocol, windows exe''s are exactly the same, except for it having different calls in the code (ie to winmain etc)?

I though that the non-program information in a windows exe is different?

Thanks for pointing that out.
quote:Original post by FearedPixel

A "console exe" IS an actual Windows executable.

quote:
So in terms of the exe protocol, windows exe''s are exactly the same, except for it having different calls in the code (ie to winmain etc)?

A console application does an AllocConsole and calls main. A "regular" Windows app just calls Winmain. Thats pretty much it.


"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement