XML based programming language

Diez B. Roggisch deets at nospam.web.de
Tue Mar 20 06:32:51 EDT 2007


stefaan wrote:

>> All of these are grammar-specifications that allow you to define the
>> structure of your XML-documents with more constraints.
> 
> Ok, I should have foreseen the schema checker answer...my point really
> is that
> yacc can do even more than just checking the conformance to a grammar.
> 
> It also allows me to specify semantic actions,
> e.g. to help in building an abstract syntax tree from
> the concrete syntax tree, or to implement a very basic
> interpreter...
> 
> mock example:
> <input><definevar name="a" value="10"/><definevar name="b" value="12" /
>></input>
> <output><sum arg1="a" arg2="b"/></output>
> 
> No schema checker can take this specification and simply output "22".
> XSLT might be able to implement it, but it is complex for anything
> real-life. Elementtree can immediately give me the concrete syntax
> tree,
> but any semantic actions have to be implemented during a
> manually programmed tree traversal.

Yep, they have. But to be brutally honest: I haven't felt the need to go
with semantic actions when using e.g. ANTLR. IMHO it only works for small
examples like the one above. The mixing of syntactic structure definition
together with "real" code gets really messy, and you are very rigid
regarding even smaller grammar changes.

The very moment you are getting more complex, you want an AST, and work upon
that. It will be much easier and robust to work on it, even if you alter
your grammar a bit.

And XML _is_ your AST, and working on it means... writing code. 
*If* there was anything as yacc regarding semantic actions, it would be an
extension to XSD or any other schema. I'm not aware of such a beast.

Diez



More information about the Python-list mailing list