473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Converting Simple BNF grammar to DTD or schema

I have a requirement to have an XML document
that consists of an arbitrarily large expression.
For simplicity's sake, assume I have the following grammar:

expr => term rest
term => ID relop ID
rest => (conjunction term) | e
conjunction => AND|OR
relop => EQ|NE|GT|GE|LT|LE

Is it possible to convert this grammar to a DTD or schema?
I've tried the following DTD without success:
<!ELEMENT expr (term,rest)>
<!ELEMENT term (id,relop,id)>
<!ELEMENT rest ((conjunction,term)|EMPTY)>
<!ELEMENT conjunction (EMPTY)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT relop (EMPTY)>
<!ATTLIST conjunction type (AND|OR)>
<!ATTLIST relop type (EQ|NE|GT|GE|LT|LE)>

Any pointers appreciated.
Thanks in advance.
Jul 20 '05 #1
1 3467
In article <76**************************@posting.google.com >,
Chris <cr******@capu.net> wrote:

% I have a requirement to have an XML document
% that consists of an arbitrarily large expression.

You might want to sketch out what you want your XML to look like
before you write the DTD.

% expr => term rest
% term => ID relop ID
% rest => (conjunction term) | e

You probably want to use Kleene closure for this kind of production
what you've written will require

<expr><term><id>i</id><relop type='EQ'/><id>7</id></term><rest/></expr>

to represent

i = 7

To represent

i = 7 and j < 4

you'd need

<expr><term><id>i</id><relop type='EQ'/><id>7</id></term>
<rest><conjunction conjunction type='AND'/>
<term><id>i</id><relop type='EQ'/><id>7</id></term></rest>
</expr>

While what you probably want is this, without a `rest' element.

<expr><term><id>i</id><relop type='EQ'/><id>7</id></term>
<conjunction conjunction type='AND'/>
<term><id>i</id><relop type='EQ'/><id>7</id></term>
</expr>
You can get that by changing the definition of expr

<!ELEMENT expr (term,(conjunction,term)*>

and removing the definition of rest.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bud Curtis | last post by:
For some reason on my system I can't get the following elementry web.xml to validate. It looks like JonAS will only process an XML if it is valid. For some reason a very similar web.xml on JBoss...
0
by: yosuke | last post by:
Does anyone know that where can I find XML Schema Grammar? I am interested in this area but i can not get much information about the grammar. I would like to design the parser by using the...
10
by: Michael Wein | last post by:
Hello, does anyone know of a way/solution how to convert XML Schema documents into DTD? I am aware of the fact that such a conversion won't be possible under certain circumstances and that...
2
by: Peter Rilling | last post by:
I am written a program that will be used to parse the lexical syntax of code files. I would like to generalize the grammar logic so that I don't hardcode any specific grammar in my program. ...
1
by: UKuser | last post by:
Hi Guys, I have a program which converts Excel spreadsheets to Javascript and allows interactivity. However it can't convert it to PHP, which is obviously better for users to view (in case J/S...
2
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 .........
107
by: bmshivaraj | last post by:
Hi, Could any one tell me how to convert a unsigned long value into string (char *) ? In C++ there is a function _ultoa so wanted a similar one in C . Regards, Shivaraj
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
2
by: sweetpotatop | last post by:
Hi, I am wondering if there is way to convert a xls (with column headers) or a plain text file to an xml file without knowing anything about xsd. I know in Excel you can actually convert the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.