Hi
Lately I've been sorta forced into looking into XML. During one of my sleepless night I started wondering about having Perl (or any programming language for that matter) translated in some kind of semi pseudo code. It would allow us (uhm programmers, hackers, whatever you want to call yourself) to write logics and have some preprocessort write the actual code. Before you all start --'ing this meditation, I'm aware of the fact that this would probably kill the fun of coming up with JAPH tricks or TMTOWTDI ways.

XML (with the right DTD) would suit the purpose, and it would improve porting issues for ancient applications. Personally, I'd rather use some kinda preprocessable pseudo code, than code in Cobol all day long. Anyway, some braindumps :

<Print Value="Hello World"></Print> <Print> <Scalar Value="Hello"></Scalar> <Scalar Value="World"></Scalar> </Print> <Array Name="List"> <Element Value="Foo"></Element> <Element Value="Bar"></Element> </Array> <Sub Name="Foo"> _yada yada_ </Sub>
I'm probably not the first to think of it, and I wont be the last... but it's just a thought.

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

Replies are listed 'Best First'.
Re: Perl as XML
by clemburg (Curate) on Jan 23, 2001 at 23:57 UTC

    It would allow us (uhm programmers, hackers, whatever you want to call yourself) to write logics and have some preprocessort write the actual code. ... Personally, I'd rather use some kinda preprocessable pseudo code, than code in Cobol all day long.

    If we regard programming as some kind of "writing" activity, like writing English prose, then I pose the question: Would you rather like to write this XML stuff you propose above or something like COBOL? Even Cobol might be less wordy than the alternative that you propose. I could see your example as *output* of some preprocessor, but for input, I would prefer something more convenient (for a good example, have a look at the input language for GraphViz or read chapter 17 (Template Driven Code Generation) in Advanced Perl Programming).

    XML (with the right DTD) would suit the purpose, and it would improve porting issues for ancient applications.

    Either you are an SGML/XML genius, or I am missing something here. I don't think it will be easy to parse a programming language (even something rather simple, like COBOL) with an SGML/XML parser.

    In fact, it is impossible for most contemporary programming languages, if I interpret Formalizing SGML and XML Instances and Schemata with Forest Automata Theory correctly (in short: "The fundamental problem is that context free grammars describe languages much more rich, powerful and complex than SGML can represent.").

    Note: If anybody out there has a clear theoretical understanding of these issues, I would welcome a more substantial discussion very much!

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

      On the Cobol issue: Yes, I would rather do XML than Cobol :) I am hardly a XML guru, but I already like it more than Cobol. Technically, Code is data. Uniform data, since it is built up out of keywords and variables. A lex parser backend would ofcourse be handy, since you have to DO something with the code.
      Two of many nice things about XML :

      <DIR>
    • XML was designed to describe data.
    • </DIR> <DIR>
    • XML tags are not predefined in XML. You must define your own tags.
    • </DIR>

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
(Ovid) Re: Perl as XML
by Ovid (Cardinal) on Jan 24, 2001 at 02:32 UTC
    About a year ago, when I worked for an insurance company, a friend of mine was writing an XML app that would take an XML document and automatically convert it into the programming language of choice. At the time I left, he had basic DTDs for VBA and Perl. He couldn't write anything horribly complex, but he was getting interesting results. I found the idea very interesting because if someone requests a particular application coded as an XML document, the server would determine what languages they could use and automatically parse the document into the correct language. Rather than store copies of every program in every language the system needed, it only needed one copy. Nifty, huh?

    The drawback is pretty obvious: nothing complex is going to be churned out of that system. Forget about regular expressions (try writing /"((?:[^?"]|\?(?!"))*)\?"/ in VB sometime). Hashes were probably out the window. In other words, anything that's "language specific" just isn't going to fly. I wish I knew what became of that project. Hmm... time to send some e-mail.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Perl as XML
by extremely (Priest) on Jan 24, 2001 at 04:24 UTC
    If I had to type that many angle brackets just for that little code, I'd strangle someone. =) Larry has made some noise about adding "Little Language" support to perl so that you could devise an alternate syntax or three. I just think the syntax you currently have is vile and without merit, I think the idea you have about transformable syntax is a perfectly valid one, hopefully in Perl 6 you will be able to do a personal syntax like that and still hand out clean, pretty perl code to the rest of the world.

    Since you have the interest and the latin-ish quote for a sig, you should check out Lingua::Romana::Perligata see what a frightening thing Damian Conway dreamed up...

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Perl as XML
by ichimunki (Priest) on Jan 24, 2001 at 04:48 UTC
    This particular XML is not quite the form I would recommend. A value attribute for empty elements seems bizarre/redundant. Just put that info right into the element and skip the value attribute is my suggestion. :)

    Along this train of thought, if you want an interesting programming challenge, write a language using XML for the source code and implement a virtual machine in Perl. Come to think of it, that actually sounds like fun, doesn't it?
Re: Perl as XML
by spaz (Pilgrim) on Jan 23, 2001 at 23:41 UTC
    It's an interesting idea, I'll give you that. But I don't see it being very scaleable. Can you imagine trying to write a KLOC of *any* code in an XML fashion? I don't really see XML as being very readable either (although some argue the same about perl ;) But I will give you that it's an interesting idea.
Re: Perl as XML
by Falkkin (Chaplain) on Jan 24, 2001 at 08:15 UTC
    I can't find the link, but I do remember a technical article on netscape.com that said that Mozilla is using XML to define GUI components... the XML is apparently then parsed into appropriate C++ code. I will admit that this subject (defining XML-based GUI) mildly interests me. I might try my hand at something similar, myself.

    Disclaimer: I am not a mozilla developer, so this story is, at best, hearsay, until I find the link. ;)

      I've seen similar stuff with Glade, where the GUI details are stored in XML, until the actual code is generated. Since Glade also does Perl (check CPAN), it can be done :)

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.