ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I Think it depends on the string you are going to generate. As far as i have know there is no particular formula or method to find the number of different derivations for a string.
If any please let me know.
that is what i was trying to specify with the "Context-free grammar", the final string will be the fronteir of the tree or "aaab" and what i was askin is how many was there are to derive that string... here would be an example of one way
You are asking how many different trees can build the same terminal string in an ambiguous grammar.. The answer is: "depends". Are these the only grammatical rules?
1)S=>AB
2)A=>a
3)A=>aA
4)B=>b
5)B=>AB
In this case I can see only a couple of trees... The one you drew and
S =1> AB =2> aB =5> aAB =3> aaAB =2> aaaB =4> aaab
But maybe I'm missing something..
From what I remember you can't compute all the trees for every string for a generic grammar. You can build a solution for a given grammar and a given string, but you have to work on every single occurrence (in other words, no generic algorithm can compute all the different trees for a string in an ambiguous grammar...). Maybe my memory falls somewhere, you should try an internet search or ask a professor of formal languages...
see this problem is from a book, and it givs you the tree and asks how many ways you can derive the string... i started doing a bunch of them... here is what i started to do...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.