Tuesday, 15 June 2010

Permutations with Context Free Grammar -


I am currently writing a grammar which requires identification of ARC, ACB, BAC, BCA etc. "Abc".

Am I forgetting something now, or I have to write all the possible combinations such as: S -> ABC. ACB | ... to get full coverage.

In fact, you must recognize each possible sequence independently with a short cut with standard BNF signaling Not with regular expressions, you can create factors to reduce the length of regular expressions, but this will not help you. (For example, if you wanted all the combinations of a , b , c and d , you would (now | BA) (CD | DC) instead of abcd | abdc | abdc | bacd | badc , but this will not help too much.

For three or four elements which is not very bad, but do not scale it. The general solution is to allow any sequence of elements, and finally, or after going to check the duplicate, its ability Are using the Parser Generator on the basis.


No comments:

Post a Comment