• Post Reply Bookmark Topic Watch Topic
  • New Topic

Context Free Grammar?!  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok lol... this crap is crazyness...

ok we have four "rules":

rule1: S ---> SR
rule2: S ---> R
rule3: R ---> (S)
rule4: R ---> ()


ok so say someone says, I want to know all combinations of paren ('()')
of length 8.

some how you apply these rules recursively to find out the different combinations...

now I understand kinda how to implement this idea on paper, but abstractly in coding, yeah, thats a different story...

could anyone help me out?...

with anything....

here is some code the prof posted on the site...



Ok, where does the N come from?... and in the beginning? what is it initialized to?...

and and same for POS....

and for instance, say you want to find all lengths of size 4.

you alwasy start with "S"

then you apply rule1 then you get "SR" after converting SR to paren,
you'll have "()()" and your done because the length is four..

then you go back to S, and apply rule2: and you get "R".

since you have "R", you then apply rule 3, and you get "(S)".

after converting S to "()", you get (()), and your done..

but then you go back to "R", and apply rule 4 before returning back

to S. I think?

See it's hard to keep track of what happens first, and how to keep track of how it's actually doing it..

can anyone help if they understand what I am talking about..

this is for the class "Survey of Programming Languages"...

Justin
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I can help ya out.

That's master's level c.s. not advanced, nor intemediate nor beginner.

I posed some question far simpler than this to a world-class master by the name of Cesar Rabek - I think they quit laughing months ago when I bought "Compiler Construction: Principals and Practice" by Kenneth C. Louden, San Jose State University - but I eased up on that book and began to write a 60,000 line database program in c/c++, with a shell written in Java - of which I spent the last week getting my first clean compile on the first phase of the shell which can mine on the order of a billion examples per day on an average feed over the open wire.

Seriously, if you do not have the time to read & re-read till you follow the code path, its:



And that's all there is to it.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, dont know if thats really help lol, but thanks anywho
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!