Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: The Perl Compiler (turning perl scripts into binary executables)

by Nitsuj (Hermit)
on Jul 11, 2001 at 02:25 UTC ( [id://95513]=note: print w/replies, xml ) Need Help??


in reply to The Perl Compiler (turning perl scripts into binary executables)

Speaking as someone who has written a compiler before. Let me point you in the direction that you need to be going.

1. You are not going to do this in PERL, you will rot your brain and go through WAYYY more frustration than is necessary trying to do so. There is already a REALLY nice suite of tools for writing compilers in C. PERL isn't written in PERL ;-)
2. The first tool you will want to learn about is LEX. Lex generates lexical analyzers.
3. The second tool that you will want to learn to use is YACC (or Bison). Bison will allow you to form the proper grammars for your language, to write the semantic analyzer, and to allow you to generate intermediate code. Intermediate code will be one of the key factors in making your compiler cross platform. You might even consider bootstrapping whatever you write to GCC, so as to to make this system cross platform that way, it will save you a lot of headaches, as you will not have to re-release for every platform.
4. These 2 tools are generally used with C. They generate sources that can be linked to each other and to your own source.
5. If you don't know anything about grammars and automata, you can forget about writing a compiler. Read up on them.
6. A textbook that you might use to get yourself started is Compilers: Principals, Techniques, and Tools by Aho, Sethi, and Ullman.


Just Another Perl Backpacker
  • Comment on Re: The Perl Compiler (turning perl scripts into binary executables)

Replies are listed 'Best First'.
Re: Re: The Perl Compiler (turning perl scripts into binary executables)
by BrentDax (Hermit) on Jul 11, 2001 at 07:46 UTC
    I'm not quite sure if you get what we're trying to do. We're not writing a compiler IN Perl, we're writing one FOR Perl. That basically requires us to figure out a way to take Perl's parse tree and somehow encode it into an executable such that we can regenerate it. (crazyinsomniac--I'll be sending you an e-mail soon explaining my idea for this.) The perl source will do all of the parsing for us--we're just parsing its parse trees, so to speak.

    Besides, even if we *were* writing a compiler in Perl, we'd probably use Parse::RecDescent. It's easily powerful enough to parse C, and supposedly the next version will be able to parse Perl.

    =cut
    --Brent Dax

    @HPAJ=split("", "rekcaH lreP rentonA tsuJ"); print reverse @HPAJ; #sucky but who cares?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://95513]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found