Context Sensitive Grammar (Automata theory)

  • Thread starter Thread starter Dafydd
  • Start date Start date
  • Tags Tags
    Theory
AI Thread Summary
Context Sensitive Grammar (CSG) allows for multiple valid substitutions, leading to confusion about the order and choice of these substitutions. In the example provided, the transformation of S to abNSc or an empty string depends on the desired outcome, and substitutions can be chosen freely as long as they adhere to the production rules. The arbitrary nature of substitutions can create the impression of randomness, but understanding the target string helps guide the process. The discussion highlights the flexibility in applying rules while constructing strings in CSG. Ultimately, the key is recognizing that while substitutions can be chosen freely, they must lead to the intended result.
Dafydd
Messages
11
Reaction score
0
Sorry if this is the wrong forum.

I'm trying to get my head around Context Sensitive Grammar. In my coursebook, there's an example ('e' here is the empty string, epsilon, and 'E' is the "set member" symbol):

The language {an bn cn | n E N} is described by the following rules:

S -> e | abNSc
bNa -> abN
bNb -> bbN
bNc -> bc

And then it shows how to build aabbcc:

S -> abNSc
-> abNabNScc
-> abNabNcc
-> aabNbcc
-> aabbNcc
-> aabbcc

The part I don't understand is why S becomes abNSc after the first substitution, while the second time it becomes an empty string. The rules state both substitutions are possible, but not when to use which one. Can this be choosen freely?

Another language (with 4 non-deterministic symbols S, D, [, ]) describes {1, 1^2, 1^4, 1^8, ...}. Its rules:

S -> [1]
[ -> [D
D1 -> 11D
D] -> ]
[ -> e
] -> e

Example, building the string 11111111:

S -> [1] -> [D1] ->* [DDD1]
-> [DD1D]
-> [D11D1D]
-> [D1111DD]
-> [11D111DD]
-> [1111D11DD]
-> [111111D1DD]
-> [11111111DDD]
-> [11111111DD]
-> [11111111D]
-> [11111111]
-> [11111111
-> 11111111

Again, the number of times a substitution is carried out seems to be random, or at least arbitrary. Why do you not just keep doing the substitution from [ to [D indefinitely? Because you know how many times it needs to be done in order to get the resulting string you want? Can you choose to do the substitutions in any order you want (as long as it gets you the result you want), or is there a pattern to follow?

Thanks for any help.
 
Technology news on Phys.org
The language defined by a grammar consists of every string that you can produce by applying the production rules.
Can you choose to do the substitutions in any order you want
So yeah.
 
That's all I needed to hear. Thank you!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
15
Views
5K
Replies
7
Views
3K
Replies
7
Views
10K
Replies
3
Views
2K
Replies
2
Views
4K
Replies
5
Views
4K
Replies
7
Views
3K
Back
Top