So I split the problem into 2 sub problems The number of a's is different from the number of b's. Therefore the a's and c's or b's and c's can be the same. The number of b's is different from the number of c's. Therefore the a's and b's or...

parsing,grammar,context-free-grammar

The set of context-free languages is closed under the operation of string reversal, which is a mathematical way of saying that if you have a context-free language, then the language which consists of the same strings backwards is also context-free. The proof is simple, and is based precisely on the...

parsing,grammar,context-free-grammar,lexical-analysis

Assuming that your lexer continues to be stateful, so that a single HTML token will be emitted for the text between END and BEGIN, there is little difference in the grammar. Aside from the first and last HTML token, every other HTML token will be preceded by END and followed...

recursion,context-free-grammar,ebnf,livescript

The grammar fragment you posted is already left-recursive, i.e. without even adding (+|-)boolprop, the non-terminal 'Expression' derives a form in which 'Expression' reappears as the leftmost symbol: Expression -> PropDefExpression -> Expression COLON Expression And it's not just left-recursive, it's ambiguous. E.g. Expression COLON Expression COLON Expression can be derived...

parsing,grammar,sml,yacc,context-free-grammar

Index has an empty production. Now consider: Exp : ID | ID Index Which of those applies? Since Index is allowed to be empty, there is no context in which only one of those is applicable. The parser generator you are using evidently prefers to reduce an empty INDEX, making...

compiler-construction,abstract-syntax-tree,context-free-grammar,semantic-analysis

