formal-languages

How to determine if a context-free grammar describes a regular language?

旧时模样 提交于 2021-02-19 07:56:05
问题 Given an arbitrary context-free grammar, how can I check whether it describes a regular language? I'm not looking for exam "tricks". I'm looking for a foolproof mechanical test that I can code. If it helps, here's an example of a CFG that I might receive as an input. Specifically, notice that the answer must be much more complicated than just looking for left- or right-recursion, since the presence of another type of recursion does not automatically imply the grammar is irregular. S: A B C D

Is L = {a^n b^m | n>m} a regular or irregular language?

梦想与她 提交于 2020-02-10 09:30:20
问题 I have troubles in solving/proving this problem. Any ideas please? 回答1: L = {a n b m | n > m} is not regular language. Yes, the problem is tricky at first few try and deserve vote-up. Pumping Lemma a necessary property of regular language is tool for formal proof that language is not regular language. Formal definition: Pumping lemma for regular languages Let L be a regular language. Then there exists an integer p ≥ 1 depending only on L such that every string w in L of length at least p ( p

Is L = {a^n b^m | n>m} a regular or irregular language?

泪湿孤枕 提交于 2020-02-10 09:29:48
问题 I have troubles in solving/proving this problem. Any ideas please? 回答1: L = {a n b m | n > m} is not regular language. Yes, the problem is tricky at first few try and deserve vote-up. Pumping Lemma a necessary property of regular language is tool for formal proof that language is not regular language. Formal definition: Pumping lemma for regular languages Let L be a regular language. Then there exists an integer p ≥ 1 depending only on L such that every string w in L of length at least p ( p

Shift-reduce: when to stop reducing?

微笑、不失礼 提交于 2020-01-23 07:43:51
问题 I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using recursive rules that enforce order of operations, inspired by the ANSI C Yacc grammar: S: A; P : NUMBER | '(' S ')' ; M : P | M '*' P | M '/' P ; A : M | A '+' M | A '-' M ; And we want to parse 1+2 using shift-reduce parsing. First, the 1 is shifted as a NUMBER. My question is, is it then reduced to P, then M, then A, then finally S? How does it know where to stop? Suppose it does reduce all the way

Finiteness of Regular Language

和自甴很熟 提交于 2019-12-28 06:27:42
问题 We all know that (a + b)* is a regular language for containing only symbols a and b . But (a + b)* is a string of infinite length and it is regular as we can build a finite automata, so it should be finite. Can anyone please explain this? 回答1: Finite automaton can be constructed for any regular language, and regular language can be a finite or an infinite set. Of-course there are infinite sets those are not regular sets. Check the Venn diagram below: Notes : 1. every finite set is a regular

How do I figure out the language generated by this context-free grammar?

时光怂恿深爱的人放手 提交于 2019-12-25 12:26:14
问题 I am dealing with the following grammar: G = ( {S, A}, {a, b}, P, S ) P = { S -> aAb, S -> bAa, A -> aSa, A -> S, A -> epsilon} I need to find out L(G). The thing is, I figured out that the words in the grammar are of the form: starts with a and ends with b, or starts with b and ends with a, and between these letters one of the combinations : ab, ba, aaba, abaa; then the next word is formed by inserting one of these 4 combinations between the a and b in the middle..but how can I express this

Conversion to Chomsky Normal Form

我的未来我决定 提交于 2019-12-23 18:34:09
问题 I do need your help. I have these productions: 1) A--> aAb 2) A--> bAa 3) A--> ε I should apply the Chomsky Normal Form (CNF). In order to apply the above rule I should: eliminate ε producions eliminate unitary productions remove useless symbols Immediately I get stuck. The reason is that A is a nullable symbol (ε is part of its body) Of course I can't remove the A symbol. Can anyone help me to get the final solution? 回答1: As the Wikipedia notes, there are two definitions of Chomsky Normal

Why is the complement of a regular language still a regular language?

橙三吉。 提交于 2019-12-23 12:45:17
问题 According to my textbook, the complement of L1 = A* - L1 is a regular language as long as L1 is a regular language. Doesn't A* also include Context Free languages, Context Sensitive languages, and Recursively Enumerable languages? A*-L1 would include all of them too, wouldn't it? How can it be regular then? Under the representation of a Finite State Machine I understand why the complement is still a regular language. However, I can't understand the theory behind it. Also, A* - L1 = A*

Scope of XML languages defined by DTD vs XSD

会有一股神秘感。 提交于 2019-12-21 17:54:41
问题 Does the following propositions hold: For every DTD there is an XSD that defines exactly the same language, and for every XSD there is a DTD that defines exactly the same language. Or put another way: The collection of languages defined by any DTD is exactly the the collection of languages defined by any XSD? Expanding on the question a little: An XML document is basically a large string. A language is a collection of strings. For example, the (infinite) set of all MathML documents is a

Why can't I specify the storage class for formal parameters of a function?

冷暖自知 提交于 2019-12-21 04:37:10
问题 When I do as below the code works fine : #include <stdio.h> void test( int a) { printf("a=%d\n",a); } int main() { test(10); return 1; } But when I do #include <stdio.h> void test( auto int a) // Or static int a Or extern int a { printf("a=%d\n",a); } int main() { test(10); return 1; } It generates an error, error: storage class specified for parameter 'a' Why is that error? What happens internally(memory management)? But it works fine without any error when I do: void test( register int a) {