Context Free Grammar

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
I have a problem where I can only figure it out by using CFG rules like so:

ij => iijjj
ij => iijjk
etc

Are you allowed to have two nonterminals on the LHS? For this particular problem, I don't see how to keep multiples sets of things in order.
 
Oct 27, 2007
17,009
5
0
I don't understand the question. Which are terminal/non-terminal? In my classes we used capital letters for non-terminals and small letters for terminals, eg.
As -> sAss

Edit - I didn't mean that to be a joke, I didn't even think about using A and s :p
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
Originally posted by: GodlessAstronomer
I don't understand the question. Which are terminal/non-terminal? In my classes we used capital letters for non-terminals and small letters for terminals, eg.
As -> sAss

Oops,

they are both non-terminals, so it should be :

IJ => IIJJJ
IK => IIJJK
 
Oct 27, 2007
17,009
5
0
Originally posted by: txrandom
Originally posted by: GodlessAstronomer
I don't understand the question. Which are terminal/non-terminal? In my classes we used capital letters for non-terminals and small letters for terminals, eg.
As -> sAss

Oops,

they are both non-terminals, so it should be :

IJ => IIJJJ
IK => IIJJK

In that case the answer seems to be ambiguous, I'm not sure how you'd answer the question. If you wanted to simplify the rule set you could have ambiguous results, like
I -> IIJ
J -> JJ

or

I -> II
J -> JJJ

It's been a few months since I've done these things, maybe my thinking is all wrong, but I don't think the problem is solvable unambiguously. Have you posted all of the CFG rules?

Edit - to answer the question in the OP, I believe you are allowed to have multiple non-terminals on the LHS as long as the rule set can be simplified such that each rule has a single non-terminal on the LHS.
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
Originally posted by: GodlessAstronomer
Originally posted by: txrandom
Originally posted by: GodlessAstronomer
I don't understand the question. Which are terminal/non-terminal? In my classes we used capital letters for non-terminals and small letters for terminals, eg.
As -> sAss

Oops,

they are both non-terminals, so it should be :

IJ => IIJJJ
IK => IIJJK

In that case the answer seems to be ambiguous, I'm not sure how you'd answer the question. If you wanted to simplify the rule set you could have ambiguous results, like
I -> IIJ
J -> JJ

or

I -> II
J -> JJJ

It's been a few months since I've done these things, maybe my thinking is all wrong, but I don't think the problem is solvable unambiguously. Have you posted all of the CFG rules?

Edit - to answer the question in the OP, I believe you are allowed to have multiple non-terminals on the LHS as long as the rule set can be simplified such that each rule has a single non-terminal on the LHS.

S -> IJK | e
I -> ab
J -> a
K-> b
IJ -> IIJJJ
IK -> IIJJK
JK -> KK | JJ

I'm trying to model the language (ab)^i a^j b^k where 2i = j + k. I'm mainly having trouble with figure out how to make sure the a^j and b^k stay in order (a's followed by b's).
 

AstroManLuca

Lifer
Jun 24, 2004
15,628
5
81
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

Formal Language
CFG
 

AstroManLuca

Lifer
Jun 24, 2004
15,628
5
81
Originally posted by: txrandom
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

Formal Language
CFG

Well maybe this should be in programming or something then.
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
Originally posted by: AstroManLuca
Originally posted by: txrandom
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

Formal Language
CFG

Well maybe this should be in programming or something then.

Nah, only a few programmers even touch this stuff. This stuff was around long before computers and programming.
 

newnameman

Platinum Member
Nov 20, 2002
2,219
0
0
Originally posted by: txrandom
Originally posted by: GodlessAstronomer
Originally posted by: txrandom
Originally posted by: GodlessAstronomer
I don't understand the question. Which are terminal/non-terminal? In my classes we used capital letters for non-terminals and small letters for terminals, eg.
As -> sAss

Oops,

they are both non-terminals, so it should be :

IJ => IIJJJ
IK => IIJJK

In that case the answer seems to be ambiguous, I'm not sure how you'd answer the question. If you wanted to simplify the rule set you could have ambiguous results, like
I -> IIJ
J -> JJ

or

I -> II
J -> JJJ

It's been a few months since I've done these things, maybe my thinking is all wrong, but I don't think the problem is solvable unambiguously. Have you posted all of the CFG rules?

Edit - to answer the question in the OP, I believe you are allowed to have multiple non-terminals on the LHS as long as the rule set can be simplified such that each rule has a single non-terminal on the LHS.

S -> IJK | e
I -> ab
J -> a
K-> b
IJ -> IIJJJ
IK -> IIJJK
JK -> KK | JJ

I'm trying to model the language (ab)^i a^j b^k where 2i = j + k. I'm mainly having trouble with figure out how to make sure the a^j and b^k stay in order (a's followed by b's).

I don't think I've ever seen a CFG with more than one non-terminal on the LHS, but you shouldn't need to do that anyways. I think something like this should work:

S -> S'b | R | e
S' -> abSb | R' e
R -> R'a | e
R' -> abRa | e
 
Oct 27, 2007
17,009
5
0
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

:laugh: It's not really programming, it's esoteric computer science stuff. It's the kind of thing you learn, pass an exam then never touch again in most cases. I'm glad I passed that exam and never have to deal with them.
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
Thanks for the insight newnameman. I think that's the right direction. I got to take a break and then work on it again.
 

seemingly random

Diamond Member
Oct 10, 2007
5,277
0
0
Originally posted by: GodlessAstronomer
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

:laugh: It's not really programming, it's esoteric computer science stuff. It's the kind of thing you learn, pass an exam then never touch again in most cases. I'm glad I passed that exam and never have to deal with them.
I think the concepts are used in yacc...

Before he got interested in conspiracies, noam chomsky cared about this in his work in linguistics.
 

fulltilt39

Golden Member
Aug 6, 2009
1,323
0
0
Originally posted by: GodlessAstronomer
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

:laugh: It's not really programming, it's esoteric computer science stuff. It's the kind of thing you learn, pass an exam then never touch again in most cases. I'm glad I passed that exam and never have to deal with them.

oohhhh...like calculus!! i get it.
 
Oct 27, 2007
17,009
5
0
Originally posted by: fulltilt39
Originally posted by: GodlessAstronomer
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

:laugh: It's not really programming, it's esoteric computer science stuff. It's the kind of thing you learn, pass an exam then never touch again in most cases. I'm glad I passed that exam and never have to deal with them.

oohhhh...like calculus!! i get it.

Don't make Dr Pizza come in here and tell you about how calculus saved his roast beef.
 

Mojoed

Diamond Member
Jul 20, 2004
4,473
1
81
Originally posted by: AstroManLuca
Seriously, what the fuck are you guys talking about? Is this some sort of programming thing that I will never in a million years understand? Is this entire thread some joke that I'm not getting?

^ This, or SpaceMan hackz0r'd the OP's account.