-1

I have created a BNF for a certain language and want to check if a certain input is valid for that BNF. For instance, if I have a BNF like

  <palindrome> ::= a <palindrome> a | b <palindrome> b |
               c <palindrome> c | d <palindrome> d | 
               e <palindrome> e | ...
                                | z <palindrome> z
  <palindrome> ::= <letter>
  <letter>     ::= a | b | c | ... | y | z

the string 'bcdcb' and 'hannah' will return true. the string 'joe' will return false.

Can someone describe an algorithm that can do this.

Joe
  • 49
  • 1
  • 9
  • 1
    You need a parser. See http://stackoverflow.com/questions/2245962/is-there-an-alternative-for-flex-bison-that-is-usable-on-8-bit-embedded-systems/2336769#2336769 – Ira Baxter May 28 '15 at 19:34
  • I am not familiar with compiler related programming. I figured that the problem I have was common enough so that someone would have probably written a bnf-checker implementation – Joe May 28 '15 at 20:42
  • There are tools called parser generators. They require you reshape your BNF into a form (pretty similar to what you have) to be processed, and then they they can parse "strings" to see if valid or not. They also usually require a bit of additional programming of one kind or another. If you aren't willing to do that, you're not going to get an answer; nobody is going to build a parser for you. [It is pretty unclear how you can be "unfamiliar" with compiler programming, and yet be capable of "creating a BNF for a language"]. – Ira Baxter May 28 '15 at 21:40

1 Answers1

-1

This algorithm doesn't work with joe because it's checking are first and last letter same, it's searching palindromes words. 'joe' is not palindrome word. So it's ok that it doesn't pass.

DarkTemplar
  • 31
  • 11