This set of rules describes an attributed grammar, a scheme for computing attributes for a tree. Such schemes are almost always purely functional (no side effects). It is computing attributes at each rule/tree node, named X.Y in the notation they are using, where X stands for the rule/tree (e.g S...

Determining whether two CFGs are equivalent is an undecidable problem, so in general there is no good way to assert the equality of two CFGs.

python,nltk,semantics,context-free-grammar

There is no subject or VP in the relevant structure. Try writing a rule for and when used to conjoin sentences. What is it? Sentence1 and Sentence2 gets the interpretation <Sentence1> & <Sentence2> I.e., take the meanings of the two sentences and conjoin them with &. In the notation of...

parsing,antlr,grammar,context-free-grammar

The answer depends primarily on the tool you are using, and what the semantics of that tool is. As written, this is not a context-free grammar in canonical form, and you'd need to produce that to get a theoretical answer, because only in that way can you clarify the intended...

parsing,antlr,grammar,antlr4,context-free-grammar

Your local variable i is starting off uninitialized (at 0) instead of 1 because of a bug introduced in ANTLR 4.3. The bug is described in more detail at https://github.com/antlr/antlr4/issues/672....

A Context Free Grammar would be: G = ({S,T},{a,b,2,},S,P) P: S-> aSa | aSb | bSa | bSb | T T-> aT | bT | 2 ...

parsing,mediawiki,grammar,context-free-grammar

"Context-sensitive" has a precise formal definition, and it does not appear to match your intuition. The grammar S -> P | E P -> '(' T '.' ')' E -> '[' T '!' ']' T -> <any context-free grammar fragment> is context free (even regular, if T is regular), despite...

context-free-grammar,automata,automata-theory

Checking whether a grammar is ambiguous or not is an Undecidable problem, which means that there exists no algorithm which will correctly output Yes/No to this problem every time. The undecidablity is shown by showing that it is equivalen to Post Correspondence Problem, which is also undecidable....

grammar,context-free-grammar,ll,regexp-grammars

I don't see how then could be in FOLLOW(X). I get the same answer as you do. The only thing that can precede then in that grammar is an E and E cannot end with L. Furthermore, FOLLOW(E) includes do as well as then, so if a followset includes FOLLOW(E)...

parsing,python-3.x,context-free-grammar,ply,python-plyplus

PlyPlus is an implementation of PLY, where L and Y stand for Lex and Yacc, so it is — for better of worse, probably worse — an LR parser, which works strictly bottom-up. This also means 'tab' cannot be parsed as TAB (or _ANON_X, or whatever names it generates for...

c++,parsing,context-free-grammar

What you want is a tool that can parse substrings of a language (in your case, Oracle SQL). Most of the parser generators out there only address the problem of parsing complete language instances (e.g, the "goal" rule). With some genius and sweat, you might bend some generators to process...

python,nlp,nltk,context-free-grammar

In short: yes it is possible but you will get through a heck of pain, it's easier to rewrite your CFG using the atis.cfg as a base then read the new CFG textfile. It's easier than to reassign each new terminal to the correct non-terminal to map them In long,...

regex,context-free-grammar,regular-language,context-free-language

No, it is not regular. Consider that the language of balanced parenthesis alone is not even regular. The proof by contradiction using the pumping lemma for the language of balanced parenthesis also works for the language of regular expressions. It is Context Free though, and it is very easy to...

python,nlp,nltk,stanford-nlp,context-free-grammar

nltk.Tree is actually a subclass of the Python list, so you can access the children of any node c by c[0], c[1], c[2], etc. Note that NLTK trees are not explicitly binary by design, so your notion of "left" and "right" might have to be enforced somewhere in a contract....

parsing,compiler-construction,context-free-grammar,ll

The original grammar was ambiguous, so it is not surprising that the new grammar is also ambiguous. Consider the string a b a b a. We can derive this in two ways from the original grammar: A ⇒ A b A ⇒ A b a ⇒ A b A b...

grammar,context-free-grammar,bnf

Nope, just look at the parse trees produced by textbook grammar vs. suggested grammar (code). Note: parse trees represent derivations.

grammar,context-free-grammar,bnf,ebnf,ambiguous-grammar

Your comment says you want equal numbers of a and c, so start with the simple grammar that does that: S -> aSc | ε and add in any number of b's before/after/between those: S -> BaScB | B B -> Bb | ε note that the above is not...

context-free-grammar,left-recursion,chomsky-normal-form

Yes, CNF allows any form of recursion.

java,grammar,context-free-grammar,lexical

A more expansive definition of "syntax" would be the set of all ordered combinations of symbols which form a correct document, in the given language. Thus, "syntactic grammar" can be summarily described as the portion of the language's grammar that describes how various tokens can be ordered, to form meaningful...

context-free-grammar,automata,context-free-language

Some hints: Start with a grammar for { anbn | n in N }. The grammar you built in part (1) probably worked by laying down a's on one side of the string and b's on the other. That way, there end up being the same number of a's and...

Looks like you slept through the class on Backus–Naur Form. The first example has two rules. The first: < S > ::= $ | < W > | $< S > Says that <S> is either a dollar symbol, a <W> or a dollar followed by a <S> The second:...

context-free-grammar,chomsky-normal-form

There is no step 2 for you. Step 2 is removing epsilon rules, and you have no epsilon rules. You don't have a step 3 either, because B->c has a terminal - not a nonterminal - on its right hand side. There are no unit rules of the form: Terminal...

programming-languages,grammar,context-free-grammar,language-theory

You can prove that it is ambiguous by finding a string with two parses :) In this case, try !id&&id. Is that (!id)&&id or !(id&&id)...

context-free-grammar,context-free-language

An Answer: S->(T)|(;)|() T->(T)|T;T|()|(;) ...

grammar,context-free-grammar,ambiguous-grammar

Given your grammar, it is clearly ambiguous. Here, it doesn't define the preference between + and * operator. As you said, if you have to parse this 0110 + 110 * 01111, it can be done using two ways :- 0110 + 110 * 01111 ----> (0110 + 110) *...

context-free-grammar,pushdown-automaton,context-free-language

Using intuition is a valuable technique. As you solve more such problems, your intuitions sharpen, so it gets easier. There's no formal technique to convert a description of a language into a CFG (unless the description is something which maps onto CFGs, of course, like a set of production rules)....

python,nlp,nltk,context-free-grammar

This is the normal form for nouns: N[NUM=sg, SEM=<\x.race(x)>] -> 'race' So, for example, you might have: Det[NUM=sg, SEM=<\P.\Q.exists x.(P(x) & Q(x))>] -> 'a' NP[NUM=?num, SEM=<?det(?n)>] -> Det[NUM=?num, SEM=?det] N[NUM=?num, SEM=?n] So that "a race" is: \P.\Q.exists x.(P(x) & Q(x))(\x.race(x)) = \Q.exists x.(\y.race(y)(x) & Q(x))) \Q.exists x.(race(x) & Q(x))) And...

