Re: XML Grammar kind
David Lacerte wrote: > Hi! I was wondering at what category of grammar the xml's belongs. Does it have the properties of a LALR(1) grammar, which is the most probable? I need that information in order to do a parser. Thanks!! If you look closely at the XML grammar productions in the recommendation, you will see that in most cases only one 'token' of look-ahead is required. There are some exceptions, but they are quite easily re-grouped to satisfy LARL(1) Exceptions known to me:-  element ::= EmptyElemTag | Stag content ETag  STag ::= '<' Name (S Attribute)* S? '>'  ETag ::= '</' Name S? '>'  EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' When parsing element, you will not know if you are parsing an EmptyElemTag or a STag until the parser comes across a '>' or '/>'. In this case the production can be re-written in LALR(1) as: element ::= '<' Name (S Attribute)* S? ('/>' | ('>' content ETag))  NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'  ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral  PublicID ::= 'PUBLIC' S PubidLiteral Here, the parser would not know if it was parsing an ExternalID or a PublicID until it found a SystemLiteral or '>'. This could be re-written as LALR(1) : NotationDecl ::= '<!NOTATION' S Name S NotationID S? '>' NotationID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral (S SystemLiteral)? However, if you are considering using standard parsing tools, I think some of the biggest problems you will have are:- 1) Determining what is a token. The XML productions go too close to the metal to be considered tokens in the normal sense 2) Entity replacement - especially parameter entities 3) Conditional Sections Regards Rob Lugt ElCel Technology
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format