Euphoria pre-processor

new topic     » topic index » view thread      » older message » newer message

I am working on an Euphoria pre-processor that should eventually translate
an extended euphoria program (including classes, pointers, structures and
other useful stuff that can be done in Euphoria, but is not easy to
implement (in my opinion). So far, I have written a program that breaks
down an Euphoria program into a sequence of tokens so that:
constant a =3D 5, b =3D 6
if a!=3Db then -- This is a comment
        puts(1, "a !=3D b!")
end if
looks to the program like:
This is a comment","puts","(","1",",","\"a !=3D b!\"",")","end","if"}
which makes it much easier to process.
I am now working on the processing part now.

I also noticed that bind doesn't remove unused stuff. I ran a test by
binding the following to programs:

t1.ex:
function p(sequence s)
        puts(1, s)
        return s
end function
puts(1, "This is a test!")

t2.ex:
puts(1, "This is a test!")

When compiled, t2.exe is 20 bytes smaller than t1.exe. This is not much,
but I think that it may add up when using large libraries (like win32lib
and eusock; winsock.ew has LOTS of constants, but very few are used.), I
think this could substantially increase the size of the file.
Also, bind doesn't remove types when types are used in the program, but
there is a without type_check command. This also increases the size of the
program, and I suspect that it may slow it down a little as well (since the
interperter must interpert the type instead of using a built-in type
directly). My pre-processor will remove unused constants, variables, and
procedures as well.

If anyone has any suggestions for the pre-processor, I'll be glad to
consider putting them into the syntax of "Euphoria++" (I am not really
great at thinking up the syntax myself, but I have a few ideas). If anyone
wants to help, that would be good too because I have been working for quite
a while just on the tokenizing part of the program, and it took me several
tries (I have tried writing it in Euphoria, Java, and Visual Basic, and
after several failed attempts, I finally wrote a working version in
Euphoria), and if that's dificult, I can just imagine how dificult it's
going to be writing the rest.

My ideas for "Euphoria++":
* structures:
        type b(sequence s)
                ...
        end type
        struct a
                b theB
                sequence name
        end struct
would convert to...
        type b(sequence s)
                ...
        end type
        constant a_theB =3D 1, a_name =3D 2
        type a(sequence s)
                if length(s) =3D 2 then
                        return b(s[a_theB]) and sequence(s[a_name])
                end if
                return 0
        end type
* classes
        class c extends a
                function getName()
                        return name
                end function
        end class
        c theC
        theC.name =3D "name"
        puts(1, theC.getName())
would convert to...
        function c_getName(a this)
                return this[a_name]
        end function
        a theC
        theC[a_name] =3D "name"
        puts(1,c_getName(theC))
also:
        class c extends a
                sequence lastName
                function getName()
                        return name & " " & lastName
                end function
        end class
        c theC
        theC.name =3D "first"
        theC.lastName =3D "last"
        puts(1, theC.getName())
would convert to...
        constant c_lastName =3D 3
        type c(sequence s)
                if length(s) =3D 3 then
                        return a(s[1..2]) and sequence(s[3])
                end if
                return 0
        end type
        function c_getName(a this)
                return this[a_name] & " " & this[c_lastName]
        end function
        a theC
        theC[a_name] =3D "name"
        puts(1,c_getName(theC))

The code above could also be modified to make it so that a must have at
least 2 elements, so any class (or structure) that extends a can be used in
place of a (I really like the object-oriented features that Java has, and
all of the features that Euphoria has, so why not put them together to get
a powerful yet simple and fast language?)

Jeffrey Fielding
JJProg at cyberbury.net

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu