English 中文(简体)
EBNF to BNF Conversion [duplicate]
原标题:
  • 时间:2010-01-25 01:44:16
  •  标签:
  • bnf
  • ebnf

I have a homework problem which I could use some help on. I need to convert the following EBNF statement to BNF

<S> -> <A>{b<A>}
<A> -> a[b]<A>

This is what I have come up with so far;

<S> -> <A> | <A><S> | b<A>
<A> -> a<A> | ab<A>

It doesn t feel right, mainly because it s a WAG. The example in my book (Concepts of Programming Languages, Sebesta) is not helping me at all. So if anyone has any insight, it would be greatly appreciated. Thanks!

问题回答

The first grammar seems buggy, or at least needlessly messy. But take a look here for a mechanical way to convert EBNF to BNF:

http://lampwww.epfl.ch/teaching/archive/compilation-ssc/2000/part4/parsing/node3.html

Your conversion of the <S> is not completely correct:

<S> -> <A> | <A><S> | b<A>

Because it is possible to recursively choose <A> without having b which is not defined by the original EBNF rule (You can only recursive <A> with b preceding it).

Solutions could be:

(* S is a sequence of A optionally followed by a sequence of b and S together. *)

<S> -> <A>
       | <A> b <S>;

(* A is composed of a , followed by an optional b , followed by another A. *)

<A> -> a <A>
       | a b <A>;

This is why I like EBNF instead. It is much easier to understand and write! :-)

Ultimately you ask yourself what is required. Write it down. Now consider the optional components and use various combinations of them with the required components (in the right order of course). Then reduce what you can (be careful not to make a mistake).





相关问题
EBNF to BNF Conversion [duplicate]

I have a homework problem which I could use some help on. I need to convert the following EBNF statement to BNF <S> -> <A>{b<A>} <A> -> a[b]<A> This is what I ...

Any BNF IDE with test features

I m working on a new language and while writting the grammar I d like to be able to test the grammar for completeness, conflicts and similar. I m not really concern about the underlaying parser ...

Grammar Syntax and Linguistics

I REALLY need a description of the english sentence structure in a way that can be translated by machine and is strictly rule based(no statistical stuff), it doesn t have to be a context-free grammar ...

Is there a BNF mode for Emacs?

I have to edit lots of grammar files in .bnf format. Is there a mode for this in Emacs? I ve looked at CEDET s semantic package, and it seems that it USED to have a bnf-mode, but not any more. This ...

Scala Parser Token Delimiter Problem

I m trying to define a grammar for the commands below. object ParserWorkshop { def main(args: Array[String]) = { ChoiceParser("todo link todo to database") ChoiceParser("todo link ...

EBNF for ECMAScript?

I m trying to find a good EBNF description of ECMAScript, but so far I ve not found anything complete. Any ideas?

Grammars, Scala Parsing Combinators and Orderless Sets

I m writing an application that will take in various "command" strings. I ve been looking at the Scala combinator library to tokenize the commands. I find in a lot of cases I want to say: "These ...

Deriving a state machine from a BNF grammar

I am trying to put together a proof of concept of an XSS-safe string interpolation scheme. Given a string with substitutions, "Hello <b>$planetoid</b>!" I want break it into literal ...

热门标签