Grammar is LL(1) or not?

S -> AS | b

A -> SA | a

I get FIRST of S = {a,b} for S->AS and FIRST of S = {b} for S->b

Hence FIRST(AS) ∩ FIRST (b) is not a disjoint This is not LL(1)

But I checked this site http://smlweb.cpsc.ucalgary.ca/start.html and this shows the grammar is LL(1). Here I am confused!

Is it LL(1) or not?

Grammar for language L on {a, b} where L = {w|na(w)mod 3 = 0}

I am able to form the regular expression but I am not confident with the grammar. I have tried the following:

S–>aaaS|bS|b|lambda

Zulfi.

Context-free Grammar Exercise

Could someone explain me how to form a context-free grammar with all rules R by this example language, please? $$$$L:=\left\{w c v c \overleftarrow{w} | w, v \in\{a, b\}^{+}\right\}$$$$

I already know that $$$$\Sigma=\{a, b, c\}$$$$ and V (non terminal symbols) maybe have to be $$$$V=\{S, A, B, C\}$$$$

Thank you for helping.

How to convert the left recursive grmmar into right recursive grammar

I got a grammar: A->Aa|bB|c

The above is the left recursive grammar. I understand that I have to remove the string “Aa” from the above grammar or to convert it into the form “aA” to avoid left recursive.

Some body please guide me how to do that.

Zulfi.

Regular expression and Right Regular grammar for decimals starting with 1 ending with 9?

I was trying to do the following:

Consider the set of all strings over the alphabet { 0,1,2,9,.}{ 0,1,2,9,.} that are decimal numbers beginning with 1 and ending with 9 and having exactly one decimal point (..). For example 12.912.9, would be a valid decimal number while 0.1290.129 would be not since it does not begin with 11.

but it didn’t seem to work:

1(0|1|2|9)*.(0|1|2|9)*9 

or

S::=1X X::=E|0X|1X|2X|9X|Y Y::=.Z Z::=E|0Z|1Z|2Z|9Z|A A::=9 

Finding a Context- free grammar (CFG) for the language [duplicate]

• How to prove that a language is context-free? 2 answers
• How to convert PDA to CFG 2 answers

I am trying to find a CFG for the language A below. I have spent hours on this but still could not find the answer. I also came up with the idea that this may not a context- free language but there is actually a PDA that recognizes it. I would very much appreciate if anyone can help me with this.

                    A= {0^a 1^b 0^c 1^d | a+b < c+d, a,b,c,d>=1} 

How do I call a system like a grammar, but where a rule has to be applied to all matches at once?

For example, given rules $$\{ a \to x, a \to y \}$$ and input $$aa$$ , I am usually allowed to derive strings $$\{ xx, xy, yx, yy \}$$. I would like to restrict this to only performing “consistent” rewrites, so that the language would be like $$\{ xx, yy \}$$. It is evidently possible to synchronize rewrites in distant parts of a sentence within the usual formal grammar setting, but I wonder if this possibility is better explored under a different name or in a different arrangement.

I notice that context-sensitive grammars pose trouble with this “consistency” condition. For example, given a ruleset $$\{ aa \to x\}$$ and initial string $$aaa$$, I am not sure if I should allow anything to be derived. Then again, it is entirely possible that only some rules, and specifically some context-free rules, may be enhanced with consistency.

I am rather sure the system I have in mind defines a language, and even that I could with some thinking propose a formal way to rewrite a given grammar so that some select context free rules are made consistent. But I wonder if this is actually widely known under some other name.

Context Free Grammar – Starting with x Number of Chars and Ending with n != x Number of Chars

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of A‘s and is followed by a non-empty sequence of B‘s. With the special condition that the number of B‘s has to be unequal to the number of A‘s.

Thus, the grammar should generate words like:

• AAAABBB
• AAABB
• ABBB

So basically I could do something like this:

$$\ G=(N,T,P,Sequence)$$

$$\ N = \{Sequence\}$$

$$\ T = \{A,B\}$$

$$\ P = \{Sequence=AA(Sequence|\epsilon)B\}$$

But then the words would always have $$\ 2n$$ A‘s and n B‘s:

• AAB
• AAAABB
• AAAAAABBB

So how is it possible to make the number of A‘s uncorrelated of the number of B‘s, without being equal?

How do I calculate the Nth result of a context-free grammar?

Given a context-free grammar and a maximum depth, how do I directly find the Nth result without calculating or caching intermediary results?

How to intuitively come up with an example for an ambiguous grammar and how to make that grammar unambiguous?

I don’t get how to intuitively come up with an example for an ambiguous grammar.

Let’s take as an example this grammar:

Declaration ::= Type D ;          Type ::= "int" | "char"          D ::= "*" D             |  D "[" number "]"             |  D "(" Type ")"             |  "(" D ")"             |  name 

I am told outright that this grammar is ambiguous. What is expected of me is to find one example that proves that it is. What I’m interested is what is the thought process that allows you to find an example. Our teacher just gave us one example that would show that we would obtain two different derivation tree like:

int *foo[5];  has two derivation tree              Declaration              Declaration              /    |   \               /    |   \            Type   D    ;            Type   D    ;             |    / \                 |    / \____            int  *   D               int  /   \ \ \                    / \____              D    [ 5 ]                   /   \ \ \            / \                  D    [ 5 ]           *   D                  |                        |                 foo                      foo  

However I have no idea how he thought to himself that int*foo[5] would be the example before doing the trees. It all boils down to how they did it without trial and error?

How to make that grammar unambiguous? I was also given the task to make the above grammar unambiguous. However I don’t know yet again what is the intuition behind making it unambiguous.

They gave us this solution:

 Declaration ::= Type D ;        Type ::= "int" | "char"        D ::= "*" D           |  "(" D ")" D'           |  name D'        D' ::= "[" number "]" D'            |  "(" Type ")" D'            |  empty               <== empty string  

There must be a pattern in all of this. What it is? What is the general method to solve this type of problem regardless of which grammar is given?