News:

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

Ent language

Started by spaceship, February 03, 2012, 10:01:51 PM

Previous topic - Next topic

spaceship

Hi!

I have been experimenting with creating a new programming language and named it Ent. The compiler reads Ent source code and produses assembly code (MASM). It's just something I have thinkered with and is far from finished (if ever).

And here is an example of Ent (circuit.ent):


voltage:
type: int
value: 220
postfix: V

current:
type: int
value: 10
postfix: A

power:
type: int
value: voltage * current
postfix: W

print "Circuit has <voltage> and <current>. Power usage is therefor <power>."



To compile:
ent circuit.ent

And compiles to assembly (circuit.asm):

.386
.model flat, stdcall
option casemap:none

include c:\masm32\include\windows.inc
include c:\masm32\include\masm32.inc
include c:\masm32\include\kernel32.inc

includelib c:\masm32\lib\masm32.lib
includelib c:\masm32\lib\kernel32.lib

.data
    main_17_print_1 db "Circuit has ",0
    main_17_print_2 db "V and ",0
    main_17_print_3 db "A. Power usage is therefor ",0
    main_17_print_4 db "W.",13,10,0

.data?
    main_12_power db 100 dup(?)
    main_2_voltage db 100 dup(?)
    main_7_current db 100 dup(?)

.code
start:
    call main

;#####################################################################
main proc

.code

    ;
    ;start of main_17_print
    ;

    ;
    ;SOURCE(17): print "Circuit has <voltage> and <current>. Power usage is therefor <power>."
    ;

    invoke StdOut, addr main_17_print_1      ;"Circuit has "

    mov eax, 220     ;voltage.value=220
    invoke dwtoa, eax, addr main_2_voltage
    invoke StdOut, addr main_2_voltage      ;"220"

    invoke StdOut, addr main_17_print_2      ;"V and "

    mov eax, 10     ;current.value=10
    invoke dwtoa, eax, addr main_7_current
    invoke StdOut, addr main_7_current      ;"10"

    invoke StdOut, addr main_17_print_3      ;"A. Power usage is therefor "

    mov eax, 220     ;power.value=voltage * current
    imul eax, 10
    invoke dwtoa, eax, addr main_12_power
    invoke StdOut, addr main_12_power      ;"voltage * current"

    invoke StdOut, addr main_17_print_4      ;"W.""

    ;
    ;end of main_17_print
    ;

    invoke ExitProcess, 0       ;return 0

main endp
;#####################################################################

end start



And we have to produse an executable (circuit.exe):

\masm32\bin\ml /c /coff "circuit.asm"
\masm32\bin\PoLink /SUBSYSTEM:CONSOLE "circuit.obj"


Finally we may run the program witch is giving us following output:

Circuit has 220V and 10A. Power usage is therefor 2200W.


First part of circuit.ent describes the Ent-variables witch feeds the compiler with extra information about the variable. Ent-variables therefore able to know how to interact with other Ent-variables, say an int variable may easily be a part of a string variable.

Second part of circuit.ent is just a simple print function witch is of type string, so if the compiler finds any <entvariable> then it automatically converts what ever int value there is and replaced <entvariable> and lastly fixes the prefix/postfix. Prefix/postfix is always string.

I just wanted to share some ideas here. By the way do anyone know if there is some languages like Ent out there?

qWord

hi,
Quote from: spaceship on February 03, 2012, 10:01:51 PMBy the way do anyone know if there is some languages like Ent out there?
not sure if I understand the semantic, but I would say each OOP-language can do similar.
FPU in a trice: SmplMath
It's that simple!

dedndave

i thought "Ent-ish" was the language spoken by the trees in Lord of the Rings   :P
better watch out for copyright violation