2 years ago

#44516

test-img

xpt

How can EBNF or BNF be parsed?

Following up on Converting W3C's EBNF to BNF

With a grammar defined as enclosed below, how can it know when a grammar rule is ended?

E.g., line 3 & 4,

Production*
Production

How can the grammar tell that the second Production is not part of Item, which can be repeated as Item Item ..., according to the rule of "(Item ( '-' Item | Item* ))?"

Most languages solve such problems with an ending symbol like ";". Is the following grammar defined precisely enough so that such an ending symbol is not necessary?

Grammar
 ::= 
Production*
Production
 ::= 

NCName '::=' Choice
NCName
 ::= 
[http://www.w3.org/TR/xml-names/#NT-NCName]

Choice
 ::= 
SequenceOrDifference ( '|' SequenceOrDifference )*

SequenceOrDifference
 ::= 
(Item ( '-' Item | Item* ))?

Item
 ::= 
Primary ( '?' | '*' | '+' )*

Primary
 ::= 
NCName | StringLiteral | CharCode | CharClass | '(' Choice ')'
StringLiteral
 ::= 
'"' [^"]* '"' | "'" [^']* "'"
/* ws: explicit */
CharCode
 ::= 
'#x' [0-9a-fA-F]+
/* ws: explicit */
CharClass
 ::= 
'[' '^'? ( Char | CharCode | CharRange | CharCodeRange )+ ']'
/* ws: explicit */
Char
 ::= 
[http://www.w3.org/TR/xml#NT-Char]
CharRange
 ::= 
Char '-' ( Char - ']' )
/* ws: explicit */
CharCodeRange
 ::= 
CharCode '-' CharCode
/* ws: explicit */
Link
 ::= 
'[' URL ']'
URL
 ::= 
[^#x5D:/?#]+ '://' [^#x5D#]+ ('#' NCName)?
/* ws: explicit */
Whitespace
 ::= 
S | Comment
S
 ::= 
#x9 | #xA | #xD | #x20
Comment
 ::= 
'/*' ( [^*] | '*'+ [^*/] )* '*'* '*/'
/* ws: explicit */

recursion

bnf

ebnf

0 Answers

Your Answer

Accepted video resources