Programming language + XML + XSL = compiler ?

Discussion in 'XML' started by rnbrady@gmail.com, Jun 23, 2006.

  1. Guest

    Hi folks

    New around here. This post may be a duplicate, I think I bungled the
    previous one.

    I've recently started out with XML and XSL and I'm very impressed with
    both. My use is non-web in nature. In fact, I'm writing a compiler of
    sorts, from high-level spec in XML, with eventual generation of VHDL.

    I've made the following observations:

    1. Given pure source code (Eg:Java,C++), one could generate an abstract
    syntax tree in XML.
    2. XML is also apposite for symbol tables and intermediate froms.
    3. XSLT can do powerful transformations of said internediate forms.
    4. XSL can generate plain text.

    I'm wondering wondering what it would take to implement a compiler for
    a given language in XML/XSL. More specifically, are there any XSL or
    XML based systems that assist in scanning pure source into XML so that
    the transformations can begin? Grammar could be provided in marked-up
    EBNF. This is probably over-optimistic could the process would need
    knowledge of LL/LALR etc.

    The alternative approach is to use your standard scanner/parser
    generator with it's own (non-interchangable) EBNF and have the action
    code generate tagged tokens, giving you an AST in XML.

    My questions:
    1. Are there any decent XML shema's for EBNF?
    2. Are there any tools / XSL extensions to do the above?
    3. What are your thoughts on the whole idea?

    Best regards,
    Richard Brady
    , Jun 23, 2006
    #1
    1. Advertising

  2. wrote:
    > I'm wondering wondering what it would take to implement a compiler for
    > a given language in XML/XSL.


    Remember, XSL is a pure functional langauge. That may make some of the
    manipulations a serious compiler would want to perform difficult.

    But, yes, a basic old-fashioned just-replace-with-equivalent-code
    transformation ought to be possible. This is not the set of tools I
    would choose to do it in -- custom data structures are likely to be much
    more efficient than trying to model everything in XML -- but if you're
    looking for a pedagogical exercise, it could be a fun thing to try.

    Were I you, I'd start with a language that has simpler syntax and
    semantics than Java or C++, and use that to establish your framework and
    understand the issues (including performance and memory space). Then, if
    you're still feeling ambitious, go for it.

    (Personally, I've stopped writing compilers for the sake of writing
    compilers. I'd rather wait until I'm reasonably sure there's something
    mine will do better than any existing alternative.)



    More specifically, are there any XSL or
    > XML based systems that assist in scanning pure source into XML so that
    > the transformations can begin? Grammar could be provided in marked-up
    > EBNF. This is probably over-optimistic could the process would need
    > knowledge of LL/LALR etc.
    >
    > The alternative approach is to use your standard scanner/parser
    > generator with it's own (non-interchangable) EBNF and have the action
    > code generate tagged tokens, giving you an AST in XML.
    >
    > My questions:
    > 1. Are there any decent XML shema's for EBNF?
    > 2. Are there any tools / XSL extensions to do the above?
    > 3. What are your thoughts on the whole idea?
    >
    > Best regards,
    > Richard Brady
    >
    Joe Kesselman, Jun 23, 2006
    #2
    1. Advertising

  3. Andy Dingley Guest

    wrote:

    > 3. XSLT can do powerful transformations of said internediate forms.


    IMHE, XSLT can't do "powerful", for interesting values of powerful. It
    does "Bulky but simple" very well indeed and is excellent for text
    processing with blocks of text. If you try and do anything involving
    semantics though, it starts to fall flat.
    Andy Dingley, Jun 23, 2006
    #3
  4. wrote:

    > I'm wondering wondering what it would take to implement a compiler for
    > a given language in XML/XSL. More specifically, are there any XSL or


    This has been suggested 5 years ago in

    http://www.idealliance.org/papers/xml2001/papers/html/03-05-04.html

    and also in comp.compilers late last year.
    Google for "xml as intermediate representation"

    > 3. What are your thoughts on the whole idea?


    Teaching compiler construction could be an area
    where this idea might be useful. But in real life,
    I would _not_ like to write my source code in XML.
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=, Jun 23, 2006
    #4
  5. Then there's always the inverse: a programming language whose syntax is
    based on XML, so it can be styled by XSLT (or generated from other XML
    sources by XSLT). IBM's Bean Markup Language and BML Scripting Pages,
    which I was involved in some years ago, were one such example, though in
    that case the language was designed for configuration and assembly of
    existing Java components (and BSF scripts, also something that I helped
    develop) rather than being intended as a completely stand-alone
    programming environment.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jun 24, 2006
    #5
  6. Andy Dingley Guest

    On Fri, 23 Jun 2006 23:46:38 -0400, Joe Kesselman
    <> wrote:

    >Then there's always the inverse: a programming language whose syntax is
    >based on XML, so it can be styled by XSLT (or generated from other XML
    >sources by XSLT).


    Ant

    SQL DDL, as managed by the Apache Torque project
    Andy Dingley, Jun 24, 2006
    #6
  7. Hm. I don't usually think of Ant as a programming language, and I don't
    think I've heard of anyone styling it, but that's an interesting
    observation -- stylesheets to adapt Ant builds to different
    environments, perhaps...


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jun 24, 2006
    #7
  8. Guest

    Hi folks

    Thanks for the input. I'm not actually thinking of doing this as a
    project, just curious about whether any investigation has been done on
    the topic. I currently use this technique to transform digital signal
    processing (DSP) algorithms specified in XML into VHDL implementations
    of those algorithms.

    Perhaps I'm off the mark with suggesting it for C++ or Java, but it's a
    particularly interesting concept when considering higher-level
    specifications such as in model driven engineering (like UML in MDA). A
    large emphasis becomes interoperability/exchangability/portability of
    models, but at the core of it all is transformations between models.

    It's interesting because we all have different backgrounds and
    therefore unique perspectives on an concept like this.

    Thanks again,
    Richard
    , Jun 26, 2006
    #8
  9. wrote:

    > the topic. I currently use this technique to transform digital signal
    > processing (DSP) algorithms specified in XML into VHDL implementations
    > of those algorithms.


    Where did you get the DSP algorithms in XML ?
    Is there any standard for this ?
    Juergen Kahrs, Jun 26, 2006
    #9
  10. Andy Dingley Guest

    Joe Kesselman wrote:
    > Hm. I don't usually think of Ant as a programming language,


    In its limited little way, it's a declarative programming language (as
    was Prolog). You can use it as a convenient dependency resolver.

    > I don't think I've heard of anyone styling it,


    I have an XSLT stylesheet that auto-documents Ant external targets.
    Handy when I'm shipping deployment scripts to users.

    I also auto-generate Ant from a vile combination of our bug tracker,
    change control, and Torque repository. This generates database patch
    scripts for upgrading customer databases from arbitrary start points to
    new product versions.
    Andy Dingley, Jun 26, 2006
    #10
  11. Another interesting reference on this topic: The folks working on a test
    suite for the W3C's DOM APIs were developing a limited XML-based
    "programming language" for binding/language-independent description of
    the tests, together with stylesheets which would render those into
    executable form. Again, that's a fairly primitive "compiler", but it's
    yet another instance of XML-based programming languages.
    Joe Kesselman, Jun 26, 2006
    #11
  12. Guest

    Juergen

    > Where did you get the DSP algorithms in XML ?


    That's a good question. I'm writing them myself and learning as I go
    along.

    > Is there any standard for this ?


    Not that I know of, but I wouldn't be surprised.

    So, now that I have these XML descriptions being converted into VHDL,
    the next step is to layer something more interesting on top. No DSP
    designer wants to type their spec in XML ... yuk!

    There are several options: text (something more readable than XML),
    visual, or both. My application is Software Defined Radio so I'm
    looking at Waveform Description Language (WDL) which has a textual form
    with equivalent representations in visual and XML forms. Another option
    would be UML2.

    For WDL I have a Lex/Yacc grammar, so I can just create a little
    compiler to mark-up the code. I thought there'd be plenty other folk
    with the same issue and some standard solution might have been
    developed. I'm a big fan of standard solutions because of the re-use
    which they encourage.

    Richard
    , Jun 26, 2006
    #12
  13. Guest

    Juergen

    PS: Your links (both the article and the comp.compiler discussion) were
    very useful. Thank you.
    , Jun 26, 2006
    #13
  14. wrote:

    > So, now that I have these XML descriptions being converted into VHDL,
    > the next step is to layer something more interesting on top. No DSP
    > designer wants to type their spec in XML ... yuk!


    Two years ago, someone posted here about a VHDL
    application. Use Google Newsgroups to search for
    "Use variables to get unique nodes". He posted
    this stuff:

    <?xml version="1.0" encoding="UTF-8"?>
    <Root>
    <E>
    <!-- If we have the key match with pin only
    the xslt does not work. If the maych is at least TEST/Pin
    it is OK
    -->
    <Pin PinName="A" PinClass="T"/>
    <!--<Pin PinName="AX" PinClass="T"/> -->
    </E>
    <x>
    <!-- in case the TEST node below is not selected by Index
    AND PinName="A" and CellType="M" matches
    the result is wrong
    -->
    <TEST Index="42" CellType="M">
    <Pin PinName="z" PinClass="R"/>
    <!--<Pin PinName="AX" PinClass="T"/>-->
    <Pin PinName="A" PinClass="T"/>
    </TEST>
    <TEST Index="43" CellType="M">
    <Pin PinName="A" PinClass="T"/>
    <Pin PinName="D" PinClass="R"/>
    <Pin PinName="C" PinClass="R"/>
    <Pin PinName="X" PinClass="R"/>
    </TEST>
    <TEST Index="44" CellType="M">
    <Pin PinName="D" PinClass="R"/>
    <Pin PinName="C" PinClass="R"/>
    <Pin PinName="X" PinClass="R"/>
    <Pin PinName="A" PinClass="T"/>
    </TEST>
    <TEST Index="45" CellType="M">
    <Pin PinName="z" PinClass="R"/>
    </TEST>
    </x>
    </Root>




    > There are several options: text (something more readable than XML),
    > visual, or both. My application is Software Defined Radio so I'm
    > looking at Waveform Description Language (WDL) which has a textual form
    > with equivalent representations in visual and XML forms. Another option
    > would be UML2.


    This is rather abstract. You should post an example.
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=, Jun 26, 2006
    #14
  15. wrote:

    > PS: Your links (both the article and the comp.compiler discussion) were
    > very useful. Thank you.


    This paper about lcc may also be interesting for you:

    http://www.cs.princeton.edu/software/lcc/asdl.html

    This is not strictly involving XML, but they also
    use a tree-representation.
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=, Jun 26, 2006
    #15
  16. Guest

    Thanks!
    , Jun 28, 2006
    #16
  17. Guest

    I recently came across the str:tokenize() function at the EXSLT
    project. It takes a string and converts it into several tokens.

    QUOTE:

    The string given by the first argument is split at any occurrence of
    any of these characters. For example:

    str:tokenize('2001-06-03T11:40:23', '-T:')


    Gives the node set consisting of:

    <token>2001</token>
    <token>06</token>
    <token>03</token>
    <token>11</token>
    <token>40</token>
    <token>23</token>

    UNQUOTE.

    This is close to what I had in mind. If you could extend the idea so
    that it takes an EBNF in XML form instead of a list of delimiters,
    wouldn't you have part of a scanner and parser?
    , Jun 29, 2006
    #17
  18. wrote:

    > This is close to what I had in mind. If you could extend the idea so
    > that it takes an EBNF in XML form instead of a list of delimiters,
    > wouldn't you have part of a scanner and parser?


    Yes, but what is it good for ?
    Do you want to write a universal Parser which
    takes an EBNF and parses according to the EBNF ?
    Such universal parsers have been suggested and
    implemented much earlier. For example, Niklaus
    Wirth presented such a parser in 1976:

    http://www.inf.ethz.ch/personal/wirth/books/Compilerbau0/
    http://www.oberon.ethz.ch/WirthPubl/CBEAll.pdf
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=, Jun 30, 2006
    #18
  19. Guest

    > Do you want to write a universal Parser which
    > takes an EBNF and parses according to the EBNF ?


    It doesn't need to be written from scratch, just integrated as an
    extension to XSL, so that XSL can take structured text (in a non-XML
    form) as input and parse it, and generate xml/html/text as output.

    > Yes, but what is it good for ?


    1. Compiler-compiler not needed as separate step in the whole process.
    2. Definition of a standard syntax for EBNF using a DTD or XSD.
    3. Entire compiler could be written in XSL.
    4. An interesting platform for academic exploration of compiler design.
    , Jul 3, 2006
    #19
  20. Andy Dingley <> wrote:
    > Joe Kesselman wrote:
    >
    >>Hm. I don't usually think of Ant as a programming language,

    >
    >
    > In its limited little way, it's a declarative programming language (as
    > was Prolog). You can use it as a convenient dependency resolver.
    >
    >
    >>I don't think I've heard of anyone styling it,

    >
    >
    > I have an XSLT stylesheet that auto-documents Ant external targets.
    > Handy when I'm shipping deployment scripts to users.
    >
    > I also auto-generate Ant from a vile combination of our bug tracker,
    > change control, and Torque repository. This generates database patch
    > scripts for upgrading customer databases from arbitrary start points to
    > new product versions.
    >


    hi,

    I have designed and implemented a general-purpose XML system that I
    called "Active Tags" which allows to make programs with XML tags ; it
    allows to mix declarative tags with imperative instructions, uses XPath
    to access object's properties, and much more...

    it is not "yet another markup language" but a framework that allows
    several markup languages to run together

    the implementation (Java) :
    http://reflex.gforge.inria.fr
    the specs :
    http://disc.inria.fr/perso/philippe.poulard/xml/active-tags/active-tags/active-tags.html
    http://disc.inria.fr/perso/philippe.poulard/xml/active-tags/

    --
    Cordialement,

    ///
    (. .)
    --------ooO--(_)--Ooo--------
    | Philippe Poulard |
    -----------------------------
    http://reflex.gforge.inria.fr/
    Have the RefleX !
    Philippe Poulard, Jul 3, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Replies:
    0
    Views:
    1,010
    Kevin Flood
    Sep 8, 2004
  2. Replies:
    1
    Views:
    3,587
    A. Bolmarcich
    May 27, 2005
  3. Casey Hawthorne
    Replies:
    4
    Views:
    984
    Jarek Zgoda
    Aug 4, 2006
  4. stefaan

    XML based programming language

    stefaan, Mar 18, 2007, in forum: Python
    Replies:
    13
    Views:
    515
    stefaan
    Mar 22, 2007
  5. Shravani
    Replies:
    8
    Views:
    780
    Bartc
    Mar 16, 2008
Loading...

Share This Page