Questions tagged [context-sensitive-grammar]

A context-sensitive grammar is a type of grammar that generates precisely the context-sensitive languages.

Context-sensitive grammars are grammars where each rule has the form

xAy -> xwy

Where A is a nonterminal and x, y, and z are strings of terminals and nonterminals.

56 questions
1
vote
2 answers

How to separate out the context-free part of a language from the context-sensitive part?

I read this fantastic post on the comp.theory list: http://coding.derkeiler.com/Archive/General/comp.theory/2004-03/0189.html The poster makes the point that most programming languages define a context-free core, and then have additional algorithms…
1
vote
1 answer

What is this grammar? Context-free or context sensitive

I am studying Formal Languages and Automata Theory, and I have a question about a problem inside the book that is not answered in it. the question is: Is this language Context Free, Regular or Context Sensitive? L= {anw wRbn| w is ( a+b )*, wR…
1
vote
2 answers

Examples of Non Context free language in C language?

What are examples of non - context free languages in C language ? How the following non-CFL exists in C language ? a) L1 = {wcw|w is {a,b}*} b) L2 = {a^n b^m c^n d^m| n,m >=1}
1
vote
1 answer

Converting a language specification into production rules (not sure if it's a CFG or CSG)

I have to write a function that checks whether input strings are valid for a given language specification. I thought that this would be a standard CFG -> Chomsky Normal Form, then CYK parsing, but one of the rules in the language is preventing this…
0
votes
0 answers

Recognize the type of the given formal language

Yesterday i did my exam of formal languages and there was a question which asked you to recognize what type of language was this: X={a,b,c} L={w€X*|#(a,w) + #(c,w) = 3n, n>=0} where #(x,w) is the number of occurency of the symbol x€X in the word…
0
votes
1 answer

Recursive grammar with increasing integers

I want to write the grammar for a list containing sequentially increasing integers like this 1 X 1 X 2 X 1 X 2 X 3 X 1 X 2 X 3 X 4 X // and so on I want to use a recursive definition to avoid defining separate rules for each case manually. Without…
mdcq
  • 1,593
  • 13
  • 30
0
votes
2 answers

Does context-sensitive tokenisation require multiple goal symbols in the lexical grammar?

According to the ECMAScript spec: There are several situations where the identification of lexical input elements is sensitive to the syntactic grammar context that is consuming the input elements. This requires multiple goal symbols for the…
0
votes
1 answer

What does context mean by context-free and context-sensitive grammars?

If I have something like var string = "var";, then after the first double quote the rules change, and the var does not mean the same thing as it means at the beginning of the text. After the second double quote things turn back to normal. How is…
inf3rno
  • 24,976
  • 11
  • 115
  • 197
0
votes
1 answer

How to match with a expression grammar only the last time a keyword occurs occurs

I want to write a expression grammar which matches strings likes these: words at the start ONE|ANOTHER wordAtTheEnd ---------^-------- ----^----- --^-- A: alphas B: choice C: alphas The issue is however that part A can contain the…
0
votes
2 answers

design a context sensitive grammar for string of a's whose length is a power of 2 ( 2^i) form ? i>=1

Please explain how to design the context sensitive grammar of the above language. I am new to context sensitive grammar.
Olivia Pearls
  • 139
  • 1
  • 11
0
votes
1 answer

Is this grammar context free or not?

G: S ---> aSb S ---> λ As tought me the first production rule is context-free (because the left side is less than right side) but for second production rule, it isn't (because the left side length equals the right side). Well, what can we…
0
votes
1 answer

How do I convert PEG parser into ambiguous one?

As far as I understand, most languages are context-free with some exceptions. For instance, a * b may stand for type * pointer_declaration or multiplication in C++. Which one takes place depends on the context, the meaning of the first identifier.…
0
votes
2 answers

What is the magic behind WS in ANTLR?

I'm trying to make a tool like ANTLR from scratch in Swift (just for fun). But I don't understand how grammar knows that there should be no whitespaces (identifier example: "_myIdentifier123"): Identifier : Identifier_head…
artyom.razinov
  • 610
  • 3
  • 17
0
votes
1 answer

Semantics-directed parser combinators

I tried this import scala.util.parsing.combinator._ def name = ident ^^ {case ident => if (ident.contains("a")) ident.toUpperCase else ident println(parseAll(name, "aa")) // parsed: AA println(parseAll(name, "bb")) with output [1.3] parsed:…
0
votes
1 answer

Examples of practical context sensitive programming structures

So, I am implementing a context sensitive syntactical analyzator. It's kind of experimantal thing and one of the things I need are usable and practical syntactical contructs to test it on. For example the following example isn't possible to parse…