context-free-grammar

How to define a grammar for a programming language

女生的网名这么多〃 提交于 2019-12-20 08:41:24
问题 How to define a grammar (context-free) for a new programming language (imperative programming language) that you want to design from scratch. In other words: How do you proceed when you want to create a new programming language from scratch. 回答1: One step at a time. No seriously, start with expressions and operators, work upwards to statements, then to functions/classes etc. Keep a list of what punctuation is used for what. In parallel define syntax for referring to variables, arrays, hashes,

Left recursion elimination

送分小仙女□ 提交于 2019-12-20 04:13:18
问题 I'm attempting to eliminate left recursion from a CFG by eliminating indirect recursion then direct recursion as this algorithm shows. I'll be using this grammar: A = A a | A B C | B C | D D When i = 1 , and j = 1 we are looking at replacing all productions of the form A -> A r with: A -> δ 1 γ | δ 2 γ | .. | δ k γ So when I look at A -> A a which matches, i should replace it with A -> A a a | A B C a a | B C a | D D a which im sure is wrong Can anyone point me in the right direction for how

Combine free-form dictation and semantic in a srgs grammar

让人想犯罪 __ 提交于 2019-12-19 11:53:08
问题 I'm trying to combine both the result of a semantic and a dictation request in the semantic value of a SRGS document. For example, I would say "Search potato" and the output would be something like out="Search Potato" where Potato is a random word spoken by the user. I tought about using the garbage special rule, but it doesn't seem to work. So far that's what I have : <rule id="rule1" scope="public"> <one-of> <item xml:lang="en-us">Search</item> <item>Cherche</item> </one-of> <tag>out

What is the context free grammar for the complement of the double word over 0,1?

℡╲_俬逩灬. 提交于 2019-12-19 09:58:06
问题 What is the CFG of the complement of L={ww|w belongs to {0,1}*}? 回答1: First of all observe the fact that any odd word is part of the language. Let's define the following languages: L1={w1w|w{0,1}*}, L0={w0w|w{0,1}*}. These languages can be defined with the following CFG: S0/1 -> |0S0|1S1|0S1|1S0 Now look at L3: L3=(L1)U(L2)U(L1L2)U(L2L1) It is context free from closure to union and concatenation. Let's prove that L3 is the language we're looking for. First of all as we have seen it deals with

What do square brackets in Java method declarations mean?

放肆的年华 提交于 2019-12-19 03:45:14
问题 The grammar for method declarations in Java is something like the following: Java method declaration BNF: method_declaration ::= { modifier } type identifier "(" [ parameter_list ] ")" { "[" "]" } ( statement_block | ";" ) And I am wondering what do the square brackets mean. Can anyone give me an example? Is method declarations in Java looks like above (What about generics)? Where can I find complete and actual BNF grammar for Java? 回答1: The square brackets are to indicate the method returns

Extension to CFG, what is it?

限于喜欢 提交于 2019-12-19 02:22:19
问题 Consider the following extension to context-free grammars that permits rules to have in the left-hand side, one (or more) terminal on the right side of the non-terminal. That is, rules of the form: A b -> ... The right-hand side may be anything, like in context-free grammars. In particular, it is not required, that the right-hand side will have exactly the same terminal symbol at the end. In that case, this extension would be context-sensitive. But the terminal is not just a context.

Converting grammar to Chomsky Normal Form?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 15:19:01
问题 Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps. S -> AB | aB A -> aab|lambda B -> bbA Ok so the first thing I did was add a new start variable S0 so now I have S0 -> S S -> AB | aB A -> aab|lambda B -> bbA then I removed all of the lambda rules: S0 -> S S -> AB | aB | B A -> aab B -> bbA | bb Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong?

Converting grammar to Chomsky Normal Form?

时光毁灭记忆、已成空白 提交于 2019-12-18 15:18:37
问题 Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps. S -> AB | aB A -> aab|lambda B -> bbA Ok so the first thing I did was add a new start variable S0 so now I have S0 -> S S -> AB | aB A -> aab|lambda B -> bbA then I removed all of the lambda rules: S0 -> S S -> AB | aB | B A -> aab B -> bbA | bb Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong?

Construct grammar given the following language {a^n b^m | n,m = 0,1,2,…,n <= 2m} [closed]

一曲冷凌霜 提交于 2019-12-18 12:42:55
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I just took my midterm but couldn't answer this question. Can someone please give a couple of examples of the language and construct a grammar for the

Regular vs Context Free Grammars

丶灬走出姿态 提交于 2019-12-17 07:59:56
问题 I'm studying for my computing languages test, and there's one idea I'm having problems wrapping my head around. I understood that regular grammars are simpler and cannot contain ambiguity, but can't do a lot of tasks that are required for programming languages. I also understood that context-free grammars allow ambiguity, but allow for some things necessary for programming languages (like palindromes). What I'm having trouble with is understanding how I can derive all of the above by knowing