bison,yacc,context-free-grammar

Use the -v option to bison, which will generate a .output file with information on all the states and conflicts. With you grammar, this gives conflicts in states 16 and 30. State 16 is: state 16 15 arraylist: arrayseg . 16 | arrayseg . Comma arraylist Comma shift, and go...

python,lambda,nltk,context-free-grammar

Short answer: You have to write your own semantic grammar. There is just no easy way to map a CFG to lambda-calculus. Longer answer: From CFG, the closest you get to a semantic tree is to specify semantic features for non-terminals and the SQL CFG example is a good guide...

algorithm,parsing,context-free-grammar,recursive-descent

It's a problem in the sense that if you write a PEG grammar like that, it will not work. That is a known problem, occasionally described as a problem with PEG parsing, but I don't find it fair to blame PEG for people writing grammars that it can't handle -...

algorithm,optimization,context-free-grammar

We can use dynamic programming here. The state is (l, r) - a [l, r] substring of the given string. The value of the state is the maximum number of matching symbols within the substring. The base case is trivial: for all substrings shorter than 2, the answer 0. For...

semantics,context-free-grammar,syntactic-sugar

The grammar is the "comprehensive mathematical formula". :) However, in the current case, it is easy to give an alternate description. Your grammar will generate strings of the form a^nb^m where s^i stands for "repeat the substring s i times", and 2n <= m <= 3n n can also be...

compiler-construction,context-free-grammar

Your grammar definition is not correct. For example, the string 011 clearly satisfies the given property, however, it cannot be recognised by your grammar. Also, your grammar recognises strings like 001, which clearly does not satisfy the given property as the first 0 is followed immediately by a 0 instead...

context-free-grammar,formal-languages,context-free-language

For languages with a "not-equal" restriction, the easiest approach is usually to first find a grammar that corresponds to the language with an "equal" restriction instead, and then change it to require more of one of the things. In this case we have a number of a tokens followed by...

python,nlp,nltk,context-free-grammar

The error comes from how NLTK implements types lambda calculus. \x.x(\y.some(y)) It expects lowercase letters to have type <e> and uppercase letters to have type <e,t>. That is to say that lowercase letters cannot represent predicates. The following parses: \X.X(\y.some(y)) As an aside, one represents the concept of "some" in...

javascript,context-free-grammar,formal-languages

No, JavaScript is not a context-free language. It is very close to one, and the ECMAScript 5 specification does indeed use a context-free grammar1 to describe the language's syntax (you can find all productions in Annex A). Of course, it does make some extensions to pure context-free grammatical productions, and...

Several rules/productions are missed in your specification. Try this one: %{ #include <stdio.h> #include <string.h> int yydebug = 0; %} %token NUMBER ST STR COURSE ASN MT ID %% program : program stmt | stmt ; stmt : func | coursedef | student_info ; coursedef : COURSE ':' '{' st_list...

grammar,context-free-grammar,language-theory

This thread says: XML is a language defined by SGML, which is a restricted form of context free grammar (essentially a Dyck language with many types of parentesis) ...

context-free-grammar,automaton,pushdown-automaton

The set of context-free languages (or PDAs) is not closed under complementation. (There's a simple demonstration in the answer to What is the context free grammar for the complement of the double word over 0,1?, which constructs a CFG for the complement of {ww|w∈{0,1}*}. The fact that {ww|w∈{0,1}*} is not...

parsing,compiler-construction,grammar,context-free-grammar,ambiguous-grammar

The original grammar is ambiguous because multiple right-most (or left-most) derivations are possible for any string of at least three letters. For example: S -> SS -> SSS -> SSa -> Saa -> aaa S -> SS -> Sa -> SSa -> Saa -> aaa The first one corresponds, roughly...