[Javascript] XML DTD for ECMAScript

liorean liorean at f2o.org
Tue Jun 1 15:20:11 CDT 2004


Greetings!

Don't know if I shoud post this in an XML related list or here, but I'll give this a shot and then move it to an XML related list if you can't give me any advice on it...

I'm currently working on an XML language to describe EMCAScripts semantically, based on the ECMA-262 3ed. specification. However, I've run into a problem that I hope some XML DTD-savvy person here can help me with. The solution doesn't have to match the ECMAScript constructs exactly, but it does have to match functionally, both inclusively and exclusively. The constructs in question are:

~~~~<@>~~~~
11.2 Left-Hand-Side Expressions Syntax

MemberExpression :
    PrimaryExpression
    FunctionExpression
    MemberExpression [ Expression ]
    MemberExpression . Identifier
    new MemberExpression Arguments

NewExpression :
    MemberExpression
    new NewExpression

CallExpression :
    MemberExpression Arguments
    CallExpression Arguments
    CallExpression [ Expression ]
    CallExpression . Identifier

Arguments :
    ( )
    ( ArgumentList )

ArgumentList :
    AssignmentExpression
    ArgumentList , AssignmentExpression

LeftHandSideExpression :
    NewExpression
    CallExpression
~~~~<@>~~~~

Limits I have, for practical reasons, had to impose on myself for this:
 - The %AssignmentExpresion; entity starts a cascade of entities that matches either the corresponding element (in the case of the %AssignmentExpresion; entity that element is AssignmentExpression) or the next entity in the hierarchy. These entities MUST resolve to either a single element or another single entity, they may NOT resolve to multiple elements.
 - The entities may, due to DTD entity handling being string replacement based, NOT recur in any entity bound way, neither directly nor through intermediary entities. They may contain elements whose content model includes them, however.
 - All composite constructs (that is all constructs that may contain multiple consecutive constructs) must be representable as a single element with those multiple consecutive construct as it's content model.
 - All redundant information should be implicit to save space.
 - It should preferably be possibly to style it using CSS2 and get code that should be runnable, or transform it using STTS, XSLT or DSSSL to pretty-printed directly runnable JavaScript code.

What I have in the DTD currently is:
<!ENTITY % LeftHandSideExpression "(%NewExpression; | %CallExpression;)">
<!ENTITY % NewExpression "(%MemberExpression; | NewExpression)">
<!ENTITY % CallExpression "(CallExpression)">
<!ENTITY % Arguments "Arguments">
<!ENTITY % MemberExpression "(%PrimaryExpression; | %FunctionExpression; | MemberExpression)"> <!-- Should I have another element, newMemberExpression, here to represent that syntax choice? Or can I use the MemberExpression syntax? Is there any risk for ambiguities going with the simplest hierarchy? How about code confusion, because evidently we have a situation where we may either have many Arguments, or many implicit new operators, but not both at once? Should I maybe make the new operator   explicit? -->

<!ELEMENT NewExpression %NewExpression.content;>
<!ELEMENT CallExpression %CallExpression.content;>
<!ELEMENT MemberExpression %NewExpression.content;>
<!ELEMENT Arguments %Arguments.content;>

<!ENTITY % NewExpression.content "%NewExpression;">
<!ENTITY % CallExpression.content "((%MemberExpression;, Arguments)|(%CallExpression;, (Arguments | %PropertyAccessor;)))">
<!ENTITY % MemberExpression.content "(%MemberExpression;, (%PropertyAccessor; | Arguments))"> <!-- Note that if we have Arguments, we must have an implicit new operator. However, we can't add it to the display using CSS2 styling, so I'm uncertain about the sense in using a single element approach here. -->

This approach solves most problems, but there are the noted problems. Anyone have any ideas?

-- 
David "liorean" Andersson

ViewStyles, ViewScripts, SwitchStyles and GraphicsInfo bookmarklets:
<http://liorean.web-graphics.com/>
Hangouts:
<http://codingforums.com/> <http://yourmusicforums.com/>



More information about the Javascript mailing list