Question on EBNF and JSON Notation

I recently studied parsers and grammars and how they work. I read the formal grammar for JSON at http://www.ietf.org/rfc/rfc4627.txt , which uses EBNF. I was very confident in my understanding of BNF and EBNF, but apparently I still do not quite understand. The RFC defines a JSON object as follows:

  object = begin-object [ member *( value-separator member ) ] end-object 

I understand that the goal here is to express that any JSON object can (optionally) have a member, and then follow 0 or more (separator pairs, member). I do not understand why an asterisk appears before (value-separator member) . Shouldn't an asterisk mimic a regular expression so that it appears after repeating paragraph 0 or more times? Should I write the grammar of a JSON object as follows:

  object = begin-object [ member ( value-separator member )* ] end-object 
+4
source share
3 answers

Syntax is how someone wants to write specific objects in order to represent something.

I agree that setting the Klein star before an entity repeats itself is non-standard, and the choice of authors simply confuses people accustomed to the convention. But that is perfectly true; the authors, to determine what the syntax means, and you, the user of the standard, just get it.

There was some argument in favor of the fact that he put the star Klein, where he did; this indicates that there is a list after you can expect the list. The Kleene star in the suffix style indicates the same thing, but it is a kind of surprise; first you read the list item (from left to right), then you will find a star.

As a practical point, the unexpected factor of the post-Clinical star is not enough at all to outweigh the factor of unexpected violation of the convention. But the authors of this standard made their choice.

Welcome to the syntax.

+8
source

The cited document http://www.ietf.org/rfc/rfc4627.txt states that

Grammar rules in this document should be interpreted as described in [RFC4234].

RFC4234 describes ABNF (Extended BNF), not EBNF. If you review this document, you will find the following definition:

 3.6. Variable Repetition: *Rule The operator "*" preceding an element indicates repetition. The full form is: <a>*<b>element where <a> and <b> are optional decimal values, indicating at least <a> and at most <b> occurrences of the element. Default values are 0 and infinity so that *<element> allows any number, including zero; 1*<element> requires at least one; 3*3<element> allows exactly 3 and 1*2<element> allows one or two. 

So the notation

 *( value-separator member ) 

is correct as defined by ABNF and allows any number of repetitions, including zero.

+11
source

The good thing about standards is that there are so many to choose from.

Apparently, Niklas Wirth wondered what you had thirty-several years ago :

The population of programming languages โ€‹โ€‹is growing steadily, and there is no end to this growth in sight. Many language definitions appear in journals, many of them are in technical reports, and perhaps even more remain limited to their own circles. After the frequent impact of these definitions, one cannot help but notice the absence of โ€œcommon denominatorsโ€. The only widely accepted fact is that the language structure is defined by syntax. But even the designation for the syntactic description eludes any agreed standard form, although the main ancestor is always the Backsu-Naur Report Form "Algol 60". In the form of variations, they are often insignificant; they become annoying due to their apparent motivation.

Yes, the notation used in RFC-4627 is less common, but not incomprehensible.

+1
source

All Articles