How to model definitions and declarations of a programming language?

Rikard Land

Usenet Archive
Joined
Oct 19, 2004
Messages
2
Reaction score
0
I try to model a data definition language in XML. It can be seen as C without any executable statements other than variable assignments. I want to allow for:
(1) type declarations ("structs" in C), which can be nested, and where each member can be (optionally) associated with a) a comment (as a help to the user who will enter data) and b) a unit such as kg, cm, etc. (2)variable declarations of ordinary types such as float, int, string, etc., as well as the types defined in (1), and (3)assignments of values to variables.

Examples (in C-like syntax) would be:
(1)Type definitions:
struct Point {
float x, comment("X coordinate"), unit(m);
float y, comment("Y coordinate"), unit(m);
}
struct Z {
int a, comment("The amount of...");
float b, comment("The bla bla..."), unit(kg);
Point point, comment("The point ...");
}

(2)Variable declarations:
Point p;
Z z;

(3)Assignments
p.x = 1.1;
p.y = 2.2;
z.a = 1
z.b = 3.3
z.point.x = 4.4
z.point.y = 5.5

I want to keep these in separate files to have a clean separation of these kinds/levels of data. (It must e.g. be possible to declare several instances of the same struct.) There will also be arrays. However, the problem is not to model this in XML syntax (that is straightforward), but my question is rather how to model the interrelationships between the files? At first sight, I thought it was obvious that (1) should be defined as a schema for (3), but there are some challenges that I cannot resolve:
* I want explicit variable declarations, mainly so that several instances of the same type can be defined. This gives by hand the inclusion of (2).
* I want to use the comment and unit in (1) for e.g. helping the user in a GUI. Isn't a schema only a template for an XML file? Or can I put things in the schema (1) that are needed there, but _shall not_ be present in the XML file (3)?
* I want to resolve the names in (2), so that only declarations of types defined in (1) (or basic types, float etc) are valid.
* I also want to make sure the assignments are made correctly, so that e.g. "z.point.x = 4.4" is valid because z is of type Z which contains a member point of type Point, which in its turn contain a float named "x".

I realize that I can do these things programmatically (people have been building compilers for some years now), but I first want to look for solutions utilizing the power of XML. I cannot find anywhere on the net someone who has attempted this – maybe I have used the wrong search terms or it is just a stupid thing to attempt...

Any help in solving any or part of the problems is highly appreciated. Regards, Rikard Land
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top