context-free-grammar

Pumping Lemma in context-free languages

这一生的挚爱 提交于 2019-12-11 05:27:08
问题 A = {0^a 1^b 2^c | a < b < c} I need to show that A is not context-free. I'm guessing I have to use the Pumping Lemma for this, but how? 回答1: The goal is to prove that for any string with length >= a minimum pumping length, the string cannot be pumped. That is, if you split it into substrings uvxyz , the string that results from making copies (or removing copies) of v and y are still in language A . Note that you only have to show that one string in the language cannot be pumped (as long as

Eliminating Epsilon Production for Left Recursion Elimination

橙三吉。 提交于 2019-12-11 05:15:33
问题 Im following the algorithm for left recursion elimination from a grammar.It says remove the epsilon production if there is any I have the following grammer S-->Aa/b A-->Ac/Sd/∈ I can see after removing the epsilon productions the grammer becomes 1) S-->Aa/a/b 2)A-->Ac/Sd/c/d Im confused where the a/b comes in 1) and c/d comes in 2) Can someone explain this? 回答1: lets look at the rule S->Aa , if A->∈ then S->∈a giving just S->a , so together with the previous rules we get S->Aa|a|b now lets

How can I generate all possible strings given a grammar rule?

旧时模样 提交于 2019-12-11 04:29:59
问题 I would like to, given a JSGF grammar, generate all the terminal strings it would map to. For example, given A (B | C) D [E] , my desired output would be: A B D E A C D E A B D A C D I decided to start with the easiest item, the optional brackets, but soon ran into a brick wall. It sort of works for 1 item, but not for an item with alternatives. Any advice would be appreciated. What I have now: import re rule = raw_input('Enter the rule you want to test: ') items = re.findall(r"\w[\w ]*\w|\w|

Left Recursive Rules in Context Free Grammar

試著忘記壹切 提交于 2019-12-11 04:02:54
问题 So everything I have been reading says that left recursive rules in a CFG traverses infinitely and proceeds to show a process of converting it to right recursive rule and accomplishes this using using alpha and beta terms to represent multiple non-terminals (I think I got that part right). So in my mind left recursive rules=bad when dealing with LL parsers. So is there a situation that left recursive rules are acceptable/desirable? If not, why do left recursive rules exist asside from bad

what is an ambiguous context free grammar?

大憨熊 提交于 2019-12-10 20:53:36
问题 I'm not really very clear on the concept of ambiguity in context free grammars. If anybody could help me out and explain the concept or provide a good resource I'd greatly appreciate it. 回答1: T * U; Is that a pointer declaration or a multiplication? You can't tell until you know what T and U actually are . So the syntax of the expression depends on the semantics (meaning) of the expression. That's not context-free -- in a context-free language, that could only be one thing, not two. (This is

Handling prolog context free grammar

我的梦境 提交于 2019-12-10 19:33:25
问题 Given a CFG S --> a S b | c | d I wanna write a predicate like, grammar('S', sentence) which generates all possible sentences like sentence=acb, sentence=acd, sentence=c, sentence=ab...................... Using left most derivation , if the encountered symbol is terminal it should print out that terminal, and if the encountered symbol is non terminal 'S' , it should backtrack and substitute and one of the grammar a S b or c or d and repeat the process. I dont want any code...just help me with

Where can I find an official grammar for the PL/SQL programming language?

扶醉桌前 提交于 2019-12-10 18:45:10
问题 Where can I find an official grammar for the PL/SQL programming language? I see that the Antlr project has a user-contributed grammar, but I was hoping to find a more authoritative source. 回答1: You mean the documentation? It'd help to know what version of Oracle -- this link covers 9i (v9.2 technically). 回答2: The official grammar for the PL/SQL can be found at the Chapter 13 of the PL/SQL Language Reference. 回答3: Also, you can take a look at a community PL/SQL ANTLR grammar in ANTLR grammars

Checking if a string is contained in a language (Prolog)

耗尽温柔 提交于 2019-12-10 16:52:58
问题 This is the CFG: S -> T | V T -> UU U -> aUb | ab V -> aVb | aWb W -> bWa | ba so this will accept some form of: {a^n b^n a^m b^m | n,m >= 1} U {a^n b^m a^m b^n | n,m >= 1} And here is the code I'm working with: in_lang([]). in_lang(L) :- mapS(L), !. mapS(L) :- mapT(L) ; mapV(L),!. mapT(L) :- append(L1, mapU(L), L), mapU(L1), !. mapU([a|T]) :- ((append(L1,[b],T), mapU(L1)) ; (T = b)),!. mapV([a|T]) :- ((append(L1,[b],T), mapV(L1)) ; (append(L1,[b],T), mapW(L1))), !. mapW([b|T]) :- ((append(L1

LR(1) - Items, Look Ahead

女生的网名这么多〃 提交于 2019-12-10 13:39:08
问题 I am having difficulties understanding the principle of lookahead in LR(1) - items. How do I compute the lookahead sets? Say for an example that I have the following grammar: S -> AB A -> aAb | b B -> d Then the first state will look like this: S -> .AB , {look ahead} A -> .aAb, {look ahead} A -> .b, {look ahead} I know what look aheads are, but I don't know how to compute them. I have googled for answers but couldn't find a webpage which explains this in a simple manner. Thanks in advance

Construct Context free Grammar

大兔子大兔子 提交于 2019-12-10 10:51:23
问题 How can I construct a context free grammar for the following language: L = {a^l b^m c^n d^p | l+n==m+p; l,m,n,p >=1} I started by attempting: S -> abcd | aAbBcd | abcCdD | aAbcdD | AabBcCd and then A = something else... but I couldn't get this working. . I was wondering how can we remember how many c's shud be increased for the no. of b's increased? For example: string : abbccd 回答1: The grammar is : S1 -> a S1 d | S2 S2 -> S3 S4 S3 -> a S3 b | epsilon S4 -> S5 S6 S5 -> b S5 c | epsilon S6 ->