There is a programming game that uses a mini assembler like language to code the actions of bots fighting each other. I have been thinking about writing a compiler that takes a higher-level language and spits out the assembler code. I had a good look at Bison and how people usually do this sort of thing and got depressed. As a project it started to look too much like hard work, c centric, completely structured etc etc. There was just one way to do it.

But what a project to help discover what is possible with perl. At the very core of compilers/persers/lexical analysers is a problem in text manipulation (isn't it?). It would take some perl-like text (probably using a very restricted subset of perl functionality) and output some assembler-like text.

Can anyone give me some help getting started? Any module that may give me inspiration? - I couldn't find much. Should I maybe look at perl internals? How about starting with a "wrapped" Bison and going from there? I imagine I could get lost very quickly.

Also let me know if you think it a project not suited to perl. I'll still give it a go though - at least to understand why.

Thanks for your help.

tonyday


In reply to perl as a compiler by tonyday

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.