How to make a new programming language with MASM32v10?

Started by FritzGamaliel, March 26, 2010, 04:56:19 AM

Previous topic - Next topic

TmX

Quote from: FritzGamaliel on March 28, 2010, 06:47:06 AM
But we still use FileName.asm
Can we use new file' type
Example:
FileName.myType

doesn't really matter, anyway
a compiler/interpreter should be able the parse the content of the file, regardless of its extension

Quote from: FritzGamaliel on March 28, 2010, 06:47:06 AM
Then, we create our grammar?

take a look at The Dragon Book
it's the de facto reference in writing compilers

donkey

Quote from: FritzGamaliel on March 28, 2010, 06:47:06 AM
But we still use FileName.asm
Can we use new file' type
Example:
FileName.myType

Then, we create our grammar?

Thank you
Fritz.

No, it doesn't make any difference just modify your build command.

ML.EXE /c /coff /Cp /I"C:\masm32\Include" "SomeSource.MOE"
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hutch--

Fritz,

To address your basic question, there are two choices, use the MACRO system in MASM and within those limits of notation, design you own macro/language system. The other choice is to write either and assembler or compiler in MASM where you have absolute control of the notation but at the price of having to do it all from scratch. The latter is a very advanced task usually done by teams of programmers with a lot of experience being funded by a large corporation.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

FritzGamaliel

Hutch,
Now, I can create accounting application in MASM32v10 with MicrosoftAccess2003 as it's database.
Then, I dis-assemble it exe file with   MASM32v10'qeditor
Then, I dis-assemble ml.exe of MASM32v10 with MASM32v10'qeditor
I compared it result..
To understand how to create a compiler easily, can I use my method?
But, it still hard for me to understand how to create a compiler...Do you have other advice?

Thank you
Fritz

donkey

Fritz,

Creating a compiler is an extremely complex task. You will have to know a lot about binary trees and hashing to build and search symbol tables, you will need to completely understand the x86 instruction set, you will have to have at least a very good knowledge of tokenization and parsing as well as about 1000 other things. It is not for a novice or even an intermediate programmer, it falls squarely in the advanced family of coding. I would take Hutch's advice and build a macro library that will meet your needs, it may not be exactly what you want but MASMs macro facilities are without equal in the assembly world and I'll bet you can come close. Doing it through macros passes off all of the really hard stuff to MASM and leaves you only to work out the syntax and logic. If you really want to go the compiler route, I posted a link in my first post in this thread that is a pretty good primer for compiler writing:

http://compilers.iecc.com/crenshaw/
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

sinsi

QuoteMASMs macro facilities are without equal in the assembly world
I would argue that fasm's macro language is a lot more advanced (even though I don't use them) :bg
Light travels faster than sound, that's why some people seem bright until you hear them.

tenkey

There are many ways to build a compiler. They all require some basics:

1) the task of analyzing the written code to discover what the programmer has asked the computer to do,
2) the task of building tables of symbols, to hold names and properties.
3) the task of creating the new code, which is a translation of what was written.

The difficulty depends on the demands of the language you create.

How much performance do you want?
It is easy to produce correct code which is many times slower than what other compilers, or a competent assembly language programmer can generate. The simplest compilers will also create redundant code. Creating faster and nonredundant code requires more complex algorithms. Some algorithms are very advanced and require knowledge of compiler theory.

What kinds of data do you want to provide?
Most users will want numbers with fractional values. Read up on floating-point arithmetic to handle them. In addition to numbers, you will probably want to provide arrays.  The nonresizable array is simple to implement, and is sufficient for many applications. Most users will also want to have strings. Strings, like the ones in Basic, PHP, or .NET, require runtime memory management. If you want objects, you are getting fancy. Objects require a complex compiler table structure to disambiguate names and track what is valid and visible to other code. Modern objects require runtime memory management that is more complex than the management needed for strings-only.

What is your target code?
Assuming the final code will be an "unmanaged" executable, you can generate MASM code, and let the assembler handle the task of generating a binary file. Most compiler writers would want to directly create at least a COFF (OBJ) file that is usable by the linker. In addition to handling the forward reference problem, you will need to create the relocation and linking information required by the linker. Or you can attempt to create the final PE-COFF (EXE) file directly. In addition to the binary translation, you will need to supply the PE header information required by the OS loader.

How much error checking do you want to do?
The simpler the language, the fewer error messages you need to provide. But you must provide meaningful error messages for "compiler doesn't understand", "compiler does not allow", and "no more room (overflow)" events.

How much debugging help do you want to provide?
As a beginning compiler writer, you probably will want to avoid this until you have built one or two working compilers. It's something to put on the list of what users might expect.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

hutch--

Fritz,

The answer to your question is simply NO, a compiler/assembler is some powers more com0pliczated than you think and if you read the postings here by some very experienced people you will get some idea of just how complicated they are. Just parsing the code that you design the language for is a sophisticated task and there are many more things you would have to do to succeed, a pre-processor is another language again, then you have opcode generation and with a bare assembler you then have to do some jump langth optimisation to compact the code. A compiler that performs wider ranging internal optimisation is a power more complicated again.

You will do OK by learning the MACRO engine in MASM and writing a set of custom macros and while the MASM macro system is a bit long in the tooth and piggy here and there it is reasonably powerful if you can master it properly and if you combine it with your own library of procedures you come close to a custom language.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

qWord

Fritz,
if you decide to use macros, you will find an good starting point in MASM Programmers Guide , Chapter 9 . For examples how creating/using macros take a look in \masm32\macros\macros.asm.
There is nearly nothing that you can't do with macros, as long as there is a will  :bg
FPU in a trice: SmplMath
It's that simple!