-1

I've trying to convert a given BNF list to EBNF and im completely clueless how. Can anyone help?

The 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

Extended BNF grammar uses the following conventions:

  • A superscript ? after a symbol means it is optional and can appear once or not at all.
  • A superscript + after a symbol means it must appear at least once but can appear more than once.
  • A superscript * after a symbol means it can appear not at all, once, or may times.
  • Paired parentheses can be used to group together symbols for purposes of the: ?, +, * operators.
  • The angle brackets are typically dropped from non-terminal symbols and a different font is used to distinguish terminals from non-terminals.

This is what I've came up with so far, but I'm not sure it's right.

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)*
admdrew
  • 3,790
  • 4
  • 27
  • 39
  • Did you search SO? What information is missing from [How to convert BNF to EBNF](http://stackoverflow.com/questions/14922242/how-to-convert-bnf-to-ebnf)? – Jonathan Leffler Nov 07 '14 at 02:51
  • Sorry I forgot to post the other part, it's fixed now. I've been given those conversion rules to help. – Matt Wallace Nov 07 '14 at 03:05
  • The EBNF conventions described are not EBNF — EBNF is an ISO standard ([ISO 14977:1996](http://www.iso.ch/cate/d26153.html), available for free). You still haven't answered my question, which is "What information is missing from the other question?", with its corrollaries "What don't you understand about your assignment or the BNF in which it is written?" and "What have you tried?". – Jonathan Leffler Nov 07 '14 at 03:13
  • There is nothing missing, I was given those conventions and told to re-write the above grammar into Extended BNF using them. I've posted what I came up with above. – Matt Wallace Nov 07 '14 at 03:28
  • 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'. – Jonathan Leffler Nov 07 '14 at 03:32
  • I'm a little confused as to which brackets to drop. I dot 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? – Matt Wallace Nov 07 '14 at 03:39

1 Answers1

0

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"
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278