context-free-grammar

Context-free grammars versus context-sensitive grammars?

大憨熊 提交于 2019-11-28 13:32:19
问题 Can someone explain to me why grammars [context-free grammar and context-sensitive grammar] of this kind accepts a String? What I know is Context-free grammar is a formal grammar in which every production(rewrite) rule is a form of V→w Where V is a single nonterminal symbol and w is a string of terminals and/or non-terminals. w can be empty Context-sensitive grammar is a formal grammar in which left-hand sides and right hand sides of any production (rewrite) rules may be surrounded by a

What programming languages are context-free?

旧时模样 提交于 2019-11-28 03:22:53
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 :-) 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 almost all languages. For example, if the set of all compiling C programs were context free, then by intersecting

What is a Context Free Grammar?

大兔子大兔子 提交于 2019-11-28 02:49:48
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, I apologize, perhaps this could be moved if so? aegrisomnia A context free grammar is a grammar which

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

本秂侑毒 提交于 2019-11-28 02:20:19
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? Section 5.1.5: Grammar Notation - A production may be parameterized by a subscripted annotation of the form “[parameters]”, which may appear as a

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

巧了我就是萌 提交于 2019-11-27 16:20:03
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 the terminals? Can't I just call A instead and grab my terminals that way? Testing to see if I can

Unambiguous grammar for exponentiation operation

寵の児 提交于 2019-11-27 15:45:02
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. 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 -> '(' expr ')' | identifier | number (taken from here ) Translated to your notation (no distinction between

Is there a fast algorithm to determine the godel number of a term of a context free language?

↘锁芯ラ 提交于 2019-11-27 13:11:24
问题 Suppose we have a simple grammar specification. There is a way to enumerate terms of that grammar that guarantees that any finite term will have a finite position, by iterating it diagonally. For example, for the following grammar: S ::= add add ::= mul | add + mul mul ::= term | mul * term term ::= number | ( S ) number ::= digit | digit number digit ::= 0 | 1 | ... | 9 You can enumerate terms like that: 0 1 0+0 0*0 0+1 (0) 1+0 0*1 0+0*0 00 ... etc My question is: is there a way to do the

How to find FIRST and FOLLOW sets of a recursive grammar?

♀尐吖头ヾ 提交于 2019-11-27 11:00:49
问题 Suppose I have the following CFG. A -> B | Cx | EPSILON B -> C | yA C -> B | w | z Now if I try to find FIRST(C) = FIRST(B) U FIRST(w) U FIRST(z) = FIRST(C) U FIRST(yA) U {w, z} That is, I'm going in a loop. Thus I assume I have to convert it into a form which has immediate left recursion, which I can do as follows. A -> B | Cx | EPSILON B -> C | yA C -> C | yA | w | z Now if I try to calculate FIRST sets, I think I can get it done as follows. FIRST(C) = FIRST(C) U FIRST(yA) U FIRST(w) U

Is there a standard C++ grammar?

左心房为你撑大大i 提交于 2019-11-27 10:00:39
问题 Does the standard specify the official C++ grammar? I searched, but did not find it anywhere. Also, I wish to read a bit about C++ grammar in detail, like which category of grammars it falls in, etc. Any links pointing me in the right direction would be helpful. By category, I mean taken from here. 回答1: Yes, it does. The grammar is described in detail throughout the standard and is summarized in Appendix A: Grammar Summary (it's Appendix A in both the C++03 standard and the C++0x final

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

为君一笑 提交于 2019-11-27 09:24:35
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 all grammar rules must have left-hand sides that consist of exactly one non-terminal symbol. Context