News:

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

Designing A Language

Started by cman, May 11, 2005, 02:22:04 PM

Previous topic - Next topic

MichaelW

You could do something like BF.

http://www.iwriteiam.nl/Ha_BF.html

Sample BF app that displays "Hello World!" and terminates (just in case you can't tell by looking at the source):

>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]
<.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[
<++++>-]<+.[-]++++++++++.

eschew obfuscation

cman

Quote from: MichaelW on May 16, 2005, 08:08:48 AM
You could do something like BF.

http://www.iwriteiam.nl/Ha_BF.html

Sample BF app that displays "Hello World!" and terminates (just in case you can't tell by looking at the source):

>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]
<.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[
<++++>-]<+.[-]++++++++++.



Wow , that is really cool! :U I've never seen anything like this! Thanks for the post! This is pretty sparce indeed. Converts one set of unreadable symbols to another. Pretty neat. Can you actually program in this language ( have you written anything big) ? Just curious. :bg

MichaelW

I have written a few small test pieces. I once ported a BF interpreter from C to QuickBASIC and I needed to have a reasonable understanding of the language to make it work. But I never really got into it -- I  already have enough problems with my brain :green



eschew obfuscation

cman

Reminds me of the idea of a Turing Machine; one read head and an infinite tape with 1's and 0's. You can reproduce and function of a more conventional computer with a Turing Machine , but I doubt it would be pretty ( its difficult enough seeing a TM add two numbers ). I guess there are many different ways to look at directiong the actions of a piece of translation software. As I look into language design I notice that the easier the language is to translate the harder it becomes to use ( I guess this should be obvious , thought ). I look at ideas in Pascal:


  type.name = [b]set  of [/b] base_type [ value ,... , value ]


restricted value ranges ( that are a pain to specify but make instruction selection easier for the compiler ).

I also noticed step type loops that make it easy to identify Induction Variables:



  for j := 1 to 14 do
     begin

     end



I noticed how binding times speed the execution time of array processing of languages like Fortran and C ( but reduce the flexablity of data structures at run time ). And I noticed the scripting languages ( Perl , ect. ) that can produce complicated algorithms in just a few lines. If one could just put all the neat features of every language into a blender....... :bg

Randall Hyde

Quote from: cman on May 17, 2005, 04:40:04 PM
I noticed how binding times speed the execution time of array processing of languages like Fortran and C ( but reduce the flexablity of data structures at run time ). And I noticed the scripting languages ( Perl , ect. ) that can produce complicated algorithms in just a few lines. If one could just put all the neat features of every language into a blender....... :bg
This is because languages like Perl, etc., are "very high-level" or "domain-specific" languages. They work fantastic for the problems they were created to solve. But once you try to solve a problem outside their domain, they aren't quite so advantageous.

"Kitchen sink languages" (as in "everything, including the kitchen sink") have been tried (PL/I, anyone?) and have failed miserably. They are too complex to write, too complex to generate efficient code for, and too complex for mere mortals to learn (how many people have completely mastered C++, for example?)
Cheers,
Randy Hyde

chep

Quote from: Randall Hyde on May 18, 2005, 12:18:49 AM(how many people have completely mastered C++, for example?)

Indeed! After 12 years I'm still a complete newbie! (well, almost)

But... ONE DAY I'll be a C++ guru... and then I'll take my revenge... muahahahaha :bdg

:toothy

cman

I guess focus is the key word when designing a language. I suppose I would be best off tring to design a language that solves a very specific problem of some sort. But what would that be.....

MichaelW

This has more to do with implementing a language than designing one, but how about creating an expression evaluator for use with MASM. The evaluator could effectively be a "string calculator" that would accept an expression in the form of a string, and return the result. For MASM applications that needed to perform complex non-time critical calculations, such an evaluator could save a lot of time and code. I think BASIC-style expressions would be the best choice because the notation is easy to use and widely understood. Here are some examples pulled at random from working apps:

Y = .299 * R + .587 * G + .114 * B
U = .492 * (B - Y)
V = .877 * (R - Y)

