The original BNF is:
<Sentence> :== <NounPhrase><VerbPhrase>
<NounPhrase> :== <Noun>
<NounPhrase> :== <Article><Noun>
<NounPhrase> :== <Article><AdjectiveList><Noun>
<NounPhrase> :== <AdjectiveList><Noun>
<AdjectiveList> :== <Adjective>
<AdjectiveList> :== <Adjective><AdjectiveList>
<VerbPhrase> :== <Verb>
<VerbPhrase> :== <Verb><Adverb>
<Noun> :== frog | grass | goblin
<Article> :== a | the | that
<Adjective> :== purple | green | tiny
<Verb> :== grows | dreams | eats
<Adverb> :== quickly | slowly | badly
The first attempt at conversion to the dialect of EBNF required is:
Sentence :== (<NounPhrase><VerbPhrase>) +
NounPhrase :== <Noun> + (<Article>< AdjectiveList>)?
AdjectiveList :== <Adjective> *
VerbPhrase :== <Verb> + <Adverb>?
Noun :== (frog | grass | goblin)*
Article :== (a | the | that)*
Adjective :== (purple | green | tiny)*
Verb :== (grows | dreams | eats)*
Adverb :== (quickly | slowly | badly)*
What you've come up with isn't correct:
- You've not dropped the angle brackets.
- In the original, a sentence is a noun phrase followed by a verb phrase; in your rewrite, it is a sequence of one or more 'noun phrase followed by verb phrase'.
- In the original, a noun phrase ends with a noun; in your rewrite, it can be followed by a list of zero or one combinations of an article and an adjective list (but not preceded by either an article or an adjective list).
- In the original, an adjective list is a sequence of one or more adjectives; in your rewrite, is a list of zero or more adjectives.
- In the original, a verb phrase is a single verb, optionally followed by an adverb; in your rewrite, it is one or more verbs followed by zero or more adverbs.
- In the original, each of noun, article, adjective, verb and adverb is exactly one of three alternative values; in your rewrite, each is a list of zero or more or the corresponding three alternative values.
I'm a little confused as to which brackets to drop. I don't know what the difference is between terminal and non terminal and how to differentiate them in the above. Would removing the superscript "+" and parenthesis correct it?
Terminal symbols are things that represent themselves. In this context, the words such as 'frog', 'the', 'green', 'dreams' and 'badly' are terminals.
Non-terminal symbols are defined in terms of other symbols, either other non-terminals or in terms of terminals. Things such as <Sentence>
and <Noun>
are non-terminals.
Angle brackets are the <
and >
symbols (versus round brackets or parentheses ()
, square brackets []
, or curly brackets or braces {}
).
Removing the parentheses and +
(and angle brackets) from Sentence :== (<NounPhrase><VerbPhrase>) +
would improve it. In standard BNF, the :==
symbol is normally ::=
and in standard EBNF is replaced by just =
, and concatenation is indicated explicitly with a comma:
Sentence = Noun Phrase, Verb Phrase
In standard EBNF, terminals are enclosed in double quotes or single quotes (rather than with a font change). And the 'superscript' isn't necessary, either — the ?
, +
and *
simply appear after the unit that repeats. (Note that standard EBNF uses [ … ]
around optional matter and { … }
around repeated (zero or more) items, and { … }-
around repeated (one or more) items).
NounPhrase = Article ? AdjectiveList ? Noun
Noun = "frog" | "grass" | "goblin"