1. Euphoria pre-processor

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 message » categorize

2. Re: Euphoria pre-processor

[Jeffry Fielding wrote about his pre-processor]

You can find my own Euphoria pre-processors on the Euphoria pages. My first
(and most successful attempt) is called PP, and it implements a number of
interesting features: case statements, C-like assignment ( +=, &=, etc.) as
well as some loop constructs borrowed from ABC.

I've also got a second pre-processor (still on the Recent Contributions, I
think) called DOT which converts dot notation instructions such as:

    foo.append( "bar" )

    if x.length > 0 then
        screen.puts( "ok" )
    end if

into:

    foo = append( foo, bar )

    if length( x ) > 0 then
        puts( screen, "ok" )
    end if

It's smart enough to know what calls get expanded to functions, and which
get expanded to procedures.

PP is the more complex of the two, because it does it's best to maintain
proper formatting and comments when rewriting the code.

Both of these pre-processors integrate into my editor (EE), so when you
select Run, they automatically are pre-processed and then run. Errors
generated by the pre-processor generate EX.ERR compliant error messages, so
even the errors generated are integrated.

If you are interested, I've also written code which parses much of
Euphoria's syntax (and generates appropriate error messages). I suspect that
it is akin to your tokenizer. It does not actually generate any code,
although that would not be that difficult to add. If you want, I can e-mail
it to you.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: Euphoria pre-processor

>I like some features of OOP too, but Euphoria is *not* OOP, and to make
>it object-oriented would bloat it IMO; look at what happened to C++:
>procedural + OO functionality made for quite a large compiler.
>And if even a subset of OO was added to the interpreter, then it would
>create larger bound programs...

I agree that adding OO to the interperter would make it much larger. What I
ment was to convert an object-oriented version of Euphoria to the standard
version. The existing interperter works fine, but it is difucult to write
programs that use an object-oriented design in standard Euphoria because
you have to set up things like:

constant FIRST_NAME =3D 1, LAST_NAME =3D 2, E_MAIL =3D 3
type entry(sequence s)
        if length(s) =3D 3 then
return sequence(s[FIRST_NAME]) and sequence(s[LAST_NAME])       
                       and
sequence(s[E_MAIL])
        end if
        return 0
end type
entry me
me[FIRST_NAME] =3D "Jeffrey"
me[LAST_NAME] =3D "Fielding"
me[E_MAIL] =3D "JJProg at cyberbury.net"
-- etc...

However, using a pre-processor, you could write:
struct entry
        sequence first_name
        sequence last_name
        sequence e_mail
end struct
entry me
me.first_name =3D "Jeffrey"
me.last_name =3D "Fielding"
me.e_mail =3D "JJProg at cyberbury.net"
-- etc...

and the pre-processor would write the standard Euphoria code for you (and
possibly even optomize it).

Jeffrey Fielding
JJProg at cyberbury.net

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu