context-free-grammar

NLTK Context Free Grammar Genaration

﹥>﹥吖頭↗ 提交于 2020-01-01 02:44:16
问题 I'm working on a non-English parser with Unicode characters. For that, I decided to use NLTK. But it requires a predefined context-free grammar as below: S -> NP VP VP -> V NP | V NP PP PP -> P NP V -> "saw" | "ate" | "walked" NP -> "John" | "Mary" | "Bob" | Det N | Det N PP Det -> "a" | "an" | "the" | "my" N -> "man" | "dog" | "cat" | "telescope" | "park" P -> "in" | "on" | "by" | "with" In my app, I am supposed to minimize hard coding with the use of a rule-based grammar. For example, I can

Step by step elimination of this indirect left recursion

♀尐吖头ヾ 提交于 2019-12-31 13:15:02
问题 I've seen this algorithm one should be able to use to remove all left recursion. Yet I'm running into problems with this particular grammar: A -> Cd B -> Ce C -> A | B | f Whatever I try I end up in loops or with a grammar that is still indirect left recursive. What are the steps to properly implement this algorithm on this grammar? 回答1: Rule is that you first establish some kind of order for non-terminals, and then find all paths where indirect recursion happens. In this case order would be

Finding a grammar is not LL(1) without using classical methods and transforming it to LL(1)

故事扮演 提交于 2019-12-31 06:04:47
问题 Let's say i have this grammar: S -> A C x | u B A A -> z A y | S u | ε B -> C x | y B u C -> B w B | w A This grammar is obviously not LL(1), which i can find constructing the parsing table. But is there any way i can prove that this grammar is not LL(1) without using the classical methods i.e. without constructing the parsing table or finding any conflicts? Also how can i convert this grammar to LL(1)? I think i have to use both epsilon-derivation elimination and left recursion elimination

Finding a grammar is not LL(1) without using classical methods and transforming it to LL(1)

时光总嘲笑我的痴心妄想 提交于 2019-12-31 06:04:06
问题 Let's say i have this grammar: S -> A C x | u B A A -> z A y | S u | ε B -> C x | y B u C -> B w B | w A This grammar is obviously not LL(1), which i can find constructing the parsing table. But is there any way i can prove that this grammar is not LL(1) without using the classical methods i.e. without constructing the parsing table or finding any conflicts? Also how can i convert this grammar to LL(1)? I think i have to use both epsilon-derivation elimination and left recursion elimination

Closure properties of context free languages

一个人想着一个人 提交于 2019-12-31 04:15:39
问题 I have the following problem: Languages L1 = {a^n * b^n : n>=0} and L2 = {b^n * a^n : n>=0} are context free languages so they are closed under the L1L2 so L={a^n * b^2n A^n : n>=0} must be context free too because it is generated by a closure property. I have to prove if this is true or not. So I checked the L language and I don’t think that it is context free then I also saw that L2 is just L1 reversed. Do I have to check if L1, L2 are deterministic? 回答1: L1={a n b n : n>=0} and L2={b n a n

Examples of Non Context free language in C language?

拟墨画扇 提交于 2019-12-30 12:12:40
问题 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: The question is clumsily worded, so I'm reading between the lines, here. Still, it's a common homework/study question. The various ambiguities [1] in the C grammar as normally presented do not render the language non-context-free. (Indeed, they don't even render the grammars non-context-free.) The general rule "if

Difference between an LL and Recursive Descent parser?

隐身守侯 提交于 2019-12-29 10:07:12
问题 I've recently being trying to teach myself how parsers (for languages/context-free grammars) work, and most of it seems to be making sense, except for one thing. I'm focusing my attention in particular on LL(k) grammars , for which the two main algorithms seem to be the LL parser (using stack/parse table) and the Recursive Descent parser (simply using recursion). As far as I can see, the recursive descent algorithm works on all LL(k) grammars and possibly more, whereas an LL parser works on

Is C++ context-free or context-sensitive?

[亡魂溺海] 提交于 2019-12-28 03:05:29
问题 I often hear claims that C++ is a context-sensitive language. Take the following example: a b(c); Is this a variable definition or a function declaration? That depends on the meaning of the symbol c . If c is a variable , then a b(c); defines a variable named b of type a . It is directly initialized with c . But if c is a type , then a b(c); declares a function named b that takes a c and returns an a . If you look up the definition of context-free languages, it will basically tell you that

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

How to Generate and display ParseTree for an expression in C# using Irony?

时光毁灭记忆、已成空白 提交于 2019-12-25 04:13:57
问题 I want to generate and display context free grammar using irony and so far I am able to write the context free grammar by following code public ExpressionGrammar() { //// 1. Terminals Terminal number = new NumberLiteral("number"); Terminal identifier = new IdentifierTerminal("identifier"); //// 2. Non-terminals NonTerminal Stmt = new NonTerminal("Stmt"); NonTerminal Dec = new NonTerminal("Dec"); NonTerminal Datattype = new NonTerminal("Datatype"); NonTerminal Def = new NonTerminal("Def");