C7 = ((1 - v ^ 2) * (a / b - b / a)) / 2
C9 = (b / a) * (((1 + v) / 2) * LOG(a / b) + ((1 - v) / 4) * (1 - ((b / a) ^ 2)))
Mt = ((-w * a ^ 3) / b ^ 2) * (1 - v ^ 2) * C9 / C7

id = SQR(od ^ 2 * (s - p) / (s + p))

I think the passed expression probably should not include the assignment. Some simple method of passing in variables and named constants would be required. Using a fixed type for all numbers, say REAL8, would make the task easier.
eschew obfuscation

jack

@MichaelW
it would be even better to have Math Expression compiler, a little utility that accepts a math expression and then translates to
optimized assembler, because trying to do that oneself is a pain :P

cman

Interesting! It would be nice if there were a utility that could produce MASM code for high level expressions so as to save programmers the tedious work of codeing long calculations in assembly language. I've read of some algorithms for register and memory management that can produce fairly decent code ( not as good as a human programmers , but OK ). A project like that would be interesting , and maybe even manageable. Hmmm..... :bg

cman

I am thinking along the lines of something like assembler with operators , like this:




DWORD array [ MAX_ARRAY_LENGTH ];


eax = ecx + array [ 1 ]; // high level array is sumed with the contents of ecx and store in eax
eax ++;  // increment eax C style
edx = ( eax | ecx ); //take logical or of two registers and move result to edx



I don't know how practical something like this would be. It certainly would make assembly more fun in certain tedious situations. I think quality object code ( MASM ) could be obtained if used by an experienced assembly language programmers. However , statements like this:



eax = ebx + ecx + edx + esi + edi .....



would cause some internal register and memory management by the compiler ( changing register names and using temporary memory locations ) , using data flow anaylsis ( the knight's armor on the cover of the Dragon Book  :bg ) , ect... Is this a stupid / bad idea? I've been studing the ANSI C grammar ( a surprizingly elegant and concise grammar , by the way ) to get some ideas on how to develop the language. I like the idea of substituting operators for assembly operations or groups of assembly operations and chaining operations to speed development. The set of C operators seems somewhat sufficient to cover a good subset of assembly operations ( + , - , * , ++ , -- , & , | , || , && , < , > , << , >> ,% ,^ , ! , ext.. ). Maybe add a few more. Hmmmm....

tenkey

Go ahead...design yet another high level assembler.
You've got good company. Give Randy a run for his money (on HLA).

Hey, even Randy acknowledges the idea predates him...he even mentions PL/360 (created by Niklaus Wirth of Pascal fame).
I've seen proposals for 8-bit machines like PL/B, and working ones like ML-80. There was even a commercial product (I think it was called BL-80 or similar).

I'm not sure about PL/360, but the others did not allow expressions that caused spillage (storing temporary results in memory).  That would spoil the idea of an assembly language, where you have complete control, or at least an easily predictable code sequence.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

cman

Thanks for the input tenkey! While I'm not even close to being in Randy's league  :'( , I thought this might be a neat "toy compiler" project ( I get to go through all the motions of building a compiler , but won't have to write anything real difficult - like a real compiler ). Just look for ideas for a hobby - style project and since this style of language would not be too far above the object code , I think this is as easy as it gets . The whole idea of writing something that would half-way work is pretty exciting for me. Thanks for the input! :U

Homer

I'd just like to point out that masm's MACRO support is powerful !!
You can write yourself a neato script-based language as a macro set, which allows the user to build the applications with masm (no need for a preprocessor).
If you don't believe me, take a look inside the macros folder of the ObjAsm32 oop model by Biterider.. you're in for a shock !!
The simple truth is that masm's macro support is:
-underrated
-misunderstood
-not well known
by most masm coders, including long-term users :cheekygreen:

hutch--

I agree,

Apart from piggish documentation, obscure syntax and the odd irritations here and there, the preprocessor in MASM is very powerful and in conjunction with normal library modules, you can do many things with it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php