context-free-grammar

Regular vs Context Free Grammars

假如想象 提交于 2019-11-27 05:52:37
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 that regular grammar nonterminals can map to a terminal or a nonterminal followed by a terminal or that

What is a Context Free Grammar?

左心房为你撑大大i 提交于 2019-11-27 04:59:06
问题 Can someone explain to me what a context free grammar is? After looking at the Wikipedia entry and then the Wikipedia entry on formal grammar, I am left utterly and totally befuddled. Would someone be so kind as to explain what these things are? I am wondering this because I wish to investigate parsing, and also on the side, the limitation of a regex engine. I'm not sure if these terms are directly programming related, or if they are related more to linguistics in general. If that is the case

What is the language of this deterministic finite automata?

时光怂恿深爱的人放手 提交于 2019-11-27 04:55:33
Given: I have no idea what the accepted language is. From looking at it you can get several end results: 1.) bb 2.) ab(a,b) 3.) bbab(a, b) 4.) bbaaa Grijesh Chauhan How to write regular expression for a DFA In any automata, the purpose of state is like memory element. A state stores some information in automate like ON-OFF fan switch. A Deterministic-Finite-Automata(DFA) called finite automata because finite amount of memory present in the form of states. For any Regular Language(RL) a DFA is always possible. Let's see what information stored in the DFA (refer my colorful figure). ( note: In

What are [Yield, Await, In, Return] in EcmaScript grammar

北战南征 提交于 2019-11-27 04:52:46
问题 Many productions in EcmaScript are given with the following "modifiers": [Yield, Await, In, Return] Here are a few examples: ArrayLiteral[Yield, Await]: ... ElementList[Yield, Await]: ... AssignmentExpression[+In, ?Yield, ?Await] I've searched through the spec for the explanation, specifically Grammar Notation section, but can't find it. It should be there. Can someone please point me to the relevant paragraph and maybe provide a short explanation? 回答1: Section 5.1.5: Grammar Notation - A

Tips for creating “Context Free Grammar”

荒凉一梦 提交于 2019-11-27 00:29:01
I am new to CFG's, Can someone give me tips in creating CFG that generates some language For example L = {a m b n | m >= n} What I got is: S o -> a | aS o | aS 1 | e S 1 -> b | bS 1 | e but I think this area is wrong, because there is a chance that the number of b 's can be greater than a 's. Grijesh Chauhan How to write CFG with example a m b n L = {a m b n | m >= n}. Language description: a m b n consist of a followed by b where number of a are equal or more then number of b . some example strings: {^, a, aa, aab, aabb, aaaab, ab......} So there is always one a for one b but extra a are

What programming languages are context-free?

有些话、适合烂在心里 提交于 2019-11-27 00:01:36
问题 Or, to be a little more precise: which programming languages are defined by a context-free grammar? From what I gather C++ is not context-free due to things like macros and templates. My gut tells me that functional languages might be context free, but I don't have any hard data to back that up with. Extra rep for concise examples :-) 回答1: The set of programs that are syntactically correct is context-free for almost all languages. The set of programs that compile is not context-free for

Why the need for terminals? Is my solution sufficient enough?

自闭症网瘾萝莉.ら 提交于 2019-11-26 18:37:21
问题 I'm trying to get my head around context free grammars and I think I'm close. What is baffling me is this one question (I'm doing practise questions as I have an exam in a month's time): I've come up with this language but I believe it's wrong. S --> aSb | A | B A --> aA | Σ B --> bB | Σ Apparently this is the correct solution: S --> aSb | aA | bB A --> aA | Σ B --> bB | Σ What I don't quite understand is why we have S --> aSb | aA | bB and not just S --> aSb | A | B . What is the need for

Unambiguous grammar for exponentiation operation

非 Y 不嫁゛ 提交于 2019-11-26 17:17:47
问题 E -> E+T | E-T | T T -> T*F | T/F | F F -> i | (E) How can I modify this grammar to allow an exponentiation operation ^ so that I can write i+i^i*i ? Since we know that order of operations is higher for ^ then all I know is that I must make it right associative. 回答1: In EBNF (Extended Backus-Naur Form), this could look as follows: expr -> term [ ('+' | '-') term ]* term -> factor [ ('*' | '/') factor ]* factor -> base [ '^' exponent ]* base -> '(' expr ')' | identifier | number exponent -> '(

What is the language of this deterministic finite automata?

戏子无情 提交于 2019-11-26 11:25:32
问题 Given: I have no idea what the accepted language is. From looking at it you can get several end results: 1.) bb 2.) ab(a,b) 3.) bbab(a, b) 4.) bbaaa 回答1: How to write regular expression for a DFA In any automata, the purpose of state is like memory element. A state stores some information in automate like ON-OFF fan switch. A Deterministic-Finite-Automata(DFA) called finite automata because finite amount of memory present in the form of states. For any Regular Language(RL) a DFA is always

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

大憨熊 提交于 2019-11-26 01:45:58
问题 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