# Tag Info

Accepted

### What would you get if you add parameters to context free grammars?

Affix grammars (parameterised context-free grammars) were studied extensively by the eminent Dutch computer scientist Cornelis HA Koster, starting with his 1962 paper "Basic English, a generative ...
• 12.1k

### What was Robert Floyd's algorithm for inserting brackets?

The seminal paper referred to is "Syntactic Analysis and Operator Precedence" (1963), which describes the operator precedence algorithm still used by many simple expression parsers today. ...
• 12.1k

### Correct name for a recursive descent parser that uses loops to handle left recursion?

It is just an LL(1) parser implemented with recursive descent. Starts with: ...
• 3,099

### Representing "but not" in formal grammar

For context-free grammars (I guess your question concerns this type of formal grammars), it would be not only painful, but also impossible in general. Suppose we have an algorithm that provides such "...
• 717

### any hope for a universal automatic parser?

You might be interested in learning about grammar induction: given a set of examples of strings from a context-free language, there are algorithms to learn a context-free grammar that generates those ...
• 164k
Accepted

### What is an IELR(1)-parser?

The IELR(1) Parsing Algorithm The IELR(1) parsing algorithm was developed in 2008 by Joel E. Denny as part of his Ph.D. research under the supervision of Brian A. Malloy at Clemson University. The ...

### Representing "but not" in formal grammar

In the case of regular languages (and in your examples, we're just talking about character classes, which are an especially simple form of regular language), they are closed under set difference. Not ...
• 23.1k

### How to find unambiguous grammar for palindromes

First, I believe you are looking for a different word than 'unambiguous'. A grammar is ambiguous if some string in its language has two or more derivations; I'm sure that a palindromic string must ...
• 81

### Representing "but not" in formal grammar

The particular grammar formalism used in the grammar you cite is defined in Appendix A of that document, which includes in section A.3, a precise definition: A grammar production may specify that ...
• 12.1k

### Check for balanced parentheses in an expression in log-space

The Dyck language on any fixed number of symbols can be recognised by a marking automaton, which is a two-way finite automaton that can mark a fixed number of input tape squares. The automaton simply ...
• 3,492
Accepted

### Is there a different resolution of the "dangling else" problem other than "match closest"?

This problem is an exact analogue of the problem of matching parentheses in an expression in which some of the close parentheses have been omitted. Here an "if" (or $a$ in the representative grammar) ...
• 12.1k
Accepted

### Finding the number of distinct strings in regular expression

In your example, think of the result as having filled four slots: _ _ _ _, each of which can take one or three substrings, namely 0, 1, or the empty string. Ignoring the empty strings, it's clear that ...
• 14.9k

### What would you get if you add parameters to context free grammars?

Take the pumping lemma for CFGs: Take the grammar S -> A("") A(p) -> p | p '\n' A(p"*") '\n' p This describes a star triangle: ...
• 4,646

### What is a "sentential form"?

Assuming you know what leftmost and rightmost derivations are, let $S \Rightarrow^*W_1W_2\dots W_m$ be a derivation (a sequence of replacement using derivation rules), where $W_i$ is a terminal or ...
• 9,877
Accepted

• 278k
Accepted

### How to find First in a left recursive grammar?

Here is how to apply the production rule $A\to AX$ to compute $\text{first}(A)$. When $\epsilon\in\text{first}(A)$, add all (non-$\epsilon$) members of $\text{first}(X)$ to $A$. More generally, ...
• 39.1k

### What would a formal grammar for a binary file format look like?

The Chomsky hierarchy is a hierarchy of grammars described by a given formalism. The other grammar descriptions that you are giving (attribute grammars, ...) are not part of that formalism so they ...
• 3,099

### Is the word problem of CFLs in NC?

The problem is not in NC unless P=NC. Jones and Laaser showed in "Complete Problems for Deterministic Polynomial Time" that the problem (therein called CFMEMBER) is P-complete. Interestingly, Ullman ...
• 41

### How to prove that Ambiguity is still present in Resolved Production of Dangling Else Problem?

A grammar $G$ for a language $L$ is ambiguous if there is a string $w \in L$ which has two different parse trees (with respect to $G$). Hence in order to show that ambiguity is still present, all you ...
• 278k
Accepted

### Eliminating cycles from a grammar

An algorithm to specifically remove cycles can be adapted from the more general algorithm to reduce a grammar to its Chomsky normal form. Specifically, it is the elimination of unit productions, ...
• 151
Accepted

### Tokenization Problem

Tokenisation does not search. [Note 1]. At each step, it matches (and consumes) a match of one of the patterns starting precisely at the current input point. Although there are other tokenisation ...
• 12.1k

### Is there a way to efficiently parse this grammar?

The grammar is ambiguous: (I used | for a and * for b ...
• 12.1k
Accepted

### Why doesn't the C/C++ compilers create different tokens for different types of numbers?

This is in fact an implementation detail of the compiler. The page you referenced only shows one way of assigning types to tokens, while there are also others. The compiler could have a lexer that ...
• 2,797
Accepted

### Are there any context-free languages that are not known to be in $\mathrm{DTIME}(O(n))$?

Theorem 1 in "If the Current Clique Algorithms are Optimal, so is Valiant’s Parser" shows an explicit context-free grammar $G$ such that if $G$ can be parsed in linear time (or even a bit slower), ...
• 3,501